gpt4 book ai didi

android - android中的交叉数算法

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:19:23 26 4
gpt4 key购买 nike

我正在为 Android 构建类似小行星的游戏。我正在阅读“Android 游戏编程示例”。我正在实现交叉数算法。该应用已完成并且可以运行,但我不明白这部分代码:

if (((cp2.currentPoint.y > cp1.currentPoint.y) !=
(cp2.currentPoint2.y > cp1.currentPoint.y)) &&
(cp1.currentPoint.x < (cp2.currentPoint2.x - cp2.currentPoint2.x) *
(cp1.currentPoint.y - cp2.currentPoint.y) / (cp2.currentPoint2.y - cp2.currentPoint.y) + cp2.currentPoint.x))

其中 cp1.currentPoint 是第一个对象的第一个顶点(所以它是一个点),cp2.currentPoint 是第二个对象的第一个顶点,cp2。 currentPoint2 是第二个点。这两点构成了我们的路线。

这部分我不明白:

(cp2.currentPoint2.x - cp2.currentPoint2.x)

这样做的结果总是 0,那我为什么要这样做呢?

最佳答案

正如您所说,它始终为零,因此您不需要它。也许其他一些值(value)观应该存在,但它被遗忘了。所以只需将其取出来清除您的代码即可。

关于android - android中的交叉数算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37644542/

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