[英]Euler Angles Y value is affected by X and Z values - how do I zero them out to get a "truthful" y value?
The effect I'm trying to achieve is to have an arrow pointed out from the camera's pointOfView
position, aligned with the scene (and gravity) on the x and z axis, but pointing in the same direction as the camera.我试图实现的效果是从相机的
pointOfView
位置指向一个箭头,在 x 和 z 轴上与场景(和重力)对齐,但指向与相机相同的方向。 It might look something like this:它可能看起来像这样:
Right now, I have its euler angles x
and z
set to 0
, and it's y
set to match that of the ARSCNView.pointOfView.eulerAngles.y
.现在,我将其欧拉角
x
和z
设置为0
,并将y
设置为与ARSCNView.pointOfView.eulerAngles.y
欧拉角相匹配。 The problem is that as I rotate the device, the eulerAngles.y
can end up having the same value for different points.问题是,当我旋转设备时,
eulerAngles.y
最终可能eulerAngles.y
不同的点具有相同的值。 For example, facing the device in one direction, my eulerAngles
are:例如,面向一个方向的设备,我的
eulerAngles
是:
x: 2.52045, y: -0.300239, z: 3.12887
Facing it in another direction, the eulerAngles
are:面向另一个方向,
eulerAngles
是:
euler angles x: -0.383826, y: -0.305686, z: -0.0239297
Even though these directions are quite far apart, the eulerAngles
is still pretty much the same.尽管这些方向相距很远,但
eulerAngles
仍然几乎相同。 The different x
and z
values mean the y
value doesn't represent which direction the device is facing.不同的
x
和z
值意味着y
值不代表设备面向的方向。 As a result, my arrow follows the camera's heading to some point, and then starts rotating back in the opposite direction.结果,我的箭头跟随相机的方向到达某个点,然后开始向相反的方向旋转。 How can I zero-out the
x
and z
values in a way that I'll get a truthful y
value, that I can then use to orient my arrow?如何将
x
和z
值归零,以便获得真实的y
值,然后我可以用它来确定箭头的方向?
Do not use euler angles to detect 'real' or 'truthful' values.不要使用欧拉角来检测“真实”或“真实”值。
Those values are always correct.这些值总是正确的。 To work with rotation you have to use either matricies or quaternions.
要使用旋转,您必须使用矩阵或四元数。
Remember.记住。 It is possible to define lots of 'euler angles' using matrix.
可以使用矩阵定义许多“欧拉角”。
Each euler angle is relative to the previous one.每个欧拉角都相对于前一个。
SceneKit applies these rotations in the reverse order of the components:
SceneKit 以与组件相反的顺序应用这些旋转:
1. first roll 2. then yaw 3. then pitch
So, to calculate the value you angle I would suggest to calculate the vector and its projection to Oxy plane.因此,要计算角度值,我建议计算向量及其到 Oxy 平面的投影。 This angle is not 'euler' angle.
这个角度不是“欧拉”角。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.