0
我试图在我的LWJGL游戏中实现模型之间的碰撞,并且看起来物体处于持续碰撞中,即使碰撞半径仅为0.我已经将碰撞的代码放在下面,以及我用来帮助解决边界球碰撞的来源的链接。边界球碰撞不起作用
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;
}
}
}
谢谢你这么多
:据相撞只有!我把它画在白板上,果然,当两个圆之间的距离小于它们的半径的平方时,就会发生碰撞! – user3140916 2014-10-20 04:56:23