linux fixes, bugfixes, comments
This commit is contained in:
@ -19,7 +19,7 @@
|
||||
#ifndef B3_BROAD_PHASE_H
|
||||
#define B3_BROAD_PHASE_H
|
||||
|
||||
#include <bounce\collision\trees\dynamic_tree.h>
|
||||
#include <bounce/collision/trees/dynamic_tree.h>
|
||||
#include <algorithm>
|
||||
|
||||
// A pair of broad-phase proxies.
|
||||
@ -29,8 +29,8 @@ struct b3Pair
|
||||
i32 proxy2;
|
||||
};
|
||||
|
||||
// The broad-phase collision interface.
|
||||
// It is used to perform ray, AABB, and overlapping-pair queries
|
||||
// The broad-phase interface.
|
||||
// It is used to perform ray casts, volume queries, and overlapping queries
|
||||
// against AABBs.
|
||||
class b3BroadPhase
|
||||
{
|
||||
@ -38,14 +38,14 @@ public:
|
||||
b3BroadPhase();
|
||||
~b3BroadPhase();
|
||||
|
||||
// Create a broad-phase proxy and return a proxy.
|
||||
// Create a proxy and return a index to it.
|
||||
i32 CreateProxy(const b3AABB3& aabb, void* userData);
|
||||
|
||||
// Destroy an existing proxy.
|
||||
// Destroy a given proxy and remove it from the broadphase.
|
||||
void DestroyProxy(i32 proxyId);
|
||||
|
||||
// Update an existing proxy with a given AABB and a displacement.
|
||||
// displacement = int[a, b](dv/dt) dt = F(b) - F(a) = x(b) - x(a) ~= v * dt
|
||||
// Update an existing proxy AABB with a given AABB and a displacement.
|
||||
// displacement = dt * velocity
|
||||
// Return true if the proxy has moved.
|
||||
bool MoveProxy(i32 proxyId, const b3AABB3& aabb, const b3Vec3& displacement);
|
||||
|
||||
@ -65,15 +65,15 @@ public:
|
||||
// Notify the client callback the AABBs that are overlapping the
|
||||
// passed ray.
|
||||
template<class T>
|
||||
void QueryRay(T* callback, const b3RayCastInput& input) const;
|
||||
void RayCast(T* callback, const b3RayCastInput& input) const;
|
||||
|
||||
// Notify the client callback the AABB pairs that are overlapping.
|
||||
// The client must store the notified pairs.
|
||||
template<class T>
|
||||
void FindNewPairs(T* callback);
|
||||
|
||||
// Debug b3Draw the AABB proxies.
|
||||
void Draw(b3Draw* b3Draw) const;
|
||||
// Draw the proxy AABBs.
|
||||
void Draw(b3Draw* draw) const;
|
||||
private :
|
||||
friend class b3DynamicTree;
|
||||
|
||||
@ -81,18 +81,18 @@ private :
|
||||
// Only moved proxies will be used as an AABB query reference object.
|
||||
void BufferMove(i32 proxyId);
|
||||
|
||||
// The client callback used to add a overlapping pair
|
||||
// The client callback used to add an overlapping pair
|
||||
// to the overlapping pair buffer.
|
||||
bool Report(i32 proxyId);
|
||||
|
||||
// The dynamic tree.
|
||||
b3DynamicTree m_tree;
|
||||
|
||||
// The current proxy being queried for
|
||||
// overlap witha another proxies. Is used to avoid a proxy overlap with itself.
|
||||
// The current proxy being queried for overlap with another proxies.
|
||||
// It is used to avoid a proxy overlap with itself.
|
||||
i32 m_queryProxyId;
|
||||
|
||||
// Keep a buffer of the objects that have moved in a step.
|
||||
// The objects that have moved in a step.
|
||||
i32* m_moveBuffer;
|
||||
u32 m_moveBufferCount;
|
||||
u32 m_moveBufferCapacity;
|
||||
@ -120,9 +120,9 @@ inline void b3BroadPhase::QueryAABB(T* callback, const b3AABB3& aabb) const
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void b3BroadPhase::QueryRay(T* callback, const b3RayCastInput& input) const
|
||||
inline void b3BroadPhase::RayCast(T* callback, const b3RayCastInput& input) const
|
||||
{
|
||||
return m_tree.QueryRay(callback, input);
|
||||
return m_tree.RayCast(callback, input);
|
||||
}
|
||||
|
||||
inline bool operator<(const b3Pair& pair1, const b3Pair& pair2)
|
||||
@ -189,9 +189,9 @@ inline void b3BroadPhase::FindNewPairs(T* callback)
|
||||
}
|
||||
}
|
||||
|
||||
inline void b3BroadPhase::Draw(b3Draw* b3Draw) const
|
||||
inline void b3BroadPhase::Draw(b3Draw* draw) const
|
||||
{
|
||||
m_tree.Draw(b3Draw);
|
||||
m_tree.Draw(draw);
|
||||
}
|
||||
|
||||
#endif
|
@ -16,27 +16,13 @@
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B3_COLLISION_H
|
||||
#define B3_COLLISION_H
|
||||
#ifndef B3_DISTANCE_H
|
||||
#define B3_DISTANCE_H
|
||||
|
||||
#include <bounce\common\geometry.h>
|
||||
#include <bounce\collision\shapes\aabb3.h>
|
||||
#include <bounce\collision\shapes\capsule.h>
|
||||
#include <bounce/common/geometry.h>
|
||||
#include <bounce/collision/shapes/aabb3.h>
|
||||
|
||||
// Input for a ray cast query.
|
||||
struct b3RayCastInput
|
||||
{
|
||||
b3Vec3 p1; // first point on segment
|
||||
b3Vec3 p2; // second point on segment
|
||||
float32 maxFraction; // maximum intersection
|
||||
};
|
||||
|
||||
// Output of ray cast query.
|
||||
struct b3RayCastOutput
|
||||
{
|
||||
float32 fraction; // time of intersection
|
||||
b3Vec3 normal; // surface normal of intersection
|
||||
};
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Find the closest point for a point P to a normalized plane.
|
||||
b3Vec3 b3ClosestPointOnPlane(const b3Vec3& P, const b3Plane& plane);
|
||||
@ -59,9 +45,26 @@ void b3ClosestPointsOnNormalizedLines(b3Vec3* C1, b3Vec3* C2,
|
||||
const b3Vec3& P1, const b3Vec3& N1,
|
||||
const b3Vec3& P2, const b3Vec3& N2);
|
||||
|
||||
// Find the closest points of two segments P1-Q1 to a segment P2-Q2.
|
||||
// Find the closest points of two segments.
|
||||
void b3ClosestPointsOnSegments(b3Vec3* C1, b3Vec3* C2,
|
||||
const b3Vec3& P1, const b3Vec3& Q1,
|
||||
const b3Vec3& P2, const b3Vec3& Q2);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Input for a ray cast.
|
||||
struct b3RayCastInput
|
||||
{
|
||||
b3Vec3 p1; // first point on segment
|
||||
b3Vec3 p2; // second point on segment
|
||||
float32 maxFraction; // maximum intersection
|
||||
};
|
||||
|
||||
// Output of a ray cast.
|
||||
struct b3RayCastOutput
|
||||
{
|
||||
float32 fraction; // time of intersection on ray-segment
|
||||
b3Vec3 normal; // surface normal of intersection
|
||||
};
|
||||
|
||||
#endif
|
@ -19,7 +19,7 @@
|
||||
#ifndef B3_GJK_H
|
||||
#define B3_GJK_H
|
||||
|
||||
#include <bounce\common\geometry.h>
|
||||
#include <bounce/common/geometry.h>
|
||||
|
||||
class b3GJKProxy;
|
||||
struct b3SimplexCache;
|
||||
@ -30,8 +30,8 @@ struct b3SimplexVertex
|
||||
b3Vec3 pointB; // support vertex on proxy B
|
||||
b3Vec3 point; // minkowski vertex
|
||||
float32 weight; // barycentric coordinate for point
|
||||
u32 indexA; // support A index
|
||||
u32 indexB; // support B index
|
||||
u32 indexA; // support A vertex index
|
||||
u32 indexB; // support B vertex index
|
||||
};
|
||||
|
||||
struct b3Simplex
|
||||
@ -58,7 +58,8 @@ struct b3Simplex
|
||||
// The output of the GJK algorithm.
|
||||
// It contains the closest points between two proxies
|
||||
// and their euclidean distance.
|
||||
struct b3GJKOutput
|
||||
// If the distance is zero then the proxies are overlapping.
|
||||
struct b3GJKOutput
|
||||
{
|
||||
b3Vec3 pointA; // closest point on proxy A
|
||||
b3Vec3 pointB; // closest point on proxy B
|
||||
@ -67,8 +68,7 @@ struct b3GJKOutput
|
||||
};
|
||||
|
||||
// Find the closest points and distance between two proxies.
|
||||
// If the distance is zero then the proxies are overlapping.
|
||||
b3GJKOutput b3GJK(const b3Transform& xfA, const b3GJKProxy& proxyA,
|
||||
const b3Transform& xfB, const b3GJKProxy& proxyB);
|
||||
|
||||
#endif
|
||||
#endif
|
@ -19,15 +19,16 @@
|
||||
#ifndef B3_GJK_CACHE_H
|
||||
#define B3_GJK_CACHE_H
|
||||
|
||||
#include <bounce\collision\gjk\gjk.h>
|
||||
#include <bounce/collision/gjk/gjk.h>
|
||||
|
||||
// A simplex used to improve the performance
|
||||
// A cached simplex is used to improve the performance
|
||||
// of the GJK when called more than once.
|
||||
// Make sure to set cache.count to zero before
|
||||
// calling the GJK for the first time.
|
||||
// passing this structure as an argument to GJK when called
|
||||
// for the first time.
|
||||
struct b3SimplexCache
|
||||
{
|
||||
float32 metric; // length or area or volume
|
||||
float32 metric; // distance or area or volume
|
||||
u32 iterations; // number of GJK iterations
|
||||
u16 count; // number of support vertices
|
||||
u8 indexA[4]; // support vertices on proxy A
|
||||
@ -36,11 +37,13 @@ struct b3SimplexCache
|
||||
|
||||
// Find the closest points and distance between two proxies.
|
||||
// Assumes a simplex is given for increasing the performance of
|
||||
// the GJK when called more than once.
|
||||
// the algorithm when called more than once.
|
||||
b3GJKOutput b3GJK(const b3Transform& xfA, const b3GJKProxy& proxyA,
|
||||
const b3Transform& xfB, const b3GJKProxy& proxyB,
|
||||
bool applyRadius, b3SimplexCache* cache);
|
||||
|
||||
// A feature pair contains the vertices of the features associated
|
||||
// with the closest points.
|
||||
struct b3GJKFeaturePair
|
||||
{
|
||||
enum Type
|
||||
@ -57,10 +60,10 @@ struct b3GJKFeaturePair
|
||||
u32 indexB[3]; // vertices on proxy B
|
||||
};
|
||||
|
||||
// Get the vertices of the features that the closest points between two
|
||||
// Identify the vertices of the features that the closest points between two
|
||||
// GJK proxies are contained on given a cached simplex.
|
||||
// The GJK must have been called using the pair of proxies and
|
||||
// cache.count must be < 4, that is, the proxies must not be overlapping.
|
||||
b3GJKFeaturePair b3GetFeaturePair(const b3SimplexCache& cache);
|
||||
|
||||
#endif
|
||||
#endif
|
@ -19,31 +19,31 @@
|
||||
#ifndef B3_GJK_PROXY_H
|
||||
#define B3_GJK_PROXY_H
|
||||
|
||||
#include <bounce\common\math\vec3.h>
|
||||
#include <bounce/common/math/vec3.h>
|
||||
|
||||
// A GJK proxy encapsulates any convex hull to be used by the GJK.
|
||||
class b3GJKProxy
|
||||
{
|
||||
public:
|
||||
b3GJKProxy() : m_vertices(nullptr), m_count(0), m_radius(0.0f) { }
|
||||
b3GJKProxy() : m_vertices(NULL), m_count(0), m_radius(0.0f) { }
|
||||
|
||||
// Get the number of vertices of this proxy.
|
||||
// Get the number of vertices in this proxy.
|
||||
u32 GetVertexCount() const;
|
||||
|
||||
// Read an indexed vertex from this proxy.
|
||||
const b3Vec3& GetVertex(u32 index) const;
|
||||
|
||||
// Get the support vertex index in a given direction.
|
||||
u32 GetSupportIndex(const b3Vec3& d) const;
|
||||
u32 GetSupportIndex(const b3Vec3& direction) const;
|
||||
|
||||
// Convenience function.
|
||||
// Get the support vertex in a given direction.
|
||||
const b3Vec3& GetSupportVertex(const b3Vec3& d) const;
|
||||
const b3Vec3& GetSupportVertex(const b3Vec3& direction) const;
|
||||
|
||||
b3Vec3 m_buffer[3]; // for childs
|
||||
const b3Vec3* m_vertices;
|
||||
u32 m_count;
|
||||
float32 m_radius;
|
||||
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
|
||||
@ -79,4 +79,4 @@ inline const b3Vec3& b3GJKProxy::GetSupportVertex(const b3Vec3& d) const
|
||||
return m_vertices[index];
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
@ -19,7 +19,7 @@
|
||||
#ifndef B3_SAT_H
|
||||
#define B3_SAT_H
|
||||
|
||||
#include <bounce\common\geometry.h>
|
||||
#include <bounce/common/geometry.h>
|
||||
|
||||
struct b3Hull;
|
||||
|
||||
|
@ -16,10 +16,10 @@
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B3_EDGE_SAT_H
|
||||
#define B3_EDGE_SAT_H
|
||||
#ifndef B3_EDGE_HULL_SAT_H
|
||||
#define B3_EDGE_HULL_SAT_H
|
||||
|
||||
#include <bounce\collision\sat\sat.h>
|
||||
#include <bounce/collision/sat/sat.h>
|
||||
|
||||
struct b3Capsule;
|
||||
|
||||
@ -37,4 +37,4 @@ float32 b3ProjectEdge(const b3Vec3& P1, const b3Vec3& E1, const b3Vec3& P2, cons
|
||||
b3EdgeQuery b3QueryEdgeSeparation(const b3Transform& xfA, const b3Capsule* hullA,
|
||||
const b3Transform& xfB, const b3Hull* hullB);
|
||||
|
||||
#endif
|
||||
#endif
|
@ -16,10 +16,10 @@
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B3_VERTEX_SAT_H
|
||||
#define B3_VERTEX_SAT_H
|
||||
#ifndef B3_VERTEX_HULL_SAT_H
|
||||
#define B3_VERTEX_HULL_SAT_H
|
||||
|
||||
#include <bounce\collision\sat\sat.h>
|
||||
#include <bounce/collision/sat/sat.h>
|
||||
|
||||
struct b3Sphere;
|
||||
|
||||
|
@ -19,11 +19,15 @@
|
||||
#ifndef B3_AABB_3_H
|
||||
#define B3_AABB_3_H
|
||||
|
||||
#include <bounce\common\math\transform.h>
|
||||
#include <bounce/common/math/transform.h>
|
||||
|
||||
// A min-max representation of a three-dimensional AABB.
|
||||
struct b3AABB3
|
||||
{
|
||||
b3Vec3 m_lower; // lower vertex
|
||||
b3Vec3 m_upper; // upper vertex
|
||||
|
||||
// Get the support vertex in a given direction.
|
||||
b3Vec3 GetSupportVertex(const b3Vec3& direction) const
|
||||
{
|
||||
b3Vec3 support;
|
||||
@ -128,7 +132,7 @@ struct b3AABB3
|
||||
}
|
||||
|
||||
// Test if this AABB contains a point.
|
||||
bool TestPoint(const b3Vec3& point) const
|
||||
bool Contains(const b3Vec3& point) const
|
||||
{
|
||||
return m_lower.x <= point.x && point.x <= m_upper.x &&
|
||||
m_lower.y <= point.y && point.y <= m_upper.y &&
|
||||
@ -138,11 +142,11 @@ struct b3AABB3
|
||||
// Test if this AABB contains another AABB.
|
||||
bool Contains(const b3AABB3& aabb) const
|
||||
{
|
||||
return TestPoint(aabb.m_lower) && TestPoint(aabb.m_upper);
|
||||
return Contains(aabb.m_lower) && Contains(aabb.m_upper);
|
||||
}
|
||||
|
||||
// Test if a ray intersect this AABB.
|
||||
// Output the minimum fraction to derive the intersection point.
|
||||
// Test if a ray intersects this AABB.
|
||||
// Output the minimum and maximum intersection fractions to derive the minimum and maximum intersection points.
|
||||
bool TestRay(const b3Vec3& p1, const b3Vec3& p2, float32 maxFraction, float32& minFraction) const
|
||||
{
|
||||
// Solve segment to slab plane.
|
||||
@ -159,9 +163,10 @@ struct b3AABB3
|
||||
for (u32 i = 0; i < 3; ++i)
|
||||
{
|
||||
float32 numerators[2], denominators[2];
|
||||
//numerators[0] = (-m_lower[i]) - (-p1[i]);
|
||||
|
||||
numerators[0] = p1[i] - m_lower[i];
|
||||
numerators[1] = m_upper[i] - p1[i];
|
||||
|
||||
denominators[0] = -d[i];
|
||||
denominators[1] = d[i];
|
||||
|
||||
@ -215,9 +220,6 @@ struct b3AABB3
|
||||
minFraction = lower;
|
||||
return true;
|
||||
}
|
||||
|
||||
b3Vec3 m_lower; // lower vertex
|
||||
b3Vec3 m_upper; // upper vertex
|
||||
};
|
||||
|
||||
// Compute an AABB that encloses two AABBs.
|
||||
@ -236,4 +238,4 @@ inline bool b3TestOverlap(const b3AABB3& a, const b3AABB3& b)
|
||||
(a.m_upper.x >= b.m_lower.x) && (a.m_upper.y >= b.m_lower.y) && (a.m_upper.z >= b.m_lower.z);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
@ -19,7 +19,7 @@
|
||||
#ifndef B3_BOX_HULL_H
|
||||
#define B3_BOX_HULL_H
|
||||
|
||||
#include <bounce\collision\shapes\hull.h>
|
||||
#include <bounce/collision/shapes/hull.h>
|
||||
|
||||
struct b3BoxHull : public b3Hull
|
||||
{
|
||||
@ -28,9 +28,10 @@ struct b3BoxHull : public b3Hull
|
||||
b3Face boxFaces[6];
|
||||
b3Plane boxPlanes[6];
|
||||
|
||||
// Does nothing for performance.
|
||||
b3BoxHull() { }
|
||||
|
||||
// Set this box to the unit box.
|
||||
// Set this box to the unit box centered at the origin.
|
||||
void SetIdentity()
|
||||
{
|
||||
boxVertices[0] = b3Vec3(1.0f, 1.0f, -1.0f);
|
||||
@ -90,9 +91,18 @@ struct b3BoxHull : public b3Hull
|
||||
planes = boxPlanes;
|
||||
faceCount = 6;
|
||||
}
|
||||
|
||||
// Set this box from three extents and centered at the origin.
|
||||
void Set(float32 ex, float32 ey, float32 ez)
|
||||
{
|
||||
b3Transform xf;
|
||||
xf.position.SetZero();
|
||||
xf.rotation = b3Diagonal(ex, ey, ez);
|
||||
SetTransform(xf);
|
||||
}
|
||||
|
||||
// Set this box to the unit box and transform
|
||||
// it. The transform must not contain non-uniform
|
||||
// Set this box to the unit box and transform it.
|
||||
// Warning: The transform must not contain non-uniform
|
||||
// scaling!
|
||||
void SetTransform(const b3Transform& T)
|
||||
{
|
||||
@ -162,4 +172,4 @@ struct b3BoxHull : public b3Hull
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
@ -19,7 +19,7 @@
|
||||
#ifndef B3_CAPSULE_H
|
||||
#define B3_CAPSULE_H
|
||||
|
||||
#include <bounce\common\math\vec3.h>
|
||||
#include <bounce/common/math/vec3.h>
|
||||
|
||||
struct b3Capsule
|
||||
{
|
||||
@ -27,7 +27,6 @@ struct b3Capsule
|
||||
float32 radius;
|
||||
|
||||
const b3Vec3& GetVertex(u32 index) const;
|
||||
|
||||
u32 GetSupportVertex(const b3Vec3& direction) const;
|
||||
};
|
||||
|
||||
@ -36,13 +35,13 @@ inline const b3Vec3& b3Capsule::GetVertex(u32 index) const
|
||||
return vertices[index];
|
||||
}
|
||||
|
||||
inline u32 b3Capsule::GetSupportVertex(const b3Vec3& direction) const
|
||||
inline u32 b3Capsule::GetSupportVertex(const b3Vec3& d) const
|
||||
{
|
||||
if (b3Dot(direction, vertices[0]) > b3Dot(direction, vertices[1]))
|
||||
if (b3Dot(d, vertices[0]) > b3Dot(d, vertices[1]))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
@ -19,7 +19,7 @@
|
||||
#ifndef B3_HULL_H
|
||||
#define B3_HULL_H
|
||||
|
||||
#include <bounce\common\geometry.h>
|
||||
#include <bounce/common/geometry.h>
|
||||
|
||||
struct b3Face
|
||||
{
|
||||
@ -52,14 +52,14 @@ struct b3Hull
|
||||
|
||||
u32 GetSupportVertex(const b3Vec3& direction) const;
|
||||
u32 GetSupportFace(const b3Vec3& direction) const;
|
||||
|
||||
b3Plane GetEdgeSidePlane(u32 index) const;
|
||||
|
||||
u32 GetSize() const;
|
||||
void Validate() const;
|
||||
void Validate(const b3Face* face) const;
|
||||
void Validate(const b3HalfEdge* edge) const;
|
||||
};
|
||||
|
||||
#include <bounce\collision\shapes\hull.inl>
|
||||
#include <bounce/collision/shapes/hull.inl>
|
||||
|
||||
#endif
|
@ -19,8 +19,8 @@
|
||||
#ifndef B3_MESH_H
|
||||
#define B3_MESH_H
|
||||
|
||||
#include <bounce\common\geometry.h>
|
||||
#include <bounce\collision\trees\static_tree.h>
|
||||
#include <bounce/common/geometry.h>
|
||||
#include <bounce/collision/trees/static_tree.h>
|
||||
|
||||
struct b3Mesh
|
||||
{
|
||||
|
@ -19,7 +19,7 @@
|
||||
#ifndef B3_SPHERE_H
|
||||
#define B3_SPHERE_H
|
||||
|
||||
#include <bounce\common\math\vec3.h>
|
||||
#include <bounce/common/math/vec3.h>
|
||||
|
||||
struct b3Sphere
|
||||
{
|
||||
@ -27,7 +27,6 @@ struct b3Sphere
|
||||
float32 radius;
|
||||
|
||||
const b3Vec3& GetVertex(u32 index) const;
|
||||
|
||||
u32 GetSupportVertex(const b3Vec3& direction) const;
|
||||
};
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
#ifndef B3_TRIANGLE_HULL_H
|
||||
#define B3_TRIANGLE_HULL_H
|
||||
|
||||
#include <bounce\collision\shapes\hull.h>
|
||||
#include <bounce/collision/shapes/hull.h>
|
||||
|
||||
struct b3TriangleHull : public b3Hull
|
||||
{
|
||||
@ -37,9 +37,7 @@ struct b3TriangleHull : public b3Hull
|
||||
|
||||
void Set(const b3Vec3& A, const b3Vec3& B, const b3Vec3& C)
|
||||
{
|
||||
const float32 kInv3 = 1.0f / 3.0f;
|
||||
|
||||
centroid = kInv3 * (A + B + C);
|
||||
centroid = (A + B + C) / 3.0f;
|
||||
|
||||
triangleVertices[0] = A;
|
||||
triangleVertices[1] = B;
|
||||
@ -73,4 +71,4 @@ struct b3TriangleHull : public b3Hull
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
@ -19,21 +19,21 @@
|
||||
#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\distance.h>
|
||||
#include <bounce/common/draw.h>
|
||||
#include <bounce/common/template/stack.h>
|
||||
#include <bounce/collision/shapes/aabb3.h>
|
||||
#include <bounce/collision/distance.h>
|
||||
|
||||
#define NULL_NODE (-1)
|
||||
|
||||
// An AABB tree for dynamic AABBs.
|
||||
// AABB tree for dynamic AABBs.
|
||||
class b3DynamicTree
|
||||
{
|
||||
public :
|
||||
b3DynamicTree();
|
||||
~b3DynamicTree();
|
||||
|
||||
// Insert a node to the tree and return its ID.
|
||||
// Insert a node into the tree and return its ID.
|
||||
i32 InsertNode(const b3AABB3& aabb, void* userData);
|
||||
|
||||
// Remove a node from the tree.
|
||||
@ -48,7 +48,7 @@ public :
|
||||
// Get the data associated with a given proxy.
|
||||
void* GetUserData(i32 proxyId) const;
|
||||
|
||||
// Check if two aabbs of this tree are overlapping.
|
||||
// Check if two aabbs in this tree are overlapping.
|
||||
bool TestOverlap(i32 proxy1, i32 proxy2) const;
|
||||
|
||||
// Keep reporting the client callback the AABBs that are overlapping with
|
||||
@ -61,22 +61,24 @@ public :
|
||||
// the given ray. The client callback must return the new intersection fraction.
|
||||
// If the fraction == 0 then the query is cancelled immediately.
|
||||
template<class T>
|
||||
void QueryRay(T* callback, const b3RayCastInput& input) const;
|
||||
void RayCast(T* callback, const b3RayCastInput& input) const;
|
||||
|
||||
// Validate a given node of this tree.
|
||||
void Validate(i32 node) const;
|
||||
|
||||
// Draw this tree.
|
||||
void Draw(b3Draw* b3Draw) const;
|
||||
void Draw(b3Draw* draw) const;
|
||||
private :
|
||||
struct b3Node
|
||||
{
|
||||
// Is this node a leaf?
|
||||
bool IsLeaf() const
|
||||
{
|
||||
return child1 == NULL_NODE; //or child 2 == NULL_NODE, or height == 0.
|
||||
//A node is a leaf if child 2 == NULL_NODE or height == 0.
|
||||
return child1 == NULL_NODE;
|
||||
}
|
||||
|
||||
// The (enlarged) AABB of this node.
|
||||
// The fattened node AABB.
|
||||
b3AABB3 aabb;
|
||||
|
||||
// The associated user data.
|
||||
@ -91,31 +93,30 @@ private :
|
||||
i32 child1;
|
||||
i32 child2;
|
||||
|
||||
// leaf = 0, free node = -1
|
||||
// leaf if 0, free node if -1
|
||||
i32 height;
|
||||
};
|
||||
|
||||
// Insert a allocated (leaf) node into the tree.
|
||||
// Insert a node into the tree.
|
||||
void InsertLeaf(i32 node);
|
||||
|
||||
// Remove a allocated node from the tree.
|
||||
// Remove a node from the tree.
|
||||
void RemoveLeaf(i32 node);
|
||||
|
||||
// Rebuild the tree hierarchy starting from the given node.
|
||||
// Rebuild the hierarchy starting from the given node.
|
||||
void WalkBackNodeAndCombineVolumes(i32 node);
|
||||
|
||||
// Perform a basic surface area heuristic search to find the best
|
||||
// node that can be merged with a given AABB.
|
||||
i32 HeuristicSearch(const b3AABB3& leafAABB) const;
|
||||
// Find the best node that can be merged with a given AABB.
|
||||
i32 FindBest(const b3AABB3& aabb) const;
|
||||
|
||||
// Peel a node from the free list and insert into the node array.
|
||||
// Allocate a new node if necessary. The function returns the new node index.
|
||||
i32 AllocateNode();
|
||||
|
||||
// Free a node (not destroy) from the node pool and add it to the free list.
|
||||
// Free a node from the node pool and add it to the free list.
|
||||
void FreeNode(i32 node);
|
||||
|
||||
// Make a node available for the next allocation request.
|
||||
// Make a node available for the next allocation.
|
||||
void AddToFreeList(i32 node);
|
||||
|
||||
// The root of this tree.
|
||||
@ -128,25 +129,25 @@ private :
|
||||
i32 m_freeList;
|
||||
};
|
||||
|
||||
inline bool b3DynamicTree::TestOverlap(i32 proxy1, i32 proxy2) const
|
||||
{
|
||||
B3_ASSERT(proxy1 < m_nodeCount);
|
||||
B3_ASSERT(proxy2 < m_nodeCount);
|
||||
return b3TestOverlap(m_nodes[proxy1].aabb, m_nodes[proxy2].aabb);
|
||||
}
|
||||
|
||||
inline const b3AABB3& b3DynamicTree::GetAABB(i32 proxyId) const
|
||||
inline const b3AABB3& b3DynamicTree::GetAABB(i32 proxyId) const
|
||||
{
|
||||
B3_ASSERT(proxyId < m_nodeCount);
|
||||
return m_nodes[proxyId].aabb;
|
||||
}
|
||||
|
||||
inline void* b3DynamicTree::GetUserData(i32 proxyId) const
|
||||
inline void* b3DynamicTree::GetUserData(i32 proxyId) const
|
||||
{
|
||||
B3_ASSERT(proxyId < m_nodeCount);
|
||||
return m_nodes[proxyId].userData;
|
||||
}
|
||||
|
||||
inline bool b3DynamicTree::TestOverlap(i32 proxy1, i32 proxy2) const
|
||||
{
|
||||
B3_ASSERT(proxy1 < m_nodeCount);
|
||||
B3_ASSERT(proxy2 < m_nodeCount);
|
||||
return b3TestOverlap(m_nodes[proxy1].aabb, m_nodes[proxy2].aabb);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void b3DynamicTree::QueryAABB(T* callback, const b3AABB3& aabb) const
|
||||
{
|
||||
@ -184,14 +185,14 @@ inline void b3DynamicTree::QueryAABB(T* callback, const b3AABB3& aabb) const
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void b3DynamicTree::QueryRay(T* callback, const b3RayCastInput& input) const
|
||||
inline void b3DynamicTree::RayCast(T* callback, const b3RayCastInput& input) const
|
||||
{
|
||||
b3Vec3 p1 = input.p1;
|
||||
b3Vec3 p2 = input.p2;
|
||||
b3Vec3 d = p2 - p1;
|
||||
float32 maxFraction = input.maxFraction;
|
||||
|
||||
// Ensure non-degeneracy.
|
||||
// Ensure non-degenerate segment.
|
||||
B3_ASSERT(b3Dot(d, d) > B3_EPSILON * B3_EPSILON);
|
||||
|
||||
b3Stack<i32, 256> stack;
|
||||
@ -237,4 +238,4 @@ inline void b3DynamicTree::QueryRay(T* callback, const b3RayCastInput& input) co
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
@ -19,28 +19,28 @@
|
||||
#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\distance.h>
|
||||
#include <bounce/common/draw.h>
|
||||
#include <bounce/common/template/stack.h>
|
||||
#include <bounce/collision/shapes/aabb3.h>
|
||||
#include <bounce/collision/distance.h>
|
||||
|
||||
#define NULL_NODE_S (0xFFFFFFFF)
|
||||
|
||||
// An AABB tree for static AABBs.
|
||||
// AABB tree for static AABBs.
|
||||
class b3StaticTree
|
||||
{
|
||||
public:
|
||||
b3StaticTree();
|
||||
~b3StaticTree();
|
||||
|
||||
// Build the tree.
|
||||
// Output a sorted index array.
|
||||
// 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);
|
||||
|
||||
// Get the AABB of a given proxy.
|
||||
const b3AABB3& GetAABB(u32 proxyId) const;
|
||||
|
||||
// Get the index associated of a given proxy.
|
||||
// Get the user data associated with a given proxy.
|
||||
u32 GetUserData(u32 proxyId) const;
|
||||
|
||||
// Report the client callback all AABBs that are overlapping with
|
||||
@ -53,10 +53,10 @@ public:
|
||||
// the given ray. The client callback must return the new intersection fraction
|
||||
// (real). If the fraction == 0 then the query is cancelled immediatly.
|
||||
template<class T>
|
||||
void QueryRay(T* callback, const b3RayCastInput& input) const;
|
||||
void RayCast(T* callback, const b3RayCastInput& input) const;
|
||||
|
||||
// Draw the hierarchy.
|
||||
void Draw(b3Draw* b3Draw) const;
|
||||
// Draw this tree.
|
||||
void Draw(b3Draw* draw) const;
|
||||
private :
|
||||
// A node in a static tree.
|
||||
struct b3Node
|
||||
@ -69,13 +69,14 @@ private :
|
||||
u32 index;
|
||||
};
|
||||
|
||||
// Check if a node is a leaf node
|
||||
// Is this node a leaf?
|
||||
bool IsLeaf() const
|
||||
{
|
||||
return child1 == NULL_NODE_S;
|
||||
}
|
||||
};
|
||||
|
||||
// The nodes of this tree stored in an array.
|
||||
u32 m_nodeCount;
|
||||
b3Node* m_nodes;
|
||||
};
|
||||
@ -109,7 +110,12 @@ inline void b3StaticTree::QueryAABB(T* callback, const b3AABB3& aabb) const
|
||||
while (stack.IsEmpty() == false)
|
||||
{
|
||||
u32 nodeIndex = stack.Top();
|
||||
|
||||
|
||||
if (nodeIndex == NULL_NODE_S)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
stack.Pop();
|
||||
|
||||
const b3Node* node = m_nodes + nodeIndex;
|
||||
@ -133,7 +139,7 @@ inline void b3StaticTree::QueryAABB(T* callback, const b3AABB3& aabb) const
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void b3StaticTree::QueryRay(T* callback, const b3RayCastInput& input) const
|
||||
inline void b3StaticTree::RayCast(T* callback, const b3RayCastInput& input) const
|
||||
{
|
||||
if (m_nodeCount == 0)
|
||||
{
|
||||
@ -145,7 +151,7 @@ inline void b3StaticTree::QueryRay(T* callback, const b3RayCastInput& input) con
|
||||
b3Vec3 d = p2 - p1;
|
||||
float32 maxFraction = input.maxFraction;
|
||||
|
||||
// Ensure non-degeneracy.
|
||||
// Ensure non-degenerate segment.
|
||||
B3_ASSERT(b3Dot(d, d) > B3_EPSILON * B3_EPSILON);
|
||||
|
||||
u32 root = 0;
|
||||
|
Reference in New Issue
Block a user