#### Archived

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

# D3DXMatrix help

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

## Recommended Posts

Ok, I wanted know what would happen to the point (x, y, z) if it was rotated A radians around the x-axis, B radians about the y- axis, and C radians about the z-axis by using D3DX matrix functions. My first thought was to use the D3DXMatrixRotation (X/Y/Z) functions to construct 3 matrices reprenting each rotation, and the D3DXMatrixTranslationation function to construct a matrix representing the point, and then combine them like so:

D3DXMatrixIdentity(&matNew);

D3DXMatrixRotationX(&matRotX, A);
D3DXMatrixRotationY(&matRotY, B);
D3DXMatrixRotationZ(&matRotZ, C);

D3DXMatrixTranslation(&matTrans, x, y, z);

D3DXMatrixMultiply(&matNew, &matNew, &matRotY);
D3DXMatrixMultiply(&matNew, &matNew, &matRotX);
D3DXMatrixMultiply(&matNew, &matNew, &matRotZ);
D3DXMatrixMultiply(&matNew, &matTrans, &matNew);

newX = matNew._41;
newY = matNew._42;
newZ = matNew._43;


This seemed to work fine until I realized that the matrices weren't being combined all at once, but in order. So if I have the point (0, 1, 0), with A=PI/2, B=0, and C=PI/2, it will be rotated first to (0, 0, 1) about the x-axis, and then, since it now lies ON the z-axis, it is not rotated about the z-axis at all. What I want to come out of this is something like (sqrt(2), 0, sqrt(2)). ie, equal rotation about both axis. Anyway, I'm probly making this problem WAY more complicated than it has to be, as I have a tendency of doing, so any help would be greatly appreciated. How can I use operations to find this new point, or should I be using something else?  weird formatting [edited by - IncarnateRW on March 1, 2003 11:15:51 PM]

##### Share on other sites
D3DMATRIX mat;D3DVECTOR3 vec, newvec;D3DXMatrixRotationYawPitchRoll(&mat, B, A, C);vec.x = x;vec.y = y;vec.z = z;D3DXVec3TransformCoord(&newvec, &vec, &mat);

That what I would probably have used, assuming I wasn''t using a quaternion.

Alternatively, using your code, I would have done this:

D3DXMatrixRotationX(&matRotX, A);D3DXMatrixRotationY(&matRotY, B);D3DXMatrixRotationZ(&matRotZ, C);D3DXMatrixMultiply(&matNew, &matRotY, &matRotX);D3DXMatrixMultiply(&matNew, &matNew, &matRotZ);vec.x = x;vec.y = y;vec.z = z;D3DXVec3TransformCoord(&newvec, &vec, &mat);

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 22
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631766
• Total Posts
3002218
×