问题
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