PDA

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

KrisPL
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;
glLoadIdentity();
gluLookAt(x,y,z,x+lx,y+ly,z+lz,0.0f,1.0f,0.0f);
}

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?

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

mobeen
12-28-2010, 07:48 PM
Hi,
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,

gluLookAt(x+tx,y,z+tz,tx,0,tz,0.0f,1.0f,0.0f);
This will strafe the camera in the XZ plane. If you allow the user to move the height then add the height like this,

gluLookAt(x+tx,y+ty,z+tz,tx,ty,tz,0.0f,1.0f,0.0f);
Hope this helps,
Mobeen