Hi everyone, I’ve got a question as to the workings of glMultMatrix(). Basically, my program is a car driving around on a track. This is some rough pseudocode of my drawCar() method.
double x,y,z = findCarPosition(time); //coordinates of car
double dx,dy,dz = findCarDirection(time); //forward unit vector
glPushMatrix();
glTranslated(x,y,z);
//(0,1,0) is global up vector
double sx,sy,sz = cross_product(0,1,0 , dx,dy,dz); // left vector
double ux,uy,uz = cross_product(dx,dy,dz , sx,sy,sz); //local up vector
glRotated(-90,ux,uy,uz);
double m[16] = {dx,dy,dz,0 , ux,uy,uz,0, sx,sy,sz,0, 0,0,0,1};
glMultMatrixd(m);
glBegin(GL_QUADS);
glColor3d(0.0,0.0,1.0);
//draw car
glEnd();
glPopMatrix();
I read somewhere the m[16] would rotate an object to the correct way. When I tried this it was off my 90 degrees, hence the other glRotated.
Anyways, the problem…The car starts out as the light blue I’ve set it as. But as it drives around the track, it varies in color from dark blue to light blue. If I comment out the glMultMatrixd() line, the car will obviously not be rotated correctly, but the color stays constant.
I thought glMultMatrix will only affect 1 matrix, but it seems to be affecting both my color and modelview? Will this always happen with glMultMatrix, and do I need to find another way to rotate the car?
Thanks for any help or advice you can offer.
-duckisking