# 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.

## 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();

final *= offset;

final *= Yspin;

final *= -offset;

final *=turretbase->pBoneMatrices[turretbase];

if I dont do this again its offset a bit for some reason;?????????
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 on other sites

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 on other sites

no not doing that in code that was just short hand.

##### 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....

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 9
• 9
• 11
• 15
• 21