Jump to content
  • Advertisement
Sign in to follow this  
Happy SDE

Calculate target pos from transform matrix and distance to target.

This topic is 1058 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 a camera. It is specified by 4x4 matrix from XML.
Also I have scalar value “distance to target”.
I need to calculate the target pos.

First step: calculate cameraPos and direction quaternion.

XMMATRIX M = LoadMatrixFromXML();
XMVECTOR scale, rotationQuaternion, cameraPos;
XMMatrixDecompose(&scale, & rotationQuaternion, &cameraPos, M);
float distanceToTarget = LoadDistanceFromXML();

How to calculate position of a target, if I have cameraPos, distanceToTarget and rotationQuaternion?




I found many sources about what are quaternions, vectors, matrices and the math that is behind of them.
I found a lot of DirectXMath functions in MSDN.
But I can’t find a missed link between them: how to link math tasks like I am struggled with the DirectXMath library.

Can anyone share a good connection link between math tasks and how are they can be solved with DirectXMath library?

It might be a link to a book, url, ....

Thanks in advance.

Edited by Happy SDE

Share this post

Link to post
Share on other sites

So your camera is pointing at the target, you have it's rotation, you have the distance to the target and you have the camera's position?


It should be a case or rotating your 'forward' vector by the rotation, multiplying it by the distance and adding it to your camera's position. It's been a while since I have done anything like this but it should be along the lines of:


toTarget = rotation*forward;

targetPos = cameraPos + toTarget  * distancetoTarget;


Forward will be just whatever is considered the default forward in the space you use (I think for DirectX is would be (0, 0, 1) but I could be wrong. toTarget is just the forward vector rotated by the rotation.

Edited by Nanoha

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!