• Create Account

# Matrix Rotation X axis * Rotataion Y axis = Crazy offset

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1ankhd  Members   -  Reputation: 664

Like
0Likes
Like

Posted 01 October 2013 - 04:35 AM

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.

### #2Paradigm Shifter  Crossbones+   -  Reputation: 3995

Like
1Likes
Like

Posted 01 October 2013 - 06:44 AM

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?

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

### #3ankhd  Members   -  Reputation: 664

Like
0Likes
Like

Posted 01 October 2013 - 07:40 AM

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

### #4ankhd  Members   -  Reputation: 664

Like
0Likes
Like

Posted 01 October 2013 - 11:17 PM

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

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS