Skip to main content
GameDev.net gamedev.net
🔒 Locked

Line / Sphere Intersection

Started by Unger Dec 25, 2001 at 12:08 AM 1 replies 600+ views
Original Post
Unger
Unger
I''m working on spherical object collision code and everything''s working great except one thing. I''m not sure if anyone can help but I''ll explain the problem and maybe someone has come across the same thing. The only time it doesn''t correctly detect the collision is when the sphere is colliding with the edge of the polygon. For instance, a poly aligned down the x-axis, and the sphere is moving along so that it barely hits the top edge of the poly. About 70% of the time it collides correctly. Other times it just flies right through. I''ve traced through the code (which I totally understand the math to it) and the Line / Sphere intersect code just doesn''t hit the sphere. I''m tracing a line from the closest point on the poly out in the opposite direction of the sphere''s velocity and it just doesn''t hit the sphere. Once I move the sphere to it''s new location (pos + velocity) it''s now embedded in the edge of the poly. I can only guess that under special circumstances (slight angles maybe?) it''s just not precise. Anyway, I''m stumped as to what to try to fix this, or even figure out what the problem could be. Has anyone run into anything like this? Maybe you have a suggestion that would help me figure it out.
LilBudyWizer
LilBudyWizer
My guess would be rounding errors, i.e. the objects do not collide, but they plot to the same pixel. It could just be a rendering error due to the depth buffer not having a high enough resolution. That causes the renderer to say both pixels should be plotted because they are both at the same distance. Which one you actually see then depends on the order they are drawn.
Keys to success: Ability, ambition and opportunity.
Tjoppen
Tjoppen
Make sure that you have a small error margin to count with in the intersection code..

for instance, instead of checking if the sum of the angles from the intersection point to the points in the point if EXACTLY 360*(or 2*PI), try saying "if it is larger than 355*, we have a collision"...Of course, this would meen that som times we get a point that lies outside the polygon, but often it´s very little outside...
delete this;

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.