Horde3D http://horde3d.org/forums/ |
|
How to: Rotate objects smoothly around their own axises http://horde3d.org/forums/viewtopic.php?f=1&t=1055 |
Page 1 of 1 |
Author: | DIMEDROLL [ 18.12.2009, 11:05 ] |
Post subject: | How to: Rotate objects smoothly around their own axises |
I'm trying to rotate a 3D object around its own axises. I have some delta value which is added to... look at the code(this is onMouseMoveEvent): Code: float tx; float ty; float tz; float rx; float ry; float rz; float sx; float sy; float sz; h3dGetNodeTransform(*i, &tx, & ty, & tz, & rx, & ry, & rz, & sx, & sy, & sz); h3dSetNodeTransform(*i, tx, ty, tz, rx+delta, ry, rz, sx, sy, sz); Everything is good for Y and Z axises, but not for X. The object rotates only for 180 degrees and stops. So I debugged and seen that when -90 < rx < 90, ry == 0 and rz == 0 but when rx passes this border, ry and rz are changed automatically: ry == 180 and rz == 180 and my code Code: h3dSetNodeTransform(*i, tx, ty, tz, rx+delta, ry, rz, sx, sy, sz); now performs rotation in reverse direction... How can I handle it? |
Author: | Volker [ 18.12.2009, 15:35 ] |
Post subject: | Re: How to: Rotate objects smoothly around their own axises |
I guess you run into some numerical problems when getting the transformation parameters. You could try to get and set the transformation matrix directly by retrieving the relative node matrix and multiplying it with your delta rotation matrix. |
Author: | DIMEDROLL [ 24.12.2009, 08:31 ] |
Post subject: | Re: How to: Rotate objects smoothly around their own axises |
thanks, that worked, here is my code: Code: const float *absMat = NULL; h3dGetNodeTransMats(*i, NULL, &absMat); Matrix4f mat = absMat; mat = mat * Matrix4f::RotMat(delta, 0, 0); But how do I do if I want to rotate an object around X Y Z axises which start from the middle point of the objects bounding box? Code: Vec3f minPt;
Vec3f maxPt; h3dGetNodeAABB(*i, &minPt.x, &minPt.y, &minPt.z, &maxPt.x, &maxPt.y , &maxPt.z); Vec3f midPt = (minPt + maxPt) / 2; |
Author: | marciano [ 24.12.2009, 13:14 ] |
Post subject: | Re: How to: Rotate objects smoothly around their own axises |
The roatation is always around the coordinate origin (0, 0, 0). The easiest thing you can do is to modify your model so that the origin (often called pivot in DCC apps) is in the center of the geometry. |
Page 1 of 1 | All times are UTC + 1 hour |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |