http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

TheGrumpyProgrammer



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Collision Detection



Question for all you 3D programmers.

I am doing a 3d submarine game, and I thought I had my collision detection
working...
but I found out that there is something not working.

Here is the basis of my collision:  (Line to Polygon)

First, find if it's on the same place an the polygon
Get the intersection point...
Then, check if the intersection point is within the polygon. (This is my
problem)

For some reason, this works GREAT if the polygons are laying straight on the
ground or
are pointing straight up in the air (Like a wall or the floor)

But when they are tilted, I start colliding into things that aren't there.
The first 2 steps work fine,
but for some reason the last step isn't working, the bounds checking.

Here is what my last step looks like:  (Basically I understand that if you
add up 3 triangles angles
that are created inside the polygon by the intersection point within the
triangle, it should add up to 360?)

BOOL InsidePolygon(VECTOR3D Point, VECTOR3D *Poly, long VertexCount)
{
 const double MATCH_FACTOR = 0.99;  // Used to cover up the error in
floating point
 double Angle = 0.0;      // Initialize the angle
 VECTOR3D A, B;       // Create temp vectors
 long n = 0;        // Counter

 for (n = 0; n < VertexCount; n++)  // Go through all of the vertex's


  A.x = Poly[n].x - Point.x;   // Subtract the intersection point from the
current vertex
  A.y = Poly[n].y - Point.y;
  A.z = Poly[n].z - Point.z;
// Subtract the point from the next vertex
  B.x = Poly[(n + 1) % VertexCount].x - Point.x;
  B.y = Poly[(n + 1) % VertexCount].y - Point.y;
  B.z = Poly[(n + 1) % VertexCount].z - Point.z;
// Use the dot product to find the angle between the 2 vertex and the point
  Angle += acos( Dot(A, B) / ( Mag(A) * Mag(B) ) );
 }
// If the angle is greater than 2 PI, (360 degrees) MATCH_FACTOR = .99 to
help fix floating point.
 if(Angle >= (MATCH_FACTOR * (1.9 * PI)) )
  return TRUE;      // The point is inside of the polygon

 return FALSE;       // If you get here, it obviously wasn't inside the
polygon, so Return FALSE
}

In theory, what part in the last step am I missing?  It's very important to
me to figure this out..
I would appreciate any advice on the matter.  I know it's something really
small,.
I actually got this last step from andre lamothe's book C++ Game
Programming,
but it doesn't seem to work.

Thanks!

Ben Humphrey
Game Programmer
WebHost of www.GameTutorials.com
benh@humongous.com
benjina@mindspring.com




=================================================================
The GameProgrammer.Com mailing list is for the open discussion
of any topic related to the art, science, and business of
programming games. This list is especially tolerant of beginners.
We were all beginners once

To SUBSCRIBE or UNSUBSCRIBE please visit:
http://gameprogrammer.com/mailinglist.html