Question

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.

Was it helpful?

Solution

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...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top