View Full Version : gluLookAt strafe (moving camera left right)

12-17-2010, 11:25 AM
Hello! I'm quite new to OpenGL. I think some basics I've already mastered, however gluLookAt still gives me some problems. I'm writing in C++ and my problem is to move the camera left right on flat surface (like in any fps game, where you strafe left or right).
I already found solution for moving forwards and backward on flat surface. It is something like this:

void moveCam(int i){
x = x+i*(lx)*0.2;
z = z+i*(lz)*0.2;

Where i is change in movement.
I tried to modify this in any reasonable way I could think of to obtain effect I desire, however with no results.
Can someone help me?

12-28-2010, 10:41 AM
Nobody knows the solution to my problem?

12-28-2010, 07:48 PM
You could do something like this, create two variables tx,tz to store the movement amount based on the user input something like this inside your keyboard func. ,

case 'w': tz-=0.1f; break;
case 's': tz+=0.1f; break;
case 'a': tx-=0.1f; break;
case 'd': tx+=0.1f; break;
Then, in your render function use gluLookAt like this x,y,z are the initial positions where your camera is placed,

This will strafe the camera in the XZ plane. If you allow the user to move the height then add the height like this,

Hope this helps,