I need to know how to make sure my camera is always directly behind my mesh.

I have it setup so if i press left or right the model will rotate left or right.

Now, the sceen shows a rotated mesh. But i want the screen to show as if the mesh hasnt rotated at all.

Meaning i want the camera to rotate with the mesh.

Im using MDX and C#.

Thanks in advanced

Re: Game Technologies: DirectX 101 Camera Behind Mesh


you have to apply the same rotations, that you apply to the mesh, to the camera so it will always be in the same place relatively to the mesh.

Re: Game Technologies: DirectX 101 Camera Behind Mesh

Robert Dunlop

Probably the easiest way to do this would be to use the Matrix.LookAtLH method, which allows you to specify a target and location for the camera. You could build these yourself from the information you have on your mesh's position or orientation, or you could generate them using the world matrix that you will be applying to the mesh, like this:

// mMesh is world matrix that will be used to render mesh
// transform 0,0,0 to get origin of mesh in world space
Vector3 vLookAt=Vector3.TransformCoordinate(new Vector3(0.0f,0.0f,0.0f),mMesh);

// transform 0,5,-10 to get coordinate a distance of 10 behind mesh origin
Vector3 vEye=Vector3.TransformCoordinate(new Vector3(0.0f,0.0f,-10.0f),mMesh);

// transform up vector to match orientation of mesh
Vector3 vUp=Vector3.TransformNormal(new Vector3(0.0f,1.0f,0.0f),mMesh);

// create and set the view transformation

// render the mesh