gpt4 book ai didi

rotation - Libgdx 两点度数计算

转载 作者:行者123 更新时间:2023-12-04 02:10:35 25 4
gpt4 key购买 nike

这里我正在计算 Actor 和触摸点之间的度数,并将这个度数作为旋转角度传递给 Actor 。我希望 Actor 应该指向手指触摸或手指拖动的方向。(考虑我在路上通过手指触摸和拉公共(public)汽车拖动)

float degrees = (float) ((Math.atan2(touchPoint.x - crocodile.position.x, -(touchPoint.y - crocodile.position.y)) * 180.0d / Math.PI));

其计算度恰到好处。只是有时在两者之间它会给出不同的程度。所以当结果确实与预期不同时,我的 Actor 会波动。

我打印的结果是:

Blockquote

    degree is :: 141.93233
degree is :: 180.0
degree is :: 180.0
degree is :: 158.61426
degree is :: 90.0
degree is :: 180.0
degree is :: 180.0
degree is :: 90.0
degree is :: 180.0
degree is :: 180.0
degree is :: 180.0
degree is :: 141.93057
degree is :: 180.0
degree is :: 180.0
degree is :: 180.0
degree is :: 141.93306
degree is :: 180.0
degree is :: 180.0
degree is :: 141.93257
degree is :: 180.0
degree is :: 180.0
degree is :: 141.93134
degree is :: 141.93257
degree is :: 180.0
degree is :: 180.0
degree is :: 180.0
degree is :: 141.93134
degree is :: 180.0
degree is :: 180.0
degree is :: 141.93306
degree is :: 180.0
degree is :: 180.0
degree is :: 141.93257
degree is :: 180.0
degree is :: 141.93134
degree is :: 180.0
degree is :: 180.0
degree is :: 141.93257
degree is :: 180.0
degree is :: 180.0
degree is :: 141.93257
degree is :: 180.0
degree is :: 141.93134
degree is :: 180.0
degree is :: 141.93257
degree is :: 180.0
degree is :: 180.0
degree is :: 141.93008
degree is :: 180.0
degree is :: 180.0
degree is :: 141.93306
degree is :: 180.0
degree is :: 180.0
degree is :: 141.93257
degree is :: 180.0
degree is :: 180.0
degree is :: 180.0
degree is :: 141.93134
degree is :: 180.0
degree is :: 180.0
degree is :: 180.0
degree is :: 180.0
degree is :: 180.0
degree is :: 180.0
degree is :: 180.0

现在,180 和 141 为什么会随这些值波动。考虑到我期望 141 不断或 180 不断我需要改变上面的公式。

最佳答案

第一个参数必须是y,第二个参数是x。

double atan2(double y, double x)

Atan2实际上是y/x的指定反正切函数

因为通常第一个参数取y。

有时当你交换 x 和 y 时你可以获得适当的度数,因为在某些边界如 x<0 和 y<0 中交换与否并不重要。

Look here for more explanation

关于rotation - Libgdx 两点度数计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18333314/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com