• ### What is your GameDev Story?

#### Archived

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

# Need Help with 3D rotations

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

## Recommended Posts

I think you are messed up with formulas.
I use the following:
- Around X axis
y1:=cbuffer[i].Y*Cos(xang)-cbuffer[i].z*sin(xang);
z1:=cbuffer[i].Y*Sin(xang)+cbuffer[i].z*cos(xang);
cBuffer[i].Y:=y1;
cBuffer[i].Z:=z1;

and soon...

FlyFire/CodeX
http://codexorg.webjump.com

##### Share on other sites
Thanks for the reply, but thats the same thing in a different form. I figured it out: its strange: all i did was change all my variables to doubles and it magically worked.

##### Share on other sites
Just goes to show you... unless memory is *really* tight, use doubles!

Btw, that code is basically a matrix multiplication, just unrolled.

Have fun,

White Fire

##### Share on other sites
Thanks for reading this. I am working on a 3D engine and i cant get my rotations working. When I press the key to start the z axis rotation, the square goes back into the z(the z value increases). And when i do a x or y axis rotation, the z value decreases(it comes towards the screen). Here are the formulas that i am using:

X:
-----
temp_y = (rect_3d.vert[i].y*cos(x_ang)) + (rect_3d.vert[i].z*sin(x_ang));
temp_z = (rect_3d.vert[i].y *-sin(x_ang)) + (rect_3d.vert[i].z*cos(x_ang));

rect_3d.vert[i].y = temp_y;
rect_3d.vert[i].z = temp_z;

Y:
-----
temp_x = (rect_3d.vert[i].x*cos(y_ang)) + (rect_3d.vert[i].z*-sin(y_ang));
temp_z = (rect_3d.vert[i].x *sin(y_ang)) + (rect_3d.vert[i].z*cos(z_ang));

rect_3d.vert[i].x = temp_x;
rect_3d.vert[i].z = temp_z;

Z:
-----
temp_x = (rect_3d.vert[i].x*cos(z_ang)) + (rect_3d.vert[i].y*sin(z_ang));
temp_y = (rect_3d.vert[i].x*-sin(z_ang)) + (rect_3d.vert[i].y*cos(z_ang));

rect_3d.vert[i].x = temp_x;
rect_3d.vert[i].y = temp_y;

--------
Any help would be appreciated, and yes i know i should use matrices.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 15
• 14
• 46
• ### Forum Statistics

• Total Topics
634058
• Total Posts
3015288
×