Set world rotation through local rotation

Programming Reality Factory and Genesis3D.
Post Reply
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Set world rotation through local rotation

Post by federico » Sat Sep 08, 2007 2:35 pm

Well, my mind is burning.... :shock:

Ragdolls are not so far, but I'm stuck:

- I can take the ragdoll and position his bodypart mirroring a pawn's bone rotation and position. In this way the ragdoll starting pose is the same of the animated actor.

- Then the ragdoll is ready to react and I can release it. The next step is to make the pawn's bone rotation and position follow the ragdoll bodyparts.

- There was a problem I was able to solve (yeah!): now I can move and rotate the actor mirroring the ragdoll root bodypart (that is the torso). So I have the pawn attached to the ragdoll torso, following it strictly in position and rotation

Now the hard part(!!!):

- I need to rotate the arms and legs but I can't assign an absolute rotation relative to the world axis. I can only set a local rotation relative to the actor vectors. This is a math problem.

Resumé:
- I get the worldaxis rotation of the bodyparts
- I attach the actor to the main bodypart (torso) rataing andd moving it. In this way I change the actor vector making it reflect the worldaxis rotation of the bodypart.
- I need to set the rotation of the bones assigning a local rotation

How can I get the local rotation data to assign on the bones????

User avatar
paradoxnj
RF2 Dev Team
Posts: 1328
Joined: Wed Mar 01, 2006 7:37 pm
Location: Brick, NJ
Contact:

Post by paradoxnj » Sat Sep 08, 2007 5:33 pm

Look at geQuaternion_ToMatrix(). Most physics libraries work with Quaternions as rotations.

User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico » Sun Sep 09, 2007 1:30 am

Thanks for the answer paradoxnj. I was hoping for your response.
You're right. using this command I can get the worldaxis rotation mixing the local rotation and the parent joint global rotation. In fact the geActor_GetBoneTrasform command is created in this way. though I don't want to Get the global rotation I want to Set the global rotation! :D
I would need a geQuaternion_Divide instead of the geQuaternion_Multiply command... but I don't have it and I have to admin I'm not able to create it with my current knowledge...

I repeat: if we are able to set the global rotation of a bone (relative to worldaxis) we have skinned ragdolls!

User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico » Sun Sep 09, 2007 1:42 am

Anyway I wouldn't use a quaternion (really I am weak on this topic) I would prefer use and XForm. My mental approach would be to take an Xform then orient it (Up left in) in the same way of the parent bodypart, then get the rotation of the child bodypart relative to that xform. But is it possible in this way? and how exactly....?

User avatar
paradoxnj
RF2 Dev Team
Posts: 1328
Joined: Wed Mar 01, 2006 7:37 pm
Location: Brick, NJ
Contact:

Post by paradoxnj » Sun Sep 09, 2007 8:34 pm

The problem with using XForms is you will get "gimbal lock". This is a flickering that happens because of the way matrices are calculated. Quaternions are immune to that. You don't need to multiply Quaternions to achieve your results. Do a google for Trilobite Shell. It's a Genesis game shell that was made for a Descent style game. It uses a Quaternion based camera and it has a good example of using quaternions for rotations.

User avatar
paradoxnj
RF2 Dev Team
Posts: 1328
Joined: Wed Mar 01, 2006 7:37 pm
Location: Brick, NJ
Contact:

Post by paradoxnj » Mon Sep 10, 2007 3:11 am

There doesn't seem to be a function in Genesis for that. The next best thing is to build your own actor rendering code around Tokamat's calcuations. This is fairly easy. I believe that the static meshes do this as they calculate their own lighting based on the world. Extract all the vertices and bones using the geBody API, create a Tokamat body (in ODE it's called a dBody) using the vertices and create joints using the bones. It's extra work, but you'll like the results much better.

User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico » Mon Sep 10, 2007 3:54 pm

This is fairly easy. I believe that the static meshes do this as they calculate their own lighting based on the world. Extract all the vertices and bones using the geBody API, create a Tokamat body (in ODE it's called a dBody) using the vertices and create joints using the bones. It's extra work, but you'll like the results much better.
You're probably right, but this is really over my capabilities...
I made some experiment adding some bone function to the g3d source try to passing the localrotation variable of the bone calculating a subtracting of the parentbone baserotation (using geQuaternion_Invert). The rotation is right quite all the time. Quite all the time is not always... so right now it's useless.

User avatar
paradoxnj
RF2 Dev Team
Posts: 1328
Joined: Wed Mar 01, 2006 7:37 pm
Location: Brick, NJ
Contact:

Post by paradoxnj » Mon Sep 10, 2007 6:45 pm

You probably can just use the static mesh rendering code in RF to accomplish this. Try not to mod the engine itself. It will become a dependency. Can you post your math code? I can take a look at it and maybe recommend something. You can contact me via AIM also.

User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico » Wed Sep 12, 2007 3:03 pm

I got it! I had to modify the genesis code, but I think that a function that sets a bone to an absolute rotation is useful.
Ragdolls are working now. I worked with a script prototype, so now I have to convert it in RF code for a physicsScript or pawnScript commands (something like RagdollTransformation). The ragdoll prototype could be tuned better (the balljoints are difficult to place), I need some more time to make some tests, but I will post a video tonight or tomorrow...

User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Post by Juutis » Wed Sep 12, 2007 3:23 pm

Excellent!!! Can't wait to see and hear more. I'm really excited about this. :D
Pain is only psychological.

User avatar
paradoxnj
RF2 Dev Team
Posts: 1328
Joined: Wed Mar 01, 2006 7:37 pm
Location: Brick, NJ
Contact:

Post by paradoxnj » Wed Sep 12, 2007 8:52 pm

Nice work federico!!

Post Reply