#### Archived

This topic is now archived and is closed to further replies.

# 3D Rotations

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

## Recommended Posts

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.

##### Share on other sites
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.

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

##### Share on other sites
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;
}

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

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

1. 1
Rutin
28
2. 2
3. 3
4. 4
5. 5

• 13
• 11
• 10
• 13
• 20
• ### Forum Statistics

• Total Topics
632952
• Total Posts
3009432
• ### Who's Online (See full list)

There are no registered users currently online

×