Results 1 to 4 of 4

Thread: move camera in the direction its looking

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2014
    Posts
    9

    Question move camera in the direction its looking

    I am rotating the camera around itself (when the camera is located at (0,0,0)) using the following:
    Code :
    glRotatef(x_camera_angle, 1.0, 0.0, 0.0);
    glRotatef(y_camera_angle, 0.0, 1.0, 0.0);

    I now want to move the camera in the direction its looking. For example, I want to move the camera 5 units right and 3 units forward. How can this be done?

    I've searched a lot and couldn't find a satisfying answer. Any help would be highly appreciated!

  2. #2
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,294
    Get the modelview matrix, see the numbers. 3 of the numbers (a column or a row) from the 3x3 sub-section (of the 4x4 matrix) are what you're looking for. Right now I don't remember which row/column.

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2014
    Posts
    9
    I tried achieving it using the modelview matrix as shown here: http://stackoverflow.com/questions/1...tion-im-facing
    However, this just doesn't seem to work:
    Code :
    float mview[16];
    float front[4], up[4], left[4];
    glGetFloatv(GL_MODELVIEW_MATRIX, mview);
    left[0] = mview[0]; left[1] = mview[1]; left[2] = mview[2]; left[3] = 1.0;
    up[0] = mview[4]; up[1] = mview[5]; up[2] = mview[6]; up[3] = 1.0;
    front[0] = mview[8]; front[1] = mview[9]; front[2] = mview[10]; front[3] = 1.0;
     
    glTranslatef(front[0] * units_forward, front[1] * units_forward, front[2] * units_forward);

  4. #4
    Member Newbie
    Join Date
    Sep 2013
    Posts
    31
    Try with some trigonometry. If you know the angles you can simply use sin and cos to move camera.

Similar Threads

  1. Replies: 10
    Last Post: 10-16-2016, 01:53 PM
  2. Particles move toward a weird direction
    By A_Shuang in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 04-09-2015, 03:29 AM
  3. Replies: 4
    Last Post: 10-02-2013, 02:59 PM
  4. Move the camera to the direction it points
    By deshan in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-08-2011, 01:23 PM
  5. how can i move a sphere on curved direction?
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-21-2005, 03:11 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