Since I was able to get excellent help ealier in less that a half an hour I figure I’ll post another question This ones a bit longer, I’ve tried to provided only the code that is required:
Can somebody please explain to me whats wrong here?
And I know its not the DEG_TO_RAD stuff, the equation is right, and I tried it without it too.
/////////////////////////////////////////////////////////////////////
#include <math.h>
#define _Z_DEG_TO_RAD ( 0.017453292519943295474371680597869271878)
#define Z_DEG_TO_RAD(d) ((d) * _Z_DEG_TO_RAD)
typedef GLfloat zfloat;
typedef GLint zint;
/////////////////////////////////////////////////////////////////////
// Matrix structure
//
class ZMatrix
{
public:
zfloat m[16];
// Constructor
ZMatrix()
{ LoadIdentity(); }
// Allow array-like interface to OpenGL's backwards matrices
inline zfloat&At(zint row, zint col)
{ return (m[col * 4 + row ]); }
// Load the Identity matrix
inline LoadIdentity()
{ m[0] = m[5] = m[10] = m[15] = 1.0;
m[1] = m[2] = m[3] =
m[4] = m[6] = m[7] =
m[8] = m[9] = m[11] =
m[12] = m[13] = m[14] = 0.0; }
inline RotateX(zfloat x)
{
LoadIdentity();
At(2,2) = At(3,3) = cos( Z_DEG_TO_RAD(x) );
At(2,3) = sin( Z_DEG_TO_RAD(x) );
At(3,2) = -sin( Z_DEG_TO_RAD(x) );
}
inline glMultMatrix()
{ glMultMatrixf( m ); }
};
//
/////////////////////////////////////////////////////////////////////
zfloat xoff = (offset controlled by keypresses);
zfloat yaw = (angle controlled by keypresses);
In my render loop I had:
glPushMatrix();
glTranslatef( 0.0, 0.0, xoff );
glRotatef( yaw, 0.0, 1.0, 0.0 );
glTranslatef( -4096.0, -768.0, 4596.0 );
glRotatef( -90.0, 1.0, 0.0, 0.0 );
Which kinda sorta worked… at least well enough for me to see and move around. If I replace the above with:
glPushMatrix();
glTranslatef( 0.0, 0.0, xoff );
glRotatef( yaw, 0.0, 1.0, 0.0 );
glTranslatef( -4096.0, -768.0, 4596.0 );
ZMatrix mat;
mat.RotateX( -90.0 );
mat.glMultMatrix();
Everything goes berserk!