Jump to content

  • Log In with Google      Sign In   
  • Create Account


3D Rotations


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 acw83   Members   -  Reputation: 174

Like
Likes
Like

Posted 17 December 1999 - 11:18 AM

Could someone please explain why this doesn't work out okay when rotating about the x or y axis. The z axis works fine...

void PrepVertex(CVertex* v, float xra, float yra, float zra)
{

float x = v->x;
float y = v->y;
float z = v->z;

float xr = v->x;
float yr = v->y;
float zr = v->z;

float xa = xra*3.14159/180;
float ya = yra*3.14159/180;
float za = zra*3.14159/180;


if(xra!=0){
yr = y*cos(xa) - z*sin(xa); // Rotate about X
zr = y*sin(xa) + z*cos(xa);
}

if(yra!=0){
xr = x*cos(ya) + z*sin(ya); // Rotate about Y
zr = x*-(sin(ya)) + z*cos(ya);
}

if(zra!=0){
xr = x*cos(za) - y*sin(za); // Rotate about Z
yr = x*sin(za) + y*cos(za);
}

v->xr = xr;
v->yr = yr;
v->zr = zr;
}


Sponsor:

#2 Gromit   Members   -  Reputation: 144

Like
Likes
Like

Posted 16 December 1999 - 05:56 PM

you are calculating yr and zr for rotation around the x axis, then totally replacing zr in your calculation of the y axis rotation...etc. You need to make temp variables so you don't lose what you just calculated in the next step.

I none to good at explaining stuff like this, so it probably doesn't make any sense. (or I may totally be off)

I'm just guessing from a quick glance at your code.

Hope I at least helped a bit.


#3 Gromit   Members   -  Reputation: 144

Like
Likes
Like

Posted 16 December 1999 - 05:58 PM

Z axis is the last calculation that you are making, that is why it is correct. That is how I came to the conclusion in the post above.

#4 acw83   Members   -  Reputation: 174

Like
Likes
Like

Posted 17 December 1999 - 10:49 AM

Okay, what'll happen is that the Vertex will move, but in a funky-unrotate-like matter...

#5 DaJudge   Members   -  Reputation: 138

Like
Likes
Like

Posted 17 December 1999 - 11:18 AM

Why don't you simply use matrices. They are way more comfortable and offer a lot more functions than simple functions.

------------------
Alexander Stockinger
Programmer





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS