#### Archived

This topic is now archived and is closed to further replies.

# Rotation, Translation, and Pivot Points!

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

## Recommended Posts

I've been working on loading a models from formats other than .x and I'm not quite sure how to do this one. The mesh file saves nine variables: x, y, z, yaw, pitch, roll, pivotx, pivoty, and pivotz. From what I understand to get my world matrix for the mesh I should do this (assuming I have all of these variables loaded properly as floats):
D3DXMATRIX mRotation, mTranslation, mPivot, mFinal;
D3DXVECTOR3 Position(x, y, z), PivotPoint(pivotx, pivoty, pivotz);
mRotation = D3DXMatrixRotationYawPitchRoll(yaw, pitch, roll);
mTranslation = D3DXMatrixTranslation(x, y, z);
mPivot = D3DXMatrixTranslation(pivotx, pivoty, pivotz);
mFinal = mPivot * mRotation * mTranslation;

Is this correct? Also, just to through an extra hoop in here, the file uses a different coordinate system, which I hate, than the typical DX (Left-Hand) system. It looks like this: |+Z  /-Y |    / |  / |/_______+X Can anyone tell me just how to do this? Thanks a bunch, ms [edited by - ms291052 on April 15, 2004 10:50:26 PM]

##### Share on other sites
Can anyone even validate the first part?

##### Share on other sites
im not sure if i understand but,

When you create an object in an external editor, im sure that you are not created it from 0,0,0 you create a ball somewhere,
the object is created in "object space", it mean that the center (ie) can be 15,-4,23

DX rotate object around the 0,0,0 coordinate.
If you load the model and only rotate the object of the sample, it rotate with a pivot point of 15,-4,23.

What you need to do is back it to 0,0,0 first.
To do this you need to traslate it with the negative of the center (15,-4,23)*-1 = -15,4,-23 (Look for Matrix.Invert())

Once made it, you can set up a desirable pivot (ie 5,0,0) and later rotate (RotateY(PI/4)

Once made it, you can move it to the original position.

##### Share on other sites
It''s kind of difficult to tell what the nine variables are for. You''re saying the the mesh file itself has all the vertex info and everything, but that it also saves those nine extra variables, right?

The yaw, pitch, and roll are obviously for rotation. But its not clear what the others are for. I would imagine that the x, y, z variables are for the model''s position in world space but that doesn''t make any sense because the artist doesn''t really know where in world space the model will be.

The pivot variables are obviously the point that all rotations will happen about. But is the pivot point in model space? Assuming that the pivot point is in model space, then you need to translate so that the pivot point is at the origin. Then you apply your rotation matrix, followed by the final translation to position x, y, z.

So my guess is that your code would look something like this.
D3DXMatrixTranslation(&matPivot, -pivotx, -pivoty, -pivotz);D3DXMatrixRotationYawPitchRoll(&matRotation, yaw, pitch, roll);D3DXMatrixTranslation(&matTranslation, x, y, z);matFinal = matPivot * matRotation * matTranslation

neneboricua

• 10
• 10
• 11
• 12
• 11