Sign in to follow this  

Rotation, model and the center :(

This topic is 3718 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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....

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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... :(

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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[i].y - sin(DEG_TO_RAD(anglex))*points[i].z;
new_z = sin(DEG_TO_RAD(anglex))*points[i].y + cos(DEG_TO_RAD(anglex))*points[i].z;
//new_x = points[i].x;

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

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

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


}//for

------ /code -------------

Share this post


Link to post
Share on other sites
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[i].x;
new_y = points[i].y;
new_z = points[i].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[i].x = new_x;
pointsToCamera[i].y = new_y;
pointsToCamera[i].z = new_z;

}//for



Share this post


Link to post
Share on other sites

This topic is 3718 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this