Jump to content
  • Advertisement
Sign in to follow this  
comfy chair

Turning head and spine

This topic is 2110 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What is the correct way to make a character turn his head and spine via code?

I use code like this to set a new transformation matrix on a bone:
 

bonePose.DefaultTransform = twist * Matrix.CreateTranslation(bonePose.DefaultTransform.Translation); 

I only want to affect rotation about one axis (yaw). But the problem with this code is that it only preserves the translation of the bone. It overwrites any pitch (head up/down) rotation.
 

To compensate, I try to re-create the original pitch rotation:
 

Vector3 rollAxis = new Vector3(0, 1, 0);//positive is dip right wing
Vector3 yawAxis = new Vector3(1, 0, 0);//positive is bearing left
Vector3 pitchAxis = new Vector3(0, 0, 1);//positive is dive

twist = Matrix.Identity; 
twist *= Matrix.CreateFromAxisAngle(yawAxis, boneAngle);                        
twist *= Matrix.CreateFromAxisAngle(pitchAxis, pitchForward);

 

But this distorts the character spine somewhat, because my approximation is not close enough to the original model pose.
Is there a better way?

Edited by comfy chair

Share this post


Link to post
Share on other sites
Advertisement

Hi.

I take it that this is a skinned mesh done like most skinning tuts out there, if so

then you should have a combined transform assigned to the bone.

 

You use the inverse combined transform matrix to offset your head bone to centre

 

create a rotation matrix on what ever axis

 

use the original head bone transfrom matrix like so.

 

matrix final   = headbone->originalmatrix;

matrix offset = headbone->combined;

matrix spin   = rotatematrix(time);

 

offset = inverse(offset);

//offset the head bone so it in centre

final *= offset;

final *= spin;

 

//add the offset back

final *=  headbone->combined;

 

//add the original trans again

final *= headbone->originalmatrix;

 

bonepose->defaulttrans = final;

 

you may need to inject the final matrix in your array that gets sent to the shader for skinning for this method to work maybe.

it should put you on the write track if nothing else.

 

 

this is like my turret rotaion question heres a link

http://www.gamedev.net/topic/648440-matrix-rotation-x-axis-rotataion-y-axis-crazy-offset/

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!