Problem with rotation matrix

Started by
3 comments, last by TomCat4711 21 years, 7 months ago
Ok, I have my matrix and I rotate it via 3 functions. (X, Y, Z) It will rotate it relativ NOT absolute. My Problem is: After each function call the scene got smaller - the axis I rotate gets shrinked - but only this axis - And it is very fast - after about 5 rotations it has nearly half the original size... However the rotations seem to be correct - i think it is not a math problem -> rounding-problem ? here one of the 3 functions
        
// double m[16];

// column-major

void MATRIX4X4::RotateY(const double& RotationY)
{

	double c = cos(RotationY);
	double s = sin(RotationY);

	m[0]  = -m[8]*s +  m[0]*c;
	m[1]  = -m[9]*s +  m[1]*c;
	m[2]  = -m[10]*s + m[2]*c;
	//m[3]  = -m[11]*s + m[3]*c;

    
	m[8]  = m[0]*s + m[8]*c;
	m[9]  = m[1]*s + m[9]*c;
	m[10] = m[2]*s + m[10]*c;
	//m[11] = m[3]*s + m[11]*c;

	
}        
sry for bad english [edited by - TomCat4711 on August 31, 2002 4:28:46 PM]
Advertisement
I forgot to mention that my Matrix will be loaded directly to OpenGL with

glLoadMatrixd(m);
OMG - slap me plz

what about saving the expressions just bevore changing and using them ?
I''m running on about 3 hours of sleep here, but your function looks basically correct. The only thing I see immediately wrong is something you already recognized in your second message. You must use temporary variables when you calculate m[0], m[1], and m[2]. Reason? You need to use the original, unmodified values of m[0], m[1], and m[2] when you calculate m[8], m[9], and m[10] later on. And if you do not use temporary variables you lose the original values. Your code should look like:

new_m0 = calculate using m[]
new_m1 = calculate using m[]
new_m2 = calculate using m[]
m[8] = calculate using m[]
m[9] = calculate using m[]
m[10] = calculate using m[]
m[0] = new_m0
m[1] = new_m1
m[2] = new_m2

Hope that helps!

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
thanks for your reply - works

This topic is closed to new replies.

Advertisement