Results 1 to 4 of 4

Thread: Freelook, a Phenomenon to me!

  1. #1
    Senior Member Regular Contributor
    Join Date
    May 2002
    Posts
    189

    Freelook, a Phenomenon to me!

    Ok so I'm trying to do freelook. For those of you unfamiliar with the concept, its found in games like Halflife, Quake, and virtually every other first person shooter. The way it works is the mouse changes the viewing and then the keyboard buttons will move towards the viewing point, perpendicular to the viewing point, or away from the viewing point (WSAD).

    After thinking long and hard about this with my Algebra 2 level math skills, I've came up with this solution. I have two angles, one for looking left and right, one for looking up and down. When the mouse moves up, the second angle variable is increased, when its moved down the second angle variable is decreased and so on.

    Right now I'm just trying to get it so changing my viewing works (using the mouse, not the keyboard). Here's my mathematical analysis of the situation:

    * 1
    | \
    | \
    | 2 \ 3
    *------*
    Offset

    Point 1 is the viewing, point 2 is the position, and point 3 is the offset (2 for right now). I'm thinking since I have two angle variables, I'll need to have two of those triangles (to satisfy the 3 dimensions).

    When the mouse is moved UP, the viewing angle 2 is incremented. Then later I would do something like viewing.x += cos(angle2) * OFFSET (2)
    the viewing.y += sin(angle2) * OFFSET (2)

    I know thats how it works when dealing with a two dimensional plane, but how do I deal with the 3 dimensional movement? Thanks a bunch and especially thanks for listening to my unclear rambling.

  2. #2
    Senior Member Regular Contributor
    Join Date
    May 2002
    Posts
    164

    Re: Freelook, a Phenomenon to me!

    You are on the right track.
    Refer to the left/right angle as yaw and the up/down angle as pitch. As the mouse moves, increment/decrement yaw/pitch accordingly. Then, before you render:

    glRotatef( -Pitch, 1.0, 0.0, 0.0 );
    glRotatef( -Yaw, 0.0, 1.0, 0.0 );

    Good Luck and Happy Coding!

  3. #3
    Senior Member Regular Contributor
    Join Date
    May 2002
    Posts
    189

    Re: Freelook, a Phenomenon to me!

    The problem there is I'm going with a gluLookAt approach for simplicity. So how do I effectively do the same with gluLookAt as you just did with rotation?

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jun 2000
    Location
    Shreveport, LA, USA
    Posts
    1,502

    Re: Freelook, a Phenomenon to me!

    Think of it this way, your 2 angles define a point on a sphere centered about the viewer. You just need to find that point on the sphere and use that as the point to look at.

Similar Threads

  1. Replies: 8
    Last Post: 11-15-2017, 01:29 AM
  2. Funny phenomenon(maybe related to perpective?)
    By in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 12-29-2005, 07:55 AM
  3. Strange specular phenomenon
    By Ninja in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 09-25-2002, 05:43 AM
  4. HELP! - FreeLook Camera
    By PSI in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 09-03-2002, 08:36 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