Quaternion * Vector3 * Distance

ε祈祈猫儿з 提交于 2020-11-29 09:58:12

问题


Could someone please help me understand the result of the following multiplications?

In the Unity VR samples project, the following two lines are used:

Quaternion headRotation = InputTracking.GetLocalRotation(VRNode.Head);

TargetMarker.position = Camera.position + (headRotation * Vector3.forward) * DistanceFromCamera;

I can understand the first line - how the user's head rotation is calculated and stored in headRotation which is a Quaternion.

I can also understand that the TargetMarker's position should be calculated by adding the Camera's position to something. What is this something?

Most importantly, how does the result of (headRotation * Vector3.forward) * DistanceFromCamera is a position?


回答1:


headRotation * Vector3.forward return a Vector3 in the direction forward of your Quaternion headRotation. (So the direction you are facing)

As Vector3.forward is the vector normalized (0, 0, 1) when you multiply it by your Quaternion you have a vector of length 1 with the same direction of your head.

Then when you multiply it by the distance between your marker and your camera you now have a vector of the same length and direction that between your camera and your marker.

Add it to your current camera position and you now have the position of your marker.



来源:https://stackoverflow.com/questions/42255348/quaternion-vector3-distance

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!