# DirectX Camera & Mesh

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

## Recommended Posts

Okay, I have a Mesh (Mesh1) that is Stationary at 0,0,0. I have a camera that rotates any direction around Mesh1 by using LookAtRH(camPosition, meshPosition, camUp). What I want is for another Mesh (Mesh2) to ALWAYS float just in front of the camera, always aimed at Mesh1, just like the camera. I can't seem to get that to work, though. I've tried device.transform.world = Matrix.LookAtRH(camPosition, meshPosition, camUp). But Mesh2 is on the opposite side of Mesh1, and rotates in the opposite direction! And never even points up! I was just wondering if anyone has run into this before.

##### Share on other sites
Try the following :

Save the rotation angle of the camera and use it to rotate mesh2 (when mesh2 is first places at 0,0,0, thus rotating around its center),
then save the camera position (edit this position so mesh2 will be a bit infront of the camera as you wanted) to create a transformation matrix for mesh2 position,
then multiply the rotation matrix with the transformation matrix (MAKE SURE THE ROTATION IS FIRST IN ORDER OF MULTIPLICATION) and use the result matrix as the mesh2 world matrix.

In pseudo-code :

MATRIX matRot, matPos, matResult;
matRot = CreateRotMatrix(cameraAngleX, cameraAngleY, cameraAngleZ);
matPos = camerapos + modifier
matResult = matRot;
matResult *= matPos;

SetTransform(WORLD, matReulst)
RenderMesh2

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633705
• Total Posts
3013464
×