Sign in to follow this  

DirectX Camera & Mesh

This topic is 4301 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)
RenderMesh2

Share this post


Link to post
Share on other sites

This topic is 4301 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this