View Vector

I want to be able to specify my view direction as a vector, but really dont have a clue how(well I thought I had a clue untill it didnt work =) ).
Any info would be helpful, I dont mind how straight to matrix or to a quaternion or to plain old rotation angles. Just some idea of how this can be acccomplished would be great.
Thanks.

I’m gonna not say “there is no camera in
OpenGL; therefore no viewing vector” because
I’m assuming you’re faking it by pre-
multiplying the modelview transform (rather
than doing it in the projection, which is a
bad idea).

You don’t need one vector; you need two.
One for “which direction to look” and one
for “up” (the “right” vector is the cross
of these).

There are two ways.

  1. If you’re in a 6DOF
    world with no gravity, it’s easiest to just
    keep your “view vector” as an actual “up”
    vector and an amount of rotation around that
    vector. When rolling/pitching you transform
    the “up” vector by the appropriate amount,
    and when yawing you add/subtract to the
    amount of rotation.

  2. If you’re “walking” in a world with
    gravity, and gravity is “down” in the -y
    direction, you can project your view vector
    to the XZ plane (which means setting y==0)
    and find the rotation around the y axis using
    trigonometry; that’s your first rotate. Then
    find the up/down angle from the X,0,Z point
    to the X,Y,Z point, again using trigonometry.
    Rotate around your “right” vector by that
    amount. If you have any “roll” you would want
    to apply that last, around the actual view
    vector. But the way matrix multiplies work
    you actually write it from last to first.

Good luck!

Thanks =)