四元数 * Vector3 * 距离 [英] Quaternion * Vector3 * Distance

查看:34
本文介绍了四元数 * Vector3 * 距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮我理解以下乘法的结果吗?

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

在 Unity VR 示例项目中,使用了以下两行:

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;

我可以理解第一行 - 如何计算用户的头部旋转并将其存储在 headRotation 中,这是一个 Quaternion.

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

我也可以理解 TargetMarker 的位置应该通过将 Camera 的位置添加到某物来计算.这是什么东西?

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

最重要的是,(headRotation * Vector3.forward) * DistanceFromCamera 的结果如何是position?

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

推荐答案

headRotation * Vector3.forward 返回一个 Vector3 在你的 Quaternion headRotation 的前进方向.(所以你面对的方向)

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

作为 Vector3.forward 是向量归一化 (0, 0, 1) 当你乘以你的 Quaternion 你有一个 向量,长度1,头部方向相同.

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.

这篇关于四元数 * Vector3 * 距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆