【问题标题】:Bounding Sphere Collision Does Not Work边界球碰撞不起作用
【发布时间】:2014-10-20 12:30:25
【问题描述】:

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

【问题讨论】:

    标签: java 3d collision-detection collision


    【解决方案1】:

    看来您已经颠倒了条件。只有在以下情况下才会发生碰撞:

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

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

    【讨论】:

    • 非常感谢!我在白板上画出来,果然,当两个圆之间的距离小于它们半径的平方时,就会发生碰撞!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-21
    • 1970-01-01
    • 2012-09-05
    • 1970-01-01
    • 2013-02-18
    • 2013-04-01
    相关资源
    最近更新 更多