improve friction quality, add shader-only support, improve debug drawing facilities, fix couple things
This commit is contained in:
@ -19,31 +19,10 @@
|
||||
#ifndef B3_MESH_H
|
||||
#define B3_MESH_H
|
||||
|
||||
#include <bounce/common/geometry.h>
|
||||
#include <bounce/collision/trees/static_tree.h>
|
||||
|
||||
// A triangle in indexed form.
|
||||
struct b3Triangle
|
||||
{
|
||||
// Does nothing for performance.
|
||||
b3Triangle() { }
|
||||
|
||||
// Set this triangle from three vertices.
|
||||
b3Triangle(u32 _v1, u32 _v2, u32 _v3)
|
||||
{
|
||||
v1 = _v1;
|
||||
v2 = _v2;
|
||||
v3 = _v3;
|
||||
}
|
||||
|
||||
// Set this triangle from three vertices.
|
||||
void Set(u32 _v1, u32 _v2, u32 _v3)
|
||||
{
|
||||
v1 = _v1;
|
||||
v2 = _v2;
|
||||
v3 = _v3;
|
||||
}
|
||||
|
||||
// Test if this triangle contains a given vertex.
|
||||
bool TestVertex(u32 v) const
|
||||
{
|
||||
@ -67,33 +46,15 @@ struct b3Mesh
|
||||
b3Triangle* triangles;
|
||||
b3StaticTree tree;
|
||||
|
||||
void BuildTree();
|
||||
|
||||
const b3Vec3& GetVertex(u32 index) const;
|
||||
const b3Triangle& GetTriangle(u32 index) const;
|
||||
|
||||
void GetTriangleVertices(b3Vec3 out[3], u32 index) const;
|
||||
b3Plane GetTrianglePlane(u32 index) const;
|
||||
b3AABB3 GetTriangleAABB(u32 index) const;
|
||||
u32 GetSize() const;
|
||||
|
||||
b3AABB3 GetTriangleAABB(u32 index) const;
|
||||
|
||||
void BuildTree();
|
||||
};
|
||||
|
||||
inline void b3Mesh::BuildTree()
|
||||
{
|
||||
b3AABB3* aabbs = (b3AABB3*)b3Alloc(triangleCount * sizeof(b3AABB3));
|
||||
u32* indices = (u32*)b3Alloc(triangleCount * sizeof(u32));
|
||||
for (u32 i = 0; i < triangleCount; ++i)
|
||||
{
|
||||
aabbs[i] = GetTriangleAABB(i);
|
||||
indices[i] = i;
|
||||
}
|
||||
|
||||
tree.Build(indices, aabbs, triangleCount);
|
||||
|
||||
b3Free(indices);
|
||||
b3Free(aabbs);
|
||||
}
|
||||
|
||||
inline const b3Vec3& b3Mesh::GetVertex(u32 index) const
|
||||
{
|
||||
return vertices[index];
|
||||
@ -104,22 +65,14 @@ inline const b3Triangle& b3Mesh::GetTriangle(u32 index) const
|
||||
return triangles[index];
|
||||
}
|
||||
|
||||
inline void b3Mesh::GetTriangleVertices(b3Vec3 out[3], u32 index) const
|
||||
inline u32 b3Mesh::GetSize() const
|
||||
{
|
||||
const b3Triangle* triangle = triangles + index;
|
||||
u32 i1 = triangle->v1;
|
||||
u32 i2 = triangle->v2;
|
||||
u32 i3 = triangle->v3;
|
||||
out[0] = vertices[i1];
|
||||
out[1] = vertices[i2];
|
||||
out[2] = vertices[i3];
|
||||
}
|
||||
|
||||
inline b3Plane b3Mesh::GetTrianglePlane(u32 index) const
|
||||
{
|
||||
b3Vec3 vs[3];
|
||||
GetTriangleVertices(vs, index);
|
||||
return b3Plane(vs[0], vs[1], vs[2]);
|
||||
u32 size = 0;
|
||||
size += sizeof(b3Mesh);
|
||||
size += sizeof(b3Vec3) * vertexCount;
|
||||
size += sizeof(b3Triangle) * triangleCount;
|
||||
size += tree.GetSize();
|
||||
return size;
|
||||
}
|
||||
|
||||
inline b3AABB3 b3Mesh::GetTriangleAABB(u32 index) const
|
||||
@ -133,18 +86,20 @@ inline b3AABB3 b3Mesh::GetTriangleAABB(u32 index) const
|
||||
b3AABB3 aabb;
|
||||
aabb.m_lower = b3Min(b3Min(vertices[i1], vertices[i2]), vertices[i3]);
|
||||
aabb.m_upper = b3Max(b3Max(vertices[i1], vertices[i2]), vertices[i3]);
|
||||
|
||||
return aabb;
|
||||
}
|
||||
|
||||
inline u32 b3Mesh::GetSize() const
|
||||
inline void b3Mesh::BuildTree()
|
||||
{
|
||||
u32 size = 0;
|
||||
size += sizeof(b3Mesh);
|
||||
size += sizeof(b3Vec3) * vertexCount;
|
||||
size += sizeof(b3Triangle) * triangleCount;
|
||||
size += tree.GetSize();
|
||||
return size;
|
||||
b3AABB3* aabbs = (b3AABB3*)b3Alloc(triangleCount * sizeof(b3AABB3));
|
||||
for (u32 i = 0; i < triangleCount; ++i)
|
||||
{
|
||||
aabbs[i] = GetTriangleAABB(i);
|
||||
}
|
||||
|
||||
tree.Build(aabbs, triangleCount);
|
||||
|
||||
b3Free(aabbs);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -33,9 +33,8 @@ public:
|
||||
b3StaticTree();
|
||||
~b3StaticTree();
|
||||
|
||||
// Build this tree from a list of AABBs and the list
|
||||
// of indices to the AABBs.
|
||||
void Build(u32* indices, const b3AABB3* aabbs, u32 count);
|
||||
// Build this tree from a list of AABBs.
|
||||
void Build(const b3AABB3* aabbs, u32 count);
|
||||
|
||||
// Get the AABB of a given proxy.
|
||||
const b3AABB3& GetAABB(u32 proxyId) const;
|
||||
|
@ -62,16 +62,22 @@ public :
|
||||
void AppendFlags(u32 flags);
|
||||
|
||||
// Draw a point.
|
||||
virtual void DrawPoint(const b3Vec3& point, const b3Color& color) = 0;
|
||||
virtual void DrawPoint(const b3Vec3& p, float32 size, const b3Color& color) = 0;
|
||||
|
||||
// Draw a line segment.
|
||||
virtual void DrawSegment(const b3Vec3& a, const b3Vec3& b, const b3Color& color) = 0;
|
||||
|
||||
virtual void DrawSegment(const b3Vec3& p1, const b3Vec3& p2, const b3Color& color) = 0;
|
||||
|
||||
// Draw a triangle with vertices ordered CCW.
|
||||
virtual void DrawTriangle(const b3Vec3& p1, const b3Vec3& p2, const b3Vec3& p3, const b3Color& color) = 0;
|
||||
|
||||
// Draw a solid triangle with vertices ordered CCW.
|
||||
virtual void DrawSolidTriangle(const b3Vec3& normal, const b3Vec3& p1, const b3Vec3& p2, const b3Vec3& p3, const b3Color& color) = 0;
|
||||
|
||||
// Draw a polygon with vertices ordered CCW.
|
||||
virtual void DrawPolygon(const b3Vec3* vertices, u32 count, const b3Color& color) = 0;
|
||||
|
||||
// Draw a solid polygon with vertices ordered CCW.
|
||||
virtual void DrawSolidPolygon(const b3Vec3* vertices, u32 count, const b3Color& color) = 0;
|
||||
virtual void DrawSolidPolygon(const b3Vec3& normal, const b3Vec3* vertices, u32 count, const b3Color& color) = 0;
|
||||
|
||||
// Draw a circle with center, normal, and radius.
|
||||
virtual void DrawCircle(const b3Vec3& normal, const b3Vec3& center, float32 radius, const b3Color& color) = 0;
|
||||
|
@ -62,9 +62,16 @@ struct b3VelocityConstraintPoint
|
||||
{
|
||||
b3Vec3 rA;
|
||||
b3Vec3 rB;
|
||||
|
||||
b3Vec3 normal;
|
||||
float32 normalMass;
|
||||
float32 normalImpulse;
|
||||
|
||||
b3Vec3 tangent1;
|
||||
b3Vec3 tangent2;
|
||||
b3Mat22 tangentMass;
|
||||
b3Vec2 tangentImpulse;
|
||||
|
||||
float32 velocityBias;
|
||||
};
|
||||
|
||||
@ -80,9 +87,7 @@ struct b3VelocityConstraintManifold
|
||||
b3Vec2 tangentImpulse;
|
||||
float32 motorImpulse;
|
||||
float32 motorMass;
|
||||
//float32 maxTangentImpulse;
|
||||
//float32 area;
|
||||
|
||||
|
||||
b3VelocityConstraintPoint* points;
|
||||
u32 pointCount;
|
||||
};
|
||||
|
@ -33,6 +33,7 @@ struct b3ManifoldPoint
|
||||
b3Vec3 localPoint; // local point on the first shape
|
||||
b3Vec3 localPoint2; // local point on the other shape
|
||||
float32 normalImpulse; // normal impulse
|
||||
b3Vec2 tangentImpulse; // tangent impulses
|
||||
u8 persisting; // indicates that the point is persisting
|
||||
};
|
||||
|
||||
@ -65,8 +66,9 @@ struct b3WorldManifoldPoint
|
||||
const b3Transform& xfA, float32 radiusA,
|
||||
const b3Transform& xfB, float32 radiusB);
|
||||
|
||||
b3Vec3 normal;
|
||||
b3Vec3 point;
|
||||
b3Vec3 normal;
|
||||
b3Vec2 tangents[2];
|
||||
float32 separation;
|
||||
};
|
||||
|
||||
|
@ -25,7 +25,8 @@
|
||||
struct DrawPoints;
|
||||
struct DrawLines;
|
||||
struct DrawTriangles;
|
||||
struct DrawShapes;
|
||||
struct DrawWire;
|
||||
struct DrawSolid;
|
||||
|
||||
class Camera
|
||||
{
|
||||
@ -66,13 +67,17 @@ public:
|
||||
DebugDraw();
|
||||
~DebugDraw();
|
||||
|
||||
void DrawPoint(const b3Vec3& point, const b3Color& color);
|
||||
void DrawPoint(const b3Vec3& p, float32 size, const b3Color& color);
|
||||
|
||||
void DrawSegment(const b3Vec3& a, const b3Vec3& b, const b3Color& color);
|
||||
void DrawSegment(const b3Vec3& p1, const b3Vec3& p2, const b3Color& color);
|
||||
|
||||
void DrawTriangle(const b3Vec3& p1, const b3Vec3& p2, const b3Vec3& p3, const b3Color& color);
|
||||
|
||||
void DrawSolidTriangle(const b3Vec3& normal, const b3Vec3& p1, const b3Vec3& p2, const b3Vec3& p3, const b3Color& color);
|
||||
|
||||
void DrawPolygon(const b3Vec3* vertices, u32 count, const b3Color& color);
|
||||
|
||||
void DrawSolidPolygon(const b3Vec3* vertices, u32 count, const b3Color& color);
|
||||
void DrawSolidPolygon(const b3Vec3& normal, const b3Vec3* vertices, u32 count, const b3Color& color);
|
||||
|
||||
void DrawCircle(const b3Vec3& normal, const b3Vec3& center, float32 radius, const b3Color& color);
|
||||
|
||||
@ -86,15 +91,30 @@ public:
|
||||
|
||||
void DrawTransform(const b3Transform& xf);
|
||||
|
||||
//
|
||||
void DrawString(const char* string, const b3Color& color, ...);
|
||||
|
||||
void Submit();
|
||||
void Submit(const b3World& world);
|
||||
void DrawSphere(const b3SphereShape* s, const b3Color& c, const b3Transform& xf);
|
||||
|
||||
void DrawCapsule(const b3CapsuleShape* s, const b3Color& c, const b3Transform& xf);
|
||||
|
||||
void DrawHull(const b3HullShape* s, const b3Color& c, const b3Transform& xf);
|
||||
|
||||
void DrawMesh(const b3MeshShape* s, const b3Color& c, const b3Transform& xf);
|
||||
|
||||
void DrawShape(const b3Shape* s, const b3Color& c, const b3Transform& xf);
|
||||
|
||||
void Draw(const b3World& world);
|
||||
|
||||
void Draw();
|
||||
private:
|
||||
friend struct DrawShapes;
|
||||
|
||||
DrawPoints* m_points;
|
||||
DrawLines* m_lines;
|
||||
DrawTriangles* m_triangles;
|
||||
DrawShapes* m_shapes;
|
||||
DrawWire* m_wire;
|
||||
DrawSolid* m_solid;
|
||||
};
|
||||
|
||||
#endif
|
@ -61,10 +61,10 @@ public:
|
||||
|
||||
if (b3Distance(pointA, pointB) > 0.0f)
|
||||
{
|
||||
g_debugDraw->DrawPoint(pointA, b3Color(1.0f, 0.0f, 0.0f));
|
||||
g_debugDraw->DrawPoint(pointB, b3Color(1.0f, 0.0f, 0.0f));
|
||||
g_debugDraw->DrawPoint(pointA, 4.0f, b3Color(0.0f, 1.0f, 0.0f));
|
||||
g_debugDraw->DrawPoint(pointB, 4.0f, b3Color(0.0f, 1.0f, 0.0f));
|
||||
|
||||
g_debugDraw->DrawSegment(pointA, pointB, b3Color(1.0f, 1.0f, 0.0f));
|
||||
g_debugDraw->DrawSegment(pointA, pointB, b3Color(1.0f, 1.0f, 1.0f));
|
||||
}
|
||||
|
||||
g_debugDraw->DrawTransform(m_xfA);
|
||||
|
@ -63,14 +63,14 @@ public:
|
||||
for (u32 i = 0; i < m_clusters.Count(); ++i)
|
||||
{
|
||||
g_debugDraw->DrawSegment(b3Vec3(0, 0, 0), m_clusters[i].centroid, b3Color(1, 1, 1));
|
||||
g_debugDraw->DrawPoint(m_clusters[i].centroid, m_colors[i]);
|
||||
g_debugDraw->DrawPoint(m_clusters[i].centroid, 4.0f, m_colors[i]);
|
||||
|
||||
for (u32 j = 0; j < m_observs.Count(); ++j)
|
||||
{
|
||||
b3Observation obs = m_observs[j];
|
||||
if (obs.cluster == i)
|
||||
{
|
||||
g_debugDraw->DrawPoint(obs.point, m_colors[i]);
|
||||
g_debugDraw->DrawPoint(obs.point, 4.0f, m_colors[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -51,13 +51,13 @@ public:
|
||||
b3Vec3 pw = wmp->point;
|
||||
b3Vec2 ps = g_camera.ConvertWorldToScreen(pw);
|
||||
|
||||
g_debugDraw->DrawPoint(pw, b3Color(0.0f, 1.0f, 0.0f));
|
||||
g_debugDraw->DrawPoint(pw, 4.0f, b3Color(0.0f, 1.0f, 0.0f));
|
||||
g_debugDraw->DrawSegment(pw, pw + wmp->normal, b3Color(1.0f, 1.0f, 1.0f));
|
||||
}
|
||||
|
||||
if (wm.pointCount > 0)
|
||||
{
|
||||
g_debugDraw->DrawPoint(wm.center, b3Color(1.0f, 1.0f, 0.0f));
|
||||
g_debugDraw->DrawPoint(wm.center, 4.0f, b3Color(1.0f, 1.0f, 0.0f));
|
||||
g_debugDraw->DrawSegment(wm.center, wm.center + wm.normal, b3Color(1.0f, 1.0f, 0.0f));
|
||||
g_debugDraw->DrawSegment(wm.center, wm.center + wm.tangent1, b3Color(1.0f, 1.0f, 0.0f));
|
||||
g_debugDraw->DrawSegment(wm.center, wm.center + wm.tangent2, b3Color(1.0f, 1.0f, 0.0f));
|
||||
|
@ -57,18 +57,18 @@ public:
|
||||
for (u32 i = 0; i < featurePair.countA; ++i)
|
||||
{
|
||||
u32 index = featurePair.indexA[i];
|
||||
g_debugDraw->DrawPoint(m_xfA * m_proxyA.GetVertex(index), b3Color(1.0f, 1.0f, 0.0f));
|
||||
g_debugDraw->DrawPoint(m_xfA * m_proxyA.GetVertex(index), 4.0f, b3Color(1.0f, 1.0f, 0.0f));
|
||||
}
|
||||
|
||||
for (u32 i = 0; i < featurePair.countB; ++i)
|
||||
{
|
||||
u32 index = featurePair.indexB[i];
|
||||
g_debugDraw->DrawPoint(m_xfB * m_proxyB.GetVertex(index), b3Color(1.0f, 1.0f, 0.0f));
|
||||
g_debugDraw->DrawPoint(m_xfB * m_proxyB.GetVertex(index), 4.0f, b3Color(1.0f, 1.0f, 0.0f));
|
||||
}
|
||||
}
|
||||
|
||||
g_debugDraw->DrawPoint(out.pointA, b3Color(0.0f, 1.0f, 0.0f));
|
||||
g_debugDraw->DrawPoint(out.pointB, b3Color(0.0f, 1.0f, 0.0f));
|
||||
g_debugDraw->DrawPoint(out.pointA, 4.0f, b3Color(0.0f, 1.0f, 0.0f));
|
||||
g_debugDraw->DrawPoint(out.pointB, 4.0f, b3Color(0.0f, 1.0f, 0.0f));
|
||||
g_debugDraw->DrawSegment(out.pointA, out.pointB, b3Color(1.0f, 1.0f, 1.0f));
|
||||
|
||||
g_debugDraw->DrawTransform(m_xfA);
|
||||
|
@ -214,7 +214,7 @@ public:
|
||||
{
|
||||
// Replace current hit
|
||||
g_debugDraw->DrawSegment(p1, hit.point, b3Color(0.0f, 1.0f, 0.0f));
|
||||
g_debugDraw->DrawPoint(hit.point, b3Color(1.0f, 0.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));
|
||||
}
|
||||
else
|
||||
|
@ -36,7 +36,8 @@ struct Settings
|
||||
warmStart = true;
|
||||
convexCache = true;
|
||||
drawCenterOfMasses = false;
|
||||
drawShapes = true;
|
||||
drawVerticesEdges = true;
|
||||
drawFaces = true;
|
||||
drawBounds = false;
|
||||
drawJoints = true;
|
||||
drawContactPoints = true;
|
||||
@ -62,7 +63,8 @@ struct Settings
|
||||
bool convexCache;
|
||||
bool drawCenterOfMasses;
|
||||
bool drawBounds;
|
||||
bool drawShapes;
|
||||
bool drawVerticesEdges;
|
||||
bool drawFaces;
|
||||
bool drawSolidShapes;
|
||||
bool drawJoints;
|
||||
bool drawContactPoints;
|
||||
|
Reference in New Issue
Block a user