Rotation, model and the center :(

Started by
6 comments, last by juglar 16 years, 6 months ago
Hi guys!! i have a model in my 3d Space, and i want to rotate the object,around his center, in a coord diferent to 0,0,0 y use this ecuatios (the euler rotation) x' = x y' = (cos é * y) - (sin é * z) z' = (sin é * y) + (cos é * z) Rotation about the y axis: x' = (cos é * x) + (sin é * z) y' = y z' = -(sin é * x) + (cos é * z) Rotation about the z axis: x' = (cos é * x) - (sin é * y) y' = (sin é * x) + (cos é * y) z' = z but this not work it turn aroun the "world center" and not around the model center any advice on how to do that thanks in advance....
Advertisement
Could you do the rotations around the orign then translate back?

O = Object Position

x' = x
y' = (cos é * y-Oy) - (sin é * z-Oz) + Oy
z' = (sin é * y-Oy) + (cos é * z-Oz) + Oz

Edit: Just to be clear, x,y,z are the vertices that make up you object.

[Edited by - Wolfdog on October 13, 2007 10:19:47 PM]
What you need to do is move your model "back" so that its center is located at 0,0,0. Then apply your rotation. Now move the model "back" to where it was originally.

If you create a scene graph structure all this "moving back" business is handled for you. Check out the videos on my website if you want to see it in action.
mmm yes but, the problem is, my object is an object created in 3dsmax, so i have all the data olready stored, i put the object in the 0,0,0 of the world and i have the same effect... :(
Quote:Original post by juglar
mmm yes but, the problem is, my object is an object created in 3dsmax, so i have all the data olready stored, i put the object in the 0,0,0 of the world and i have the same effect... :(
Can you explain what it is you are trying to do? I am very confused here.

Are you rendering this model in your own program with OpenGL/DirectX/Something Else? Or are you doing something different?
Yes,i want to load a model, and rotate it in any part of the world around his own axis(local rotation ? ) an not in the word axis here is the code for made a rotation that i did it's extranger work fine por the rotation in X but no for the rest... any clue?
------ code -----
int i;
float new_z,new_y,new_x;

for(i=0;i<numPoints;i++){

if(anglex){
new_y = cos(DEG_TO_RAD(anglex))*points.y - sin(DEG_TO_RAD(anglex))*points.z;
new_z = sin(DEG_TO_RAD(anglex))*points.y + cos(DEG_TO_RAD(anglex))*points.z;
//new_x = points.x;

//pointsToCamera.x = new_x;
pointsToCamera.y = new_y;
pointsToCamera.z = new_z;
}
//transform y
if(angley){
new_x = cos(DEG_TO_RAD(angley))*points.x + sin(DEG_TO_RAD(angley))*points.z;
//new_y = points.y;
new_z = -sin(DEG_TO_RAD(angley))*points.x + cos(DEG_TO_RAD(angley))*points.z;

pointsToCamera.x = new_x;
//pointsToCamera.y = new_y;
pointsToCamera.z = new_z;
}
//transform z
if(anglez){
new_x = cos(DEG_TO_RAD(anglez))*points.x - sin(DEG_TO_RAD(anglez))*points.y;
new_y = sin(DEG_TO_RAD(anglez))*points.x + cos(DEG_TO_RAD(anglez))*points.y;
//new_z = points.z;

pointsToCamera.x = new_x;
pointsToCamera.y = new_y;
//pointsToCamera.z = new_z;
}


}//for

------ /code -------------
Have you thought about using matrices? They could be used to clean all this up and have many great benefits.

Now there one obvious problem with this code. If you have more than two angles set you overwrite the other. For example if you set anglex and angley then you end up replacing all the changes of X because you don't take it into account.

I'll fix this real quick, but I think you might want to look around for basic examples of these things, nehe.gamedev.net is a good place to start and perhaps mmakrzem's own video tutorials might be helpful.
int i; float new_z,new_y,new_x;for(i=0;i<numPoints;i++){    new_x = points.x;   new_y = points.y;   new_z = points.z;    if(anglex){      new_y = cos(DEG_TO_RAD(anglex))*new_y - sin(DEG_TO_RAD(anglex))*new_z;      new_z = sin(DEG_TO_RAD(anglex))*new_y + cos(DEG_TO_RAD(anglex))*new_z;   }   //transform y   if(angley){      new_x = cos(DEG_TO_RAD(angley))*new_x + sin(DEG_TO_RAD(angley))*new_z;      new_z = -sin(DEG_TO_RAD(angley))*new_x + cos(DEG_TO_RAD(angley))*new_z   }   //transform z   if(anglez){      new_x = cos(DEG_TO_RAD(anglez))*new_x - sin(DEG_TO_RAD(anglez))*new_y;      new_y = sin(DEG_TO_RAD(anglez))*new_x + cos(DEG_TO_RAD(anglez))*new_y;   }    pointsToCamera.x = new_x;   pointsToCamera.y = new_y;   pointsToCamera.z = new_z; }//for
:( it's was a very newby bug.... this happend when i program so much hours at night , thanks people for the help!! :), i will do it with matrix

This topic is closed to new replies.

Advertisement