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