将 3D Angle/vector(不是位置)转换为 2 个角度(Angle,Pitch)

Convert 3D Angle/vector (not position) to 2 angles (Angle, Pitch)

我 mapping/modding 主要是在名为 Doom 2 的旧游戏中,但在端口中,在编写脚本时我遇到了 3D 世界中的角度问题。 screenshot of model with this problem. Note: Red points are the real and correct normal angles, and the Arrows are my attempt to convert these real 3D angles to doom's angle and pitch but failed and only facing up or down but not right or left... 例如,我这里有一个 MD3/Model/3D 某个对象的模型,我想显示他的网格顶点法线以指向它们所面对的确切位置(法线的真实正确角度)。但我只设法(可能)只得到一个俯仰角(或 Z 角),“角度”是指当它向左或向右旋转 360 度时,游戏中也有“滚动”角,但我不知道不认为它重要。

我想做的是从 Real 3D Angle 转换为 Doom's Angle and Pitch,但我对三角学和它的公式一无所知...我认为这对知道这些的人来说很容易东西。

注意: 真正的 3D 角度值是从 -1 到 1 浮点数。 厄运的角度从 0 到 360 浮动,俯仰从 -90 到 90 浮动。

这是我转换为厄运的角度和俯仰(上下左右角度)的代码:

vector3 ConvertAngletoDoomAngle(vector3 ang) {
    return (
        0,      //angle (this one i have problem with, i want to make arrows turn correctly left and right)
        0,      //roll (this is not important and i bet it's harder to get...)
        90 * ang.z          //pitch (where arrows points down and up was looking kinda correct...)
    );
}

我认为将角度转换为二维角度需要“cos”和“sin”...我不知道:( 目标:这些箭头必须朝向红点。

我想你给的是表面法向量n,用笛卡尔坐标系xyz描述向量方向的分量.

并且你想求关于xz平面的方位角φ,以及倾角ψxz 平面上方。

这些首先被描述为绕 y 轴的旋转,然后是绕旋转后的 z' 轴的旋转

这个序列导致

nx = cos(φ)
ny = sin(φ)*sin(ψ)
nz =-sin(φ)*cos(ψ)

逆过程求角度的方法如下

φ = atan2(-nz, sqrt(nx^2+ny^2))
ψ = atan(ny/nx)

其中atan2(dy,dx)是全象限反正切函数,atan(r)是标准反正切函数。