To main page |

gluLookAt and Strafe

Strafe (C++)

If you're using gluLookAt, you already have eye and center point, so to make a person strafe, you need to add or subtract right vector from both "eye" coordinate and center coordinate.

The right vector is modelview's 0,4,8 (see Right-up-back from modelview).

(Strafe right, In C++)
GLdouble m[16];
// strafe right
eye_x += m[0];
eye_y += m[4];
eye_z += m[8];
center_x += m[0];
center_y += m[4];
center_z += m[8];
gluLookAt(eye_x, eye_y, eye_z, center_x, center_y, center_z,
        up_x, up_y, up_z)
(Strafe left, In C++)
To strafe left, replace every "+=" with "-=" (i.e. do the same, but with opposite sign).

If that doesn't work correctly (because possibly you are working with transposed matrices), try m[0],m[1],m[2] instead of m[0],m[4],m[8] respectively.

up_x, up_y, up_z (up vector) is yours to calculate (you should have it already, if you are using gluLookAt).

Better way

Alternatively see Freelook spectator on how to do all this without gluLookAt, for mouselook and correct up vector.