We get it. We use ad blockers too. But GameDev.net displays them so we can continue to be a great platform for you.
Please whitelist GameDev.net and our advertisers.
Also consider a GDNet+ Pro subscription to remove all ads from GameDev.net.
Subscribe to GameDev.net's newsletters to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 10 February 2008 - 12:07 PM
Posted 10 February 2008 - 12:27 PM
Posted 11 February 2008 - 10:40 AM
inline static float PointDistToLineSeg( Vector P, Vector vSrc, Vector vEnd )
{
Vector v = vEnd - vSrc;
Vector w = P - vSrc;
float c1 = w.Dot(v);
if ( c1 <= 0 )
return w.Length();
float c2 = v.Dot(v);
if ( c2 <= c1 )
return (P - vEnd).Length();
float frac = 0.0f;
if ( fabsf( c2 ) < 1.0e-6f ){ frac = 0.0f; }
else { frac = c1 / c2; }
return (P - (vSrc + v * frac)).Length();
}
// swept circle vs swept line
bool SegmentCircleIntersect( const circle_t &circ, const lineseg_t &line, circ_int_t &int_info )
{
// substitute for moving line
Vector transition = circ.transition - line.transition; // souldn't use that!!!! not works!
// If the center of the sphere moves like: center = position + t * translation for t -> [0, 1]
// then the sphere intersects the plane if: -R <= distance plane to center <= R
float dist_norm = Dot(line.normal, transition); // something from plane equation
float dist_to_c = PointDistToLineSeg(circ.position, line.src, line.end); // NOTE: !SIGNED! distance to line seg? how?
if ( fabsf(dist_norm) < 1.0e-6f )
{
// The sphere is moving nearly parallel to the plane, check if the distance
// is smaller than the radius
if ( fabsf(dist_to_c) > circ.radius )
return false;
// Intersection on the entire range
int_info.entire_range = true;
int_info.fraction1 = 0.0f;
int_info.fraction2 = 1.0f;
}
else
{
// Determine interval of intersection
int_info.fraction1 = ( circ.radius - dist_to_c) / dist_norm;
int_info.fraction2 = (-circ.radius - dist_to_c) / dist_norm;
// Order the results
if (int_info.fraction1 > int_info.fraction2)
swap(int_info.fraction1, int_info.fraction2);
// Early out if no hit possible
if (int_info.fraction1 > 1.0f || int_info.fraction2 < 0.0f)
return false;
// Clamp it to the range [0, 1], the range of the swept circle
if (int_info.fraction1 < 0.0f) int_info.fraction1 = 0.0f;
if (int_info.fraction2 > 1.0f) int_info.fraction2 = 1.0f;
// contact points
Vector point1 = circ.position + transition * int_info.fraction1; // determine where exactly circle should stop
Vector point2 = circ.position + transition * int_info.fraction2; // determine where exactly circle should exit
int_info.numpts = 1; // determine whether or not second point should be used
int_info.points[0].position = point1;
// int_info.points[1] = point2;
int_info.points[0].separation = dist_to_c - circ.radius;
int_info.points[0].normal = line.normal;
}
return true;
}
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.