improve segment vs segment collision, small fixes

This commit is contained in:
Irlan
2017-02-17 13:52:24 -02:00
parent a346a1472d
commit 012460f6b0
16 changed files with 175 additions and 150 deletions

View File

@ -32,6 +32,15 @@ struct b3Color
float32 r, g, b, a;
};
// Color pallete commonly used by the debug draw interface.
extern const b3Color b3Color_black;
extern const b3Color b3Color_white;
extern const b3Color b3Color_red;
extern const b3Color b3Color_green;
extern const b3Color b3Color_blue;
extern const b3Color b3Color_yellow;
extern const b3Color b3Color_pink;
// Implement this interface and set to a world so it can draw the physics entities.
class b3Draw
{

View File

@ -34,6 +34,14 @@ class b3ContactListener;
class b3ContactFilter;
class b3Draw;
struct b3RayCastSingleOutput
{
b3Shape* shape; // shape
b3Vec3 point; // intersection point on surface
b3Vec3 normal; // surface normal of intersection
float32 fraction; // time of intersection on segment
};
// Use a physics world to create/destroy rigid bodies, execute ray cast and volume queries.
class b3World
{
@ -83,6 +91,13 @@ public:
// and the number of constraint solver iterations.
void Step(float32 dt, u32 velocityIterations, u32 positionIterations);
// Perform a ray cast with the world.
// If the ray doesn't intersect with a shape in the world then return false.
// The ray cast output is the intercepted shape, the intersection
// point in world space, the face normal on the shape associated with the point,
// and the intersection fraction.
bool RayCastSingle(b3RayCastSingleOutput* output, const b3Vec3& p1, const b3Vec3& p2) const;
// Perform a ray cast with the world.
// The given ray cast listener will be notified when a ray intersects a shape
// in the world.
@ -91,13 +106,6 @@ public:
// and the intersection fraction.
void RayCast(b3RayCastListener* listener, const b3Vec3& p1, const b3Vec3& p2) const;
// Convenience function.
// Perform a ray cast with the world.
// If there is an intersection then the given ray cast listener will be notified once with
// the shape closest to the ray origin and the associated ray cast output.
// @todo Centralize all queries to a common scene query class?
void RayCastFirst(b3RayCastListener* listener, const b3Vec3& p1, const b3Vec3& p2) const;
// Perform a AABB cast with the world.
// The query listener will be notified when two shape AABBs are overlapping.
// If the listener returns false then the query is stopped immediately.

View File

@ -106,7 +106,7 @@ public:
void Draw(const b3World& world);
void Draw();
void Submit();
private:
friend struct DrawShapes;

View File

@ -204,18 +204,12 @@ public:
void CastRay(const b3Vec3 p1, const b3Vec3 p2) const
{
// Perform the ray cast
RayCastListener listener;
listener.hit.shape = NULL;
m_world.RayCastFirst(&listener, p1, p2);
RayCastHit hit = listener.hit;
if (hit.shape)
b3RayCastSingleOutput out;
if (m_world.RayCastSingle(&out, p1, p2))
{
// Replace current hit
g_debugDraw->DrawSegment(p1, hit.point, b3Color(0.0f, 1.0f, 0.0f));
g_debugDraw->DrawPoint(hit.point, 4.0f, b3Color(1.0f, 0.0f, 0.0f));
g_debugDraw->DrawSegment(hit.point, hit.point + hit.normal, b3Color(1.0f, 1.0f, 1.0f));
g_debugDraw->DrawSegment(p1, out.point, b3Color(0.0f, 1.0f, 0.0f));
g_debugDraw->DrawPoint(out.point, 4.0f, b3Color(1.0f, 0.0f, 0.0f));
g_debugDraw->DrawSegment(out.point, out.point + out.normal, b3Color(1.0f, 1.0f, 1.0f));
}
else
{

View File

@ -88,14 +88,6 @@ struct TestEntry
extern TestEntry g_tests[];
struct RayCastHit
{
b3Shape* shape;
b3Vec3 point;
b3Vec3 normal;
float32 fraction;
};
class RayCastListener : public b3RayCastListener
{
public:
@ -108,7 +100,7 @@ public:
return 1.0f;
}
RayCastHit hit;
b3RayCastSingleOutput hit;
};
class Test : public b3ContactListener
@ -142,7 +134,7 @@ public:
b3Profile m_profile;
b3Profile m_maxProfile;
RayCastHit m_rayHit;
b3RayCastSingleOutput m_rayHit;
b3BoxHull m_groundHull;
b3BoxHull m_boxHull;
b3BoxHull m_tallHull;