XNA Creators Club Online
Page 1 of 1 (8 items)
Sort Posts: Previous Next

Collision Detection Algorithim

Last post 11/10/2009 10:38 PM by Steve Walker. 7 replies.
  • 11/9/2009 5:18 AM

    Collision Detection Algorithim

    I'm working on a project right now that requires a pretty precise collision detector. All collisions (at least for now) are between a sphere, and an irregular, arbitrarily shaped model. The collision detection also needs to return the slope of the surface that the sphere is colliding with at the point of collision. Any suggestions would be appreciated.

    Thanks
  • 11/9/2009 5:21 AM In reply to

    Re: Collision Detection Algorithim

    If the object is defined as a set of 2D lines, look up circle/line collision.  If it's in 3D, look up sphere/plane collision.  This should be a good start.  Once you know there's a collision, determining the slope shouldn't be difficult.
  • 11/9/2009 8:31 PM In reply to
    • (23)
    • premium membership
    • Posts 74

    Re: Collision Detection Algorithim

    Apply newton's 1st law to the situation.  Force is reapplied in the direction from the center of the sphere to the point where the irregular object touches it.  Then because of the 3rd law your sphere will move backwards in the opposite direction.  This should make the irregular object have a reflection pattern from the vector it was previously traveling.  To check your math make sure that the irregular object moves in the same direction it would if it had bounced off a wall tangent to the point where it intersected with the sphere.
    I hope this helps.
  • 11/9/2009 9:35 PM In reply to

    Re: Collision Detection Algorithim

    Its a 3D Model, and the problem I'm having is constructing the plane and detecting the collision in order to call the function that can then construct the tangent plane. The models are made of vertices (as far as I know, I'm using Autodesk Softimage Mod Tool 7.5), the one I'm using to test with describes a bowl shape. I'm not worried about the physics engine (yet), I just need to figure out when (especially when) and where the sphere collides with the surface in order to send slope data to the physics engine and not have the sphere fall through my models.
  • 11/9/2009 10:27 PM In reply to

    Re: Collision Detection Algorithim

    First I would recommend creating a face class. 

     

    public class Face  
        {  
            public Vector3[] verts;  
            public Plane plane;  
     
            public Face(Vector3 v1, Vector3 v2, Vector3 v3)  
            {  
                verts = new Vector3[3];  
                verts[0] = v1;  
                verts[1] = v2;  
                verts[2] = v3;  
                plane = new Plane(v1, v2, v3);  
            }  
       } 

     Then create a custom processor to process the vertex data and store each triangle into your face class. From there just loop through each face seeing if the sphere intersects the plane the triangle lies on. If the sphere does intersect the plane, test to see if it intersects within the triangle. Depending on the amount of triangles in your model, I would recommend creating an octree.

     

     Just google how to do each, they are relatively simple. I am not exactly sure how to determine if the sphere intersects within the triangle, I'm using an AABB for my collision detection.

    edit: I believe that to determine if it intersects the triangle, create a ray from the center of the circle with a direction of the triangle's normal. Then determine the point of intersection between the ray and the plane. Then do a simple check if this point lies inside the triangle. And if that produces a false result, make sure neither of the edges of the triangle intersect the sphere. Then if both those tests produce a false result, there is no collision.

  • 11/10/2009 2:18 AM In reply to

    Re: Collision Detection Algorithim

    Where are you getting the vectors that make up the plane?
  • 11/10/2009 5:43 AM In reply to

    Re: Collision Detection Algorithim

    Lord Takkera:
    Where are you getting the vectors that make up the plane?
    A plane can be defined by three verticies; in other words, three verticies always lie on a plane. (Three verticies also happen to make up a triangle!)
    Madness? This is SUNSHINE.
  • 11/10/2009 10:38 PM In reply to

    Re: Collision Detection Algorithim

    The plane represents the plane that the triangle lies on. The three vectors are the verticies of the triangle. The data for the verticies will be stored using the Custom Processor.
Page 1 of 1 (8 items) Previous Next