Turning head and spine

Started by
0 comments, last by ankhd 10 years, 7 months ago

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?

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/

This topic is closed to new replies.

Advertisement