[will it work?] kinematic->moveGlobal... +joint+ContactPair

nargil

14-08-2009 01:34:16

1. What i need:
- move an equipment (sword) with a bone
- call a callback if hit something (static, kinematic, dynamic; well I could live without kinematic, but I need static)
- not move into objects

2. What I can't do
- use a kinematic sword actor, because there is no collision callback with non-dynamic actors

3. How i want to achieve it:
- create a small kinematic actor to put in characters hand
- create a dynamic sword actor with a contact callback
- attach them with a fixed joint
- move the sword by calling ->moveGlobal... for the kinematic actor

4. I'm not sure it will work:
- will moveGlobalPosition / Orientation stop moving if the dynamic actor hits something ? (guess not)
- will it create a smooth force on hiting a door ? *
- will the NX_NOTIFY_ON_START_TOUCH contact callback be called ? **

*as for now i use only a dynamic sword actor with NX_BF_DISABLE_GRAVITY | NX_AF_DISABLE_RESPONSE, and use SETglobal... which causes bad behavious if the sword hits a door, as there are unexpected collisions (the actors lands within another one)
** current solution sometimes lands in another object without calling START_TOUCH

nargil

14-08-2009 11:36:16

Ok, it does not work as I would expect it:
- the sword move has a delay!
- the sword is not always moved. Sometimes it just hangs in the air (pretty random I'd say)

Any ideas ?

edit: Ok it was my mistake - i forgot i set the update function back to set position instead of move position. Now I think it works ok with move. There is still a very small delay from what I can say, but it's ok for the collision. I'm goint to separate the graphics sword from physx sword, and attach it directly to the bone. Then it should be ok.

betajaen

14-08-2009 12:01:50

You could always mimic it to be kinematic but retain collision detection other behaviour of dynamic actors.

This is how I think kinematic actors work;

- Linear and angular moments are reset to zero every frame; stopping any further action from previous events.
- Gravity is ignored or counteracted; Stopping the actor falling to the ground.
- Linear and angular damping is increased; Increasing the stability of the actor.

To move to a specific position - a displacement force is calculated, then applied to the actor.

I'll see if I can come up with something in cake for you.

nargil

14-08-2009 12:10:38

Look at the edit, and don't bother anymore. Sorry for writing a post before I double or tripple check ;)

betajaen

14-08-2009 12:11:18

It's okay. I'm interested to see if it works or not.

Creating a kinematic actor with collisions would be quite useful for some people.

betajaen

14-08-2009 12:15:25

My first test;

class kactor : public NxOgre::Machine
{
public:

kactor(Shape* shape, float mass, const Vec3& position, OGRE3DRenderSystem* render_sys, Scene* scene)
: mScene(scene), mRenderSystem(render_sys)
{
NxOgre::RigidBodyDescription description;
description.mMass = mass;
description.mBodyFlags |= NxOgre::Enums::BodyFlags_DisableGravity;

mActor = mRenderSystem->createBody(shape, position, "cube.1m.mesh", description);

mScene->registerMachine(this);
}

~kactor()
{
mRenderSystem->destroyBody(mActor);
mScene->unregisterMachine(this);
}

void simulate(float user_deltatime)
{
mActor->setLinearMomentum(NxOgre::Vec3(0,0,0));
mActor->setAngularMomentum(NxOgre::Vec3(0,0,0));
}

NxOgre::Scene* mScene;
OGRE3DRenderSystem* mRenderSystem;
OGRE3DBody* mActor;
};


Works really well, and responds to the collisions of other actors. I haven't tried out forces, or to see if it will keep absolutely still. But I have noticed it falling asleep in the Visual Debugger - so PhysX must like it.

nargil

14-08-2009 12:33:26

Thats what I had earlier. The problem was to set smoothly the "kactor's" position and orientation to a desired pose. So i decided to attach it with a fixed joint to a kinematic actor.

Florin

09-09-2009 22:08:16

Hi,

I want to have a tennis racket which hits some tennis balls. I want to control the position and orientation of the racket.

I thought about disabling the gravity of an OGRE3DBody but doing like this: "OGRE3DBody mSphere->getNxActor()->raiseBodyFlag(NX_BF_DISABLE_GRAVITY);" ... I got this: ... "error C2027: use of undefined type 'NxActor'" which I don't really enjoy. Anyway I would need some tips on this one. Should I use kinematic actor ?

Many thanks !

betajaen

09-09-2009 22:14:16

If your going for accuracy. I wouldn't even use an Actor. Just do a scenenode/entity in Ogre, and to use an intersection to see if the racket hits the ball, then apply a force to simulate hitting it. A little complicated but you would get far accurate results than with hitting to Actors together.

Otherwise; Kinematic Actor would be fine. You could even use my KActor code above.

spakowski

26-10-2009 12:37:46

I perform the attachment of the Dynamic Actor to Kinematic Actor like this
m_AttachedBody->getNxActor()->clearBodyFlag ( NX_BF_KINEMATIC );
NxOgre::Scene* scene = hand->getScene();
NxOgre::FixedJointDescription desc;
m_AttachedBody->getNxActor()->raiseActorFlag( NX_AF_DISABLE_RESPONSE ); //if required
m_Joint = scene->createFixedJoint( m_HandBody, m_AttachedBody, desc );


Moving the hand body which is a kinematic actor will automatically move your attached object too.

if you want to re-enable response to the attached object you can call on the collision callback events and perform other operations on the body

m_AttachedBody->getNxActor()->clearActorFlag( NX_AF_DISABLE_RESPONSE );

Hope this works for you.