Results 1 to 3 of 3

Thread: gluLookAt strafe (moving camera left right)

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2010
    Location
    Poland
    Posts
    2

    gluLookAt strafe (moving camera left right)

    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:
    Code :
    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?

  2. #2
    Junior Member Newbie
    Join Date
    Dec 2010
    Location
    Poland
    Posts
    2

    Re: gluLookAt strafe (moving camera left right)

    Nobody knows the solution to my problem?

  3. #3
    Senior Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Karachi, Pakistan
    Posts
    810

    Re: gluLookAt strafe (moving camera left right)

    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. ,
    Code :
    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,
    Code :
    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,
    Code :
    gluLookAt(x+tx,y+ty,z+tz,tx,ty,tz,0.0f,1.0f,0.0f);
    Hope this helps,
    Mobeen
    Regards,
    Mobeen

Similar Threads

  1. Replies: 0
    Last Post: 07-12-2018, 05:57 AM
  2. Moving a Camera using gluLookAt
    By codelyoko373 in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 03-07-2018, 06:26 PM
  3. "Moving camera forward" relative to world rotation using gluLookAt()
    By Mr_Rockers in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-27-2015, 05:18 PM
  4. creating up/down/left/right keys by moving the camera
    By cg-hci_novice in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 11-09-2003, 10:00 PM
  5. moving left & right glulookat
    By imported_robert in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 01-02-2002, 11:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean