Axis Angle Rotation

Howdy, I’m currently sitting infront of a computer with no compiler at hand…

So I’m making “free-flight” programming into a text editor (don’t laugh).

I’m currently writing a matrix class to work with OpenGL and D3D shaders. I’m working in a right-handed (like GL) coordinate system.

Can someone please verify this:

/// Four dimensional matrix in column major order.
struct Matrix4
	float m11, m21, m31, m41;
	float m12, m22, m32, m42;
	float m13, m23, m33, m43;
	float m14, m24, m34, m44;

	/// Rotation about an axis.
	void Rotation(const float angle, const float x, const float y, const float z)
		// Angle in radians.
		const float radians = angle * Math::DEG2RAD;

		// Rotations.
		const float s = sinf(radians);
		const float c = cosf(radians);
		const float t = 1.0F - c;

		m11 = t * x * x + c;
		m21 = t * x * y + s * z;
		m31 = t * x * z - s * y;
		m41 = 0.0F;

		m12 = t * y * x - s * z;
		m22 = t * y * y + c;
		m32 = t * y * z + s * x;
		m42 = 0.0F;

		m13 = t * z * x + s * y;
		m23 = t * z * y - s * x;
		m33 = t * z * z + c;
		m43 = 0.0F;

		m14 = 0.0F;
		m24 = 0.0F;
		m34 = 0.0F;
		m44 = 1.0F;

I somehow get the feeling that the matrix is in transposed order, sigh. Can someone please verify against glRotatef? Or against D3DXMatrixRotationAxis and afterwars D3DXMatrixTranspose. Thanks :slight_smile: Should give the same results imho.

Thanks in advance.

P.S. Programming without a compiler at hand sucks.

Damn… I should spice up my math skills :frowning:


I checked your maths against my own rotation routines (originally from Eberly’s Geo. Tools book) and they look correct.

I use JOGL and am unaware of D3DXMatrixRotationAxis() and D3DXMatrixRotationAxis(). What are these? Are they the opengl standard LoadMatrix() and LoadTransposeMatrix() methods?