我对碰撞检测有一些疑问。我在Java中使用LWJGL进行游戏。我没有这方面的经验,并且一直在关注游戏核心的精简矩阵OpenGL教程。我有html,css,c ++,当然还有java的经验。 我一直在网上搜索,但没有找到任何有用的东西。
在我的游戏中实现3D碰撞检测的最简单方法是什么?
答案 0 :(得分:0)
我建议使用一个识别碰撞的3d引擎,就像jMonkey一样。 jMonkey可以使用LWJGL。这里有一个很棒的教程:http://wiki.jmonkeyengine.org/doku.php/jme3:beginner:hello_collision
如果你想像我一样自己滚动,我会在空间中创建一个3d点的哈希值。如果另一个对象具有相同的散列,则它几乎碰撞。
import static java.lang.System.out;
public class App {
public static int hash(float x, float y, float z) {
double hash = (((x * 31) + (y * 37) + (z * 41)));//31,37 and 41 are prime numbers
return (int) (hash);//multiplying the hash by 1000 for example may increase the accuracy significantly. Depends on the size of your space
}
public static void main(String[] args) {
for (float count = 0; count < 2; count += 0.01) {
out.println(hash(0, 0, count));
}
}
}
正如您所看到的那样,输出中的哈希显示紧密碰撞,因为计数增加0.01。
0
0
0
1
1
2
2
2
3
3
4
4
4
5
5
6
6
6
您可以修改素数以获得更高的准确度。