Jump to content
  • Advertisement
Sign in to follow this  
ankhd

Matrix Rotation X axis * Rotataion Y axis = Crazy offset

This topic is 2212 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

Howdy All.

 

The thing I'm triying to do is rotate 2 bones(frames).
The bones are layed out like this.

                 

                                 _____________Base1Bone
                                 |
                                 |BaseBone offset from the root

    __ root bone

 

these bone also have animation as well that play fine(working)

what I do first is.
UpdateAnimation();

UpdateMeshSkinned(&identity); this does 2 things it
Recurse down the tree and generate a frame's toRoot transform from the updated pose.
and
Premultiply the offset-transform to transform the vertices to the bone's local
coordinate system first, before applying the other transforms.(world and stuff)

and this data is stored in a MATRIX pBoneMatrices[MaxBones];

the pBoneMatrices is what gets sent to the shader for skinning(works)

Now here is what I want to do after the updatemeshskinned which transforms all the Matrices in pBoneMatrices
to bones local coordinates.

First both bones are found in the array these are turretbase, turretelevation,

then both bones are decomposed into its pos, scale and rotation.Each bone hase a combined matrix
this is the offset to the centre of the mesh(what I use to offset the matrix to rotate them on.

so for the turrets base the rotation is about the Y axis here is what I do

Matrix offset = combined;

matrix final = turretbase->pBoneMatrices[turretbase];

matrix Yspin = D3DXMatrixRotationY();

//addoffset so we can rotate about centre
final *= offset;

final *= Yspin;

//add the offset back
final *= -offset;

//add the original transform again
final *=turretbase->pBoneMatrices[turretbase];

if I dont do this again its offset a bit for some reason;?????????
//add the original transform
final *=turretbase->pBoneMatrices[turretbase];

//Incerted in to the matrix now
turretbase->pBoneMatrices[turretbase] = final;

 

this works for the turretElevation  in the Y only as soon as I add in the X axis rotation its offsets(orbits again how)

all Im doing here is createing a X axis rotation matrix at 45 and changing the line here

final *= Yspin; to final *= Xspin *Yspin; or this final *= Yspin * Xspin;

and the turrets elevation will rotate at the original offset it orbits whats the X axis rotation doing to the Y axises rotation

I hope I have explained this correct, as I don't know what Im doing with this as it is Thanks.

 

 

Share this post


Link to post
Share on other sites
Advertisement

//add the offset back
final *= -offset;

 

That looks dodgy, negating a matrix is seldom useful (it flips the transformation making the model inside out, for one thing). You probably want to multiply by the inverse matrix of offset?

Share this post


Link to post
Share on other sites

well there you go. infact I had it wrong from the word go see I was making my offset like this

 

offset.x = -(DX10FrameTurretElevation[ctr]->matCombined._41);

offset.y = (DX10FrameTurretElevation[ctr]->matCombined._42);

offset.z = -(DX10FrameTurretElevation[ctr]->matCombined._43 );

 

the making a matrix like so

 

 

D3DXMatrixTranslation(&t, offset.x,

offset.y,

offset.z);

 

when all I needed was the invers matrix of combined for the offset.

I did tray that first about 6 weeks ago but had other issues I fixed inbetween.

 

Oh I now have programable turrets cool. an this may even be a run around the block nood moment lol....

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!