• 10
• 9
• 12
• 14
• 14

Calculate target pos from transform matrix and distance to target.

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

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


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, ....

Edited by Happy SDE

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 on other sites

Thank you, Nanoha!

It works.

The vector (0,0,1) is exactly the view direction.