• Advertisement
Sign in to follow this  

Calculate target pos from transform matrix and distance to target.

This topic is 730 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

Part1

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();

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

 

=============================================

Part2.

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.

Quesion2:
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
Advertisement

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