gpt4 book ai didi

java - 边界球碰撞不起作用

转载 作者:行者123 更新时间:2023-12-01 12:24:36 24 4
gpt4 key购买 nike

我尝试在我的 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;
}

}

}

Collision Detection Page

最佳答案

看来您已经颠倒了条件。仅当出现以下情况时才会发生碰撞:

((x2 + y2 + z2) <= r2)

如果你想要重叠而不是碰撞,那么“<=”将是“<”

关于java - 边界球碰撞不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26458431/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com