Jump to content
  • Advertisement


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


Eular Rotation Matrix

This topic is 5860 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

I'm transforming coordinates into an opengl matrix:
	float cx, cy, cz, sx, sy, sz;

	cx = (float) cos((double) g_pCamera->m_Rotation3fv[0]);
	cy = (float) cos((double) g_pCamera->m_Rotation3fv[1]);
	cz = (float) cos((double) g_pCamera->m_Rotation3fv[2]);

	sx = (float) sin((double) g_pCamera->m_Rotation3fv[0]);
	sy = (float) sin((double) g_pCamera->m_Rotation3fv[1]);
	sz = (float) sin((double) g_pCamera->m_Rotation3fv[2]);

	matrix[ 0] = cy * cz;
	matrix[ 1] = sx * sy * cz - cx * sz;
	matrix[ 2] = cx * sy * cz + sx * sz;
	matrix[ 3] = 0.f;

	matrix[ 4] = cy * sz;
	matrix[ 5] = sx * sy * sz + cx * cz;
	matrix[ 6] = cx * sy * sz - sx * cz;
	matrix[ 7] = 0.f;

	matrix[ 8] = - sy;
	matrix[ 9] = sx * cy;
	matrix[10] = cx * cy;
	matrix[11] = 0.f;

	matrix[12] = g_pCamera->m_Position3fv[0];
	matrix[13] = g_pCamera->m_Position3fv[1];
	matrix[14] = g_pCamera->m_Position3fv[2];
	matrix[15] = 1.f;
Rotation around the x and y axis works perfectly, but the z axis rotation only works correctly when the camera faces down the world z axis. Otherwise the more the angle deviates from the world z-axis the more the rotation changes from a z-rotation to an x rotation. Is there a flaw in my math? [edited by - MindCode on December 2, 2002 4:31:16 PM]

Share this post

Link to post
Share on other sites
some things to check:

- order that you do the rotations, i think the typical order is y,x,z
- are you storing your matrix in row or column order? if your storing in row order and then sending this off to OpenGL things will be screwy as gl uses column ordered matricies. just try transposing and see if that fixes the problem.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!