Added algorithms for collision stubs

This commit is contained in:
Robin Engman 2013-12-18 08:57:10 +01:00 committed by Dander7BD
parent e8952dc739
commit 9cdbe2c861
1 changed files with 45 additions and 27 deletions

View File

@ -525,21 +525,22 @@ namespace Oyster { namespace Collision3D { namespace Utility
}
bool Intersect( const Sphere &sphereA, const Sphere &sphereB, ::Oyster::Math::Float3 &worldPointOfContact )
{ // by Robin Engman
Float3 C = sphereA.center;
C -= sphereB.center;
Float r = sphereA.radius + sphereB.radius;
if ( r*r >= C.Dot(C) )
{
//Float3 C = sphereA.center;
//C -= sphereB.center;
//Float r = (sphereA.radius + sphereB.radius);
Float distance;
Ray ray(sphereB.center, C.Normalize());
//if (r*r >= C.Dot(C))
//{
// Float distance;
Intersect( sphereA, ray, distance );
// Intersect(sphereA, Ray(sphereB.center, C.Normalize()), distance);
worldPointOfContact = ray.origin + ray.direction*distance;
// worldPointOfContact = sphereB.center+C.Normalize()*distance;
// return true; // Intersect detected!
//}
return true;
}
return false;
}
@ -668,9 +669,18 @@ namespace Oyster { namespace Collision3D { namespace Utility
}
bool Intersect( const BoxAxisAligned &box, const Sphere &sphere, Float3 &worldPointOfContact )
{ // by Robin Engman
if(Intersect(box, sphere))
{
//! @todo TODO: implement stub
return Intersect( box, sphere );
Float distance;
Float3 boxMiddle = (box.maxVertex - box.minVertex)*0.5f;
Ray ray(boxMiddle, Float3(sphere.center - boxMiddle).Normalize());
Intersect( sphere, ray, distance );
worldPointOfContact = ray.origin + ray.direction * distance;
}
return false;
}
bool Intersect( const BoxAxisAligned &box, const Plane &plane )
@ -769,9 +779,17 @@ namespace Oyster { namespace Collision3D { namespace Utility
}
bool Intersect( const Box &box, const Sphere &sphere, Float3 &worldPointOfContact )
{ // by Robin Engman
if( Intersect(box, sphere) )
{
//! @todo TODO: implement stub
return Intersect( box, sphere );
Float distance;
Ray ray( sphere.center, Float3(box.center - sphere.center) );
Intersect( box, ray, distance );
worldPointOfContact = ray.origin + ray.direction*distance;
}
return false;
}
bool Intersect( const Box &box, const Plane &plane )