Added algorithms for collision stubs
This commit is contained in:
parent
e8952dc739
commit
9cdbe2c861
|
@ -525,21 +525,22 @@ namespace Oyster { namespace Collision3D { namespace Utility
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Intersect( const Sphere &sphereA, const Sphere &sphereB, ::Oyster::Math::Float3 &worldPointOfContact )
|
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;
|
Float distance;
|
||||||
//C -= sphereB.center;
|
Ray ray(sphereB.center, C.Normalize());
|
||||||
//Float r = (sphereA.radius + sphereB.radius);
|
|
||||||
|
|
||||||
//if (r*r >= C.Dot(C))
|
Intersect( sphereA, ray, distance );
|
||||||
//{
|
|
||||||
// Float distance;
|
|
||||||
|
|
||||||
// Intersect(sphereA, Ray(sphereB.center, C.Normalize()), distance);
|
worldPointOfContact = ray.origin + ray.direction*distance;
|
||||||
|
|
||||||
// worldPointOfContact = sphereB.center+C.Normalize()*distance;
|
return true;
|
||||||
|
}
|
||||||
// return true; // Intersect detected!
|
|
||||||
//}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -668,9 +669,18 @@ namespace Oyster { namespace Collision3D { namespace Utility
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Intersect( const BoxAxisAligned &box, const Sphere &sphere, Float3 &worldPointOfContact )
|
bool Intersect( const BoxAxisAligned &box, const Sphere &sphere, Float3 &worldPointOfContact )
|
||||||
|
{ // by Robin Engman
|
||||||
|
|
||||||
|
if(Intersect(box, sphere))
|
||||||
{
|
{
|
||||||
//! @todo TODO: implement stub
|
Float distance;
|
||||||
return Intersect( box, sphere );
|
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 )
|
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 )
|
bool Intersect( const Box &box, const Sphere &sphere, Float3 &worldPointOfContact )
|
||||||
|
{ // by Robin Engman
|
||||||
|
if( Intersect(box, sphere) )
|
||||||
{
|
{
|
||||||
//! @todo TODO: implement stub
|
Float distance;
|
||||||
return Intersect( box, sphere );
|
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 )
|
bool Intersect( const Box &box, const Plane &plane )
|
||||||
|
|
Loading…
Reference in New Issue