add collision detection routines for shape against sphere

This commit is contained in:
Irlan
2018-03-26 15:56:01 -03:00
parent be812ed897
commit 3e55b28956
10 changed files with 228 additions and 23 deletions

View File

@ -33,7 +33,9 @@ public:
void ComputeAABB(b3AABB3* aabb, const b3Transform& xf) const;
bool TestPoint(const b3Vec3& point, const b3Transform& xf) const;
bool TestSphere(const b3Sphere& sphere, const b3Transform& xf) const;
bool TestSphere(b3TestSphereOutput* output, const b3Sphere& sphere, const b3Transform& xf) const;
bool RayCast(b3RayCastOutput* output, const b3RayCastInput& input, const b3Transform& xf) const;

View File

@ -35,7 +35,9 @@ public :
void ComputeAABB(b3AABB3* aabb, const b3Transform& xf) const;
bool TestPoint(const b3Vec3& point, const b3Transform& xf) const;
bool TestSphere(const b3Sphere& sphere, const b3Transform& xf) const;
bool TestSphere(b3TestSphereOutput* output, const b3Sphere& sphere, const b3Transform& xf) const;
bool RayCast(b3RayCastOutput* output, const b3RayCastInput& input, const b3Transform& xf) const;

View File

@ -37,8 +37,10 @@ public:
void ComputeAABB(b3AABB3* output, const b3Transform& xf, u32 childIndex) const;
bool TestPoint(const b3Vec3& point, const b3Transform& xf) const;
bool TestSphere(const b3Sphere& sphere, const b3Transform& xf) const;
bool TestSphere(b3TestSphereOutput* output, const b3Sphere& sphere, const b3Transform& xf) const;
bool RayCast(b3RayCastOutput* output, const b3RayCastInput& input, const b3Transform& xf) const;
bool RayCast(b3RayCastOutput* output, const b3RayCastInput& input, const b3Transform& xf, u32 childIndex) const;

View File

@ -22,6 +22,7 @@
#include <bounce/common/math/transform.h>
#include <bounce/common/template/list.h>
#include <bounce/collision/collision.h>
#include <bounce/collision/shapes/sphere.h>
struct b3ContactEdge;
@ -37,6 +38,12 @@ enum b3ShapeType
e_maxShapes
};
struct b3TestSphereOutput
{
float32 separation;
b3Vec3 normal;
};
struct b3ShapeDef
{
b3ShapeDef()
@ -72,7 +79,7 @@ struct b3MassData
class b3Shape
{
public:
b3Shape() { }
b3Shape();
virtual ~b3Shape() { }
// Get the shape type.
@ -88,8 +95,13 @@ public:
// Compute the shape world AABB.
virtual void ComputeAABB(b3AABB3* aabb, const b3Transform& xf) const = 0;
// Test if a point is contained inside this shape.
virtual bool TestPoint(const b3Vec3& point, const b3Transform& xf) const = 0;
// Test if a sphere is contained inside this shape.
virtual bool TestSphere(const b3Sphere& sphere, const b3Transform& xf) const = 0;
// Test if a sphere is contained inside this shape.
// If the sphere is inside this shape then return the minimum separation distance and normal.
// The direction of the normal points from this shape to the sphere.
virtual bool TestSphere(b3TestSphereOutput* output, const b3Sphere& sphere, const b3Transform& xf) const = 0;
// Compute the ray intersection point, normal of surface, and fraction.
virtual bool RayCast(b3RayCastOutput* output, const b3RayCastInput& input, const b3Transform& xf) const = 0;

View File

@ -33,8 +33,10 @@ public :
void ComputeAABB(b3AABB3* aabb, const b3Transform& xf) const;
bool TestPoint(const b3Vec3& point, const b3Transform& xf) const;
bool TestSphere(const b3Sphere& sphere, const b3Transform& xf) const;
bool TestSphere(b3TestSphereOutput* output, const b3Sphere& sphere, const b3Transform& xf) const;
bool RayCast(b3RayCastOutput* output, const b3RayCastInput& input, const b3Transform& xf) const;
b3Vec3 m_center;