Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Camera

  1. #1
    Newbie Newbie
    Join Date
    Feb 2013
    Posts
    3

    Camera

    Hello, I have made a simple camera. The only problem is it doesn't follow the mouse. Ex: I will want to walk where I'm pointing and it walks forwards. After looking through tutorials I have found trig that I do not understand and did not use it. Can someone please help me with this? I currently have this:
    Code :
    Variables
     
    float camera_x = 0.5f; // X Axis
    float camera_y = -1.8f; // Depth
    float camera_z = -5.0f; // Y axis
    float pitch = 0.0f; // Camera mouse x
    float yaw = 0.0f; // Camera mouse y
    float roll = 0.0f; // Not used
     
    Key
     
    case 'w':
    camera_z += 0.1;
    break;
     
    case 's':
    camera_z -= 0.1;
    break;
     
    case 'a':
    camera_x += 0.1;
    break;
     
    case 'd':
    camera_x -= 0.1;
    break;
     
    Mouse
     
        if( 512 < x )
        {
     
            yaw += 1;
     
            if( 360 < yaw )
            {
                yaw = 0;
            }
     
        }
        if( 512 > x )
        {
     
            yaw -= 1;
     
            if( -360 > yaw )
            {
                yaw = 0;
            }
     
        }
     
        if( 384 < y )
        pitch += 1;
     
        if( 384 > y )
        pitch -= 1;
     
        if( x != 512 || y != 384 )
        glutWarpPointer(512,384);
     
    Actual camera function
     
      glRotatef(pitch, 1.0f, 0.0f, 0.0f);
      glRotatef(yaw, 0.0f, 1.0f, 0.0f);
      glRotatef(roll, 0.0f, 0.0f, 1.0f);
      glTranslatef(camera_x, camera_y, camera_z);

    I'm using the OpenGlut library.

    The mouse camera thing works. It's just the movement. If you want the full code reach me on steam ( Runedog48 ) or on my Yahoo ( runedog48 AT yahoo (DOT) com ) I do not want people taking my code that I've worked on.

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    590
    It's just the movement
    have you set a breakpoint in the keyboard event to be sure you are processing keys correctly.

  3. #3
    Newbie Newbie
    Join Date
    Feb 2013
    Posts
    3
    What I meant was that I want the movement to follow where you're looking. So if I press W it goes where I'm currently looking instead of forward.

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    590
    So if I press W it goes where I'm currently looking instead of forward.
    You mean along the axis from the camera to the taget.

    The easiest is to create your view matrix with the gluLookAt function modifing the eye and lookat positions

  5. #5
    Newbie Newbie
    Join Date
    Feb 2013
    Posts
    3
    Quote Originally Posted by tonyo_au View Post
    You mean along the axis from the camera to the taget.

    The easiest is to create your view matrix with the gluLookAt function modifing the eye and lookat positions
    Hmm, I didn't want to use gluLookAt but from what I've read it seems like the best way to do this.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •