3D Cameras

Started by
15 comments, last by Trienco 18 years, 4 months ago
Okay, I have a nice little class called CD3DCamera. I will use it for different types of cameras, a more or less base class so I don’t hae to keep writing the same code over and over again. I haven’t tested it yet because I don’t want to go to all the trouble and have something not work right, I want to make sure the math is correct first. I’m not that good and 3D math, a bummer because I use Direct3D all the time. 1. ) I need to make sure I’m calculating the UP vector correctly. I use the D3DXVec4Cross helper function to get the UP vector. I use the cross product of the look-at-target vector and the original up (0,1,0) vector. 2. ) To rotate, I use D3DXRotationAxis to rotate the camera on any axis I choose. I apply the rotation and use D3DXVec4TransformCoord with the look-at-target vector as the source and destination vector. Then I apply the cross product again to achieve the UP vector. Is this all correct?
Take back the internet with the most awsome browser around, FireFox
Advertisement
Hmm... no replys, I guess that means I'm correct then.
Take back the internet with the most awsome browser around, FireFox
Quote:Original post by sakky
1. ) I need to make sure I’m calculating the UP vector correctly. I use the D3DXVec4Cross helper function to get the UP vector. I use the cross product of the look-at-target vector and the original up (0,1,0) vector.


Well... if you take the cross product of the look-at-target vector (I'm assuming this is a vector from the position of the camera to the look-at target?) and the original up vector. How can you get the new up-vector??
The cross product of two vectors gives you a vector that is perpendicular to both of those vectors.

Which is saying. If you are at the origon and looking(0,0,1) with up(0,1,0) the cross product will return the right vector(1,0,0)


If your getting your look at vector by transforming a base vector by a matrix, then you can do the same for your up vector


vlook = {1,0,0}; //with no rotation look in the +x direction
vup = {0,1,0}; //with no rotation up is +y


vlook.tranform3(viewChangeMatrix);
vup.tranform3(viewChangeMatrix);

I have three vectors, position, look and up. I use the three in the D3DXMatrixLookAt function. I need the new up vector for the look. How do I get that then?
Take back the internet with the most awsome browser around, FireFox
Generally people use either the world up vector or the camera up vector

You can get the camera up vector by cross product of the forward and right vectors.
Quote:Original post by sakky
I have three vectors, position, look and up. I use the three in the D3DXMatrixLookAt function. I need the new up vector for the look. How do I get that then?


You say you have three vectors but then you ask how to calculate the 3rd? So what you mean is you have 2 points (which is really 1 vector) and you have to ask yourself how did you arrive at this vector. You need to take the same steps and apply them to your up vector to get accurate results. Or just set it to up (0,1,0) always and never look straight up or down.

If you calculate a matrix to get you to your final view vectors this is easy. Just transform your base view vectors by the same matrix and they are all the correct vectors. No cross product or anything.

As far as I know its mathematicaly imposible to calculate the up vector given only the lookFrom and lookAt positions. There is not enough data present.
Quote:Original post by sakky

2. ) To rotate, I use D3DXRotationAxis to rotate the camera on any axis I choose.



You mean D3DXMatrixRotationAxis? Then the resulting matrix contains all the vectors you need. If I remember correctly first row is right vector, second is up vector and third is look-at vector.
Quote:Original post by Zook
Quote:Original post by sakky

2. ) To rotate, I use D3DXRotationAxis to rotate the camera on any axis I choose.



You mean D3DXMatrixRotationAxis? Then the resulting matrix contains all the vectors you need. If I remember correctly first row is right vector, second is up vector and third is look-at vector.


Really? Like I said, I'm not to good with the math. I've been studying though.

Okay, I start off with Position(0,0,0), Look(0,0,1) and Up(0,1,0). So the camera is located at the origin looking straigh down the +Z axis, with the up vector, up, as usual. So to translate or rotate, I apply the same to all three vectors. When I translate, I add a vecctor or three floats to the position of the camera. I'm also suppose to do this to the look and up vectors too?

Okay then, so what ever I do to the one, I must to do to all others.
Take back the internet with the most awsome browser around, FireFox

This topic is closed to new replies.

Advertisement