本文介绍了一个BoundingBox的和libgdx一球之间的碰撞检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我libgdx游戏我有3D BoundingBoxes和球在地图和球员的对象。我想要计算它们是否以正确地模拟这些对象的运动相互碰撞。用什么方法,我可以用它来计算这些对象是否发生碰撞/相交?
In my libgdx game I have 3D BoundingBoxes and Spheres for map and player objects. I want to calculate whether they collide with each other in order to properly simulate the motion of these objects. What method can I use to calculate whether these objects collide/intersect?
推荐答案
您可以使用下面的方法:
You can use the following method:
public static boolean intersectsWith(BoundingBox boundingBox, Sphere sphere) {
float dmin = 0;
Vector3 center = sphere.center;
Vector3 bmin = boundingBox.getMin();
Vector3 bmax = boundingBox.getMax();
if (center.x < bmin.x) {
dmin += Math.pow(center.x - bmin.x, 2);
} else if (center.x > bmax.x) {
dmin += Math.pow(center.x - bmax.x, 2);
}
if (center.y < bmin.y) {
dmin += Math.pow(center.y - bmin.y, 2);
} else if (center.y > bmax.y) {
dmin += Math.pow(center.y - bmax.y, 2);
}
if (center.z < bmin.z) {
dmin += Math.pow(center.z - bmin.z, 2);
} else if (center.z > bmax.z) {
dmin += Math.pow(center.z - bmax.z, 2);
}
return dmin <= Math.pow(sphere.radius, 2);
}
它的后
有关箱球相交测试的简单方法
由吉姆·帕特
从图形宝石,学术preSS,1990年
样本C code,对于它可以在这里找到:
The sample C code for which can be found here: http://www.realtimerendering.com/resources/GraphicsGems/gems/BoxSphere.c
这篇关于一个BoundingBox的和libgdx一球之间的碰撞检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!