Sign in to follow this  
sakky

3D Camera

Recommended Posts

I need a FPS type camera for my application. I figured out how to translate, rotate the viewer, but how do I figure the UP vector? I think it's perpendicular to the EYE vector correct? I forgot the formula to find the perpendicular vector of a vector. From what I remember, its something like x' = x + -y or something of that sort. I'm still not really sure IF I'm figuring the camera correctly, am I?

Share this post


Link to post
Share on other sites
You use the CrossProduct to determine a vector perpendicular to a plane - however it requires two vectors to determine the plane. In your FPS can the player ever go upside down - I mean are they always standing upright? If so then the solution is to force the up vector to always be 0,1,0 and then togther with the eye vector you can calculate your right vector. You then have everything needed to do a FPS camera that can pitch and yaw (but not roll).

Share this post


Link to post
Share on other sites
In a first person shooter, yaw is always about 0,1,0 in relation to the
camera's position. Unlike a flight simulator, where yaw makes the plane
turn to ITS right, as a FPS camera aims up, yaw should start to behave like roll
in a way. Rotate the camera's forward vector around 0,1,0 for yaw. Use the
cross product between 0,1,0 and the new forward to find the right vector.
Then rotate the forward vector around the right vector for pitch. The up vector
is constant.

Share this post


Link to post
Share on other sites
I have a very different opinion about the whole camera thing.

First of all, I think the whole thing about the up vector always being constant is COMPLETELY wrong. How can it always eb constant. When you tilt your head up, your head's whole coordinate frame rotates - including the up vector.

Therefore here is how I have approached this problem and have never ran into deciding how to manage the up vector.

Represent your camera with one matrix. You may open up any interface, but under the hood, represent the oriantation + position of the camera with just 1 matrix.

[rx ry rz 0]
[ux uy uz 0]
[vx vy vz 0]
[px py pz 1]

where x y and z are the three components, and
r= right, u = up, v = view, and p = position.

Now say you want to look in certain direction. Compute a rotation matrix (figure out what axis, and how much angle) that is required to line up your view vector (== 3rd row) in that direction. (If you do not know how to, let me know in another question).

And now just multiply this matrix with your camera matrix. (Do pre multiply so that camera position does not get changed). As a result you will get a new camea matrix, with ALL of its vectors updated correctly. You need not worryabout updating the up and right vector individually.

Infact, as so many books say, (and if I may be bold enough to add, quite incorrectly as well), you can not rotate past 89 or so deg in up direction. This way you can easily make a camera that can rotate full 360 degrees.

Share this post


Link to post
Share on other sites
What if I just roate the UP vector every tiem I rotate the EYE vector? Wouldn't that work if both vectors were initialized properly?

What about moving? For example, I'm looking at the origin and I'm standing at POS(10, 0, 10). I need to move forwards by 2.

I tried to figure this out by using physics distance formula:

P' = P + (E * T) + (0.5 * A * T^2)

P' = new psoition
P = old position
E = eye
T = time and is always 1 in my case

So if I wanted to move backwards A = -2 and to move forwards A = 2. So then my position would then be POS(11, 1, 11)! Why am I movin backwards and not forwards?

What if I subtracted the POS and EYE vectors. If it negative then multiply A by -1 or 1 if its positive. But that owuld work fine until I looked at (0, 0, 0). Man I'm never going to figure this out!

Share this post


Link to post
Share on other sites
Alright, are you directly modifying the view matrix's right forward and up?
Because if that's the case, then yeah, the up vector shouldn't stay constant.
Otherwise, what I said was exactly the same as what you said, except that you
now have to keep your own set of rotation axes. You always rotate around
a constant up direction in an FPS. That is a FACT. The pitch vector rotates
around it, and the forward vector rotates around it. The yaw rotation vector
never changes. However to actually generate a matrix, the up vector should
be calculated each time. I was talking about the working vectors, the ones
that you actually use to generate an axis rotation.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this