Java 碰撞检测不需要';不要推回

Java 碰撞检测不需要';不要推回,java,math,vector,3d,collision-detection,Java,Math,Vector,3d,Collision Detection,好的,我正在为一个3d游戏进行碰撞检测,这是我目前得到的结果: public void mapCol(Spatial map, Node model2){ Mesh m = (Mesh) ((Node) map).getChild("obj_mesh0"); int c = 0; m.updateWorldBound(true); boolean col = false;

好的,我正在为一个3d游戏进行碰撞检测,这是我目前得到的结果:

public void mapCol(Spatial map, Node model2){
             Mesh m = (Mesh) ((Node) map).getChild("obj_mesh0");
              int c = 0;
              m.updateWorldBound(true);
              boolean col = false;
              c = m.getMeshData().getPrimitiveCount(0);
             // System.out.println(c);
              Vector3[][] v3 = new Vector3[c][3];
              for(int s = 0; s < c; s++){
                 v3[s] = null;
                 v3[s] = m.getMeshData().getPrimitive(s, 0, v3[s]);

                 Vector3 min = new Vector3((float)Math.min((float) Math.min(v3[s][0].getXf(), v3[s][1].getXf()), v3[s][2].getXf()),
                       (float)Math.min((float)Math.min(v3[s][0].getYf(), v3[s][1].getYf()), v3[s][2].getYf()),
                       (float)Math.min((float)Math.min(v3[s][0].getZf(), v3[s][1].getZf()), v3[s][2].getZf()));

                 Vector3 max = new Vector3((float) Math.max((float)Math.max(v3[s][0].getXf(), v3[s][1].getXf()), v3[s][2].getXf()),
                       (float)Math.max((float)Math.max(v3[s][0].getYf(), v3[s][1].getYf()), v3[s][2].getYf()),
                       (float)Math.max((float)Math.max(v3[s][0].getZf(), v3[s][1].getZf()), v3[s][2].getZf()));


                 Vector3 v2 = new Vector3();
                v2 = max.add(min, v2);
                v2.divideLocal(2);            

                 if(max.getXf() > model2.getTranslation().getXf() -  sp1.getRadius()&&
                    min.getXf() < model2.getTranslation().getXf() +  sp1.getRadius()  &&
                    max.getZf() > model2.getTranslation().getZf()  -  sp1.getRadius()  &&
                    min.getZf() < model2.getTranslation().getZf()  + sp1.getRadius() &&
                    max.getYf() > model2.getTranslation().getYf() + sp1.getRadius()&&
                    !col){


                    float cosine = (float) v2.dot(v2);
                      float angle = (float) Math.toDegrees(Math.acos( cosine ));
                    float pangle = (float) Math.toDegrees(Math.atan2((min.getX() + ((max.getX() - min.getX())/2)) - model2.getTranslation().getX(), (min.getZ() + ((max.getZ() - min.getZ())/2) - model2.getTranslation().getZ())));



                    if(min.getY() < max.getY()){   

                       System.out.println("pangle:" + pangle + " angle:" + angle);


                       model2.setTranslation(
                             (min.getX() + ((max.getX() - min.getX())/2)) - (Math.sin(Math.toRadians(pangle)) * (sp1.getRadius())),
                                   model2.getTranslation().getYf(),
                                   (min.getZ() + ((max.getZ() - min.getZ())/2)) -  (-Math.cos(Math.toRadians(pangle)) * (sp1.getRadius()))
                             );
                       col = true;
}
                    }
                 }     
          }
你知道为什么它不会将model2 modle2的半径设置为远离墙壁吗?(让它停在路边,不能再往前走)

这是故意的吗

因为它只给出了v2的长度,平方

也许应该是这样

float cosine = velocity.dot(normalVector)/(velocity.length()*normalVector.length())

,如果你想要它们之间的余弦角,但我不完全理解你的代码,所以我不知道。

如果你想让别人来解决这个问题,请告诉我们1)这段代码应该做什么,2)它实际做什么,以及3)你已经测试了这五行代码,而不仅仅是猜测。
float cosine = v2.dot(v2)
float cosine = velocity.dot(normalVector)/(velocity.length()*normalVector.length())