use mvc for the testbed, update almost all tests, bugfixes, improvements, cleanup
Since I started altering the testbed for better maintainability, I prefered to drop this (tested) large change with a single commit. Some changes below: Put some globals in their correct place, Now Testbed uses the MVC pattern (Model-View Controller). This way it becomes better to maintain than using no pattern in my opinion. Fixed some bugs in the debug draw interface. Of course, updated almost all tests because of the differences. Update script.
This commit is contained in:
@ -77,7 +77,7 @@ public:
|
||||
void FindNewPairs(T* callback);
|
||||
|
||||
// Draw the proxy AABBs.
|
||||
void Draw(b3Draw* draw) const;
|
||||
void Draw() const;
|
||||
private :
|
||||
friend class b3DynamicTree;
|
||||
|
||||
@ -189,9 +189,9 @@ inline void b3BroadPhase::FindNewPairs(T* callback)
|
||||
}
|
||||
}
|
||||
|
||||
inline void b3BroadPhase::Draw(b3Draw* draw) const
|
||||
inline void b3BroadPhase::Draw() const
|
||||
{
|
||||
m_tree.Draw(draw);
|
||||
m_tree.Draw();
|
||||
}
|
||||
|
||||
#endif
|
@ -21,20 +21,20 @@
|
||||
|
||||
#include <bounce/collision/sat/sat.h>
|
||||
|
||||
struct b3Segment;
|
||||
struct b3Capsule;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
float32 b3ProjectEdge(const b3Segment* hull, const b3Plane& plane);
|
||||
float32 b3ProjectEdge(const b3Capsule* hull, const b3Plane& plane);
|
||||
|
||||
b3FaceQuery b3QueryFaceSeparation(const b3Transform& xf1, const b3Segment* hull1,
|
||||
b3FaceQuery b3QueryFaceSeparation(const b3Transform& xf1, const b3Capsule* hull1,
|
||||
const b3Transform& xf2, const b3Hull* hull2);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
float32 b3ProjectEdge(const b3Vec3& P1, const b3Vec3& E1, const b3Vec3& P2, const b3Vec3& E2, const b3Vec3& C2);
|
||||
|
||||
b3EdgeQuery b3QueryEdgeSeparation(const b3Transform& xf1, const b3Segment* hull1,
|
||||
b3EdgeQuery b3QueryEdgeSeparation(const b3Transform& xf1, const b3Capsule* hull1,
|
||||
const b3Transform& xf2, const b3Hull* hull2);
|
||||
|
||||
#endif
|
@ -21,11 +21,13 @@
|
||||
|
||||
#include <bounce/collision/sat/sat.h>
|
||||
|
||||
struct b3Sphere;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
float32 b3ProjectVertex(const b3Vec3& hull, const b3Plane& plane);
|
||||
float32 b3ProjectVertex(const b3Sphere* hull, const b3Plane& plane);
|
||||
|
||||
b3FaceQuery b3QueryFaceSeparation(const b3Transform& xf1, const b3Vec3& hull1,
|
||||
b3FaceQuery b3QueryFaceSeparation(const b3Transform& xf1, const b3Sphere* hull1,
|
||||
const b3Transform& xf2, const b3Hull* hull2);
|
||||
|
||||
#endif
|
||||
|
@ -31,6 +31,12 @@ struct b3BoxHull : public b3Hull
|
||||
// Does nothing for performance.
|
||||
b3BoxHull() { }
|
||||
|
||||
// Construct this box from three extents and centered at the origin.
|
||||
b3BoxHull(float32 ex, float32 ey, float32 ez)
|
||||
{
|
||||
Set(ex, ey, ez);
|
||||
}
|
||||
|
||||
// Set this box to the unit box centered at the origin.
|
||||
void SetIdentity()
|
||||
{
|
||||
@ -174,4 +180,6 @@ struct b3BoxHull : public b3Hull
|
||||
}
|
||||
};
|
||||
|
||||
extern const b3BoxHull b3BoxHull_identity;
|
||||
|
||||
#endif
|
@ -21,20 +21,38 @@
|
||||
|
||||
#include <bounce/common/math/vec3.h>
|
||||
|
||||
struct b3Segment
|
||||
struct b3Capsule
|
||||
{
|
||||
//
|
||||
b3Capsule() { }
|
||||
|
||||
//
|
||||
b3Capsule(const b3Vec3& v1, const b3Vec3& v2, float32 r)
|
||||
{
|
||||
vertices[0] = v1;
|
||||
vertices[1] = v2;
|
||||
radius = r;
|
||||
}
|
||||
|
||||
//
|
||||
~b3Capsule() { }
|
||||
|
||||
b3Vec3 vertices[2];
|
||||
|
||||
float32 radius;
|
||||
|
||||
const b3Vec3& GetVertex(u32 index) const;
|
||||
u32 GetSupportVertex(const b3Vec3& direction) const;
|
||||
};
|
||||
|
||||
inline const b3Vec3& b3Segment::GetVertex(u32 index) const
|
||||
// Unit capsule centered at the origin
|
||||
extern const b3Capsule b3Capsule_identity;
|
||||
|
||||
inline const b3Vec3& b3Capsule::GetVertex(u32 index) const
|
||||
{
|
||||
return vertices[index];
|
||||
}
|
||||
|
||||
inline u32 b3Segment::GetSupportVertex(const b3Vec3& d) const
|
||||
inline u32 b3Capsule::GetSupportVertex(const b3Vec3& d) const
|
||||
{
|
||||
if (b3Dot(d, vertices[0]) > b3Dot(d, vertices[1]))
|
||||
{
|
||||
|
@ -57,6 +57,9 @@ struct b3Hull
|
||||
b3Plane GetEdgeSidePlane(u32 index) const;
|
||||
|
||||
u32 GetSize() const;
|
||||
|
||||
b3Vec3 GetCentroid() const;
|
||||
|
||||
void Validate() const;
|
||||
void Validate(const b3Face* face) const;
|
||||
void Validate(const b3HalfEdge* edge) const;
|
||||
|
@ -23,6 +23,19 @@
|
||||
|
||||
struct b3Sphere
|
||||
{
|
||||
//
|
||||
b3Sphere() { }
|
||||
|
||||
//
|
||||
b3Sphere(const b3Vec3& v, float32 r)
|
||||
{
|
||||
vertex = v;
|
||||
radius = r;
|
||||
}
|
||||
|
||||
//
|
||||
~b3Sphere() { }
|
||||
|
||||
b3Vec3 vertex;
|
||||
float32 radius;
|
||||
|
||||
@ -30,6 +43,9 @@ struct b3Sphere
|
||||
u32 GetSupportVertex(const b3Vec3& direction) const;
|
||||
};
|
||||
|
||||
// Unit sphere centered at origin
|
||||
extern const b3Sphere b3Sphere_identity;
|
||||
|
||||
inline const b3Vec3& b3Sphere::GetVertex(u32 index) const
|
||||
{
|
||||
B3_NOT_USED(index);
|
||||
|
@ -19,7 +19,6 @@
|
||||
#ifndef B3_DYNAMIC_TREE_H
|
||||
#define B3_DYNAMIC_TREE_H
|
||||
|
||||
#include <bounce/common/draw.h>
|
||||
#include <bounce/common/template/stack.h>
|
||||
#include <bounce/collision/shapes/aabb3.h>
|
||||
#include <bounce/collision/collision.h>
|
||||
@ -67,7 +66,7 @@ public :
|
||||
void Validate(i32 node) const;
|
||||
|
||||
// Draw this tree.
|
||||
void Draw(b3Draw* draw) const;
|
||||
void Draw() const;
|
||||
private :
|
||||
struct b3Node
|
||||
{
|
||||
|
@ -19,7 +19,6 @@
|
||||
#ifndef B3_STATIC_TREE_H
|
||||
#define B3_STATIC_TREE_H
|
||||
|
||||
#include <bounce/common/draw.h>
|
||||
#include <bounce/common/template/stack.h>
|
||||
#include <bounce/collision/shapes/aabb3.h>
|
||||
#include <bounce/collision/collision.h>
|
||||
@ -55,7 +54,7 @@ public:
|
||||
void RayCast(T* callback, const b3RayCastInput& input) const;
|
||||
|
||||
// Draw this tree.
|
||||
void Draw(b3Draw* draw) const;
|
||||
void Draw() const;
|
||||
|
||||
u32 GetSize() const;
|
||||
private :
|
||||
|
@ -117,6 +117,11 @@ public :
|
||||
u32 m_flags;
|
||||
};
|
||||
|
||||
// The debug drawer interface used by Bounce.
|
||||
// You should set this to an implementation
|
||||
// before calling any function that uses the interface.
|
||||
extern b3Draw* b3Draw_draw;
|
||||
|
||||
inline void b3Draw::SetFlags(u32 flags)
|
||||
{
|
||||
m_flags = flags;
|
||||
|
@ -46,6 +46,12 @@ struct b3Mat22
|
||||
b3Vec2 x, y;
|
||||
};
|
||||
|
||||
// Zero matrix
|
||||
extern const b3Mat22 b3Mat22_zero;
|
||||
|
||||
// Identity matrix
|
||||
extern const b3Mat22 b3Mat22_identity;
|
||||
|
||||
// Multiply a matrix times a vector.
|
||||
inline b3Vec2 operator*(const b3Mat22& A, const b3Vec2& v)
|
||||
{
|
||||
|
@ -90,8 +90,8 @@ struct b3Mat33
|
||||
};
|
||||
|
||||
// Usefull constants.
|
||||
extern b3Mat33 b3Mat33_zero;
|
||||
extern b3Mat33 b3Mat33_identity;
|
||||
extern const b3Mat33 b3Mat33_zero;
|
||||
extern const b3Mat33 b3Mat33_identity;
|
||||
|
||||
// Add two matrices.
|
||||
inline b3Mat33 operator+(const b3Mat33& A, const b3Mat33& B)
|
||||
|
@ -141,6 +141,9 @@ struct b3Quat
|
||||
float32 x, y, z, w;
|
||||
};
|
||||
|
||||
// Identity quaternion
|
||||
extern const b3Quat b3Quat_identity;
|
||||
|
||||
// Add two quaternions.
|
||||
inline b3Quat operator+(const b3Quat& a, const b3Quat& b)
|
||||
{
|
||||
|
@ -31,6 +31,13 @@ struct b3Transform
|
||||
// Default ctor does nothing for performance.
|
||||
b3Transform() { }
|
||||
|
||||
// Set this transform from a rotation matrix and a translation vector.
|
||||
b3Transform(const b3Mat33& _rotation, const b3Vec3& _translation)
|
||||
{
|
||||
rotation = _rotation;
|
||||
position = _translation;
|
||||
}
|
||||
|
||||
// Set this transform from a rotation quaternion and a translation vector.
|
||||
b3Transform(const b3Quat& _rotation, const b3Vec3& _translation)
|
||||
{
|
||||
@ -49,6 +56,9 @@ struct b3Transform
|
||||
b3Vec3 position; // in fact a translation
|
||||
};
|
||||
|
||||
// Identity transformation
|
||||
extern const b3Transform b3Transform_identity;
|
||||
|
||||
// Multiply a transform times a vector.
|
||||
inline b3Vec3 b3Mul(const b3Transform& T, const b3Vec3& v)
|
||||
{
|
||||
|
@ -91,6 +91,15 @@ struct b3Vec2
|
||||
float32 x, y;
|
||||
};
|
||||
|
||||
// Zero vector
|
||||
extern const b3Vec2 b3Vec2_zero;
|
||||
|
||||
// Left vector
|
||||
extern const b3Vec2 b3Vec2_x;
|
||||
|
||||
// Right vector
|
||||
extern const b3Vec2 b3Vec2_y;
|
||||
|
||||
// Negate a vector.
|
||||
inline b3Vec2 operator-(const b3Vec2& v)
|
||||
{
|
||||
|
@ -106,6 +106,18 @@ struct b3Vec3
|
||||
float32 x, y, z;
|
||||
};
|
||||
|
||||
// Zero vector
|
||||
extern const b3Vec3 b3Vec3_zero;
|
||||
|
||||
// Right vector
|
||||
extern const b3Vec3 b3Vec3_x;
|
||||
|
||||
// Up vector
|
||||
extern const b3Vec3 b3Vec3_y;
|
||||
|
||||
// Forward vector
|
||||
extern const b3Vec3 b3Vec3_z;
|
||||
|
||||
// Negate a vector.
|
||||
inline b3Vec3 operator-(const b3Vec3& v)
|
||||
{
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include <bounce/collision/collision.h>
|
||||
|
||||
struct b3Mesh;
|
||||
class b3Draw;
|
||||
|
||||
struct b3ClothDef
|
||||
{
|
||||
@ -110,7 +109,7 @@ public:
|
||||
return m_ps;
|
||||
}
|
||||
|
||||
void Draw(b3Draw* draw) const;
|
||||
void Draw() const;
|
||||
private:
|
||||
void SolveC1();
|
||||
void SolveC2();
|
||||
|
@ -25,7 +25,6 @@
|
||||
#define B3_CLOTH_SHAPE_CAPACITY 32
|
||||
|
||||
class b3StackAllocator;
|
||||
class b3Draw;
|
||||
|
||||
class b3Shape;
|
||||
|
||||
@ -188,7 +187,7 @@ public:
|
||||
void Apply() const;
|
||||
|
||||
// Debug draw the cloth mesh.
|
||||
void Draw(b3Draw* draw) const;
|
||||
void Draw() const;
|
||||
protected:
|
||||
friend class b3SpringSolver;
|
||||
|
||||
|
@ -75,11 +75,11 @@ struct b3ClipPlane
|
||||
};
|
||||
|
||||
struct b3Hull;
|
||||
struct b3Segment;
|
||||
struct b3Capsule;
|
||||
|
||||
// Build a clip edge for an edge.
|
||||
void b3BuildEdge(b3ClipVertex vOut[2],
|
||||
const b3Segment* hull);
|
||||
const b3Capsule* hull);
|
||||
|
||||
// Build a clip polygon given an index to the polygon face.
|
||||
void b3BuildPolygon(b3ClipPolygon& pOut,
|
||||
@ -99,7 +99,7 @@ void b3ClipPolygonToPlane(b3ClipPolygon& pOut,
|
||||
// Clip a segment by a hull face (side planes).
|
||||
// Return the number of output points.
|
||||
u32 b3ClipEdgeToFace(b3ClipVertex vOut[2],
|
||||
const b3ClipVertex vIn[2], const b3Segment* hull);
|
||||
const b3ClipVertex vIn[2], const b3Capsule* hull);
|
||||
|
||||
// Clip a segment by a hull face (side planes).
|
||||
// Return the number of output points.
|
||||
|
@ -81,7 +81,7 @@ public:
|
||||
void SetConeAngle(float32 angle);
|
||||
|
||||
// Draw this joint.
|
||||
void Draw(b3Draw* draw) const;
|
||||
void Draw() const;
|
||||
private:
|
||||
friend class b3Joint;
|
||||
friend class b3Body;
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include <bounce/common/template/list.h>
|
||||
#include <bounce/dynamics/time_step.h>
|
||||
|
||||
class b3Draw;
|
||||
class b3Body;
|
||||
class b3Joint;
|
||||
struct b3SolverData;
|
||||
@ -116,6 +115,12 @@ public:
|
||||
b3Log("Dump feature not implemented for this joint type.\n");
|
||||
}
|
||||
|
||||
// Draw this joint.
|
||||
virtual void Draw() const
|
||||
{
|
||||
b3Log("Draw feature not implemented for this joint type.\n");
|
||||
}
|
||||
|
||||
// Get the next joint in the world joint list.
|
||||
const b3Joint* GetNext() const;
|
||||
b3Joint* GetNext();
|
||||
|
@ -58,7 +58,7 @@ public:
|
||||
void SetTarget(const b3Vec3& target);
|
||||
|
||||
// Draw this joint.
|
||||
void Draw(b3Draw* draw) const;
|
||||
void Draw() const;
|
||||
private:
|
||||
friend class b3Joint;
|
||||
friend class b3JointManager;
|
||||
|
@ -132,7 +132,7 @@ public:
|
||||
void SetMaxMotorTorque(float32 torque);
|
||||
|
||||
// Draw this joint.
|
||||
void Draw(b3Draw* draw) const;
|
||||
void Draw() const;
|
||||
private:
|
||||
friend class b3Joint;
|
||||
friend class b3JointManager;
|
||||
|
@ -52,7 +52,7 @@ public:
|
||||
b3Vec3 GetAnchorB() const;
|
||||
|
||||
// Draw this joint.
|
||||
void Draw(b3Draw* draw) const;
|
||||
void Draw() const;
|
||||
private:
|
||||
friend class b3Joint;
|
||||
friend class b3JointManager;
|
||||
|
@ -94,7 +94,7 @@ public:
|
||||
void SetDampingRatio(float32 ratio);
|
||||
|
||||
// Draw this joint.
|
||||
void Draw(b3Draw* draw) const;
|
||||
void Draw() const;
|
||||
private:
|
||||
friend class b3Joint;
|
||||
friend class b3JointManager;
|
||||
|
@ -57,7 +57,7 @@ public:
|
||||
b3Vec3 GetAnchorB() const;
|
||||
|
||||
// Draw this joint.
|
||||
void Draw(b3Draw* draw) const;
|
||||
void Draw() const;
|
||||
private:
|
||||
friend class b3Joint;
|
||||
friend class b3JointManager;
|
||||
|
@ -21,8 +21,6 @@
|
||||
|
||||
#include <bounce/common/math/transform.h>
|
||||
|
||||
class b3Draw;
|
||||
|
||||
struct b3RopeBody;
|
||||
|
||||
//
|
||||
@ -86,7 +84,7 @@ public:
|
||||
void Step(float32 dt);
|
||||
|
||||
//
|
||||
void Draw(b3Draw* draw) const;
|
||||
void Draw() const;
|
||||
private:
|
||||
//
|
||||
float32 m_kd1, m_kd2;
|
||||
|
@ -117,13 +117,11 @@ public:
|
||||
const b3List2<b3Contact>& GetContactList() const;
|
||||
b3List2<b3Contact>& GetContactList();
|
||||
|
||||
// Debug draw the physics entities that belong to this world.
|
||||
// The user must implement the debug draw interface b3Draw and b3_debugDraw must have been
|
||||
// set to the user implementation.
|
||||
void DebugDraw() const;
|
||||
// Draw the entities in this world.
|
||||
void Draw() const;
|
||||
|
||||
// Draw a shape.
|
||||
void DrawShape(const b3Transform& xf, const b3Shape* shape) const;
|
||||
void DrawJoint(const b3Joint* joint) const;
|
||||
void DrawContact(const b3Contact* contact) const;
|
||||
private :
|
||||
enum b3Flags
|
||||
{
|
||||
@ -144,7 +142,6 @@ private :
|
||||
bool m_warmStarting;
|
||||
u32 m_flags;
|
||||
b3Vec3 m_gravity;
|
||||
b3Draw* m_debugDraw;
|
||||
|
||||
b3StackAllocator m_stackAllocator;
|
||||
b3BlockPool m_bodyBlocks;
|
||||
|
Reference in New Issue
Block a user