Horde3D

Next-Generation Graphics Engine
It is currently 16.05.2024, 13:56

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: 18.12.2009, 11:05 
Offline

Joined: 11.12.2009, 12:59
Posts: 19
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?


Top
 Profile  
Reply with quote  
PostPosted: 18.12.2009, 15:35 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
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.


Top
 Profile  
Reply with quote  
PostPosted: 24.12.2009, 08:31 
Offline

Joined: 11.12.2009, 12:59
Posts: 19
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;


Top
 Profile  
Reply with quote  
PostPosted: 24.12.2009, 13:14 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
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.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group