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:
27
src/bounce/collision/collision.cpp
Normal file
27
src/bounce/collision/collision.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2016 Irlan Robson http://www.irlan.net
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include <bounce/collision/shapes/sphere.h>
|
||||
#include <bounce/collision/shapes/capsule.h>
|
||||
#include <bounce/collision/shapes/box_hull.h>
|
||||
|
||||
const b3Sphere b3Sphere_identity(b3Vec3_zero, 1.0f);
|
||||
|
||||
const b3Capsule b3Capsule_identity(b3Vec3(0.0f, -0.5f, 0.0f), b3Vec3(0.0f, 0.5f, 0.0f), 1.0f);
|
||||
|
||||
const b3BoxHull b3BoxHull_identity(1.0f, 1.0f, 1.0f);
|
@ -20,13 +20,13 @@
|
||||
#include <bounce/collision/shapes/capsule.h>
|
||||
#include <bounce/collision/shapes/hull.h>
|
||||
|
||||
float32 b3ProjectEdge(const b3Segment* hull, const b3Plane& plane)
|
||||
float32 b3ProjectEdge(const b3Capsule* hull, const b3Plane& plane)
|
||||
{
|
||||
b3Vec3 support = hull->GetVertex(hull->GetSupportVertex(-plane.normal));
|
||||
return b3Distance(support, plane);
|
||||
}
|
||||
|
||||
b3FaceQuery b3QueryFaceSeparation(const b3Transform& xf1, const b3Segment* hull1,
|
||||
b3FaceQuery b3QueryFaceSeparation(const b3Transform& xf1, const b3Capsule* hull1,
|
||||
const b3Transform& xf2, const b3Hull* hull2)
|
||||
{
|
||||
// Perform computations in the local space of the first hull.
|
||||
@ -95,7 +95,7 @@ float32 b3ProjectEdge(const b3Vec3& P1, const b3Vec3& E1,
|
||||
return b3Dot(N, P2 - P1);
|
||||
}
|
||||
|
||||
b3EdgeQuery b3QueryEdgeSeparation(const b3Transform& xf1, const b3Segment* hull1, const b3Transform& xf2, const b3Hull* hull2)
|
||||
b3EdgeQuery b3QueryEdgeSeparation(const b3Transform& xf1, const b3Capsule* hull1, const b3Transform& xf2, const b3Hull* hull2)
|
||||
{
|
||||
// Query minimum edge separation.
|
||||
u32 maxIndex = 0;
|
||||
|
@ -20,17 +20,17 @@
|
||||
#include <bounce/collision/shapes/sphere.h>
|
||||
#include <bounce/collision/shapes/hull.h>
|
||||
|
||||
float32 b3ProjectVertex(const b3Vec3& hull, const b3Plane& plane)
|
||||
float32 b3ProjectVertex(const b3Sphere* hull, const b3Plane& plane)
|
||||
{
|
||||
b3Vec3 support = hull;
|
||||
b3Vec3 support = hull->GetVertex(hull->GetSupportVertex(-plane.normal));
|
||||
return b3Distance(support, plane);
|
||||
}
|
||||
|
||||
b3FaceQuery b3QueryFaceSeparation(const b3Transform& xf1, const b3Vec3& hull,
|
||||
b3FaceQuery b3QueryFaceSeparation(const b3Transform& xf1, const b3Sphere* hull,
|
||||
const b3Transform& xf2, const b3Hull* hull2)
|
||||
{
|
||||
// Perform computations in the local space of the second hull.
|
||||
b3Vec3 support = b3MulT(xf2, b3Mul(xf1, hull));
|
||||
b3Vec3 support = b3MulT(xf2, b3Mul(xf1, hull->vertex));
|
||||
|
||||
u32 maxIndex = 0;
|
||||
float32 maxSeparation = -B3_MAX_FLOAT;
|
||||
|
@ -77,4 +77,70 @@ void b3Hull::Validate(const b3HalfEdge* e) const
|
||||
B3_ASSERT(count < edgeCount);
|
||||
++count;
|
||||
} while (e != begin);
|
||||
}
|
||||
|
||||
b3Vec3 b3Hull::GetCentroid() const
|
||||
{
|
||||
Validate();
|
||||
|
||||
b3Vec3 c(0.0f, 0.0f, 0.0f);
|
||||
float32 volume = 0.0f;
|
||||
|
||||
// Pick reference point not too away from the origin
|
||||
// to minimize floating point rounding errors.
|
||||
b3Vec3 p1(0.0f, 0.0f, 0.0f);
|
||||
// Put it inside the hull.
|
||||
for (u32 i = 0; i < vertexCount; ++i)
|
||||
{
|
||||
p1 += vertices[i];
|
||||
}
|
||||
p1 /= float32(vertexCount);
|
||||
|
||||
const float32 inv4 = 0.25f;
|
||||
const float32 inv6 = 1.0f / 6.0f;
|
||||
const float32 inv60 = 1.0f / 60.0f;
|
||||
const float32 inv120 = 1.0f / 120.0f;
|
||||
|
||||
b3Vec3 diag(0.0f, 0.0f, 0.0f);
|
||||
b3Vec3 offDiag(0.0f, 0.0f, 0.0f);
|
||||
|
||||
// Triangulate convex polygons
|
||||
for (u32 i = 0; i < faceCount; ++i)
|
||||
{
|
||||
const b3Face* face = GetFace(i);
|
||||
const b3HalfEdge* begin = GetEdge(face->edge);
|
||||
|
||||
const b3HalfEdge* edge = GetEdge(begin->next);
|
||||
do
|
||||
{
|
||||
u32 i1 = begin->origin;
|
||||
u32 i2 = edge->origin;
|
||||
const b3HalfEdge* next = GetEdge(edge->next);
|
||||
u32 i3 = next->origin;
|
||||
|
||||
b3Vec3 p2 = vertices[i1];
|
||||
b3Vec3 p3 = vertices[i2];
|
||||
b3Vec3 p4 = vertices[i3];
|
||||
|
||||
b3Vec3 e1 = p2 - p1;
|
||||
b3Vec3 e2 = p3 - p1;
|
||||
b3Vec3 e3 = p4 - p1;
|
||||
|
||||
float32 D = b3Det(e1, e2, e3);
|
||||
|
||||
float32 tetraVolume = inv6 * D;
|
||||
volume += tetraVolume;
|
||||
|
||||
// Volume weighted centroid
|
||||
c += tetraVolume * inv4 * (e1 + e2 + e3);
|
||||
|
||||
edge = next;
|
||||
} while (GetEdge(edge->next) != begin);
|
||||
}
|
||||
|
||||
// Centroid
|
||||
B3_ASSERT(volume > B3_EPSILON);
|
||||
c /= volume;
|
||||
c += p1;
|
||||
return c;
|
||||
}
|
@ -17,6 +17,7 @@
|
||||
*/
|
||||
|
||||
#include <bounce/collision/trees/dynamic_tree.h>
|
||||
#include <bounce/common/draw.h>
|
||||
|
||||
b3DynamicTree::b3DynamicTree()
|
||||
{
|
||||
@ -362,7 +363,7 @@ void b3DynamicTree::Validate(i32 nodeID) const
|
||||
}
|
||||
}
|
||||
|
||||
void b3DynamicTree::Draw(b3Draw* draw) const
|
||||
void b3DynamicTree::Draw() const
|
||||
{
|
||||
if (m_nodeCount == 0)
|
||||
{
|
||||
@ -385,11 +386,11 @@ void b3DynamicTree::Draw(b3Draw* draw) const
|
||||
const b3Node* node = m_nodes + nodeIndex;
|
||||
if (node->IsLeaf())
|
||||
{
|
||||
draw->DrawAABB(node->aabb, b3Color_pink);
|
||||
b3Draw_draw->DrawAABB(node->aabb, b3Color_pink);
|
||||
}
|
||||
else
|
||||
{
|
||||
draw->DrawAABB(node->aabb, b3Color_red);
|
||||
b3Draw_draw->DrawAABB(node->aabb, b3Color_red);
|
||||
|
||||
stack.Push(node->child1);
|
||||
stack.Push(node->child2);
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include <bounce/collision/trees/static_tree.h>
|
||||
#include <bounce/common/template/stack.h>
|
||||
#include <bounce/common/draw.h>
|
||||
|
||||
b3StaticTree::b3StaticTree()
|
||||
{
|
||||
@ -178,7 +179,7 @@ void b3StaticTree::Build(const b3AABB3* set, u32 count)
|
||||
B3_ASSERT(m_nodeCount == nodeCapacity);
|
||||
}
|
||||
|
||||
void b3StaticTree::Draw(b3Draw* draw) const
|
||||
void b3StaticTree::Draw() const
|
||||
{
|
||||
if (m_nodeCount == 0)
|
||||
{
|
||||
@ -199,11 +200,11 @@ void b3StaticTree::Draw(b3Draw* draw) const
|
||||
const b3Node* node = m_nodes + nodeIndex;
|
||||
if (node->IsLeaf())
|
||||
{
|
||||
draw->DrawAABB(node->aabb, b3Color_pink);
|
||||
b3Draw_draw->DrawAABB(node->aabb, b3Color_pink);
|
||||
}
|
||||
else
|
||||
{
|
||||
draw->DrawAABB(node->aabb, b3Color_red);
|
||||
b3Draw_draw->DrawAABB(node->aabb, b3Color_red);
|
||||
|
||||
stack.Push(node->child1);
|
||||
stack.Push(node->child2);
|
||||
|
@ -16,28 +16,45 @@
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include <bounce/common/math/vec2.h>
|
||||
#include <bounce/common/math/vec3.h>
|
||||
|
||||
#include <bounce/common/math/mat22.h>
|
||||
#include <bounce/common/math/mat33.h>
|
||||
#include <bounce/common/math/mat44.h>
|
||||
#include <bounce/common/math/transform.h>
|
||||
|
||||
b3Mat22 b3Mat22_zero = b3Mat22(
|
||||
const b3Vec2 b3Vec2_zero(0.0f, 0.0f);
|
||||
const b3Vec2 b3Vec2_x(1.0f, 0.0f);
|
||||
const b3Vec2 b3Vec2_y(0.0f, 1.0f);
|
||||
|
||||
const b3Vec3 b3Vec3_zero(0.0f, 0.0f, 0.0f);
|
||||
const b3Vec3 b3Vec3_x(1.0f, 0.0f, 0.0f);
|
||||
const b3Vec3 b3Vec3_y(0.0f, 1.0f, 0.0f);
|
||||
const b3Vec3 b3Vec3_z(0.0f, 0.0f, 1.0f);
|
||||
|
||||
const b3Mat22 b3Mat22_zero(
|
||||
b3Vec2(0.0f, 0.0f),
|
||||
b3Vec2(0.0f, 0.0f));
|
||||
|
||||
b3Mat22 b3Mat22_identity = b3Mat22(
|
||||
const b3Mat22 b3Mat22_identity(
|
||||
b3Vec2(1.0f, 0.0f),
|
||||
b3Vec2(0.0f, 1.0f));
|
||||
|
||||
b3Mat33 b3Mat33_zero = b3Mat33(
|
||||
const b3Mat33 b3Mat33_zero(
|
||||
b3Vec3(0.0f, 0.0f, 0.0f),
|
||||
b3Vec3(0.0f, 0.0f, 0.0f),
|
||||
b3Vec3(0.0f, 0.0f, 0.0f));
|
||||
|
||||
b3Mat33 b3Mat33_identity = b3Mat33(
|
||||
const b3Mat33 b3Mat33_identity(
|
||||
b3Vec3(1.0f, 0.0f, 0.0f),
|
||||
b3Vec3(0.0f, 1.0f, 0.0f),
|
||||
b3Vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
const b3Transform b3Transform_identity(b3Mat33_identity, b3Vec3_zero);
|
||||
|
||||
const b3Quat b3Quat_identity(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
b3Vec2 b3Mat22::Solve(const b3Vec2& b) const
|
||||
{
|
||||
// Cramer's rule
|
@ -368,13 +368,13 @@ void b3Cloth::SolveC2()
|
||||
}
|
||||
}
|
||||
|
||||
void b3Cloth::Draw(b3Draw* draw) const
|
||||
void b3Cloth::Draw() const
|
||||
{
|
||||
const b3Mesh* m = m_mesh;
|
||||
|
||||
for (u32 i = 0; i < m->vertexCount; ++i)
|
||||
{
|
||||
draw->DrawPoint(m_ps[i].p, 6.0f, b3Color_green);
|
||||
b3Draw_draw->DrawPoint(m_ps[i].p, 6.0f, b3Color_green);
|
||||
}
|
||||
|
||||
for (u32 i = 0; i < m->triangleCount; ++i)
|
||||
@ -394,7 +394,7 @@ void b3Cloth::Draw(b3Draw* draw) const
|
||||
|
||||
b3Vec3 n2 = -n1;
|
||||
|
||||
draw->DrawSolidTriangle(n1, v1, v2, v3, b3Color_blue);
|
||||
draw->DrawSolidTriangle(n2, v1, v3, v2, b3Color_blue);
|
||||
b3Draw_draw->DrawSolidTriangle(n1, v1, v2, v3, b3Color_blue);
|
||||
b3Draw_draw->DrawSolidTriangle(n2, v1, v3, v2, b3Color_blue);
|
||||
}
|
||||
}
|
@ -23,6 +23,7 @@
|
||||
#include <bounce/dynamics/shapes/shape.h>
|
||||
#include <bounce/collision/shapes/mesh.h>
|
||||
#include <bounce/common/memory/stack_allocator.h>
|
||||
#include <bounce/common/draw.h>
|
||||
|
||||
#define B3_FORCE_THRESHOLD (0.1f)
|
||||
|
||||
@ -610,7 +611,7 @@ void b3SpringCloth::Apply() const
|
||||
}
|
||||
}
|
||||
|
||||
void b3SpringCloth::Draw(b3Draw* draw) const
|
||||
void b3SpringCloth::Draw() const
|
||||
{
|
||||
const b3Mesh* m = m_mesh;
|
||||
|
||||
@ -620,16 +621,16 @@ void b3SpringCloth::Draw(b3Draw* draw) const
|
||||
{
|
||||
if (m_contacts[i].Fn < B3_FORCE_THRESHOLD)
|
||||
{
|
||||
draw->DrawPoint(m_x[i], 6.0f, b3Color_yellow);
|
||||
b3Draw_draw->DrawPoint(m_x[i], 6.0f, b3Color_yellow);
|
||||
}
|
||||
else
|
||||
{
|
||||
draw->DrawPoint(m_x[i], 6.0f, b3Color_red);
|
||||
b3Draw_draw->DrawPoint(m_x[i], 6.0f, b3Color_red);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
draw->DrawPoint(m_x[i], 6.0f, b3Color_green);
|
||||
b3Draw_draw->DrawPoint(m_x[i], 6.0f, b3Color_green);
|
||||
}
|
||||
}
|
||||
|
||||
@ -646,7 +647,7 @@ void b3SpringCloth::Draw(b3Draw* draw) const
|
||||
|
||||
b3Vec3 n2 = -n1;
|
||||
|
||||
draw->DrawSolidTriangle(n1, v1, v2, v3, b3Color_blue);
|
||||
draw->DrawSolidTriangle(n2, v1, v3, v2, b3Color_blue);
|
||||
b3Draw_draw->DrawSolidTriangle(n1, v1, v2, v3, b3Color_blue);
|
||||
b3Draw_draw->DrawSolidTriangle(n2, v1, v3, v2, b3Color_blue);
|
||||
}
|
||||
}
|
@ -21,7 +21,7 @@
|
||||
#include <bounce/collision/shapes/hull.h>
|
||||
|
||||
void b3BuildEdge(b3ClipVertex vOut[2],
|
||||
const b3Segment* hull)
|
||||
const b3Capsule* hull)
|
||||
{
|
||||
vOut[0].position = hull->vertices[0];
|
||||
vOut[0].pair = b3MakePair(0, B3_NULL_EDGE, 0, B3_NULL_EDGE);
|
||||
@ -150,7 +150,7 @@ void b3ClipPolygonToPlane(b3ClipPolygon& pOut,
|
||||
|
||||
// Clip a segment to edge side planes.
|
||||
u32 b3ClipEdgeToFace(b3ClipVertex vOut[2],
|
||||
const b3ClipVertex vIn[2], const b3Segment* hull)
|
||||
const b3ClipVertex vIn[2], const b3Capsule* hull)
|
||||
{
|
||||
// Start from somewhere.
|
||||
vOut[0] = vIn[0];
|
||||
@ -277,4 +277,4 @@ void b3ClipPolygonToFace(b3ClipPolygon& pOut,
|
||||
} while (edge != begin);
|
||||
|
||||
// Now pOut contains the clipped points.
|
||||
}
|
||||
}
|
@ -94,13 +94,11 @@ static void b3BuildFaceContact(b3Manifold& manifold,
|
||||
const b3Transform& xf2, u32 index2, const b3HullShape* s2)
|
||||
{
|
||||
// Clip edge 1 against the side planes of the face 2.
|
||||
b3Segment segment1;
|
||||
segment1.vertices[0] = xf1 * s1->m_centers[0];
|
||||
segment1.vertices[1] = xf1 * s1->m_centers[1];
|
||||
const b3Capsule hull1(xf1 * s1->m_centers[0], xf1 * s1->m_centers[1], 0.0f);
|
||||
float32 r1 = s1->m_radius;
|
||||
|
||||
b3ClipVertex edge1[2];
|
||||
b3BuildEdge(edge1, &segment1);
|
||||
b3BuildEdge(edge1, &hull1);
|
||||
|
||||
const b3Hull* hull2 = s2->m_hull;
|
||||
float32 r2 = s2->m_radius;
|
||||
@ -162,10 +160,7 @@ void b3CollideCapsuleAndHull(b3Manifold& manifold,
|
||||
return;
|
||||
}
|
||||
|
||||
b3Segment hull1;
|
||||
hull1.vertices[0] = s1->m_centers[0];
|
||||
hull1.vertices[1] = s1->m_centers[1];
|
||||
|
||||
const b3Capsule hull1(s1->m_centers[0], s1->m_centers[1], 0.0f);
|
||||
const b3Hull* hull2 = s2->m_hull;
|
||||
|
||||
if (gjk.distance > B3_EPSILON)
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include <bounce/collision/shapes/capsule.h>
|
||||
|
||||
// Compute the closest point on a segment to a point.
|
||||
static b3Vec3 b3ClosestPoint(const b3Vec3& Q, const b3Segment& hull)
|
||||
static b3Vec3 b3ClosestPoint(const b3Vec3& Q, const b3Capsule& hull)
|
||||
{
|
||||
b3Vec3 A = hull.vertices[0];
|
||||
b3Vec3 B = hull.vertices[1];
|
||||
@ -56,7 +56,7 @@ static b3Vec3 b3ClosestPoint(const b3Vec3& Q, const b3Segment& hull)
|
||||
|
||||
// Compute the closest points between two line segments.
|
||||
static void b3ClosestPoints(b3Vec3& C1, b3Vec3& C2,
|
||||
const b3Segment& hull1, const b3Segment& hull2)
|
||||
const b3Capsule& hull1, const b3Capsule& hull2)
|
||||
{
|
||||
b3Vec3 P1 = hull1.vertices[0];
|
||||
b3Vec3 Q1 = hull1.vertices[1];
|
||||
@ -136,7 +136,7 @@ static void b3ClosestPoints(b3Vec3& C1, b3Vec3& C2,
|
||||
C1 = b3ClosestPoint(C2, hull1);
|
||||
}
|
||||
|
||||
static bool b3AreParalell(const b3Segment& hull1, const b3Segment& hull2)
|
||||
static bool b3AreParalell(const b3Capsule& hull1, const b3Capsule& hull2)
|
||||
{
|
||||
b3Vec3 E1 = hull1.vertices[1] - hull1.vertices[0];
|
||||
float32 L1 = b3Length(E1);
|
||||
@ -162,11 +162,11 @@ void b3CollideCapsuleAndCapsule(b3Manifold& manifold,
|
||||
const b3Transform& xf1, const b3CapsuleShape* s1,
|
||||
const b3Transform& xf2, const b3CapsuleShape* s2)
|
||||
{
|
||||
b3Segment hull1;
|
||||
b3Capsule hull1;
|
||||
hull1.vertices[0] = xf1 * s1->m_centers[0];
|
||||
hull1.vertices[1] = xf1 * s1->m_centers[1];
|
||||
|
||||
b3Segment hull2;
|
||||
b3Capsule hull2;
|
||||
hull2.vertices[0] = xf2 * s2->m_centers[0];
|
||||
hull2.vertices[1] = xf2 * s2->m_centers[1];
|
||||
|
||||
|
@ -58,10 +58,10 @@ void b3CollideSphereAndHull(b3Manifold& manifold,
|
||||
return;
|
||||
}
|
||||
|
||||
const b3Vec3& hull1 = s1->m_center;
|
||||
const b3Sphere hull1(s1->m_center, 0.0f);
|
||||
const b3Hull* hull2 = s2->m_hull;
|
||||
|
||||
b3FaceQuery faceQuery = b3QueryFaceSeparation(xf1, hull1, xf2, hull2);
|
||||
b3FaceQuery faceQuery = b3QueryFaceSeparation(xf1, &hull1, xf2, hull2);
|
||||
if (faceQuery.separation > totalRadius)
|
||||
{
|
||||
return;
|
||||
@ -70,7 +70,7 @@ void b3CollideSphereAndHull(b3Manifold& manifold,
|
||||
b3Plane localPlane2 = hull2->planes[faceQuery.index];
|
||||
b3Plane plane2 = xf2 * localPlane2;
|
||||
|
||||
b3Vec3 c1 = xf1 * hull1;
|
||||
b3Vec3 c1 = xf1 * hull1.vertex;
|
||||
b3Vec3 c2 = b3ClosestPointOnPlane(c1, plane2);
|
||||
|
||||
// Ensure normal orientation to shape 2
|
||||
|
@ -26,13 +26,13 @@ const b3Color b3Color_blue(0.0f, 0.0f, 1.0f);
|
||||
const b3Color b3Color_yellow(1.0f, 1.0f, 0.0f);
|
||||
const b3Color b3Color_pink(1.0f, 0.0f, 1.0f);
|
||||
|
||||
b3Draw* b3_debugDraw = NULL;
|
||||
b3Draw* b3Draw_draw(nullptr);
|
||||
|
||||
void b3World::DebugDraw() const
|
||||
void b3World::Draw() const
|
||||
{
|
||||
B3_ASSERT(b3_debugDraw);
|
||||
B3_ASSERT(b3Draw_draw);
|
||||
|
||||
u32 flags = b3_debugDraw->m_flags;
|
||||
u32 flags = b3Draw_draw->m_flags;
|
||||
|
||||
if (flags & b3Draw::e_centerOfMassesFlag)
|
||||
{
|
||||
@ -40,7 +40,7 @@ void b3World::DebugDraw() const
|
||||
{
|
||||
b3Transform xf = b->m_xf;
|
||||
xf.position = b->m_sweep.worldCenter;
|
||||
b3_debugDraw->DrawTransform(xf);
|
||||
b3Draw_draw->DrawTransform(xf);
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,7 +63,7 @@ void b3World::DebugDraw() const
|
||||
for (b3Shape* s = b->m_shapeList.m_head; s; s = s->m_next)
|
||||
{
|
||||
const b3AABB3& aabb = m_contactMan.m_broadPhase.GetAABB(s->m_broadPhaseID);
|
||||
b3_debugDraw->DrawAABB(aabb, b3Color_pink);
|
||||
b3Draw_draw->DrawAABB(aabb, b3Color_pink);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -72,7 +72,7 @@ void b3World::DebugDraw() const
|
||||
{
|
||||
for (b3Joint* j = m_jointMan.m_jointList.m_head; j; j = j->m_next)
|
||||
{
|
||||
DrawJoint(j);
|
||||
j->Draw();
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,12 +103,12 @@ void b3World::DebugDraw() const
|
||||
|
||||
if (flags & b3Draw::e_contactPointsFlag)
|
||||
{
|
||||
b3_debugDraw->DrawPoint(p, 4.0f, mp->persisting ? b3Color_green : b3Color_red);
|
||||
b3Draw_draw->DrawPoint(p, 4.0f, mp->persisting ? b3Color_green : b3Color_red);
|
||||
}
|
||||
|
||||
if (flags & b3Draw::e_contactNormalsFlag)
|
||||
{
|
||||
b3_debugDraw->DrawSegment(p, p + n, b3Color_white);
|
||||
b3Draw_draw->DrawSegment(p, p + n, b3Color_white);
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,20 +121,20 @@ void b3World::DebugDraw() const
|
||||
|
||||
if (flags & b3Draw::e_contactNormalsFlag)
|
||||
{
|
||||
b3_debugDraw->DrawSegment(p, p + n, b3Color_yellow);
|
||||
b3Draw_draw->DrawSegment(p, p + n, b3Color_yellow);
|
||||
}
|
||||
|
||||
if (flags & b3Draw::e_contactTangentsFlag)
|
||||
{
|
||||
b3_debugDraw->DrawSegment(p, p + t1, b3Color_yellow);
|
||||
b3_debugDraw->DrawSegment(p, p + t2, b3Color_yellow);
|
||||
b3Draw_draw->DrawSegment(p, p + t1, b3Color_yellow);
|
||||
b3Draw_draw->DrawSegment(p, p + t2, b3Color_yellow);
|
||||
}
|
||||
|
||||
if (m->pointCount > 2)
|
||||
{
|
||||
if (flags & b3Draw::e_contactPolygonsFlag)
|
||||
{
|
||||
b3_debugDraw->DrawSolidPolygon(wm.normal, points, m->pointCount, b3Color_pink);
|
||||
b3Draw_draw->DrawSolidPolygon(wm.normal, points, m->pointCount, b3Color_pink);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -151,7 +151,7 @@ void b3World::DrawShape(const b3Transform& xf, const b3Shape* shape) const
|
||||
{
|
||||
const b3SphereShape* sphere = (b3SphereShape*)shape;
|
||||
b3Vec3 p = xf * sphere->m_center;
|
||||
b3_debugDraw->DrawPoint(p, 4.0f, wireColor);
|
||||
b3Draw_draw->DrawPoint(p, 4.0f, wireColor);
|
||||
break;
|
||||
}
|
||||
case e_capsuleShape:
|
||||
@ -159,9 +159,9 @@ void b3World::DrawShape(const b3Transform& xf, const b3Shape* shape) const
|
||||
const b3CapsuleShape* capsule = (b3CapsuleShape*)shape;
|
||||
b3Vec3 p1 = xf * capsule->m_centers[0];
|
||||
b3Vec3 p2 = xf * capsule->m_centers[1];
|
||||
b3_debugDraw->DrawPoint(p1, 4.0f, wireColor);
|
||||
b3_debugDraw->DrawPoint(p2, 4.0f, wireColor);
|
||||
b3_debugDraw->DrawSegment(p1, p2, wireColor);
|
||||
b3Draw_draw->DrawPoint(p1, 4.0f, wireColor);
|
||||
b3Draw_draw->DrawPoint(p2, 4.0f, wireColor);
|
||||
b3Draw_draw->DrawSegment(p1, p2, wireColor);
|
||||
break;
|
||||
}
|
||||
case e_hullShape:
|
||||
@ -176,7 +176,7 @@ void b3World::DrawShape(const b3Transform& xf, const b3Shape* shape) const
|
||||
b3Vec3 p1 = xf * hull->vertices[edge->origin];
|
||||
b3Vec3 p2 = xf * hull->vertices[twin->origin];
|
||||
|
||||
b3_debugDraw->DrawSegment(p1, p2, wireColor);
|
||||
b3Draw_draw->DrawSegment(p1, p2, wireColor);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -192,7 +192,7 @@ void b3World::DrawShape(const b3Transform& xf, const b3Shape* shape) const
|
||||
b3Vec3 p2 = xf * mesh->vertices[t->v2];
|
||||
b3Vec3 p3 = xf * mesh->vertices[t->v3];
|
||||
|
||||
b3_debugDraw->DrawTriangle(p1, p2, p3, wireColor);
|
||||
b3Draw_draw->DrawTriangle(p1, p2, p3, wireColor);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -201,59 +201,4 @@ void b3World::DrawShape(const b3Transform& xf, const b3Shape* shape) const
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void b3World::DrawJoint(const b3Joint* joint) const
|
||||
{
|
||||
b3JointType type = joint->GetType();
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case e_mouseJoint:
|
||||
{
|
||||
b3MouseJoint* o = (b3MouseJoint*)joint;
|
||||
o->Draw(b3_debugDraw);
|
||||
break;
|
||||
}
|
||||
case e_springJoint:
|
||||
{
|
||||
b3SpringJoint* o = (b3SpringJoint*)joint;
|
||||
o->Draw(b3_debugDraw);
|
||||
break;
|
||||
}
|
||||
case e_weldJoint:
|
||||
{
|
||||
b3WeldJoint* o = (b3WeldJoint*)joint;
|
||||
o->Draw(b3_debugDraw);
|
||||
break;
|
||||
}
|
||||
case e_revoluteJoint:
|
||||
{
|
||||
b3RevoluteJoint* o = (b3RevoluteJoint*)joint;
|
||||
o->Draw(b3_debugDraw);
|
||||
break;
|
||||
}
|
||||
case e_sphereJoint:
|
||||
{
|
||||
b3SphereJoint* o = (b3SphereJoint*)joint;
|
||||
o->Draw(b3_debugDraw);
|
||||
break;
|
||||
}
|
||||
case e_coneJoint:
|
||||
{
|
||||
b3ConeJoint* o = (b3ConeJoint*)joint;
|
||||
o->Draw(b3_debugDraw);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
B3_ASSERT(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void b3World::DrawContact(const b3Contact* c) const
|
||||
{
|
||||
B3_NOT_USED(c);
|
||||
}
|
||||
}
|
@ -346,10 +346,10 @@ void b3ConeJoint::SetConeAngle(float32 angle)
|
||||
}
|
||||
}
|
||||
|
||||
void b3ConeJoint::Draw(b3Draw* draw) const
|
||||
void b3ConeJoint::Draw() const
|
||||
{
|
||||
b3Transform xfA = GetFrameA();
|
||||
draw->DrawTransform(xfA);
|
||||
b3Draw_draw->DrawTransform(xfA);
|
||||
b3Transform xfB = GetFrameB();
|
||||
draw->DrawTransform(xfB);
|
||||
b3Draw_draw->DrawTransform(xfB);
|
||||
}
|
@ -109,12 +109,12 @@ void b3MouseJoint::SetTarget(const b3Vec3& target)
|
||||
GetBodyB()->SetAwake(true);
|
||||
}
|
||||
|
||||
void b3MouseJoint::Draw(b3Draw* draw) const
|
||||
void b3MouseJoint::Draw() const
|
||||
{
|
||||
b3Vec3 a = GetAnchorA();
|
||||
b3Vec3 b = GetAnchorB();
|
||||
|
||||
draw->DrawPoint(a, 4.0f, b3Color_green);
|
||||
draw->DrawPoint(b, 4.0f, b3Color_red);
|
||||
draw->DrawSegment(a, b, b3Color_yellow);
|
||||
b3Draw_draw->DrawPoint(a, 4.0f, b3Color_green);
|
||||
b3Draw_draw->DrawPoint(b, 4.0f, b3Color_red);
|
||||
b3Draw_draw->DrawSegment(a, b, b3Color_yellow);
|
||||
}
|
@ -749,10 +749,11 @@ void b3RevoluteJoint::SetMaxMotorTorque(float32 torque)
|
||||
m_maxMotorTorque = torque;
|
||||
}
|
||||
|
||||
void b3RevoluteJoint::Draw(b3Draw* draw) const
|
||||
void b3RevoluteJoint::Draw() const
|
||||
{
|
||||
b3Transform xfA = GetFrameA();
|
||||
b3Draw_draw->DrawTransform(xfA);
|
||||
|
||||
b3Transform xfB = GetFrameB();
|
||||
draw->DrawTransform(xfA);
|
||||
draw->DrawTransform(xfB);
|
||||
b3Draw_draw->DrawTransform(xfB);
|
||||
}
|
@ -157,12 +157,13 @@ b3Vec3 b3SphereJoint::GetAnchorB() const
|
||||
return GetBodyB()->GetWorldPoint(m_localAnchorB);
|
||||
}
|
||||
|
||||
void b3SphereJoint::Draw(b3Draw* draw) const
|
||||
void b3SphereJoint::Draw() const
|
||||
{
|
||||
b3Vec3 a = GetAnchorA();
|
||||
b3Vec3 b = GetAnchorB();
|
||||
b3Draw_draw->DrawPoint(a, 4.0f, b3Color_red);
|
||||
|
||||
draw->DrawPoint(a, 4.0f, b3Color_red);
|
||||
draw->DrawPoint(b, 4.0f, b3Color_green);
|
||||
draw->DrawSegment(a, b, b3Color_yellow);
|
||||
b3Vec3 b = GetAnchorB();
|
||||
b3Draw_draw->DrawPoint(b, 4.0f, b3Color_green);
|
||||
|
||||
b3Draw_draw->DrawSegment(a, b, b3Color_yellow);
|
||||
}
|
||||
|
@ -252,12 +252,13 @@ bool b3SpringJoint::SolvePositionConstraints(const b3SolverData* data)
|
||||
return b3Abs(C) < B3_LINEAR_SLOP;
|
||||
}
|
||||
|
||||
void b3SpringJoint::Draw(b3Draw* draw) const
|
||||
void b3SpringJoint::Draw() const
|
||||
{
|
||||
b3Vec3 a = GetBodyA()->GetWorldPoint(m_localAnchorA);
|
||||
b3Vec3 b = GetBodyB()->GetWorldPoint(m_localAnchorB);
|
||||
b3Draw_draw->DrawPoint(a, 4.0f, b3Color_red);
|
||||
|
||||
draw->DrawPoint(a, 4.0f, b3Color_red);
|
||||
draw->DrawPoint(b, 4.0f, b3Color_green);
|
||||
draw->DrawSegment(a, b, b3Color_yellow);
|
||||
}
|
||||
b3Vec3 b = GetBodyB()->GetWorldPoint(m_localAnchorB);
|
||||
b3Draw_draw->DrawPoint(b, 4.0f, b3Color_green);
|
||||
|
||||
b3Draw_draw->DrawSegment(a, b, b3Color_yellow);
|
||||
}
|
@ -311,12 +311,13 @@ b3Vec3 b3WeldJoint::GetAnchorB() const
|
||||
return GetBodyB()->GetWorldPoint(m_localAnchorB);
|
||||
}
|
||||
|
||||
void b3WeldJoint::Draw(b3Draw* draw) const
|
||||
void b3WeldJoint::Draw() const
|
||||
{
|
||||
b3Vec3 a = GetAnchorA();
|
||||
b3Draw_draw->DrawPoint(a, 4.0f, b3Color_red);
|
||||
|
||||
b3Vec3 b = GetAnchorB();
|
||||
|
||||
draw->DrawPoint(a, 4.0f, b3Color_red);
|
||||
draw->DrawPoint(b, 4.0f, b3Color_green);
|
||||
draw->DrawSegment(a, b, b3Color_yellow);
|
||||
}
|
||||
b3Draw_draw->DrawPoint(b, 4.0f, b3Color_green);
|
||||
|
||||
b3Draw_draw->DrawSegment(a, b, b3Color_yellow);
|
||||
}
|
@ -170,12 +170,13 @@ void b3Rope::Initialize(const b3RopeDef& def)
|
||||
|
||||
b3Vec3 d = -b->m_X_J_j.position;
|
||||
|
||||
b3Vec3 w1(1.0f, 0.0f, 0.0f);
|
||||
b3Vec3 w2(0.0f, 1.0f, 0.0f);
|
||||
b3Vec3 w3(0.0f, 0.0f, 1.0f);
|
||||
|
||||
b3Vec3 w1(b3Vec3_x);
|
||||
b3Vec3 v1 = b3Cross(w1, d);
|
||||
|
||||
b3Vec3 w2(b3Vec3_y);
|
||||
b3Vec3 v2 = b3Cross(w2, d);
|
||||
|
||||
b3Vec3 w3(b3Vec3_z);
|
||||
b3Vec3 v3 = b3Cross(w3, d);
|
||||
|
||||
b->m_S[0].w = w1;
|
||||
@ -468,7 +469,7 @@ void b3Rope::Step(float32 h)
|
||||
}
|
||||
}
|
||||
|
||||
void b3Rope::Draw(b3Draw* draw) const
|
||||
void b3Rope::Draw() const
|
||||
{
|
||||
if (m_count == 0)
|
||||
{
|
||||
@ -478,8 +479,8 @@ void b3Rope::Draw(b3Draw* draw) const
|
||||
{
|
||||
b3RopeBody* b = m_links;
|
||||
|
||||
draw->DrawTransform(b->m_X);
|
||||
draw->DrawSolidSphere(b->m_X.position, 0.2f, b3Color_green);
|
||||
b3Draw_draw->DrawTransform(b->m_X);
|
||||
b3Draw_draw->DrawSolidSphere(b->m_X.position, 0.2f, b3Color_green);
|
||||
}
|
||||
|
||||
for (u32 i = 1; i < m_count; ++i)
|
||||
@ -490,13 +491,13 @@ void b3Rope::Draw(b3Draw* draw) const
|
||||
b3Transform X_J = b0->m_X * b3Inverse(b->m_X_i_J);
|
||||
b3Transform X_J0 = b->m_X * b->m_X_J_j;
|
||||
|
||||
draw->DrawTransform(X_J);
|
||||
draw->DrawPoint(X_J.position, 5.0f, b3Color_red);
|
||||
b3Draw_draw->DrawTransform(X_J);
|
||||
b3Draw_draw->DrawPoint(X_J.position, 5.0f, b3Color_red);
|
||||
|
||||
draw->DrawTransform(X_J0);
|
||||
draw->DrawPoint(X_J0.position, 5.0f, b3Color_red);
|
||||
b3Draw_draw->DrawTransform(X_J0);
|
||||
b3Draw_draw->DrawPoint(X_J0.position, 5.0f, b3Color_red);
|
||||
|
||||
draw->DrawTransform(b->m_X);
|
||||
draw->DrawSolidSphere(b->m_X.position, 0.2f, b3Color_green);
|
||||
b3Draw_draw->DrawTransform(b->m_X);
|
||||
b3Draw_draw->DrawSolidSphere(b->m_X.position, 0.2f, b3Color_green);
|
||||
}
|
||||
}
|
@ -32,7 +32,6 @@ b3World::b3World() : m_bodyBlocks(sizeof(b3Body))
|
||||
{
|
||||
b3_allocCalls = 0;
|
||||
b3_maxAllocCalls = 0;
|
||||
m_debugDraw = NULL;
|
||||
|
||||
m_flags = e_clearForcesFlag;
|
||||
m_sleeping = false;
|
||||
|
Reference in New Issue
Block a user