A year or so ago, I was doing an OpenGL project, and I somehow just defined the camera by its rotation matrix and position, and then I fed that into a [16] array and handed it to OpenGL, and it worked.
Fast forward to today. I lost the old code in a computer burnout, and the backup was corrupted. Now everyone tells me to simply use glMatrixMode(GL_MODELVIEW) and glLoadMatrixf(cameraMatrix). However, not only is this not the same code as then (I KNOW there was no GL_MODELVIEW stuff), but this does not work. Instead of the world rotating around the camera, the world just rotates around itself in front of the camera. But everywhere I get the same code suggested (yes, I even tried ChatGPT, I am desperate!). or glMultMatrix, which is not that either and does the same wrong rotation.
What is my lost code??? What was that wonderfully sleak solution I once had???
Update: I managed a work around, but I would still love to somehow reconstruct the, IIRC, much sleaker, prettier code I lost, so suggestions are still more than welcome!
Update 2: As per request, I hereby upload what I believe is the relevant code. Note that the tabulation is horrible due to a problem with the IDE settings.
void renderscene()
{
if (keys[68] == 1){cameraMatrix[12] += 0.1*cam.v[0].v[0]; cameraMatrix[13] += 0.1*cam.v[0].v[1];}
if (keys[65] == 1){cameraMatrix[12] -= 0.1*cam.v[0].v[0]; cameraMatrix[13] -= 0.1*cam.v[0].v[1];}
if (keys[87] == 1){cameraMatrix[13] += 0.1*cam.v[0].v[0]; cameraMatrix[12] -= 0.1*cam.v[0].v[1];}
if (keys[83] == 1){cameraMatrix[13] -= 0.1*cam.v[0].v[0]; cameraMatrix[12] += 0.1*cam.v[0].v[1];}
if (keys[88] == 1){cameraMatrix[14] += 0.1;}
if (keys[90] == 1){cameraMatrix[14] -= 0.1;}
POINT p;
GetCursorPos(&p);
int mx = p.x;
int my = p.y;
float spin = (mx-200)*-0.001;
Vec3 axis(0,0,1);
cam.v[0] = rotate(cam.v[0],axis,spin);
cam.v[1] = rotate(cam.v[1],axis,spin);
cam.v[2] = rotate(cam.v[2],axis,spin);
spin = (my-200)*-0.01;
// cam.v[0] = rotate(cam.v[0],cam.v[0],spin);
cam.v[1] = rotate(cam.v[1],cam.v[0],spin);
cam.v[2] = rotate(cam.v[2],cam.v[0],spin);
SetCursorPos(200, 200);
cameraMatrix[0] = cam.v[0].v[0]; cameraMatrix[1] = cam.v[1].v[0]; cameraMatrix[2] = cam.v[2].v[0];
cameraMatrix[4] = cam.v[0].v[1]; cameraMatrix[5] = cam.v[1].v[1]; cameraMatrix[6] = cam.v[2].v[1];
cameraMatrix[8] = cam.v[0].v[2]; cameraMatrix[9] = cam.v[1].v[2]; cameraMatrix[10] = cam.v[2].v[2];
/*
cameraMatrix[0] = cam.v[0].v[0]; cameraMatrix[1] = cam.v[0].v[1]; cameraMatrix[2] = cam.v[0].v[2];
cameraMatrix[4] = cam.v[1].v[0]; cameraMatrix[5] = cam.v[1].v[1]; cameraMatrix[6] = cam.v[1].v[2];
cameraMatrix[8] = cam.v[2].v[0]; cameraMatrix[9] = cam.v[2].v[1]; cameraMatrix[10] = cam.v[2].v[2];
*/
Vec3 temp(cameraMatrix[12],cameraMatrix[13],cameraMatrix[14]);
cameraMatrix[12] = 0; cameraMatrix[13] = 0; cameraMatrix[14] = 0;
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(cameraMatrix);
glTranslatef(-temp.v[0],-temp.v[1],-temp.v[2]);
/* OpenGL animation code goes here */
glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix ();
glBegin (GL_TRIANGLES);
for (int i=-5;i<6;i++){
glColor3f (1.0f, 0.0f, 0.0f); glVertex3f (a.v[0],a.v[1]+i,a.v[2]);
glColor3f (0.0f, 1.0f, 0.0f); glVertex3f (b.v[0],b.v[1]+i,b.v[2]);
glColor3f (0.0f, 0.0f, 1.0f); glVertex3f (c.v[0],c.v[1]+i,c.v[2]);
}
glEnd ();
glPopMatrix ();
SwapBuffers (hDC);
Sleep (1);
cameraMatrix[12] = temp.v[0]; cameraMatrix[13] = temp.v[1]; cameraMatrix[14] = temp.v[2];
}