Jump to content
  • Advertisement
Sign in to follow this  
sakky

3D Cameras

This topic is 4591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites


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);

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!