PDA

View Full Version : Freelook, a Phenomenon to me!

31337
12-31-2002, 04:59 PM
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.

azcoder
12-31-2002, 08:11 PM
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!

31337
01-01-2003, 01:50 AM
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?

DFrey
01-01-2003, 08:27 AM
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.