Jump to content
  • Advertisement
Sign in to follow this  

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.

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

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 this post

Link to post
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)

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!