Yet another camera implementation question

Hello, I’ve been trying for a long time to find good resources on creating a camera that rotates and translates according to the current view, but to no avail. And gluLookAt seems to be really slow (not to mention the difficult calculating the up vector); I’d prefer to do this in pure OpenGL.

What should I be using? glTranslatef doesn’t seem to care whether I rotated first (and I’ve tried translating back, etc.), and it looks like it’d be really difficult to calculate exactly what axes to rotate the camera around to do what I want. I’ve messed around a bit with push/popmatrix. I’m sorry; I just haven’t found anything, and I’ve put off starting a 3D game for months now because I just can’t make this first step.

gluLookAt can’t be slow; or roll your own version - it’s just normalization and cross product.

Extract the 3x3 rotational matrix from the modelview, extract the translation from modelview. (below their values are used in mvrot, mvtrans)


vec3 strafeDir = vec3(-0.3,0,0); // if you want to go right 0.3 units
mat3 rotateDir = ...// calculate how you want to rotate, or identity if there's no rotation to be applied

vec3 newTranslation = mvtrans + mvrot * strafeDir;
mat3 newRotation = mvrot * rotateDir;

Merge the new results into a 4x4 matrix, upload with glLoadMatrix.

I haven’t used vec3 or mat3 before, but I’ll get back when I try that!