Skeletal animation in a physics world

mizio

16-05-2006 15:29:52

Hey,
I must move a mesh rotating the bones of an entity, after that the physics engine must to consider the "new" mesh.

I have write (this is only part of the code):

nxOgre::body *newBody;

newBody = mScene->createBody("ninja", "ninja.mesh", new nxOgre::meshShape("ninja.mesh",mScene), 80.0f, position);

playerEntity = mSceneMgr->getEntity("ninja");
playerSkeleton = playerEntity->getSkeleton();
playerSkeleton->load();

b1 = playerSkeleton->getBone("Joint1");
b1->setManuallyControlled(true);
b1->pitch(Degree(45));

With the above code, I can see the ninja modifyed but the physics engine work like if the ninja is not modifyed. :cry:

Who can help me?

P.S. Sorry for my English but I'am Italien and have to improve it

betajaen

16-05-2006 18:10:22

You could probably use capsules as the bones, then set them as "Kinetic" and then apply the orientation and position by hand. Once the Ninja has died you'll have to turn those bodies back to normal, create all the joints and turn over controller of the mesh to NxOgre so it becomes a ragdoll.

There is a very basic (but really buggy and crashes when used) Ragdoll class with NxOgre which can get you started.


And don't worry about your English, it's better than mine!

mizio

16-05-2006 18:30:01

Hello betajaen

If I create a "skeleton" with bones and joints, I can link it with a mesh for create a more detailed character?

If yes, how can I create the relationship between the bones? With the Ogre function?

I can obtain the vector of vertex of an entity? So I can create and destroy time after time a convexShape...

Thank's much

betajaen

16-05-2006 20:46:21

If I create a "skeleton" with bones and joints, I can link it with a mesh for create a more detailed character?

Yep.


If yes, how can I create the relationship between the bones? With the Ogre function?

You'd have to create your own function; to match the bone locations and orientation to the represented bones.

I can obtain the vector of vertex of an entity? So I can create and destroy time after time a convexShape...

Yep, but if you're thinking of using a convexShape to represent the player it won't work. To many vertices and it'd turn out as a nasty blob.

mizio

19-05-2006 15:48:34

Hey,
I have realized ha new "skeleton" with the cube and sphere in the physics world.

Now, how can I link the my "skeleton" with the mesh of the characters (the ninja for example), there is a function that link and transform the mesh follow the my skeleton movements? Note that my "skeleton" is not an istance of the skeleton class but more bones link with joints.

Thank's

betajaen

22-05-2006 14:56:33

There is no function for this, you'd have to write that code yourself. It should quite simple to do, but tweaking it and making it stable would be the hard part.

mizio

24-05-2006 17:56:44

Hey,
I have realized a function that with a skeleton like parameter build a "physics skeleton": a skeleton made with capsule and sphere that follow the physics world.
Now I have to realize another function that link the "physics skeleton" with the skeleton of ogre.

How can I create a capsule or a cube mesh in a parametric mode, for example when I create the capsule, for show it I must have a file .mesh, but at priori I don't know the exact dimension of evry bone of the skeleton, so I search a way for create a function like "createCube(xDim, yDim, zDim)"

Who can help me?

I have a video that show the "physics skeleton" of a simple human that I have created that fall down...do you like?
See it at http://spazioinwind.libero.it/conventi8 ... taUomo.wmv

betajaen

24-05-2006 23:13:33

You would want to look at the ragdoll prefab for that, I must warn you it does compile, but it crashes a lot.

But you can sneak a peek or two at OgreNewt which I believe has a working ragdoll class and take a snippet of code here and there. :D

It's all the same anyway.

mizio

25-05-2006 19:03:09

If I have 2 nodes that not are parent, but I want know te position and Orientation of a node respect the other (like if one is the child of the other), how can I do?
I have think

mNode1->getWorldPosition()-mNode2->getWorldPosition()

for obtain the relative position, and

mNode1->getWorldOrientatio()-mNode2->getWorldOrientation()

for obtain the relative rotation but don't function in the correct way

Who can help me?

mizio

26-05-2006 09:00:02

Hey,
I have Solved with the rotation matrixes:

Quaternion qO;
Matrix3 rotParent, rotChild, rotParentChild, transpose;

Quaternion qO = mNode1->getWorldOrientation();
rotParent.FromAxes(qO.xAxis(), qO.yAxis(), qO.zAxis());

qO = mNode2->getWorldOrientation();
rotChild.FromAxes(qO.xAxis(), qO.yAxis(), qO.zAxis());

transpose = rotParent.Transpose();
rotParentChild = transpose*rotChild;

For the position, what that I have write previously is correct

I hope can be useful

betajaen

26-05-2006 09:53:20

Oh excellent. Sounds like your on a roll. :D

mizio

26-05-2006 11:33:58

Hey,
How can I create a FixedJoint?

I have do:
mScene->createJoint(new nxOgre::revoluteJoint(parentBody,childBody,parentJointPosition,Ogre::Vector3(0,0,-1), true, new nxOgre::jointDescription(0, 0.000000001 * NxPi)));

the result is good but the the bodies shake, the cause is of the joint that I have used?

betajaen

26-05-2006 12:35:11

I haven't written the fixedJoint class yet, but you can create one manually through PhysX. The actors needed are "mActor" in the body class.

mizio

27-05-2006 11:11:55

I have solved; the problem wasn't the joint but the dimension of the joints and the "bones"...

I have link the physics skeleton with thw mesh...Now I have create a new video...see it at
http://spazioinwind.libero.it/conventi8 ... taUomo.wmv

and tell me if it can is realistic or not...the critics are useful

mizio

27-05-2006 17:18:21

Now, I want rotate a joint but I don't want set kinetic it, the joint must rotate and after that it must endure the gravity force...I think to write

joint->setKinematic(true);
joint->moveGlobalOrientationQuat(joint->getGlobalOrientation() *Quaternion(Degree(10),Vector3(1,0,0)));
joint->setKinematic(false);

but don't rotate...How can I do? betajaen help me

betajaen

27-05-2006 18:48:25

I don't think you're giving PhysX enough time to move it there do it. Perhaps moving the orientation in the next frame then setting it not kinematic afterwards, but give it a frame or two to react to it.