ATAN2用于右手坐标系的音高

发布于 2025-01-27 13:46:42 字数 1323 浏览 1 评论 0原文

        public double GetPitchToFace(double Z2, double Z1, double X2, double X1)
    {            
        double Arc;
        Arc = Math.Atan2(Z2 - Z1, X2 - X1);
        Arc = (Arc >= 0) ? Arc+Math.PI : (2 * Math.PI + Arc);      
        return Arc;
    }

我正在尝试计算游戏中玩家的正确音高,以便面对和前往航路点。

可能值得注意的是,游戏坐标系统是右撇子。

我已经确认AtAN2正在接收正确的值,但返回值不正确。

尽管路点高于球员,但似乎仍在向下返回。有时它会返回看似正确的音高 - 我怀疑当点 /播放器移动象限时,这可能会有什么可做的?

(次要旁注 - 我是2 * Math.pi的原因,如果arc是> = 0只是游戏商店和管理玩家音调更多信息的方式,可以在此处找到更多信息: pitch-gingame

这是上述手动计算的一个示例:

Atan2(Z2 - Z1, X2 - X1)
Arc = Atan2(179.7 - 157.9, -3457.1-(-3432.1))
Arc = Atan2(21.7,-25.3)
Arc = 2.4 Radians
Arc = Arc + PI (without adding PI we return 137.51 degrees this is the opposite angle I need so I add PI to flip it to the correct side or add 180 degrees)
Arc = 5.5 Radians
Arc = 315,127 Degrees (this is a downwards trend from the point meaning we still miss the end point)

这是上述点的真正不好图 “点示例”

请记住,这些点是绘制的,例如x,z而不是x,y

        public double GetPitchToFace(double Z2, double Z1, double X2, double X1)
    {            
        double Arc;
        Arc = Math.Atan2(Z2 - Z1, X2 - X1);
        Arc = (Arc >= 0) ? Arc+Math.PI : (2 * Math.PI + Arc);      
        return Arc;
    }

I am attempting to calculate the correct pitch of a player in-game in order to face and travel to a waypoint.

It might be worth noting that the games coordinate system is Right-Handed.

I've confirmed that ATan2 is receiving the correct values yet the return value is incorrect.

It seems to be returning a downward pitch despite the waypoint being above the player. Yet other times it returns the seemingly correct pitch - I suspect this might have something to do when the point / player shift quadrants ?

(Minor side note - the reason I am 2 * Math.PI if Arc is >= 0 is simply the way the game stores and manages player pitch more info can be found here :
Pitch-Ingame
)

Here is an example of the above manually calculated :

Atan2(Z2 - Z1, X2 - X1)
Arc = Atan2(179.7 - 157.9, -3457.1-(-3432.1))
Arc = Atan2(21.7,-25.3)
Arc = 2.4 Radians
Arc = Arc + PI (without adding PI we return 137.51 degrees this is the opposite angle I need so I add PI to flip it to the correct side or add 180 degrees)
Arc = 5.5 Radians
Arc = 315,127 Degrees (this is a downwards trend from the point meaning we still miss the end point)

Here is the really bad plot of the above pointsExample of points

Please keep in mind that the points are plotted such as X,Z not X,Y

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文