Results 1 to 3 of 3

Thread: Collision Detection?

  1. #1
    Guest

    Collision Detection?

    I need help coding for collision detection. Can someone please help me? thanks

  2. #2
    Member Contributor
    Join Date
    May 2000
    Location
    Ottawa, Ontario, Canada
    Posts
    75

    Re: Collision Detection?

    Lots of stuff on this here website, also gamasutra. None of it is simple tho.

  3. #3
    Guest

    Re: Collision Detection?

    This is the way I did it for a project, but it seems pretty complicated. There's probably an easier way (and if anybody knows one for convex polygon perfect collision detection, I'm all ears...)

    In my project, I didn't want any polygon from one object to intersect any polygons from the other objects in the scene. This was accomplished by making sure no line segment of any polygon from one object intersected any polygon from the other object.
    1) First I test whether the line intersects the polygons plane. This is not required, but speeds up things a bit. I test if both points of the line are on the left, or if both points are on the right (using dot product, see crappy code below). Exit with no collision if true.
    2)Then I determined the x,y,z coords of the intersection of the plane, by changing into parametric equations and getting the t value for this.
    3)Now, is this point in the polygon? Picture it in the center. If you draw a line segment from this point to a point on the polygon, then swoop it around to every other point in order, you should go 360 degrees. However, outside the polygon, you should get less than this. So, add up all the angles I mentioned. If it is between 359 and 361, assume your line has intersected your polygon.


    Here's some code, hope it's not too bad
    //determines if line intersects triangle
    //code might be hard to understand
    int detLineCol(vector *plane, vector *line)
    {
    vector normal,intersectionP;
    GLfloat t,angleSum;

    //plane's normal
    normal = crossVec(subVec(plane[0],plane[1]),subVec(plane[1],plane[2]));

    //intersect plane?
    if( dotVec( subVec(line[0],plane[0]), normal)>0&& //both points on left of plane
    dotVec( subVec(line[1],plane[0]), normal)>0)
    return(FALSE); //so no intersection

    if( dotVec( subVec(line[0],plane[0]), normal)<0&& //both point on right of plane
    dotVec( subVec(line[1],plane[0]), normal)<0)
    return(FALSE); //so no intersection

    //if intersect plane, get point of intersection
    angleSum=0;
    t = - (normal.x*(line[0].x -plane[0].x) + normal.y*(line[0].y-plane[0].y) + normal.z*(line[0].z - plane[0].z))/
    (normal.x*(line[1].x - line[0].x) + normal.y*(line[1].y - line[0].y) + normal.z*(line[1].z - line[0].z));
    intersectionP.x = line[0].x + (line[1].x - line[0].x)*t;
    intersectionP.y = line[0].y + (line[1].y - line[0].y)*t;
    intersectionP.z = line[0].z + (line[1].z - line[0].z)*t;

    angleSum+=(float)acos(dotVec(normalizeVec(subVec(i ntersectionP,plane[0])),normalizeVec(subVec(intersectionP,plane[1]))));
    angleSum+=(float)acos(dotVec(normalizeVec(subVec(i ntersectionP,plane[1])),normalizeVec(subVec(intersectionP,plane[2]))));
    angleSum+=(float)acos(dotVec(normalizeVec(subVec(i ntersectionP,plane[2])),normalizeVec(subVec(intersectionP,plane[3]))));
    angleSum+=(float)acos(dotVec(normalizeVec(subVec(i ntersectionP,plane[3])),normalizeVec(subVec(intersectionP,plane[0]))));

    if(angleSum>2*3.14&&angleSum<2*3.142){
    return(TRUE);
    }

    return(FALSE);
    }

Similar Threads

  1. Collision Detection
    By ardalanbiz in forum OpenGL: General
    Replies: 5
    Last Post: 02-07-2004, 02:49 PM
  2. Collision detection.... please help
    By Music_Man in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 11-28-2002, 06:38 PM
  3. collision detection
    By imported_robert in forum OpenGL: Basic Coding
    Replies: 13
    Last Post: 02-17-2001, 03:09 AM
  4. collision detection
    By chip in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-08-2000, 07:09 AM
  5. collision detection contest: collision crazy
    By in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 09-19-2000, 02:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean