can someone help me with ellispsoid
i got an article talking about collision detection with ellipsoid .
this one
General Collision Detection for Games Using Ellipsoids
by Paul Nettle
the only part that i don''t anderstand is when he come to detect collision .
because he talk about sphere again.
are we using an ellipsoid or a sphere
???????????
if some one can explain me this code how to use it .
things to consider
i anderstands the global algorithm and the respons too but the detection talk about a sphereintersectionpoint that we don''t have and i don''t anderstand why???????????????????
please help
// The collision detection entry point
collisionDetection(Point sourcePoint, Vector velocityVector, Vector gravityVector)
{
// We need to do any pre-collision detection work here. Such as adding
// gravity to our veoclity vector. We want to do it in this
// separate routine because the following routine is recursive, and we
// don''t want to recursively add gravity.
velocityVector += gravityVector;
call collideWithWorld(sourcePoint, velocityVector);
}
// The collision detection recursive routine
collideWithWorld(Point sourcePoint, Vector velocityVector)
{
// How far do we need to go?
Double distanceToTravel = length of velocityVector;
// Do we need to bother?
if (distanceToTravel < EPSILON) return;
// What''s our destination?
Point destinationPoint = sourcePoint + velocityVector;
// Whom might we collide with?
List potentialColliders = determine list of potential colliders;
// If there are none, we can safely move to the destination and bail
if (potentialColliders is empty)
{
sourcePoint += velocityVector;
return;
}
// Determine the nearest collider from the list potentialColliders
bool firstTimeThrough = true;
Double nearestDistance = -1.0;
Poly nearestCollider = NULL;
Point nearestIntersectionPoint = NULL;
Point nearestPolygonIntersectionPoint = NULL;
for (each polygon in potentialColliders)
{
// Plane origin/normal
Point pOrigin = any vertex from the current polygon;
Vector pNormal = surface normal from the current polygon;
// Determine the distance from the plane to the source
Double pDist = intersect(source, -pNormal, pOrigin, pNormal);
Point sphereIntersectionPoint;
Point planeIntersectionPoint;
// The radius of the ellipsoid (in the direction of pNormal)
Vector directionalRadius = -pNormal * radiusVector;
Double radius = length of directionalRadius;
// Is the plane embedded?
if (fabs(pDist) <= radius)
{
// Calculate the plane intersection point
Vector temp = -pNormal with length set to pDist;
planeIntersectionPoint = source + temp;
}
else
{
// Calculate the ellipsoid intersection point
Vector temp = -pNormal with length set to radius;
ellipsoidIntersectionPoint = source + temp;
// Calculate the plane intersection point
Ray ray(sphereIntersectionPoint, Velocity);
Double t = intersect(ellipsoidIntersectionPoint, Velocity, pOrigin, pNormal);
// Calculate the plane intersection point
Vector V = velocityVector with length set to t;
planeIntersectionPoint = ellipsoidIntersectionPoint + V;
}
// Unless otherwise stated, our polygonIntersectionPoint is the
// same point as planeIntersectionPoint
Point polygonIntersectionPoint = planeIntersectionPoint;
// So… are they the same?
if (planeIntersectionPoint is not within the current polygon)
{
polygonIntersectionPoint = nearest point on polygon''s perimeter to planeIntersectionPoint;
}
// Invert the velocity vector
Vector negativeVelocityVector = -velocityVector;
// Using the polygonIntersectionPoint, we need to reverse-intersect
// with the ellipsoid
Double t = intersectEllipse(sourcePoint, radiusVector,
polygonIntersectionPoint, negativeVelocityVector);
// Was there an intersection with the ellipsoid?
if (t >= 0.0 && t <= distanceToTravel)
{
Vector V = negativeVelocityVector with length set to t;
// Where did we intersect the ellipsoid?
Vector intersectionPoint = polygonIntersectionPoint + V;
// Closest intersection thus far?
if (firstTimeThrough || t < nearestDistance)
{
nearestDistance = t;
nearestCollider = current collider;
nearestIntersectionPoint = intersectionPoint;
nearestPolygonIntersectionPoint =
polygonIntersectionPoint;
firstTimeThrough = false;
}
}
}
// If we never found a collision, we can safely move to the destination
// and bail
if (firstTimeThrough)
{
sourcePoint += velocityVector;
return;
}
// Move to the nearest collision
Vector V = velocityVector with length set to (nearestDistance - EPSILON);
sourcePoint += V;
// Determine the sliding plane (we do this now, because we''re about to
// change sourcePoint)
Point slidePlaneOrigin = nearestPolygonIntersectionPoint;
Vector slidePlaneNormal = nearestPolygonIntersectionPoint - sourcePoint;
// We now project the destination point onto the sliding plane
Double time = intersect(destinationPoint, slidePlaneNormal,
slidePlaneOrigin, slidePlaneNormal);
Set length of slidePlaneNormal to time;
Vector destinationProjectionNormal = slidePlaneNormal;
Point newDestinationPoint = destination + destinationProjectionNormal;
// Generate the slide vector, which will become our new velocity vector
// for the next iteration
Vector newVelocityVector = newDestinationPoint –
nearestPolygonIntersectionPoint;
// Recursively slide (without adding gravity)
collideWithWorld(sourcePoint, newVelocityVector);
}
love and peace
love and peace
The code is prototype rather than working code - some of it, such as
>Double distanceToTravel = length of velocityVector;
you can replace with vector functions, but a lot of it, such as
>List potentialColliders = determine list of potential colliders;
>polygonIntersectionPoint = nearest point on polygon''s perimeter to planeIntersectionPoint;
>Double t = intersect(...);
>Double t = intersectEllipse(...);
need to be replaced with a lot more specialised code. From its name I guess the last function does the actual work of dealing with the ellipse(oid), but without source code it''s impossible to say whether it''s correct or explain it.
>Double distanceToTravel = length of velocityVector;
you can replace with vector functions, but a lot of it, such as
>List potentialColliders = determine list of potential colliders;
>polygonIntersectionPoint = nearest point on polygon''s perimeter to planeIntersectionPoint;
>Double t = intersect(...);
>Double t = intersectEllipse(...);
need to be replaced with a lot more specialised code. From its name I guess the last function does the actual work of dealing with the ellipse(oid), but without source code it''s impossible to say whether it''s correct or explain it.
John BlackburneProgrammer, The Pitbull Syndicate
i resolve my problem cause i ask to the autor.
but what i don''t anderstand is that he says that for an ellipse you have to define a radius vector
so can you explain me it
and show me how to implment it with my player class
like
player=class(tobject);
olpos:tvector;
.
.
.
.
.
.
raduis:glfloat;//for a simple sphere
but for an ellipse i don''t know how it goes
love and peace
but what i don''t anderstand is that he says that for an ellipse you have to define a radius vector
so can you explain me it
and show me how to implment it with my player class
like
player=class(tobject);
olpos:tvector;
.
.
.
.
.
.
raduis:glfloat;//for a simple sphere
but for an ellipse i don''t know how it goes
love and peace
love and peace
Theres no difference for what you need to do between a sphere radius and an ellipsoid radius other than if you have an ellipsoid, all the radii may not be equal. So make a vector with x, y, z radius for it....
[edited by - rgirard413 on April 26, 2002 6:54:31 PM]
[edited by - rgirard413 on April 26, 2002 6:54:31 PM]
http://www.thedizzle.com
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement