Results 1 to 2 of 2

Thread: Move the camera to the direction it points

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    16

    Move the camera to the direction it points

    Hi
    This may be a very basic question, but I do not know how to do this.
    I am trying to make a fps type camera and I am using following code to move and setting orientation of the camera

    Code :
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();
     
    glRotatef(rollValue, 0, 0, 1);	// roll
    glRotatef(yawValue, 0, 1, 0);	// yaw
    glRotatef(pitchValue, 1, 0, 0); // pitch
    glTranslatef(x, y, .z); // to move
     
    // then draw shapes

    The problem is I can move the camera but not to the direction it points to.
    Could you please tell me how to do that?

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Feb 2006
    Location
    Sweden
    Posts
    744

    Re: Move the camera to the direction it points

    there are basically two ways, the first one is to use basic trigonometry like this

    #define PI_OVER_180 0.017453292519943295769236907684886

    x=((float)sin(-yawValue/PI_OVER_180)*forward)-((float)sin(+(yawValue+90)/PI_OVER_180)*strafe);
    y=((float)sin(pitchValue/PI_OVER_180)*forward)+up;
    z=(-((float)cos(-yawValue/PI_OVER_180)*forward))-((float)cos(+(yawValue+90)/PI_OVER_180)*strafe);

    or you could get the modelview matrix and then multiply it with the vector you wish to move in (with the fourth value being 0) and get the result directly.

Similar Threads

  1. Replies: 10
    Last Post: 10-16-2016, 01:53 PM
  2. move camera in the direction its looking
    By xorserq in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 06-01-2014, 08:42 PM
  3. Replies: 4
    Last Post: 10-02-2013, 02:59 PM
  4. Camera move along points defined
    By sodx999 in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 08-19-2003, 11:32 PM
  5. Camera move along points defined
    By sodx999 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-18-2003, 05:29 PM

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