小编Gyo*_*Gyo的帖子

使用分离轴定理找到MTV(最小平移向量)

因此,我一直在尝试使用分离轴定理在我的游戏项目中使用碰撞检测和响应.我设法发现了碰撞,但是对于我的生活,我无法弄清楚如何应对它.我试图找到最小翻译向量,但我不知道如何使它成为一个实际向量,以便我可以计算如何响应碰撞.我已经阅读了教程后的教程,我在这里看了许多以前问过的问题,但我无法弄清楚如何实现它.我很难理解如何找到和使用MTV,所以如果有人真的可以帮助我理解,也许给我一些例子,这样我就可以在实现中理解它而不仅仅是理论,它会很多感谢,对于给您带来的任何不便,我们深表歉意.我的代码确实成功检测到了碰撞,现在它在下面:

//NOTE: This is within the HitPolygon class, so "this" is referencing itself as a polygon
public Projection project(Vector2D axis){

    float min = axis.dot(this.getVertices().get(0));
    float max = min;
    Vector2D vecMax  = new Vector2D(0, 0), vecMin = new Vector2D(0, 0);

    for(int i = 1; i < this.getVertices().size(); i++){
        float p = axis.dot(this.getVertices().get(i));
        if(p < min){
            min = p;
            vecMin = this.getVertices().get(i);
        }
        if(p > max){
            max = p;
            vecMax = this.getVertices().get(i);
        }
    }

    Projection result = new Projection(min, max, vecMin, vecMax, …
Run Code Online (Sandbox Code Playgroud)

java collision-detection separating-axis-theorem

2
推荐指数
1
解决办法
1087
查看次数