3rd Person Camera Math

Started by
0 comments, last by Alan Kemp 21 years, 5 months ago
Hi, I am trying to get a sort of third-person camera working. The exact effect I am try to achive is like the camera in Neverwinter Nights, or Warcraft 3. Basically my world is aligned to the x/z axis (and is pretty much flat). I have a point on that axis which I want to look at. I also have a distance value (the distance back I want the camera to be from the target coordinate), a pitch angle (the angle, from verticle (pointing down the y-axis) to flat (looking along the x/z plane), and a rotation value (the rotation around the y-axis). The problem I am having is forming the required view matrix in direct3d. To calculate the cameras location I belive I can just: - Translate up the y-axis by the distance. - Rotate around the x-axis by the pitch angle. - Rotate around the y-axis by the rotation angle. - Translate by the objects offset from the origin. This gives me the camera position, and I have the look at point (the object on the x/z axis). To use the D3DXMatrixLookAtLH function I still need an up vector, and this is where I am stuck. How do I calulate the up vector from the information I have available? And have I made any assumption errors in my basic methodology? Thanks for your time, Alan
"There will come a time when you believe everything is finished. That will be the beginning." -Louis L'Amour
Advertisement
if you never look striaght down, just use the y-axis vector.
cross it with your lookat to get the true left right vector.
cross this new vector with the lookat to get you true up vector.
make sure to do your crossproducts in the correct order..right or left hand rules apply..just be consistent.

This topic is closed to new replies.

Advertisement