Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: setting up direction to projection

  1. #1
    Junior Member Newbie
    Join Date
    May 2008
    Location
    Manheim, Pa
    Posts
    23

    setting up direction to projection

    I have been trying to devolve a system for a 3d game that will allow direction like in a fps. I have been able to get some of this done myself. The code below is part of it, the only thing I am having issues at it xto,yto,zto (the 4th, 5th, and 6th arguments in the function). I understand what they do in code but I have no idea how to use them to setup a 360 direction system. The code below is a test code I setup and I was wondering if that was a smart way of doing it. If not can anyone lend a idea. Thanks

    Code :
    gluLookAt(cord_x,cord_y+5.0f,cord_z,cord_x-sin(yaw*pi/180),cord_y+5.0f,cord_z+cos(yaw*pi/180),0.0f,1.0f,0.0f);

  2. #2
    Junior Member Newbie
    Join Date
    Jul 2008
    Posts
    5

    Re: setting up direction to projection

    Shouldn't you be more worried about the first 3 arguments?
    They are the ones that determine the direction you look at.

    Only thing you can do with the 4 till 6the argument is determining the camera position.

  3. #3
    Junior Member Newbie
    Join Date
    May 2008
    Location
    Manheim, Pa
    Posts
    23

    Re: setting up direction to projection

    Actually the first 3 arguments set the cameras location, the next 3 are the x,y, and z of where the camera is looking. For a while I have been using a code like this:

    Code :
    gluLookAt(cord_x,cord_y+5.0f,cord_z,eye_x,eye_y,eye_z,0.0f,1.0f,0.0f)

    The problem with this code is that it has no direction to it. It used the variables eye_z, eye_y, and eye_z to choose the point at which the camera is looking. What I need is a step up from this kind of code, one where the cameras 360 direction is set on a variable. In other words a first person shooter style of camera. Any idea what I would need to look into to do this?

  4. #4
    Junior Member Regular Contributor
    Join Date
    Dec 2007
    Location
    Brighton, UK
    Posts
    156

    Re: setting up direction to projection

    Why wouldn't you keep a direction variable, and then add it to your eye position to find where the camera is looking? There are tons of tutorials for cameras on the net, you could check some out.

  5. #5
    Junior Member Newbie
    Join Date
    May 2008
    Location
    Manheim, Pa
    Posts
    23

    Re: setting up direction to projection

    Meh it works in Game Maker. If that does work what will? Or can I at least get the name of the camera system I am trying to form.

  6. #6
    Senior Member OpenGL Pro Zengar's Avatar
    Join Date
    Sep 2001
    Location
    Germany
    Posts
    1,979

    Re: setting up direction to projection

    Assuming the camera angle of zero corresponds to the (0, 0, 1) direction vector; you can get the direction vector by rotating (0, 0, 1) x degrees around the up vector (0, 1, 0). The camera target is then simply camera position + direction (or compute the camera matrix yourself – see gluLookAt documentation for formula).

  7. #7
    Senior Member OpenGL Guru zed's Avatar
    Join Date
    Jul 2000
    Location
    S41.16.25 E173.16.21
    Posts
    2,609

    Re: setting up direction to projection

    First Person viewpoint

    keep pitch_rot between > -90 && < 90 / -PI -> PI

    dir.x = ( sin( heading_rot ) * cos( pitch_rot ) );
    dir.z = ( cos( heading_rot ) * cos( pitch_rot ) );
    dir.y = ( sin( pitch_rot ) );

  8. #8
    Junior Member Newbie
    Join Date
    May 2008
    Location
    Manheim, Pa
    Posts
    23

    Re: setting up direction to projection

    So pitch_rot would be for vertical direction and heading_rot is for horizontal rot?

    Also how exactly would I put this into the function gluLookAt? Would dir.x, dir.y, and dir.z go in for centerX, centerY, and centerZ of the function gluLookAt?

  9. #9
    Junior Member Regular Contributor
    Join Date
    Dec 2007
    Location
    Brighton, UK
    Posts
    156

    Re: setting up direction to projection

    you should add this direction to your eye position to compute the "lookAt" point :

    gluLookAt(eye_x,eye_y,eye_z,eye_x + dir.x,eye_y +dir.y,eye_z+dir.z,up_x,up_y,up_z)

    After all, you want to look at a point which lies from your eye position in the direction 'dir'.

  10. #10
    Intern Contributor
    Join Date
    Jul 2008
    Posts
    89

    Re: setting up direction to projection

    You should just look at this code...it works and I've used it myself:

    http://www.codesampler.com/oglsrc/og...l_fps_controls

    Here is another:
    http://www.geocities.com/fragtheplan...GL/Camera.html

Posting Permissions

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