Advertisement

Arbitrary Axis?

Started by January 09, 2003 03:42 PM
4 comments, last by Funkymunky 22 years, 1 month ago
Hi, Im currently rotating a 3d object i''ve loaded, but I have a problem. It always rotates about the origin! It''s a jeep, so instead of spinning left, it is swing in a wide arc to the left, as if it were still attached to the origin point. This of course only happens when I move the object away from the origin, it behaves correctly when it hasn''t been moved. Help?
the order you do your transformation in is important here since it''s all based on matrix-multiplication which isn''t kommutative..so to solve your problem: first rotate (while the object is centered at the origin), then translate.



Runicsoft -- home of my open source Function Parser and more
Advertisement
thanks! well, now it rotates according to itself no matter what, but I can't move it correctly. When I rotate the object, it moves in different directions. I think it has to do in my matrix multiplications: here's my code:


      // Move,  by amount vector vD3DXMATRIX R, Rx, Ry, Rz;D3DXVECTOR3 Dir;D3DXMatrixRotationZ(&Rz, roll);D3DXMatrixRotationX(&Rx, pitch);D3DXMatrixRotationY(&Ry, yaw);R = Rz * Rx * Ry;Dir.x = (v.x*R._11)+(v.y*R._21)+(v.z*R._31);Dir.y = (v.x*R._12)+(v.y*R._22)+(v.z*R._32);Dir.z = (v.x*R._13)+(v.y*R._23)+(v.z*R._33);Pos+=Dir;// Update, perform all rotations and movementsD3DXMATRIX R, T, Rx, Ry, Rz;float x, y, z;D3DXMatrixTranslation(&T, Pos.x, Pos.y, Pos.z);D3DXMatrixRotationX(&Rx, -pitch);D3DXMatrixRotationY(&Ry, -yaw);D3DXMatrixRotationZ(&Rz, -roll);R = Rz * Rx * Ry * T;//  for all vertices, this is how i compute the new positionx = vertices[i].position.x * R(0, 0) + vertices[i].position.y * R(1, 0) + vertices[i].position.z * R(2, 0) + R(3, 0);y = vertices[i].position.x * R(0, 1) + vertices[i].position.y * R(1, 1) + vertices[i].position.z * R(2, 1) + R(3, 1);z = vertices[i].position.x * R(0, 2) + vertices[i].position.y * R(1, 2) + vertices[i].position.z * R(2, 2) + R(3, 2);      


These two calls are made at different points in the program, such that while checking for keystrokes I call the move (and the rotatex, y, and z functions) then I call an update of the object before rendering. Any help?
[edited by - Funkymunky on January 9, 2003 7:43:59 PM]

[edited by - Funkymunky on January 11, 2003 2:53:27 AM]

[edited by - Funkymunky on January 11, 2003 2:54:00 AM]
Noone knows??
Ok, I fixed up the obvious errors in the code, and it worked. I call a move in the y direction, and the car moves toward the Z. Now, if I have a camera defined in the same manner (Position and a roll, pitch, yaw) how could I attach it to the object?
as we are already talking about transformations
i have a question about keyframe animations

i have the bones with their rotation info


how do i render such a model
because you have faces whose vertices are attached to multiple bones

should i precalculate the geometry or should i only precalculate the polygons which have been assigned to multiple bones and then render the rest with modelview transformations?
http://www.8ung.at/basiror/theironcross.html

This topic is closed to new replies.

Advertisement