From 4b5df1dfc2d3e70f9c1dbc08caf5372c7d6fb88f Mon Sep 17 00:00:00 2001 From: Irlan <-> Date: Wed, 23 May 2018 03:47:34 -0300 Subject: [PATCH] change class to structure for consistency --- include/bounce/collision/gjk/gjk.h | 2 +- include/bounce/collision/gjk/gjk_proxy.h | 27 ++++++++--------- .../dynamics/contacts/collide/collide.h | 5 ++-- src/bounce/collision/gjk/gjk.cpp | 4 +-- .../dynamics/contacts/collide/collide.cpp | 30 +++++++++---------- 5 files changed, 32 insertions(+), 36 deletions(-) diff --git a/include/bounce/collision/gjk/gjk.h b/include/bounce/collision/gjk/gjk.h index d1f06b9..2fd5459 100644 --- a/include/bounce/collision/gjk/gjk.h +++ b/include/bounce/collision/gjk/gjk.h @@ -23,7 +23,7 @@ /////////////////////////////////////////////////////////////////////////////////////////////////// -class b3GJKProxy; +struct b3GJKProxy; struct b3SimplexCache; struct b3SimplexVertex diff --git a/include/bounce/collision/gjk/gjk_proxy.h b/include/bounce/collision/gjk/gjk_proxy.h index a9189e1..5a4766e 100644 --- a/include/bounce/collision/gjk/gjk_proxy.h +++ b/include/bounce/collision/gjk/gjk_proxy.h @@ -22,10 +22,12 @@ #include // A GJK proxy encapsulates any convex hull to be used by the GJK. -class b3GJKProxy +struct b3GJKProxy { -public: - b3GJKProxy() : m_vertices(NULL), m_count(0), m_radius(0.0f) { } + const b3Vec3* vertices; // vertices in this proxy + u32 vertexCount; // number of vertices + float32 radius; // proxy radius + b3Vec3 vertexBuffer[3]; // vertex buffer for convenience // Get the number of vertices in this proxy. u32 GetVertexCount() const; @@ -39,31 +41,26 @@ public: // Convenience function. // Get the support vertex in a given direction. const b3Vec3& GetSupportVertex(const b3Vec3& direction) const; - - const b3Vec3* m_vertices; // vertices in this proxy - u32 m_count; // number of vertices - float32 m_radius; // shape radius - b3Vec3 m_buffer[3]; // vertices from a child shape }; inline u32 b3GJKProxy::GetVertexCount() const { - return m_count; + return vertexCount; } inline const b3Vec3& b3GJKProxy::GetVertex(u32 index) const { - B3_ASSERT(0 <= index && index < m_count); - return m_vertices[index]; + B3_ASSERT(0 <= index && index < vertexCount); + return vertices[index]; } inline u32 b3GJKProxy::GetSupportIndex(const b3Vec3& d) const { u32 maxIndex = 0; - float32 maxProjection = b3Dot(d, m_vertices[maxIndex]); - for (u32 i = 1; i < m_count; ++i) + float32 maxProjection = b3Dot(d, vertices[maxIndex]); + for (u32 i = 1; i < vertexCount; ++i) { - float32 projection = b3Dot(d, m_vertices[i]); + float32 projection = b3Dot(d, vertices[i]); if (projection > maxProjection) { maxIndex = i; @@ -76,7 +73,7 @@ inline u32 b3GJKProxy::GetSupportIndex(const b3Vec3& d) const inline const b3Vec3& b3GJKProxy::GetSupportVertex(const b3Vec3& d) const { u32 index = GetSupportIndex(d); - return m_vertices[index]; + return vertices[index]; } #endif \ No newline at end of file diff --git a/include/bounce/dynamics/contacts/collide/collide.h b/include/bounce/dynamics/contacts/collide/collide.h index 584e437..12ec99a 100644 --- a/include/bounce/dynamics/contacts/collide/collide.h +++ b/include/bounce/dynamics/contacts/collide/collide.h @@ -42,11 +42,10 @@ struct b3ConvexCache }; // Used for computing the distance between two generic shapes. -class b3ShapeGJKProxy : public b3GJKProxy +struct b3ShapeGJKProxy : public b3GJKProxy { -public: b3ShapeGJKProxy() { } - + b3ShapeGJKProxy(const b3Shape* shape, u32 index) { Set(shape, index); diff --git a/src/bounce/collision/gjk/gjk.cpp b/src/bounce/collision/gjk/gjk.cpp index 7a143e7..cfa8b59 100644 --- a/src/bounce/collision/gjk/gjk.cpp +++ b/src/bounce/collision/gjk/gjk.cpp @@ -708,8 +708,8 @@ b3GJKOutput b3GJK(const b3Transform& xf1, const b3GJKProxy& proxy1, // Apply radius if requested. if (applyRadius) { - float32 r1 = proxy1.m_radius; - float32 r2 = proxy2.m_radius; + float32 r1 = proxy1.radius; + float32 r2 = proxy2.radius; if (output.distance > r1 + r2 && output.distance > B3_EPSILON) { diff --git a/src/bounce/dynamics/contacts/collide/collide.cpp b/src/bounce/dynamics/contacts/collide/collide.cpp index 7dfa9c8..9292145 100644 --- a/src/bounce/dynamics/contacts/collide/collide.cpp +++ b/src/bounce/dynamics/contacts/collide/collide.cpp @@ -34,25 +34,25 @@ void b3ShapeGJKProxy::Set(const b3Shape* shape, u32 index) case e_sphereShape: { const b3SphereShape* sphere = (b3SphereShape*)shape; - m_count = 1; - m_vertices = &sphere->m_center; - m_radius = sphere->m_radius; + vertexCount = 1; + vertices = &sphere->m_center; + radius = sphere->m_radius; break; } case e_capsuleShape: { const b3CapsuleShape* capsule = (b3CapsuleShape*)shape; - m_count = 2; - m_vertices = capsule->m_centers; - m_radius = capsule->m_radius; + vertexCount = 2; + vertices = capsule->m_centers; + radius = capsule->m_radius; break; } case e_hullShape: { const b3HullShape* hull = (b3HullShape*)shape; - m_count = hull->m_hull->vertexCount; - m_vertices = hull->m_hull->vertices; - m_radius = hull->m_radius; + vertexCount = hull->m_hull->vertexCount; + vertices = hull->m_hull->vertices; + radius = hull->m_radius; break; } case e_meshShape: @@ -64,13 +64,13 @@ void b3ShapeGJKProxy::Set(const b3Shape* shape, u32 index) const b3Triangle& triangle = mesh->m_mesh->GetTriangle(index); - m_buffer[0] = mesh->m_mesh->vertices[triangle.v1]; - m_buffer[1] = mesh->m_mesh->vertices[triangle.v2]; - m_buffer[2] = mesh->m_mesh->vertices[triangle.v3]; + vertexBuffer[0] = mesh->m_mesh->vertices[triangle.v1]; + vertexBuffer[1] = mesh->m_mesh->vertices[triangle.v2]; + vertexBuffer[2] = mesh->m_mesh->vertices[triangle.v3]; - m_count = 3; - m_vertices = m_buffer; - m_radius = mesh->m_radius; + vertexCount = 3; + vertices = vertexBuffer; + radius = mesh->m_radius; break; } default: