Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

3D Rotations

Status
Not open for further replies.

tcollins

Programmer
Sep 12, 2000
34
US
Ok, I'm confusecd about the mathematics required for 3D rotations. I have:

void xrot(D3DMATRIX &mat, double rot)
{
mat._11 = 1; mat._12 = 0; mat._13 = 0; mat._14 = 0;
mat._21 = 0; mat._22 = cos(rot); mat._23 = sin(rot); mat._24 = 0;
mat._31 = 0; mat._32 = -sin(rot); mat._33 = cos(rot); mat._34 = 0;
mat._41 = 0; mat._42 = 0; mat._43 = 0; mat._44 = 1;
}
void yrot(D3DMATRIX &mat, double rot)
{
mat._11 = cos(rot); mat._12 = 0; mat._13 = -sin(rot); mat._14 = 0;
mat._21 = 0; mat._22 = 1; mat._23 = 0; mat._24 = 0;
mat._31 = sin(rot); mat._32 = 0; mat._33 = cos(rot); mat._34 = 0;
mat._41 = 0; mat._42 = 0; mat._43 = 0; mat._44 = 1;
}
void zrot(D3DMATRIX &mat, double rot)
{
mat._11 = cos(rot); mat._12 = sin(rot); mat._13 = 0; mat._14 = 0;
mat._21 = -sin(rot); mat._22 = cos(rot); mat._23 = 0; mat._24 = 0;
mat._31 = 0; mat._32 = 0; mat._33 = 1; mat._34 = 0;
mat._41 = 0; mat._42 = 0; mat._43 = 0; mat._44 = 1;
}
which cause a rotation around their respective axies. Do I assume they are in the form:
11 12 13 14
21 22 23 24
31 32 33 34
41 42 43 44
??? or am I orientated wrong? The thing is, when I rotate, I'm not seeing what I expect. One problem is if I have a 2D plane along the Z axis at 0, and I multiply the 'rotation around the x axis' by it, I get, well, 0 multiplied by anything is 0. I loose the depth. I want to rotate a plane (like a floor) around the X-axis. Is there any good online help? Or can you help?

Thanks

Taylor
 
Can you specify what you get and you want to abtain, cause it's a little bit confusing what you wrote ...
 
It would be nice if you could specify a little better your purpose. You're talking about a plane along the Z axis, but a plane is 2D so the plane should be along Z and X or Z and Y, or better is Z the normal of the plane ?

When you do 3D programming you have to be very precise. You won't get something work if you're approximative !
 
I eventually ended up preforming three operations in one with:

void rotate(D3DLVERTEX &v, double rx, double ry, double rz, D3DVECTOR &transformation)
{
float x1, y1, z1;

// v.x *= transformation.x;
// v.y *= transformation.y;
// v.z *= transformation.z;

x1 = cos(ry) * v.x - sin(ry) * v.z;
z1 = sin(ry) * v.x + cos(ry) * v.z;
v.x = cos(rz) * x1 + sin(rz) * v.y;
y1 = cos(rz) * v.y - sin(rz) * x1;
v.z = cos(rx) * z1 - sin(rx) * y1;
v.y = sin(rx) * z1 + cos(rx) * y1;

v.x += transformation.dvX;
v.y += transformation.dvY;
v.z += transformation.dvZ;

}

My confusion was probably one of having the matricies that allowed rotation around a particular access, but with me using it wrong. For example, if I were to rotate around the z-axis, I should see the image rotate on end parallel to my eye level, though everytime I used it, it looks like it was performing x and y-axis rotations in one, which is wrong. With that said, my project is starting to become successful, however even now I'm starting to see a performance issue with all the sine and cosine calls. I will need to look at optimizing code very soon here. The conclusion? I got around the matricie problem by using a simpler soluion, I belive, but might not be as 'elegant'?

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top