문제

So I have managed to create and successfully test boundingbox. I have now got all 8 corner points in vector[] corners = new vector[8] and vector[] corners1 = new vector[8] and just wondering what the code would be instead of model.intersect(model1). reason why I want to do this is because then hopefully I can change some points in the vectors to get my model going up a slope.

도움이 되었습니까?

해결책

First... you have a BoundingBox struct that does it for you for AABB collisions....

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.boundingbox.aspx

Second... if you want do it by yourself,

  1. if you only need to checks AABB collisions, only have to determine min and max coords of every vertex in the bounding box to compare with the bounding min and max...

    foreach (vertex in vertices) {
        Min.X = Min(Min.X, vertex.X);
        Min.Y = Min(Min.Y, vertex.Y);
        ....
        // Idem for max
    }
    
    bool collide(BoundingBox other)
    {
         if (min.X > other.max.X) return false;
         if (min.y > other.max.y) return false;
         ....
    
    }
    
  2. if you need to check obb collision between A and B objects, you only need to convert B vertex to A space, and work in A space

    BVertexInASpace = B.WorldVertex.Select( v => Matrix.Transform(v, A.TransformInverted));
    

    In A space the min vertex is (0,0,0) and the max vertex is (width, height, depth) so you only have to check if the BVertexInASpace vertex are inside...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top