Archived

This topic is now archived and is closed to further replies.

iNsAn1tY

Collision Detection...

Recommended Posts

iNsAn1tY    476
Hi. I''m writing a 3D engine, and everything was going OK, until the other day. It''s my first attempt, and I haven''t written any collision detection code before. I''ve researched some different ways of doing it, and I''m using the dot product system, whereby you calculate to see if the player has passed a plane, so if the point is in the halfspace behind all the hyperplanes, it''s inside the object. But I''m having a problem with the formula: DotProduct(Polygon.Normal, Player.Position) + Plane.Distance I can''t calculate the minimum distance of the plane the triangular polygon lies on from the origin. I have managed to do it with polygons in the three major axes, x, y and z, but not with any others. I think I have to calculate the plane equation from the points of the polygon, and then I can find the minimum distance, but I''m not sure how to do this...can anyone help? I got the method above from http://www.flipcode.com/tutorials/tut_collision.shtml, if you want some clarification on what I''m talking about. The above formula is about 1/4 of the way down the page...

Share this post


Link to post
Share on other sites
FragLegs    122
An easier way to do this is as follows:

// assume that v1 is a vertex in your polygon
DotProduct(Polygon.Normal, Player.Position - v1);

If the dot product is negative, the player is "inside" the halfspace.

FragLegs

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Thank you, thank you, thank you! Now, I can finish my collision detection, and start on the physics!

Share this post


Link to post
Share on other sites