Jump to content
  • Advertisement
Sign in to follow this  
deathtrap

Cant get camera to stay behind object

This topic is 4476 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

I have an object in space with Position and Rotation vectors, and I have a camera object that has a Position vector only. I've tried for hours to find a solution but i'm stumped and this is my last resort. How can i get the camera to stay behind the object, looking at the object, regardless of which way the object is facing? edit: figured I would say what i'm already doing that doesnt work. DX.Vector3 rotation = boundEntity.Rotation; DX.Matrix translationFirst = DX.Matrix.Translation(ePos); DX.Matrix rotationCam = DX.Matrix.RotationZ(rotation.Z); DX.Matrix final = translationFirst * rotationCam; DX.Vector3 finalValue = DX.Vector3.TransformCoordinate(DX.Vector3.Empty,final); basically this is my final attempt, there were others which were equally unsuccessful. what i tried doing was getting a rotation and translation matrix and then transforming an empty (0 for all axes) vector by it. its behaving erratically though.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Is the rotation vector normalized??

Share this post


Link to post
Share on other sites
The rotation vector is just a Vector3 holding the rotation values in radians for each axes. Dont see how it could be normalized.

Share this post


Link to post
Share on other sites
I do this by using Sin and Cos to calculate the position of the camera, treating the position like a circle around the object, the radius of this circle representing the distance away from the object. The same can then be done for the camera target, only at a different radius and the same Angle + 180 degrees (so that the camera is looking to the other side of the object).

If you really need I can post an example, but its rather specific to my camera class so may be hard to understand.

Share this post


Link to post
Share on other sites
Use the D3DXMatrixLookAtLH() function to set your camera based on your object. Your object must have a world position, look vector, and up vector (just like your camera must have). Using the object, set the camera's position (pEye) using the object's look vector.

// position the camera 5 units behind the object
CameraPos = ObjectPos - ObjectLookVector * 5;

// position it 2 units above the object (if you want)
CameraPos = ObjectPos + ObjectUpVector * 2;

Then you can use the D3DXMatrixLookAtLH() function, using the CameraPos as pEye, the object's look vector as pAt, and the object's up vector as pUp.

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!