Java 边界球体碰撞不起作用
我试图在我的LWJGL游戏中实现模型之间的碰撞,但似乎对象处于不断的碰撞中,即使碰撞半径仅为0。我已将碰撞代码放在下面,并提供了一个链接,指向我用来帮助处理边界球体碰撞的源Java 边界球体碰撞不起作用,java,3d,collision-detection,collision,Java,3d,Collision Detection,Collision,我试图在我的LWJGL游戏中实现模型之间的碰撞,但似乎对象处于不断的碰撞中,即使碰撞半径仅为0。我已将碰撞代码放在下面,并提供了一个链接,指向我用来帮助处理边界球体碰撞的源 package model; import org.lwjgl.util.vector.Vector3f; public class BoundingSphere { private Vector3f mid = new Vector3f(); private float radius; pu
package model;
import org.lwjgl.util.vector.Vector3f;
public class BoundingSphere {
private Vector3f mid = new Vector3f();
private float radius;
public BoundingSphere(Vector3f midpoint, float radius) {
this.mid = midpoint;
this.radius = radius;
}
public boolean isColliding(BoundingSphere other){
float diffX = (other.mid.x - mid.x);
float diffY = (other.mid.y - mid.y);
float diffZ = (other.mid.z - mid.z);
float diffXSquared = (float) Math.pow(diffX, 2);
float diffYSquared = (float) Math.pow(diffY, 2);
float diffZSquared = (float) Math.pow(diffZ, 2);
float radiusSums = (other.radius + radius);
float radiusSumsSquared = (float)Math.pow(radiusSums, 2);
if (diffXSquared + diffYSquared + diffZSquared > radiusSumsSquared){
return true;
}
else{
return false;
}
}
}
您似乎已将该条件颠倒过来。只有在以下情况下才会发生碰撞:
((x2 + y2 + z2) <= r2)
((x2+y2+z2)非常感谢!我在白板上画了出来,果然,当两个圆之间的距离小于其半径的平方时,就会发生碰撞!