improve friction quality, add shader-only support, improve debug drawing facilities, fix couple things

This commit is contained in:
Irlan
2017-02-07 14:31:52 -02:00
parent d59b67c3c3
commit a346a1472d
30 changed files with 1795 additions and 20880 deletions

View File

@ -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

View File

@ -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;