linux fixes, bugfixes, comments
This commit is contained in:
@ -21,40 +21,40 @@
|
||||
|
||||
// Include this file header in your project to directly access Bounce objects.
|
||||
|
||||
#include <bounce\common\settings.h>
|
||||
#include <bounce\common\math\math.h>
|
||||
#include <bounce\common\time.h>
|
||||
#include <bounce\common\draw.h>
|
||||
#include <bounce/common/settings.h>
|
||||
#include <bounce/common/math/math.h>
|
||||
#include <bounce/common/time.h>
|
||||
#include <bounce/common/draw.h>
|
||||
|
||||
#include <bounce\collision\broad_phase.h>
|
||||
#include <bounce\collision\gjk\gjk.h>
|
||||
#include <bounce\collision\gjk\gjk_cache.h>
|
||||
#include <bounce\collision\sat\sat.h>
|
||||
#include <bounce/collision/gjk/gjk.h>
|
||||
#include <bounce/collision/gjk/gjk_cache.h>
|
||||
#include <bounce/collision/sat/sat.h>
|
||||
#include <bounce/collision/distance.h>
|
||||
#include <bounce/collision/broad_phase.h>
|
||||
|
||||
#include <bounce\collision\shapes\sphere.h>
|
||||
#include <bounce\collision\shapes\capsule.h>
|
||||
#include <bounce\collision\shapes\hull.h>
|
||||
#include <bounce\collision\shapes\triangle_hull.h>
|
||||
#include <bounce\collision\shapes\box_hull.h>
|
||||
#include <bounce\collision\shapes\mesh.h>
|
||||
#include <bounce/collision/shapes/sphere.h>
|
||||
#include <bounce/collision/shapes/capsule.h>
|
||||
#include <bounce/collision/shapes/hull.h>
|
||||
#include <bounce/collision/shapes/box_hull.h>
|
||||
#include <bounce/collision/shapes/mesh.h>
|
||||
|
||||
#include <bounce\dynamics\joints\mouse_joint.h>
|
||||
#include <bounce\dynamics\joints\spring_joint.h>
|
||||
#include <bounce\dynamics\joints\sphere_joint.h>
|
||||
#include <bounce\dynamics\joints\revolute_joint.h>
|
||||
#include <bounce\dynamics\joints\cone_joint.h>
|
||||
#include <bounce/dynamics/joints/mouse_joint.h>
|
||||
#include <bounce/dynamics/joints/spring_joint.h>
|
||||
#include <bounce/dynamics/joints/sphere_joint.h>
|
||||
#include <bounce/dynamics/joints/revolute_joint.h>
|
||||
#include <bounce/dynamics/joints/cone_joint.h>
|
||||
|
||||
#include <bounce\dynamics\shapes\sphere_shape.h>
|
||||
#include <bounce\dynamics\shapes\capsule_shape.h>
|
||||
#include <bounce\dynamics\shapes\hull_shape.h>
|
||||
#include <bounce\dynamics\shapes\mesh_shape.h>
|
||||
#include <bounce/dynamics/shapes/sphere_shape.h>
|
||||
#include <bounce/dynamics/shapes/capsule_shape.h>
|
||||
#include <bounce/dynamics/shapes/hull_shape.h>
|
||||
#include <bounce/dynamics/shapes/mesh_shape.h>
|
||||
|
||||
#include <bounce\dynamics\contacts\contact.h>
|
||||
#include <bounce\dynamics\contacts\convex_contact.h>
|
||||
#include <bounce\dynamics\contacts\mesh_contact.h>
|
||||
#include <bounce/dynamics/contacts/contact.h>
|
||||
#include <bounce/dynamics/contacts/convex_contact.h>
|
||||
#include <bounce/dynamics/contacts/mesh_contact.h>
|
||||
|
||||
#include <bounce\dynamics\body.h>
|
||||
#include <bounce\dynamics\world.h>
|
||||
#include <bounce\dynamics\world_listeners.h>
|
||||
#include <bounce/dynamics/body.h>
|
||||
#include <bounce/dynamics/world.h>
|
||||
#include <bounce/dynamics/world_listeners.h>
|
||||
|
||||
#endif
|
@ -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;
|
||||
|
@ -19,10 +19,10 @@
|
||||
#ifndef B3_DRAW_H
|
||||
#define B3_DRAW_H
|
||||
|
||||
#include <bounce\common\math\math.h>
|
||||
#include <bounce\collision\shapes\aabb3.h>
|
||||
#include <bounce/common/math/math.h>
|
||||
#include <bounce/collision/shapes/aabb3.h>
|
||||
|
||||
// Color channels used by the debug b3Draw interface.
|
||||
// Color channels used by the debug draw interface.
|
||||
struct b3Color
|
||||
{
|
||||
b3Color() { }
|
||||
@ -32,11 +32,11 @@ struct b3Color
|
||||
float32 r, g, b, a;
|
||||
};
|
||||
|
||||
// Implement this interface and set to a world so it can b3Draw the physics entities.
|
||||
// Implement this interface and set to a world so it can draw the physics entities.
|
||||
class b3Draw
|
||||
{
|
||||
public :
|
||||
// Bit flags to tell the world what needs to be b3Draw.
|
||||
// Bit flags to tell the world what needs to be draw.
|
||||
enum b3Flags
|
||||
{
|
||||
e_shapesFlag = 0x0001,
|
||||
@ -88,10 +88,10 @@ public :
|
||||
// Draw a AABB.
|
||||
virtual void DrawAABB(const b3AABB3& aabb, const b3Color& color) = 0;
|
||||
|
||||
// Draw a b3Transform.
|
||||
// Draw a transform.
|
||||
virtual void DrawTransform(const b3Transform& xf) = 0;
|
||||
|
||||
// Debug b3Draw flags.
|
||||
// Debug draw flags.
|
||||
u32 m_flags;
|
||||
};
|
||||
|
||||
|
@ -19,8 +19,8 @@
|
||||
#ifndef B3_GEOMETRY_H
|
||||
#define B3_GEOMETRY_H
|
||||
|
||||
#include <bounce\common\math\math.h>
|
||||
#include <bounce\common\math\transform.h>
|
||||
#include <bounce/common/math/math.h>
|
||||
#include <bounce/common/math/transform.h>
|
||||
|
||||
// A triangle in indexed form.
|
||||
struct b3Triangle
|
||||
@ -106,13 +106,13 @@ inline b3Plane b3Mul(const b3Transform& T, const b3Plane& plane)
|
||||
return b3Plane(normal, plane.offset + b3Dot(normal, T.position));
|
||||
}
|
||||
|
||||
// Compute the distance between a point and a plane.
|
||||
inline float32 b3Distance(const b3Vec3& P, const b3Plane& plane)
|
||||
{
|
||||
return b3Dot(plane.normal, P) - plane.offset;
|
||||
}
|
||||
|
||||
// Project a point onto a plane.
|
||||
// The plane must be normalized.
|
||||
// Project a point onto a normal plane.
|
||||
inline b3Vec3 b3Project(const b3Vec3& P, const b3Plane& plane)
|
||||
{
|
||||
float32 fraction = b3Distance(P, plane);
|
||||
|
@ -19,7 +19,7 @@
|
||||
#ifndef B3_MAT_H
|
||||
#define B3_MAT_H
|
||||
|
||||
#include <bounce\common\math\math.h>
|
||||
#include <bounce/common/math/math.h>
|
||||
|
||||
// A vector stored in column-major order.
|
||||
template<u32 n>
|
||||
@ -79,7 +79,10 @@ struct b3Mat
|
||||
};
|
||||
|
||||
// Solve Ax = b.
|
||||
// Warning: Make sure to pass a copy of A to the function. It will be invalidated.
|
||||
// It doesn't compute the inverse.
|
||||
// Therefore, is more efficient.
|
||||
// Returns false if the matrix is singular.
|
||||
// Warning: Make sure to pass a copy of the original matrix to the function. A will be invalidated.
|
||||
bool b3Solve(float32* b, float32* A, u32 n);
|
||||
|
||||
#endif
|
||||
#endif
|
@ -19,7 +19,7 @@
|
||||
#ifndef B3_MAT_22_H
|
||||
#define B3_MAT_22_H
|
||||
|
||||
#include <bounce\common\math\vec2.h>
|
||||
#include <bounce/common/math/vec2.h>
|
||||
|
||||
// A 2-by-2 matrix stored in column-major order.
|
||||
struct b3Mat22
|
||||
@ -27,7 +27,7 @@ struct b3Mat22
|
||||
// Does nothing for performance.
|
||||
b3Mat22() { }
|
||||
|
||||
// Set this matrix from two vector elements.
|
||||
// Set this matrix from two vectors.
|
||||
b3Mat22(const b3Vec2& _x, const b3Vec2& _y) : x(_x), y(_y) { }
|
||||
|
||||
// Solve Ax = b.
|
||||
|
@ -19,7 +19,7 @@
|
||||
#ifndef B3_MAT_33_H
|
||||
#define B3_MAT_33_H
|
||||
|
||||
#include <bounce\common\math\vec3.h>
|
||||
#include <bounce/common/math/vec3.h>
|
||||
|
||||
// A 3-by-3 matrix stored in column-major order.
|
||||
struct b3Mat33
|
||||
@ -27,7 +27,7 @@ struct b3Mat33
|
||||
// Does nothing for performance.
|
||||
b3Mat33() { }
|
||||
|
||||
// Set this matrix from three elements.
|
||||
// Set this matrix from three column vectors.
|
||||
b3Mat33(const b3Vec3& _x, const b3Vec3& _y, const b3Vec3& _z) : x(_x), y(_y), z(_z) { }
|
||||
|
||||
// Read an indexed column vector from this matrix.
|
||||
@ -42,6 +42,12 @@ struct b3Mat33
|
||||
return (&x)[i];
|
||||
}
|
||||
|
||||
// Read an indexed element from this matrix.
|
||||
float32 operator()(u32 i, u32 j) const
|
||||
{
|
||||
return (&x.x)[i + 3 * j];
|
||||
}
|
||||
|
||||
// Add a matrix to this matrix.
|
||||
void operator+=(const b3Mat33& B)
|
||||
{
|
||||
@ -72,11 +78,6 @@ struct b3Mat33
|
||||
// Returns the zero vector if the matrix is singular.
|
||||
b3Vec3 Solve(const b3Vec3& b) const;
|
||||
|
||||
float32 operator()(u32 i, u32 j) const
|
||||
{
|
||||
return (&x.x)[i + 3 * j];
|
||||
}
|
||||
|
||||
b3Vec3 x, y, z;
|
||||
};
|
||||
|
||||
@ -134,7 +135,7 @@ inline b3Mat33 b3Mul(const b3Mat33& A, const b3Mat33& B)
|
||||
|
||||
// Multiply the transpose of a matrix times a vector. If
|
||||
// the matrix represents a rotation frame this transforms the
|
||||
// vector from one frame to another (inverse b3Transform).
|
||||
// vector from one frame to another (inverse transform).
|
||||
inline b3Vec3 b3MulT(const b3Mat33& A, const b3Vec3& v)
|
||||
{
|
||||
return b3Vec3(b3Dot(A.x, v), b3Dot(A.y, v), b3Dot(A.z, v));
|
||||
|
@ -20,7 +20,7 @@
|
||||
#define B3_MATH_H
|
||||
|
||||
#include <cmath>
|
||||
#include <bounce\common\settings.h>
|
||||
#include <bounce/common/settings.h>
|
||||
|
||||
inline bool b3IsValid(float32 fx)
|
||||
{
|
||||
@ -30,13 +30,13 @@ inline bool b3IsValid(float32 fx)
|
||||
|
||||
inline float32 b3Sqrt(float32 x)
|
||||
{
|
||||
return sqrtf(x);
|
||||
return std::sqrt(x);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T b3Abs(T x)
|
||||
{
|
||||
return abs(x);
|
||||
return std::abs(x);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
|
@ -19,10 +19,10 @@
|
||||
#ifndef B3_QUAT_H
|
||||
#define B3_QUAT_H
|
||||
|
||||
#include <bounce\common\math\math.h>
|
||||
#include <bounce\common\math\mat33.h>
|
||||
#include <bounce/common/math/math.h>
|
||||
#include <bounce/common/math/mat33.h>
|
||||
|
||||
// A quaternion represents an orientation with 4 real numbers.
|
||||
// A quaternion can represent an orientation with 4 scalars.
|
||||
struct b3Quat
|
||||
{
|
||||
// Default constructor does nothing for performance.
|
||||
@ -157,13 +157,13 @@ inline b3Quat b3Normalize(const b3Quat& q)
|
||||
return b3Quat(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
// Compute the dot poduct of two quaternions.
|
||||
// Perform the dot poduct of two quaternions.
|
||||
inline float b3Dot(const b3Quat& a, const b3Quat& b)
|
||||
{
|
||||
return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
|
||||
}
|
||||
|
||||
// Compute the conjugate of a quaternion.
|
||||
// Conjugate of a quaternion.
|
||||
inline b3Quat b3Conjugate(const b3Quat& q)
|
||||
{
|
||||
return b3Quat(-q.x, -q.y, -q.z, q.w);
|
||||
@ -230,7 +230,6 @@ inline b3Quat b3Slerp(const b3Quat& a, const b3Quat& b, float32 fraction)
|
||||
b3Quat q1 = sin(w1 * angle) * a;
|
||||
b3Quat q2 = sin(w2 * angle) * b2;
|
||||
float32 invSin = 1.0f / sine;
|
||||
|
||||
return invSin * (q1 + q2);
|
||||
}
|
||||
|
||||
|
@ -19,10 +19,10 @@
|
||||
#ifndef B3_TRANSFORM_H
|
||||
#define B3_TRANSFORM_H
|
||||
|
||||
#include <bounce\common\math\mat33.h>
|
||||
#include <bounce\common\math\quat.h>
|
||||
#include <bounce/common/math/mat33.h>
|
||||
#include <bounce/common/math/quat.h>
|
||||
|
||||
// A b3Transform represents a rigid frame.
|
||||
// A transform represents a rigid frame.
|
||||
// It has a translation representing a position
|
||||
// and a rotation representing an orientation.
|
||||
struct b3Transform
|
||||
@ -30,7 +30,7 @@ struct b3Transform
|
||||
// Default ctor does nothing for performance.
|
||||
b3Transform() { }
|
||||
|
||||
// Set this b3Transform from a translation vector and an orientation
|
||||
// Set this transform from a translation vector and an orientation
|
||||
// quaternion.
|
||||
b3Transform(const b3Vec3& p, const b3Quat& q)
|
||||
{
|
||||
@ -38,7 +38,7 @@ struct b3Transform
|
||||
rotation = b3ConvertQuatToRot(q);
|
||||
}
|
||||
|
||||
// Set this b3Transform to the identity.
|
||||
// Set this transform to the identity.
|
||||
void SetIdentity()
|
||||
{
|
||||
position.SetZero();
|
||||
@ -61,7 +61,7 @@ struct b3Sweep
|
||||
b3Vec3 worldCenter; // world center
|
||||
b3Quat orientation; // world orientation
|
||||
|
||||
// Get this sweep b3Transform at a given time between [0, 1]
|
||||
// Get this sweep transform at a given time between [0, 1]
|
||||
b3Transform GetTransform(float32 t) const;
|
||||
|
||||
// Advance to a new initial state.
|
||||
@ -90,7 +90,7 @@ inline void b3Sweep::Advance(float32 t)
|
||||
t0 = t;
|
||||
}
|
||||
|
||||
// Multiply a b3Transform times a vector. If the b3Transform
|
||||
// Multiply a transform times a vector. If the transform
|
||||
// represents a frame this returns the vector in terms
|
||||
// of the frame.
|
||||
inline b3Vec3 operator*(const b3Transform& T, const b3Vec3& v)
|
||||
@ -98,7 +98,7 @@ inline b3Vec3 operator*(const b3Transform& T, const b3Vec3& v)
|
||||
return b3Mul(T.rotation, v) + T.position;
|
||||
}
|
||||
|
||||
// Multiply a b3Transform times another b3Transform (composed b3Transform).
|
||||
// Multiply a transform times another transform (composed transform).
|
||||
// [A y][B x] = [AB Ax+y]
|
||||
// [0 1][0 1] [0 1 ]
|
||||
inline b3Transform operator*(const b3Transform& A, const b3Transform& B)
|
||||
@ -109,13 +109,13 @@ inline b3Transform operator*(const b3Transform& A, const b3Transform& B)
|
||||
return C;
|
||||
}
|
||||
|
||||
// Multiply a b3Transform times a vector.
|
||||
// Multiply a transform times a vector.
|
||||
inline b3Vec3 b3Mul(const b3Transform& T, const b3Vec3& v)
|
||||
{
|
||||
return b3Mul(T.rotation, v) + T.position;
|
||||
}
|
||||
|
||||
// Multiply a b3Transform times another b3Transform.
|
||||
// Multiply a transform times another transform.
|
||||
// [A y][B x] = [AB Ax+y]
|
||||
// [0 1][0 1] [0 1 ]
|
||||
inline b3Transform b3Mul(const b3Transform& A, const b3Transform& B)
|
||||
@ -126,8 +126,8 @@ inline b3Transform b3Mul(const b3Transform& A, const b3Transform& B)
|
||||
return C;
|
||||
}
|
||||
|
||||
// Multiply the transpose of one b3Transform (inverse
|
||||
// b3Transform) times another b3Transform (composed b3Transform).
|
||||
// Multiply the transpose of one transform (inverse
|
||||
// transform) times another transform (composed transform).
|
||||
//[A^-1 -A^-1*y][B x] = [A^-1*B A^-1(x-y)]
|
||||
//[0 1 ][0 1] [0 1 ]
|
||||
inline b3Transform b3MulT(const b3Transform& A, const b3Transform& B)
|
||||
@ -138,9 +138,9 @@ inline b3Transform b3MulT(const b3Transform& A, const b3Transform& B)
|
||||
return C;
|
||||
}
|
||||
|
||||
// Multiply the transpose of a b3Transform times a vector.
|
||||
// If the b3Transform represents a frame then this transforms
|
||||
// the vector from one frame to another (inverse b3Transform).
|
||||
// Multiply the transpose of a transform times a vector.
|
||||
// If the transform represents a frame then this transforms
|
||||
// the vector from one frame to another (inverse transform).
|
||||
//[A^-1 -A^-1*y][x] = A^-1*x - A^-1*y = A^-1 * (x - y)
|
||||
//[0 1 ][1]
|
||||
inline b3Vec3 b3MulT(const b3Transform& A, const b3Vec3& v)
|
||||
@ -148,7 +148,7 @@ inline b3Vec3 b3MulT(const b3Transform& A, const b3Vec3& v)
|
||||
return b3MulT(A.rotation, v - A.position);
|
||||
}
|
||||
|
||||
// Inverse b3Transform.
|
||||
// Inverse transform.
|
||||
inline b3Transform b3Inverse(const b3Transform& T)
|
||||
{
|
||||
b3Transform B;
|
||||
|
@ -19,7 +19,7 @@
|
||||
#ifndef B3_VEC2_H
|
||||
#define B3_VEC2_H
|
||||
|
||||
#include <bounce\common\math\math.h>
|
||||
#include <bounce/common/math/math.h>
|
||||
|
||||
// A 2D column vector.
|
||||
struct b3Vec2
|
||||
|
@ -19,7 +19,7 @@
|
||||
#ifndef B3_VEC_3_H
|
||||
#define B3_VEC_3_H
|
||||
|
||||
#include <bounce\common\math\math.h>
|
||||
#include <bounce/common/math/math.h>
|
||||
|
||||
// A 3D column vector.
|
||||
struct b3Vec3
|
||||
|
@ -19,7 +19,7 @@
|
||||
#ifndef B3_BLOCK_POOL_H
|
||||
#define B3_BLOCK_POOL_H
|
||||
|
||||
#include <bounce\common\settings.h>
|
||||
#include <bounce/common/settings.h>
|
||||
|
||||
// Number of blocks per chunk.
|
||||
const u32 b3_blockCount = 32;
|
||||
|
@ -19,13 +19,13 @@
|
||||
#ifndef B3_STACK_ALLOCATOR_H
|
||||
#define B3_STACK_ALLOCATOR_H
|
||||
|
||||
#include <bounce\common\settings.h>
|
||||
#include <bounce/common/settings.h>
|
||||
|
||||
// Allocate 10 MiB from the stack.
|
||||
// Increase as you want.
|
||||
const u32 b3_maxStackSize = B3_MiB(10);
|
||||
|
||||
// An stack allocator.
|
||||
// A stack allocator.
|
||||
class b3StackAllocator
|
||||
{
|
||||
public :
|
||||
|
@ -60,7 +60,7 @@ typedef float float32;
|
||||
#define B3_AABB_MULTIPLIER (2.0f)
|
||||
|
||||
// Collision and constraint tolerance.
|
||||
#define B3_LINEAR_SLOP (0.005f)
|
||||
#define B3_LINEAR_SLOP (0.01f)
|
||||
|
||||
// Collision and constraint tolerance.
|
||||
#define B3_ANGULAR_SLOP (2.0f / 180.0f * B3_PI)
|
||||
|
@ -19,7 +19,7 @@
|
||||
#ifndef B3_ARRAY_POD_H
|
||||
#define B3_ARRAY_POD_H
|
||||
|
||||
#include <bounce\common\settings.h>
|
||||
#include <bounce/common/settings.h>
|
||||
|
||||
// An array for bytes (POD).
|
||||
template <typename T>
|
||||
|
@ -19,7 +19,7 @@
|
||||
#ifndef B3_LIST_H
|
||||
#define B3_LIST_H
|
||||
|
||||
#include <bounce\common\settings.h>
|
||||
#include <bounce/common/settings.h>
|
||||
|
||||
// A singly-linked list.
|
||||
template<class T>
|
||||
@ -28,7 +28,7 @@ class b3List1
|
||||
public:
|
||||
b3List1()
|
||||
{
|
||||
m_head = nullptr;
|
||||
m_head = NULL;
|
||||
m_count = 0;
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ class b3List2
|
||||
public:
|
||||
b3List2()
|
||||
{
|
||||
m_head = nullptr;
|
||||
m_head = NULL;
|
||||
m_count = 0;
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ public:
|
||||
|
||||
void PushFront(T* link)
|
||||
{
|
||||
link->m_prev = nullptr;
|
||||
link->m_prev = NULL;
|
||||
link->m_next = m_head;
|
||||
if (m_head)
|
||||
{
|
||||
|
@ -19,7 +19,7 @@
|
||||
#ifndef B3_OBJECT_ARRAY_H
|
||||
#define B3_OBJECT_ARRAY_H
|
||||
|
||||
#include <bounce\common\settings.h>
|
||||
#include <bounce/common/settings.h>
|
||||
|
||||
// An array for objects.
|
||||
template <typename T>
|
||||
|
@ -19,7 +19,7 @@
|
||||
#ifndef B3_STACK_H
|
||||
#define B3_STACK_H
|
||||
|
||||
#include <bounce\common\settings.h>
|
||||
#include <bounce/common/settings.h>
|
||||
|
||||
// A growable stack for plain-old-data (POD).
|
||||
template <typename T, u32 N>
|
||||
@ -39,7 +39,7 @@ public:
|
||||
{
|
||||
b3Free(m_elements);
|
||||
}
|
||||
m_elements = nullptr;
|
||||
m_elements = NULL;
|
||||
}
|
||||
|
||||
const T& Top() const
|
||||
|
@ -19,45 +19,195 @@
|
||||
#ifndef B3_TIME_H
|
||||
#define B3_TIME_H
|
||||
|
||||
#include <bounce\common\settings.h>
|
||||
#include <bounce/common/settings.h>
|
||||
|
||||
#define B3_WINDOWS 1
|
||||
#define B3_MAC 2
|
||||
#define B3_UNIX 3
|
||||
|
||||
#if defined (_WIN32)
|
||||
#define B3_PLATFORM B3_WINDOWS
|
||||
#elif defined( __APPLE__ )
|
||||
#define B3_PLATFORM B3_MAC
|
||||
#else
|
||||
#define B3_PLATFORM B3_UNIX
|
||||
#endif
|
||||
|
||||
#if B3_PLATFORM == B3_WINDOWS
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
// A timer class that accumulates time.
|
||||
// Usefull for measuring elapsed times of
|
||||
// sections of code.
|
||||
// Usefull for measuring elapsed times between code sections.
|
||||
class b3Time
|
||||
{
|
||||
public :
|
||||
b3Time();
|
||||
public:
|
||||
b3Time()
|
||||
{
|
||||
LARGE_INTEGER c;
|
||||
QueryPerformanceCounter(&c);
|
||||
m_c0 = c.QuadPart;
|
||||
m_t0 = 0.0;
|
||||
m_t = 0.0;
|
||||
}
|
||||
|
||||
// Get the accumulated time in miliseconds
|
||||
// from this timer.
|
||||
float64 GetCurMilis() const;
|
||||
// Get the accumulated time in miliseconds from this timer.
|
||||
float64 GetCurrentMilis() const
|
||||
{
|
||||
return m_t;
|
||||
}
|
||||
|
||||
// Get the elapsed time since this timer was updated.
|
||||
float64 GetElapsedMilis() const;
|
||||
float64 GetElapsedMilis() const
|
||||
{
|
||||
return m_t - m_t0;
|
||||
}
|
||||
|
||||
// Add the elapsed time since this function
|
||||
// was called to this timer.
|
||||
void Update();
|
||||
// Add the elapsed time since this function was called to this timer.
|
||||
void Update()
|
||||
{
|
||||
static float64 inv_frequency = 0.0;
|
||||
if (inv_frequency == 0.0)
|
||||
{
|
||||
LARGE_INTEGER c;
|
||||
QueryPerformanceFrequency(&c);
|
||||
|
||||
float64 cycles_per_s = float64(c.QuadPart);
|
||||
float64 s_per_cycle = 1.0 / cycles_per_s;
|
||||
float64 ms_per_cycle = 1000.0 * s_per_cycle;
|
||||
inv_frequency = ms_per_cycle;
|
||||
}
|
||||
|
||||
LARGE_INTEGER c;
|
||||
QueryPerformanceCounter(&c);
|
||||
|
||||
float64 dt = inv_frequency * float64(c.QuadPart - m_c0);
|
||||
m_c0 = c.QuadPart;
|
||||
Add(dt);
|
||||
}
|
||||
|
||||
// Add time to this timer.
|
||||
void Add(float64 dt)
|
||||
{
|
||||
m_t0 = m_t;
|
||||
m_t += dt;
|
||||
}
|
||||
|
||||
// Add a given ammout of time to this timer.
|
||||
void UpdateBy(float64 dt);
|
||||
private:
|
||||
static float64 m_invFrequency;
|
||||
|
||||
u64 m_lastRealTime;
|
||||
float64 m_lastTime;
|
||||
float64 m_curTime;
|
||||
u64 m_c0;
|
||||
float64 m_t0;
|
||||
float64 m_t;
|
||||
};
|
||||
|
||||
inline float64 b3Time::GetCurMilis() const
|
||||
{
|
||||
return m_curTime;
|
||||
}
|
||||
#elif B3_PLATFORM == B3_MAC
|
||||
|
||||
inline float64 b3Time::GetElapsedMilis() const
|
||||
{
|
||||
return m_curTime - m_lastTime;
|
||||
}
|
||||
#include <mach/mach_time.h>
|
||||
|
||||
// A timer class that accumulates time.
|
||||
// Usefull for measuring elapsed times between code sections.
|
||||
class b3Time
|
||||
{
|
||||
public:
|
||||
b3Time()
|
||||
{
|
||||
m_c0 = mach_absolute_time();
|
||||
m_t0 = 0.0;
|
||||
m_t = 0.0;
|
||||
}
|
||||
|
||||
// Get the accumulated time in miliseconds from this timer.
|
||||
double GetCurrentMilis() const
|
||||
{
|
||||
return m_t;
|
||||
}
|
||||
|
||||
// Get the elapsed time since this timer was updated.
|
||||
double GetElapsedMilis() const
|
||||
{
|
||||
return m_t - m_t0;
|
||||
}
|
||||
|
||||
// Add the elapsed time since this function was called to this timer.
|
||||
void Update()
|
||||
{
|
||||
static double inv_frequency = 0.0;
|
||||
if (inv_frequency == 0.0)
|
||||
{
|
||||
mach_timebase_info_data_t info;
|
||||
mach_timebase_info(&info);
|
||||
inv_frequency = double(info.numer) / (double(info.denom) * 1.0e6);
|
||||
}
|
||||
|
||||
uint64_t c = mach_absolute_time();
|
||||
double dt = inv_frequency * (double)(c - m_c0);
|
||||
m_c0 = c;
|
||||
Add(dt);
|
||||
}
|
||||
|
||||
// Add time to this timer.
|
||||
void Add(double dt)
|
||||
{
|
||||
m_t0 = m_t;
|
||||
m_t += dt;
|
||||
}
|
||||
|
||||
private:
|
||||
uint64_t m_c0;
|
||||
double m_t0;
|
||||
double m_t;
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
#include <time.h>
|
||||
|
||||
// A timer class that accumulates time.
|
||||
// Usefull for measuring elapsed times between code sections.
|
||||
class b3Time
|
||||
{
|
||||
public:
|
||||
b3Time()
|
||||
{
|
||||
clock_gettime(CLOCK_MONOTONIC, &m_c0);
|
||||
m_t0 = 0.0;
|
||||
m_t = 0.0;
|
||||
}
|
||||
|
||||
// Get the accumulated time in miliseconds from this timer.
|
||||
double GetCurrentMilis() const
|
||||
{
|
||||
return m_t;
|
||||
}
|
||||
|
||||
// Get the elapsed time since this timer was updated.
|
||||
double GetElapsedMilis() const
|
||||
{
|
||||
return m_t - m_t0;
|
||||
}
|
||||
|
||||
// Add the elapsed time since this function was called to this timer.
|
||||
void Update()
|
||||
{
|
||||
struct timespec c;
|
||||
clock_gettime(CLOCK_MONOTONIC, &c);
|
||||
double dt = (double)(c.tv_nsec - m_c0.tv_nsec) * 1.0e-6;
|
||||
m_c0 = c;
|
||||
Add(dt);
|
||||
}
|
||||
|
||||
// Add time to this timer.
|
||||
void Add(double dt)
|
||||
{
|
||||
m_t0 = m_t;
|
||||
m_t += dt;
|
||||
}
|
||||
|
||||
private:
|
||||
struct timespec m_c0;
|
||||
double m_t0;
|
||||
double m_t;
|
||||
};
|
||||
|
||||
#endif // B3_PLATFORM
|
||||
|
||||
#endif
|
||||
|
@ -19,11 +19,11 @@
|
||||
#ifndef B3_BODY_H
|
||||
#define B3_BODY_H
|
||||
|
||||
#include <bounce\common\math\vec3.h>
|
||||
#include <bounce\common\math\mat33.h>
|
||||
#include <bounce\common\math\quat.h>
|
||||
#include <bounce\common\math\transform.h>
|
||||
#include <bounce\common\template\list.h>
|
||||
#include <bounce/common/math/vec3.h>
|
||||
#include <bounce/common/math/mat33.h>
|
||||
#include <bounce/common/math/quat.h>
|
||||
#include <bounce/common/math/transform.h>
|
||||
#include <bounce/common/template/list.h>
|
||||
|
||||
class b3World;
|
||||
class b3Shape;
|
||||
@ -51,7 +51,7 @@ struct b3BodyDef
|
||||
fixedRotationX = false;
|
||||
fixedRotationY = false;
|
||||
fixedRotationZ = false;
|
||||
userData = nullptr;
|
||||
userData = NULL;
|
||||
position.SetZero();
|
||||
orientation.SetIdentity();
|
||||
linearVelocity.SetZero();
|
||||
@ -81,6 +81,13 @@ public:
|
||||
// A world manages the body destruction.
|
||||
~b3Body() { }
|
||||
|
||||
// Get the type of the body.
|
||||
b3BodyType GetType() const;
|
||||
|
||||
// Set the type of the body.
|
||||
// This will reset the current body inertial properties.
|
||||
void SetType(b3BodyType type);
|
||||
|
||||
// Create a new shape for the body given the shape definition and return a pointer to its clone.
|
||||
// The shape passed to the definition it will be cloned and is not recommended modifying
|
||||
// it inside simulation callbacks.
|
||||
@ -90,36 +97,20 @@ public:
|
||||
// Destroy a given shape from the body.
|
||||
void DestroyShape(b3Shape* shape);
|
||||
|
||||
// Destroy all shapes associated with the body.
|
||||
void DestroyShapes();
|
||||
|
||||
// Destroy all contacts associated with the body.
|
||||
void DestroyContacts();
|
||||
|
||||
// Destroy all joints connected to the body.
|
||||
void DestroyJoints();
|
||||
|
||||
// Get the shapes associated with the body.
|
||||
const b3List1<b3Shape>& GetShapeList() const;
|
||||
b3List1<b3Shape>& GetShapeList();
|
||||
|
||||
// Get the type of the body.
|
||||
b3BodyType GetType() const;
|
||||
|
||||
// Set the type of the body.
|
||||
// This will reset the current body inertial properties.
|
||||
void SetType(b3BodyType type);
|
||||
|
||||
// Get the world the body belongs to.
|
||||
const b3World* GetWorld() const;
|
||||
b3World* GetWorld();
|
||||
|
||||
// Get the body world b3Transform.
|
||||
// Get the body world transform.
|
||||
const b3Transform& GetTransform() const;
|
||||
|
||||
// Set the body world b3Transform from a position, axis of rotation and an angle
|
||||
// Set the body world transform from a position, axis of rotation and an angle
|
||||
// of rotation about the axis.
|
||||
// However, manipulating a body b3Transform during the simulation may cause non-physical behaviour.
|
||||
// However, manipulating a body transform during the simulation may cause non-physical behaviour.
|
||||
void SetTransform(const b3Vec3& position, const b3Vec3& axis, float32 angle);
|
||||
|
||||
// Get the gravity scale of the body. One is used by default.
|
||||
@ -186,7 +177,7 @@ public:
|
||||
// Get the rotational inertia of the body about the center of mass. Typically in kg/m^3.
|
||||
const b3Mat33& GetInertia() const;
|
||||
|
||||
// Get the total kinetic energy of the body.
|
||||
// Get the total kinetic energy of the body in Joules (kilogram-meters squared per second squared).
|
||||
float32 GetKineticEnergy() const;
|
||||
|
||||
// Transform a vector to the local space of this body.
|
||||
@ -242,18 +233,25 @@ private:
|
||||
e_fixedRotationY = 0x0008,
|
||||
e_fixedRotationZ = 0x0010,
|
||||
};
|
||||
|
||||
|
||||
// Destroy all shapes associated with the body.
|
||||
void DestroyShapes();
|
||||
|
||||
// Destroy all contacts associated with the body.
|
||||
void DestroyContacts();
|
||||
|
||||
// Destroy all joints connected to the body.
|
||||
void DestroyJoints();
|
||||
|
||||
// Recalculate the mass of the body based on the shapes associated
|
||||
// with it.
|
||||
void ResetMass();
|
||||
|
||||
// Synchronize this body b3Transform with its world
|
||||
// Synchronize this body transform with its world
|
||||
// center of mass and orientation.
|
||||
void SynchronizeTransform();
|
||||
|
||||
// Compute the body world inertial tensor.
|
||||
// Compute the shapes world AABBs.
|
||||
// Usually this is called after the body b3Transform is synchronized.
|
||||
// Synchronize this body shape AABBs with the synchronized transform.
|
||||
void SynchronizeShapes();
|
||||
|
||||
// Check if this body should collide with another.
|
||||
@ -267,7 +265,7 @@ private:
|
||||
// The shapes attached to this body.
|
||||
b3List1<b3Shape> m_shapeList;
|
||||
|
||||
// Bidirectional joint edges for this body
|
||||
// Joint edges for this body joint graph.
|
||||
b3List2<b3JointEdge> m_jointEdges;
|
||||
|
||||
// User associated data (usually an entity).
|
||||
@ -275,13 +273,16 @@ private:
|
||||
|
||||
// Body mass.
|
||||
float32 m_mass;
|
||||
|
||||
// Inverse body mass.
|
||||
float32 m_invMass;
|
||||
|
||||
// Inertia about the body local center of mass.
|
||||
b3Mat33 m_I;
|
||||
|
||||
// Inverse inertia about the body local center of mass.
|
||||
b3Mat33 m_invI;
|
||||
|
||||
// Inverse inertia about the body world center of mass.
|
||||
b3Mat33 m_worldInvI;
|
||||
|
||||
|
@ -19,9 +19,9 @@
|
||||
#ifndef B3_CONTACT_MANAGER_H
|
||||
#define B3_CONTACT_MANAGER_H
|
||||
|
||||
#include <bounce\common\memory\block_pool.h>
|
||||
#include <bounce\common\template\list.h>
|
||||
#include <bounce\collision\broad_phase.h>
|
||||
#include <bounce/common/memory/block_pool.h>
|
||||
#include <bounce/common/template/list.h>
|
||||
#include <bounce/collision/broad_phase.h>
|
||||
|
||||
class b3Shape;
|
||||
class b3Contact;
|
||||
@ -29,7 +29,7 @@ class b3ContactFilter;
|
||||
class b3ContactListener;
|
||||
struct b3MeshContactLink;
|
||||
|
||||
// This is used to avoid b3World pollution.
|
||||
// Contact delegator for b3World.
|
||||
class b3ContactManager
|
||||
{
|
||||
public:
|
||||
@ -38,6 +38,8 @@ public:
|
||||
// The broad-phase callback.
|
||||
void AddPair(void* proxyDataA, void* proxyDataB);
|
||||
|
||||
// Reference AABBs in mesh contacts need to be synchronized with the
|
||||
// synchronized body transforms.
|
||||
void SynchronizeShapes();
|
||||
|
||||
void FindNewContacts();
|
||||
@ -45,7 +47,6 @@ public:
|
||||
void UpdateContacts();
|
||||
|
||||
b3Contact* Create(b3Shape* shapeA, b3Shape* shapeB);
|
||||
|
||||
void Destroy(b3Contact* c);
|
||||
|
||||
b3BlockPool m_convexBlocks;
|
||||
|
@ -19,8 +19,8 @@
|
||||
#ifndef B3_CLIP_H
|
||||
#define B3_CLIP_H
|
||||
|
||||
#include <bounce\common\template\array.h>
|
||||
#include <bounce\common\geometry.h>
|
||||
#include <bounce/common/template/array.h>
|
||||
#include <bounce/common/geometry.h>
|
||||
|
||||
#define B3_NULL_EDGE (0xFF)
|
||||
|
||||
|
@ -19,11 +19,11 @@
|
||||
#ifndef B3_COLLIDE_H
|
||||
#define B3_COLLIDE_H
|
||||
|
||||
#include <bounce\collision\gjk\gjk_proxy.h>
|
||||
#include <bounce\collision\gjk\gjk_cache.h>
|
||||
#include <bounce\collision\sat\sat.h>
|
||||
#include <bounce\collision\sat\sat_edge_and_hull.h>
|
||||
#include <bounce\collision\sat\sat_vertex_and_hull.h>
|
||||
#include <bounce/collision/gjk/gjk_proxy.h>
|
||||
#include <bounce/collision/gjk/gjk_cache.h>
|
||||
#include <bounce/collision/sat/sat.h>
|
||||
#include <bounce/collision/sat/sat_edge_and_hull.h>
|
||||
#include <bounce/collision/sat/sat_vertex_and_hull.h>
|
||||
|
||||
class b3Shape;
|
||||
class b3SphereShape;
|
||||
|
@ -19,9 +19,9 @@
|
||||
#ifndef B3_CONTACT_H
|
||||
#define B3_CONTACT_H
|
||||
|
||||
#include <bounce\common\math\math.h>
|
||||
#include <bounce\common\template\list.h>
|
||||
#include <bounce\common\template\array.h>
|
||||
#include <bounce/common/math/math.h>
|
||||
#include <bounce/common/template/list.h>
|
||||
#include <bounce/common/template/array.h>
|
||||
|
||||
struct b3Manifold;
|
||||
struct b3WorldManifold;
|
||||
@ -58,7 +58,7 @@ struct b3OverlappingPair
|
||||
// todo
|
||||
struct b3TOIEvent
|
||||
{
|
||||
//float32 t;
|
||||
float32 t;
|
||||
};
|
||||
|
||||
enum b3ContactType
|
||||
|
@ -19,9 +19,9 @@
|
||||
#ifndef B3_CONTACT_CLUSTER_H
|
||||
#define B3_CONTACT_CLUSTER_H
|
||||
|
||||
#include <bounce\common\geometry.h>
|
||||
#include <bounce\common\template\array.h>
|
||||
#include <bounce\dynamics\contacts\manifold.h>
|
||||
#include <bounce/common/geometry.h>
|
||||
#include <bounce/common/template/array.h>
|
||||
#include <bounce/dynamics/contacts/manifold.h>
|
||||
|
||||
#define B3_NULL_CLUSTER (-1)
|
||||
|
||||
@ -40,7 +40,7 @@ struct b3Observation
|
||||
{
|
||||
u32 manifold;
|
||||
u32 manifoldPoint;
|
||||
b3Vec3 point;
|
||||
b3Vec3 point; // normal
|
||||
i32 cluster; // normal
|
||||
};
|
||||
|
||||
|
@ -19,10 +19,10 @@
|
||||
#ifndef B3_CONTACT_SOLVER_H
|
||||
#define B3_CONTACT_SOLVER_H
|
||||
|
||||
#include <bounce\common\math\vec2.h>
|
||||
#include <bounce\common\math\mat22.h>
|
||||
#include <bounce\dynamics\time_step.h>
|
||||
#include <bounce\dynamics\contacts\manifold.h>
|
||||
#include <bounce/common/math/vec2.h>
|
||||
#include <bounce/common/math/mat22.h>
|
||||
#include <bounce/dynamics/time_step.h>
|
||||
#include <bounce/dynamics/contacts/manifold.h>
|
||||
|
||||
class b3StackAllocator;
|
||||
class b3Contact;
|
||||
|
@ -19,9 +19,9 @@
|
||||
#ifndef B3_CONVEX_CONTACT_H
|
||||
#define B3_CONVEX_CONTACT_H
|
||||
|
||||
#include <bounce\dynamics\contacts\contact.h>
|
||||
#include <bounce\dynamics\contacts\manifold.h>
|
||||
#include <bounce\dynamics\contacts\collide\collide.h>
|
||||
#include <bounce/dynamics/contacts/contact.h>
|
||||
#include <bounce/dynamics/contacts/manifold.h>
|
||||
#include <bounce/dynamics/contacts/collide/collide.h>
|
||||
|
||||
class b3ConvexContact : public b3Contact
|
||||
{
|
||||
@ -36,8 +36,6 @@ private:
|
||||
|
||||
void Collide();
|
||||
|
||||
void SynchronizeShapes();
|
||||
|
||||
b3Manifold m_stackManifold;
|
||||
b3ConvexCache m_cache;
|
||||
};
|
||||
|
@ -19,8 +19,8 @@
|
||||
#ifndef B3_MANIFOLD_H
|
||||
#define B3_MANIFOLD_H
|
||||
|
||||
#include <bounce\common\math\vec2.h>
|
||||
#include <bounce\common\geometry.h>
|
||||
#include <bounce/common/math/vec2.h>
|
||||
#include <bounce/common/geometry.h>
|
||||
|
||||
#define B3_NULL_TRIANGLE (0xFFFFFFFF)
|
||||
|
||||
|
@ -19,19 +19,23 @@
|
||||
#ifndef B3_MESH_CONTACT_H
|
||||
#define B3_MESH_CONTACT_H
|
||||
|
||||
#include <bounce\collision\shapes\aabb3.h>
|
||||
#include <bounce\dynamics\contacts\contact.h>
|
||||
#include <bounce\dynamics\contacts\manifold.h>
|
||||
#include <bounce\dynamics\contacts\collide\collide.h>
|
||||
#include <bounce/dynamics/contacts/contact.h>
|
||||
#include <bounce/dynamics/contacts/manifold.h>
|
||||
#include <bounce/dynamics/contacts/collide/collide.h>
|
||||
#include <bounce/collision/shapes/aabb3.h>
|
||||
|
||||
// This structure helps replicate the convex contact per convex-triangle pair scenario,
|
||||
// but efficiently. There is no need to store a manifold here since they're reduced
|
||||
// by the cluster algorithm.
|
||||
struct b3TriangleCache
|
||||
{
|
||||
u32 index;
|
||||
u32 index; // triangle index
|
||||
b3ConvexCache cache;
|
||||
};
|
||||
|
||||
class b3MeshContact;
|
||||
|
||||
// Links for the world mesh contact link list.
|
||||
struct b3MeshContactLink
|
||||
{
|
||||
b3MeshContact* m_c;
|
||||
@ -60,16 +64,16 @@ private:
|
||||
|
||||
void FindNewPairs();
|
||||
|
||||
// Static tree callback. There is no midphase.
|
||||
bool Report(u32 proxyId);
|
||||
|
||||
// Did the AABB move significantly?
|
||||
bool m_aabbMoved;
|
||||
|
||||
// The first shape AABB in the frame of the other shape.
|
||||
// The AABB A relative to shape B's origin.
|
||||
b3AABB3 m_aabbA;
|
||||
|
||||
// Child shapes potentially overlapping with
|
||||
// the first shape.
|
||||
// Triangles potentially overlapping with the first shape.
|
||||
u32 m_triangleCapacity;
|
||||
b3TriangleCache* m_triangles;
|
||||
u32 m_triangleCount;
|
||||
@ -77,8 +81,8 @@ private:
|
||||
// Contact manifolds.
|
||||
b3Manifold m_stackManifolds[B3_MAX_MANIFOLDS];
|
||||
|
||||
// Links to the world mesh contact list.
|
||||
// Link to the world mesh contact list.
|
||||
b3MeshContactLink m_link;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
@ -19,7 +19,7 @@
|
||||
#ifndef B3_ISLAND_H
|
||||
#define B3_ISLAND_H
|
||||
|
||||
#include <bounce\common\math\vec3.h>
|
||||
#include <bounce/common/math/vec3.h>
|
||||
|
||||
class b3StackAllocator;
|
||||
class b3Contact;
|
||||
@ -90,4 +90,4 @@ private :
|
||||
b3Velocity* m_velocities;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
@ -16,15 +16,15 @@
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B3_JOINT_MAN_H
|
||||
#define B3_JOINT_MAN_H
|
||||
#ifndef B3_JOINT_MANAGER_H
|
||||
#define B3_JOINT_MANAGER_H
|
||||
|
||||
#include <bounce\common\template\list.h>
|
||||
#include <bounce/common/template/list.h>
|
||||
|
||||
struct b3JointDef;
|
||||
class b3Joint;
|
||||
|
||||
// This is used to avoid b3World pollution.
|
||||
// Joint delegator for b3World.
|
||||
class b3JointManager
|
||||
{
|
||||
public:
|
||||
@ -36,4 +36,4 @@ public:
|
||||
b3List2<b3Joint> m_jointList;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
@ -19,7 +19,7 @@
|
||||
#ifndef B3_CONE_JOINT_H
|
||||
#define B3_CONE_JOINT_H
|
||||
|
||||
#include <bounce\dynamics\joints\joint.h>
|
||||
#include <bounce/dynamics/joints/joint.h>
|
||||
|
||||
struct b3ConeJointDef : public b3JointDef
|
||||
{
|
||||
@ -32,36 +32,41 @@ struct b3ConeJointDef : public b3JointDef
|
||||
coneAngle = 0.0f;
|
||||
}
|
||||
|
||||
// Initialize this definition given an axis, anchor point, and cone angle limit in radians.
|
||||
// Initialize this definition from bodies, cone axis, anchor point, and full cone angle in radians.
|
||||
void Initialize(b3Body* bodyA, b3Body* bodyB, const b3Vec3& axis, const b3Vec3& anchor, float32 angle);
|
||||
|
||||
// The joint frame in the frame of body A.
|
||||
// The joint frame relative to body A's frame.
|
||||
b3Transform localFrameA;
|
||||
|
||||
// The joint frame in the frame of body B.
|
||||
// The joint frame relative to body B's frame.
|
||||
b3Transform localFrameB;
|
||||
|
||||
// Enable the joint limit.
|
||||
// Enable cone angle limit.
|
||||
bool enableLimit;
|
||||
|
||||
// The cone angle limit in radians.
|
||||
// The full cone angle in radians.
|
||||
float32 coneAngle;
|
||||
};
|
||||
|
||||
// This joint constrains the bodies to share a common point (cone tip).
|
||||
// The relative rotation about the shared axis is the joint angle.
|
||||
// If the joint angle exceeds the half-cone angle then the axis is shared.
|
||||
// You can limit the relative rotation with a lower angle limit.
|
||||
// This joint can be used to create structures such as ragdolls.
|
||||
class b3ConeJoint : public b3Joint
|
||||
{
|
||||
public:
|
||||
// Get the joint frame in the frame of body A.
|
||||
const b3Transform& GetFrameA() const;
|
||||
// Get the joint frame on body A in world coordinates.
|
||||
b3Transform GetFrameA() const;
|
||||
|
||||
// Set the joint frame in the frame of body A.
|
||||
void SetFrameA(const b3Transform& xf);
|
||||
// Get the joint frame on body B in world coordinates.
|
||||
b3Transform GetFrameB() const;
|
||||
|
||||
// Get the joint frame in the frame of body B.
|
||||
const b3Transform& GetFrameB() const;
|
||||
|
||||
// Set the joint frame in the frame of body B.
|
||||
void SetFrameB(const b3Transform& xf);
|
||||
// Get the joint frame relative to body A's frame.
|
||||
const b3Transform& GetLocalFrameA() const;
|
||||
|
||||
// Get the joint frame relative to body B's frame.
|
||||
const b3Transform& GetLocalFrameB() const;
|
||||
|
||||
// Is the joint limit enabled?
|
||||
bool IsLimitEnabled() const;
|
||||
@ -69,14 +74,14 @@ public:
|
||||
// Set the joint limit enabled.
|
||||
void SetEnableLimit(bool bit);
|
||||
|
||||
// Get the lower cone angle limit.
|
||||
float32 GetLowerLimit() const;
|
||||
// Get the cone angle in radians.
|
||||
float32 GetConeAngle() const;
|
||||
|
||||
// Set the lower cone angle limit.
|
||||
void SetLimit(float32 lowerAngle);
|
||||
// Set the cone angle in radians.
|
||||
void SetConeAngle(float32 angle);
|
||||
|
||||
// Draw this joint.
|
||||
void Draw(b3Draw* b3Draw) const;
|
||||
void Draw(b3Draw* draw) const;
|
||||
private:
|
||||
friend class b3Joint;
|
||||
friend class b3Body;
|
||||
@ -95,10 +100,9 @@ private:
|
||||
// Solver shared
|
||||
b3Transform m_localFrameA;
|
||||
b3Transform m_localFrameB;
|
||||
|
||||
bool m_enableLimit;
|
||||
float32 m_coneAngle;
|
||||
|
||||
bool m_enableLimit;
|
||||
|
||||
// Solver temp
|
||||
u32 m_indexA;
|
||||
u32 m_indexB;
|
||||
@ -122,4 +126,4 @@ private:
|
||||
b3LimitState m_limitState;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
@ -19,9 +19,9 @@
|
||||
#ifndef B3_JOINT_H
|
||||
#define B3_JOINT_H
|
||||
|
||||
#include <bounce\common\math\transform.h>
|
||||
#include <bounce\common\template\list.h>
|
||||
#include <bounce\dynamics\time_step.h>
|
||||
#include <bounce/common/math/transform.h>
|
||||
#include <bounce/common/template/list.h>
|
||||
#include <bounce/dynamics/time_step.h>
|
||||
|
||||
class b3Draw;
|
||||
class b3Body;
|
||||
@ -44,9 +44,9 @@ struct b3JointDef
|
||||
b3JointDef()
|
||||
{
|
||||
type = e_unknownJoint;
|
||||
bodyA = nullptr;
|
||||
bodyB = nullptr;
|
||||
userData = nullptr;
|
||||
bodyA = NULL;
|
||||
bodyB = NULL;
|
||||
userData = NULL;
|
||||
collideLinked = false;
|
||||
}
|
||||
|
||||
@ -57,6 +57,7 @@ struct b3JointDef
|
||||
bool collideLinked;
|
||||
};
|
||||
|
||||
// A joint edge to a joint graph, where a body is a vertex and a joint an edge.
|
||||
struct b3JointEdge
|
||||
{
|
||||
b3Body* other;
|
||||
@ -66,8 +67,7 @@ struct b3JointEdge
|
||||
b3JointEdge* m_next;
|
||||
};
|
||||
|
||||
// This goes inside a joint.
|
||||
// It holds two bodies that are linked.
|
||||
// This is stored in a joint. It stores two bodies that are linked by the joint.
|
||||
struct b3LinkedPair
|
||||
{
|
||||
// To the body A joint edge list
|
||||
@ -79,66 +79,54 @@ struct b3LinkedPair
|
||||
b3JointEdge edgeB;
|
||||
};
|
||||
|
||||
// @note All the data members of the joint structure they will be initialized
|
||||
// by the world.
|
||||
// Base joint class. For simplicity, a joint is unique per body pair.
|
||||
// There are many joint types, some of them provide motors and limits.
|
||||
class b3Joint
|
||||
{
|
||||
public :
|
||||
// Get the joint type.
|
||||
public:
|
||||
// Get this joint type.
|
||||
b3JointType GetType() const;
|
||||
|
||||
// Get the first body connected to the joint.
|
||||
// Get the body A connected to this joint.
|
||||
const b3Body* GetBodyA() const;
|
||||
b3Body* GetBodyA();
|
||||
|
||||
// Set the body to be connected to the joint as the first body.
|
||||
virtual void SetBodyA(b3Body* bodyA);
|
||||
|
||||
// Get the second body connected to the joint.
|
||||
// Get the body B connected to this joint.
|
||||
const b3Body* GetBodyB() const;
|
||||
b3Body* GetBodyB();
|
||||
|
||||
// Set the body to be connected to the joint as the second body.
|
||||
virtual void SetBodyB(b3Body* bodyB);
|
||||
|
||||
// Get the user specific data associated with the joint.
|
||||
// Get the user data associated with this joint.
|
||||
void* GetUserData();
|
||||
const void* GetUserData() const;
|
||||
|
||||
// Set the user data to be associated with the joint.
|
||||
void SetUserData(void* data);
|
||||
|
||||
// Tell the world if the bodies linked by this joint
|
||||
// should collide with each other.
|
||||
void SetCollideLinked(bool flag);
|
||||
|
||||
// Check if the bodies linked by this joint
|
||||
// should collide with each other.
|
||||
// Should the bodies linked by this joint collide with each other?
|
||||
bool CollideLinked() const;
|
||||
|
||||
|
||||
// Set if the bodies linked by this joint should collide with each other.
|
||||
void SetCollideLinked(bool bit);
|
||||
|
||||
// Dump this joint to the log file.
|
||||
virtual void Dump() const
|
||||
{
|
||||
b3Log("Dump not implemented for this joint type.\n");
|
||||
b3Log("Dump feature not implemented for this joint type.\n");
|
||||
}
|
||||
|
||||
// Get the next joint in the world joint list.
|
||||
b3Joint* GetNext();
|
||||
const b3Joint* GetNext() const;
|
||||
|
||||
// Create joint.
|
||||
static b3Joint* Create(const b3JointDef* def);
|
||||
|
||||
// Destroy joint.
|
||||
static void Destroy(b3Joint* j);
|
||||
protected :
|
||||
b3Joint* GetNext();
|
||||
protected:
|
||||
friend class b3Body;
|
||||
friend class b3World;
|
||||
friend class b3Island;
|
||||
friend class b3JointManager;
|
||||
friend class b3JointSolver;
|
||||
|
||||
friend class b3List2<b3Joint>;
|
||||
|
||||
static b3Joint* Create(const b3JointDef* def);
|
||||
static void Destroy(b3Joint* j);
|
||||
|
||||
b3Joint() { }
|
||||
virtual ~b3Joint() { }
|
||||
@ -181,9 +169,9 @@ inline b3Body* b3Joint::GetBodyA()
|
||||
return m_pair.bodyA;
|
||||
}
|
||||
|
||||
inline void b3Joint::SetBodyA(b3Body* bodyA)
|
||||
inline const b3Body* b3Joint::GetBodyB() const
|
||||
{
|
||||
m_pair.bodyA = bodyA;
|
||||
return m_pair.bodyB;
|
||||
}
|
||||
|
||||
inline b3Body* b3Joint::GetBodyB()
|
||||
@ -191,21 +179,6 @@ inline b3Body* b3Joint::GetBodyB()
|
||||
return m_pair.bodyB;
|
||||
}
|
||||
|
||||
inline const b3Body* b3Joint::GetBodyB() const
|
||||
{
|
||||
return m_pair.bodyB;
|
||||
}
|
||||
|
||||
inline void b3Joint::SetBodyB(b3Body* bodyB)
|
||||
{
|
||||
m_pair.bodyB = bodyB;
|
||||
}
|
||||
|
||||
inline void b3Joint::SetUserData(void* data)
|
||||
{
|
||||
m_userData = data;
|
||||
}
|
||||
|
||||
inline void* b3Joint::GetUserData()
|
||||
{
|
||||
return m_userData;
|
||||
@ -216,6 +189,11 @@ inline const void* b3Joint::GetUserData() const
|
||||
return m_userData;
|
||||
}
|
||||
|
||||
inline void b3Joint::SetUserData(void* data)
|
||||
{
|
||||
m_userData = data;
|
||||
}
|
||||
|
||||
inline void b3Joint::SetCollideLinked(bool bit)
|
||||
{
|
||||
m_collideLinked = bit;
|
||||
|
@ -19,7 +19,7 @@
|
||||
#ifndef B3_JOINT_SOLVER_H
|
||||
#define B3_JOINT_SOLVER_H
|
||||
|
||||
#include <bounce\dynamics\time_step.h>
|
||||
#include <bounce/dynamics/time_step.h>
|
||||
|
||||
class b3Joint;
|
||||
|
||||
@ -32,18 +32,6 @@ struct b3Jacobian
|
||||
b3Vec3 angularB;
|
||||
};
|
||||
|
||||
// 1x3 times 3x3.
|
||||
inline b3Vec3 b3Mul(const b3Vec3& v, const b3Mat33& A)
|
||||
{
|
||||
return b3Transpose(A) * v;
|
||||
}
|
||||
|
||||
// 1x3 times 3x1.
|
||||
inline float32 b3Mul(const b3Vec3& v, const b3Vec3& w)
|
||||
{
|
||||
return b3Dot(v, w);
|
||||
}
|
||||
|
||||
struct b3JointSolverDef
|
||||
{
|
||||
float32 dt;
|
||||
|
@ -19,43 +19,46 @@
|
||||
#ifndef B3_MOUSE_JOINT_H
|
||||
#define B3_MOUSE_JOINT_H
|
||||
|
||||
#include <bounce\dynamics\joints\joint.h>
|
||||
#include <bounce/dynamics/joints/joint.h>
|
||||
|
||||
// Mouse joint definition defines a world target
|
||||
// point and tunable parameters.
|
||||
struct b3MouseJointDef : public b3JointDef
|
||||
{
|
||||
b3MouseJointDef()
|
||||
{
|
||||
type = e_mouseJoint;
|
||||
worldAnchorA.SetZero();
|
||||
localAnchorB.SetZero();
|
||||
target.SetZero();
|
||||
maxForce = 0.0f;
|
||||
}
|
||||
|
||||
b3Vec3 worldAnchorA;
|
||||
b3Vec3 localAnchorB;
|
||||
// The initial world target point. Initially is assumed
|
||||
// to be coincident to the body anchor (satisfied constraint).
|
||||
b3Vec3 target;
|
||||
|
||||
// Maximum joint reaction force in newtons.
|
||||
float32 maxForce;
|
||||
};
|
||||
|
||||
// A mouse joint is used to make a local point on a body
|
||||
// follow a defined world point.
|
||||
class b3MouseJoint : public b3Joint
|
||||
{
|
||||
public :
|
||||
// Get the world space anchor point on the first body (usually the mouse world space position).
|
||||
b3Vec3 GetWorldAnchorA() const;
|
||||
public:
|
||||
// Get the world anchor point on body A.
|
||||
b3Vec3 GetAnchorA() const;
|
||||
|
||||
// Set the world space anchor position on the first body.
|
||||
void SetWorldAnchorA(const b3Vec3& v);
|
||||
// Get the world target point on body B.
|
||||
b3Vec3 GetAnchorB() const;
|
||||
|
||||
// Get the world space anchor point on the first body (usually the mouse world space position).
|
||||
b3Vec3 GetWorldAnchorB() const;
|
||||
// Get the world target point.
|
||||
const b3Vec3& GetTarget() const;
|
||||
|
||||
// Set the world target point.
|
||||
void SetTarget(const b3Vec3& target);
|
||||
|
||||
// Get the local space anchor point on the second body (usually the ray cast intersection).
|
||||
const b3Vec3& GetLocalAnchorB() const;
|
||||
|
||||
// Set the mouse position on the space of the second body (usually the ray cast intersection).
|
||||
void SetLocalAnchorB(const b3Vec3& v);
|
||||
|
||||
// Implement b3Joint.
|
||||
void Draw(b3Draw* b3Draw) const;
|
||||
// Draw this joint.
|
||||
void Draw(b3Draw* draw) const;
|
||||
private:
|
||||
friend class b3Joint;
|
||||
friend class b3JointManager;
|
||||
@ -68,14 +71,12 @@ private:
|
||||
virtual void SolveVelocityConstraints(const b3SolverData* data);
|
||||
virtual bool SolvePositionConstraints(const b3SolverData* data);
|
||||
|
||||
// The two anchor points on each body.
|
||||
// The first body has infinite mass. Therefore,
|
||||
// we store the world space anchor point.
|
||||
b3Vec3 m_worldAnchorA;
|
||||
// Solver shared
|
||||
b3Vec3 m_worldTargetA;
|
||||
b3Vec3 m_localAnchorB;
|
||||
float32 m_maxForce; // maximum reaction force in Newtons
|
||||
float32 m_maxForce;
|
||||
|
||||
// Constraint data for the solver.
|
||||
// Solver temp
|
||||
u32 m_indexB;
|
||||
float32 m_mB;
|
||||
b3Mat33 m_iB;
|
||||
@ -85,24 +86,4 @@ private:
|
||||
b3Vec3 m_C;
|
||||
};
|
||||
|
||||
inline b3Vec3 b3MouseJoint::GetWorldAnchorA() const
|
||||
{
|
||||
return m_worldAnchorA;
|
||||
}
|
||||
|
||||
inline void b3MouseJoint::SetWorldAnchorA(const b3Vec3& v)
|
||||
{
|
||||
m_worldAnchorA = v;
|
||||
}
|
||||
|
||||
inline const b3Vec3& b3MouseJoint::GetLocalAnchorB() const
|
||||
{
|
||||
return m_localAnchorB;
|
||||
}
|
||||
|
||||
inline void b3MouseJoint::SetLocalAnchorB(const b3Vec3& v)
|
||||
{
|
||||
m_localAnchorB = v;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
@ -19,8 +19,8 @@
|
||||
#ifndef B3_REVOLUTE_JOINT_H
|
||||
#define B3_REVOLUTE_JOINT_H
|
||||
|
||||
#include <bounce\dynamics\joints\joint.h>
|
||||
#include <bounce\common\math\mat.h>
|
||||
#include <bounce/dynamics/joints/joint.h>
|
||||
#include <bounce/common/math/mat.h>
|
||||
|
||||
struct b3RevoluteJointDef : public b3JointDef
|
||||
{
|
||||
@ -37,13 +37,13 @@ struct b3RevoluteJointDef : public b3JointDef
|
||||
maxMotorTorque = 0.0f;
|
||||
}
|
||||
|
||||
// Initialize this definition given an axis, anchor point, and the lower and upper angle limits in radians.
|
||||
// Initialize this definition from hinge axis, anchor point, and the lower and upper angle limits in radians.
|
||||
void Initialize(b3Body* bodyA, b3Body* bodyB, const b3Vec3& axis, const b3Vec3& anchor, float32 lowerAngle, float32 upperAngle);
|
||||
|
||||
// The joint frame relative to the frame of body A.
|
||||
// The joint frame relative body A's frame.
|
||||
b3Transform localFrameA;
|
||||
|
||||
// The joint frame relative to the frame of body B.
|
||||
// The joint frame relative body B's frame.
|
||||
b3Transform localFrameB;
|
||||
|
||||
// Enable the joint limit.
|
||||
@ -65,27 +65,27 @@ struct b3RevoluteJointDef : public b3JointDef
|
||||
float32 maxMotorTorque;
|
||||
};
|
||||
|
||||
// A revolute joint constrains two bodies to share a common point while they
|
||||
// are free to rotate about the point and a given axis.
|
||||
// The relative rotation about the shared axis
|
||||
// is the joint angle. You can limit the relative rotation with
|
||||
// a lower and upper angle limit. Also, you can use a motor
|
||||
// to drive the relative rotation about the shared axis.
|
||||
// A revolute joint constrains two bodies to share a point and an axis while
|
||||
// they are free to rotate about the point and the axis.
|
||||
// The relative rotation about the shared axis is the joint angle.
|
||||
// You can limit the relative rotation with a lower and upper angle limit.
|
||||
// You can use a motor to drive the relative rotation about the shared axis.
|
||||
// A maximum motor torque is provided so that infinite forces are not generated.
|
||||
// This joint can be used to create structures such as doors.
|
||||
class b3RevoluteJoint : public b3Joint
|
||||
{
|
||||
public:
|
||||
// Get the joint frame relative to the frame of body A.
|
||||
const b3Transform& GetFrameA() const;
|
||||
// Get the joint frame on body A in world coordinates.
|
||||
b3Transform GetFrameA() const;
|
||||
|
||||
// Set the joint frame relative to the frame of body A.
|
||||
void SetFrameA(const b3Transform& xf);
|
||||
// Get the joint frame on body B in world coordinates.
|
||||
b3Transform GetFrameB() const;
|
||||
|
||||
// Get the joint frame relative to the frame of body B.
|
||||
const b3Transform& GetFrameB() const;
|
||||
|
||||
// Set the joint frame relative to the frame of body B.
|
||||
void SetFrameB(const b3Transform& xf);
|
||||
// Get the joint frame relative body A's frame.
|
||||
const b3Transform& GetLocalFrameA() const;
|
||||
|
||||
// Get the joint frame relative body B's frame.
|
||||
const b3Transform& GetLocalFrameB() const;
|
||||
|
||||
// Is the joint limit enabled?
|
||||
bool IsLimitEnabled() const;
|
||||
@ -96,7 +96,7 @@ public:
|
||||
// Get the lower angle limit.
|
||||
float32 GetLowerLimit() const;
|
||||
|
||||
// Get the upper limit.
|
||||
// Get the upper angle limit.
|
||||
float32 GetUpperLimit() const;
|
||||
|
||||
// Set the angle limits.
|
||||
@ -108,20 +108,20 @@ public:
|
||||
// Set the joint motor enabled.
|
||||
void SetEnableMotor(bool bit);
|
||||
|
||||
// Get the desired motor speed (radians per second).
|
||||
// Get the desired motor speed in radians per second.
|
||||
float32 GetMotorSpeed() const;
|
||||
|
||||
// Set the desired motor speed (radians per second).
|
||||
// Set the desired motor speed in radians per second.
|
||||
void SetMotorSpeed(float32 speed);
|
||||
|
||||
// Get the maximum motor torque (Newton per meter).
|
||||
// Get the maximum motor torque in Newton per meter.
|
||||
float32 GetMaxMotorTorque() const;
|
||||
|
||||
// Set the maximum motor torque (Newton per meter).
|
||||
// Set the maximum motor torque in Newton per meter.
|
||||
void SetMaxMotorTorque(float32 torque);
|
||||
|
||||
// Draw this joint.
|
||||
void Draw(b3Draw* b3Draw) const;
|
||||
void Draw(b3Draw* draw) const;
|
||||
private:
|
||||
friend class b3Joint;
|
||||
friend class b3JointManager;
|
||||
@ -171,8 +171,8 @@ private:
|
||||
b3Vec3 m_rB;
|
||||
b3Vec3 m_nA;
|
||||
b3Vec3 m_nB;
|
||||
b3Mat<5, 5> m_mass;
|
||||
b3Vec<5> m_impulse;
|
||||
b3Mat<5, 5> m_mass; // block solver
|
||||
b3Vec<5> m_impulse; // block solver
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
@ -19,7 +19,7 @@
|
||||
#ifndef B3_SPHERE_JOINT_H
|
||||
#define B3_SPHERE_JOINT_H
|
||||
|
||||
#include <bounce\dynamics\joints\joint.h>
|
||||
#include <bounce/dynamics/joints/joint.h>
|
||||
|
||||
struct b3SphereJointDef : public b3JointDef
|
||||
{
|
||||
@ -30,31 +30,29 @@ struct b3SphereJointDef : public b3JointDef
|
||||
localAnchorB.SetZero();
|
||||
}
|
||||
|
||||
// Initialize this definition.
|
||||
// Initialize this definition from bodies and world anchor point.
|
||||
void Initialize(b3Body* bodyA, b3Body* bodyB, const b3Vec3& anchor);
|
||||
|
||||
// The anchor point relative to body A's origin
|
||||
b3Vec3 localAnchorA;
|
||||
|
||||
// The anchor point relative to body B's origin
|
||||
b3Vec3 localAnchorB;
|
||||
};
|
||||
|
||||
// A ball-in-socket joint.
|
||||
// A sphere joint constrains the bodies to rotate relative to each
|
||||
// other about a specified anchor point.
|
||||
class b3SphereJoint : public b3Joint
|
||||
{
|
||||
public:
|
||||
// Get the local anchor point on body A.
|
||||
const b3Vec3& GetLocalAnchorA() const;
|
||||
// Get the anchor point on body A in world coordinates.
|
||||
b3Vec3 GetAnchorA() const;
|
||||
|
||||
// Set the local anchor point on body A.
|
||||
void SetLocalAnchorA(const b3Vec3& point);
|
||||
|
||||
// Get the local anchor point on body B.
|
||||
const b3Vec3& GetLocalAnchorB() const;
|
||||
// Get the anchor point on body B in world coordinates.
|
||||
b3Vec3 GetAnchorB() const;
|
||||
|
||||
// Set the local anchor point on body B.
|
||||
void SetLocalAnchorB(const b3Vec3& point);
|
||||
|
||||
// Implement b3Joint
|
||||
void Draw(b3Draw* b3Draw) const;
|
||||
// Draw this joint.
|
||||
void Draw(b3Draw* draw) const;
|
||||
private:
|
||||
friend class b3Joint;
|
||||
friend class b3JointManager;
|
||||
@ -67,12 +65,11 @@ private:
|
||||
virtual void SolveVelocityConstraints(const b3SolverData* data);
|
||||
virtual bool SolvePositionConstraints(const b3SolverData* data);
|
||||
|
||||
// The local joint frames on each body.
|
||||
// Solver shared
|
||||
b3Vec3 m_localAnchorA;
|
||||
b3Vec3 m_localAnchorB;
|
||||
|
||||
// Temporary data copied from the joint solver
|
||||
// to reduce cache misses.
|
||||
// Solver temp
|
||||
u32 m_indexA;
|
||||
u32 m_indexB;
|
||||
float32 m_mA;
|
||||
@ -80,7 +77,6 @@ private:
|
||||
b3Mat33 m_iA;
|
||||
b3Mat33 m_iB;
|
||||
|
||||
// Constraint data.
|
||||
b3Vec3 m_localCenterA;
|
||||
b3Vec3 m_localCenterB;
|
||||
b3Vec3 m_rA;
|
||||
@ -89,24 +85,4 @@ private:
|
||||
b3Vec3 m_impulse;
|
||||
};
|
||||
|
||||
inline const b3Vec3& b3SphereJoint::GetLocalAnchorA() const
|
||||
{
|
||||
return m_localAnchorA;
|
||||
}
|
||||
|
||||
inline void b3SphereJoint::SetLocalAnchorA(const b3Vec3& point)
|
||||
{
|
||||
m_localAnchorA = point;
|
||||
}
|
||||
|
||||
inline const b3Vec3& b3SphereJoint::GetLocalAnchorB() const
|
||||
{
|
||||
return m_localAnchorB;
|
||||
}
|
||||
|
||||
inline void b3SphereJoint::SetLocalAnchorB(const b3Vec3& point)
|
||||
{
|
||||
m_localAnchorB = point;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
@ -19,7 +19,7 @@
|
||||
#ifndef B3_SPRING_JOINT_H
|
||||
#define B3_SPRING_JOINT_H
|
||||
|
||||
#include <bounce\dynamics\joints\joint.h>
|
||||
#include <bounce/dynamics/joints/joint.h>
|
||||
|
||||
struct b3SpringJointDef : public b3JointDef
|
||||
{
|
||||
@ -36,35 +36,65 @@ struct b3SpringJointDef : public b3JointDef
|
||||
// Initialize this definition from bodies and world anchors.
|
||||
void Initialize(b3Body* bodyA, b3Body* bodyB, const b3Vec3& anchorA, const b3Vec3& anchorB);
|
||||
|
||||
// The joint anchor point relative to the frame of body A
|
||||
// The anchor point relative to body A's origin
|
||||
b3Vec3 localAnchorA;
|
||||
|
||||
// The joint anchor point relative to the frame of body B
|
||||
// The anchor point relative to body B's origin
|
||||
b3Vec3 localAnchorB;
|
||||
|
||||
// The spring rest length
|
||||
// The spring rest length.
|
||||
float32 length;
|
||||
|
||||
// The mass-spring-damper frequency in units of hertz
|
||||
// 0 = disable spring softness
|
||||
// The mass-spring-damper frequency in Hz
|
||||
// 0 = disable softness
|
||||
float32 frequencyHz;
|
||||
|
||||
// The damping ration in the interval [0, 1].
|
||||
// The damping ration in the interval [0, 1]
|
||||
// 0 = undamped spring
|
||||
// 1 = critical damping
|
||||
float32 dampingRatio;
|
||||
};
|
||||
|
||||
// A spring joint constrains the bodies to rotate relative to each
|
||||
// other about a specified spring position.
|
||||
// The tunable soft parameters control how much/fast the bodies should translate
|
||||
// relative to each other about the spring position.
|
||||
// This joint can be used to create behaviours such as a car suspension.
|
||||
class b3SpringJoint : public b3Joint
|
||||
{
|
||||
public :
|
||||
// Get the local anchor point in the local space of the first body.
|
||||
public:
|
||||
// Get the anchor point on body A in world coordinates.
|
||||
b3Vec3 GetAnchorA() const;
|
||||
|
||||
// Get the anchor point on body B in world coordinates.
|
||||
b3Vec3 GetAnchorB() const;
|
||||
|
||||
// Get the anchor point relative to body A's origin.
|
||||
const b3Vec3& GetLocalAnchorA() const;
|
||||
|
||||
// Get the local anchor point in the local space of the second body.
|
||||
// Get the anchor point relative to body B's origin.
|
||||
const b3Vec3& GetLocalAnchorB() const;
|
||||
|
||||
void Draw(b3Draw* b3Draw) const;
|
||||
// Get the natural spring length.
|
||||
float32 GetLength() const;
|
||||
|
||||
// Set the natural spring length.
|
||||
void SetLength(float32 length);
|
||||
|
||||
// Get the damper frequency in Hz.
|
||||
float32 GetFrequency() const;
|
||||
|
||||
// Set the damper frequency in Hz.
|
||||
void SetFrequency(float32 frequency);
|
||||
|
||||
// Get the damping ratio.
|
||||
float32 GetDampingRatio() const;
|
||||
|
||||
// Set the damping ratio.
|
||||
void SetDampingRatio(float32 ratio);
|
||||
|
||||
// Draw this joint.
|
||||
void Draw(b3Draw* draw) const;
|
||||
private:
|
||||
friend class b3Joint;
|
||||
friend class b3JointManager;
|
||||
@ -103,14 +133,4 @@ private:
|
||||
float32 m_impulse;
|
||||
};
|
||||
|
||||
inline const b3Vec3& b3SpringJoint::GetLocalAnchorA() const
|
||||
{
|
||||
return m_localAnchorA;
|
||||
}
|
||||
|
||||
inline const b3Vec3& b3SpringJoint::GetLocalAnchorB() const
|
||||
{
|
||||
return m_localAnchorB;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
@ -19,7 +19,7 @@
|
||||
#ifndef B3_CAPSULE_SHAPE_H
|
||||
#define B3_CAPSULE_SHAPE_H
|
||||
|
||||
#include <bounce\dynamics\shapes\shape.h>
|
||||
#include <bounce/dynamics/shapes/shape.h>
|
||||
|
||||
// A capsule defined along the up-axis.
|
||||
class b3CapsuleShape : public b3Shape
|
||||
|
@ -19,7 +19,7 @@
|
||||
#ifndef B3_HULL_SHAPE_H
|
||||
#define B3_HULL_SHAPE_H
|
||||
|
||||
#include <bounce\dynamics\shapes\shape.h>
|
||||
#include <bounce/dynamics/shapes/shape.h>
|
||||
|
||||
struct b3Hull;
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
#ifndef B3_MESH_SHAPE_H
|
||||
#define B3_MESH_SHAPE_H
|
||||
|
||||
#include <bounce\dynamics\shapes\shape.h>
|
||||
#include <bounce/dynamics/shapes/shape.h>
|
||||
|
||||
struct b3Mesh;
|
||||
|
||||
|
@ -19,9 +19,9 @@
|
||||
#ifndef B3_SHAPE_H
|
||||
#define B3_SHAPE_H
|
||||
|
||||
#include <bounce\common\math\transform.h>
|
||||
#include <bounce\common\template\list.h>
|
||||
#include <bounce\collision\distance.h>
|
||||
#include <bounce/common/math/transform.h>
|
||||
#include <bounce/common/template/list.h>
|
||||
#include <bounce/collision/distance.h>
|
||||
|
||||
struct b3ContactEdge;
|
||||
|
||||
@ -41,8 +41,8 @@ struct b3ShapeDef
|
||||
{
|
||||
b3ShapeDef()
|
||||
{
|
||||
shape = nullptr;
|
||||
userData = nullptr;
|
||||
shape = NULL;
|
||||
userData = NULL;
|
||||
isSensor = false;
|
||||
density = 0.0f;
|
||||
friction = 0.3f;
|
||||
@ -59,15 +59,19 @@ struct b3ShapeDef
|
||||
|
||||
struct b3MassData
|
||||
{
|
||||
// The mass of the shape in kilograms.
|
||||
float32 mass;
|
||||
|
||||
// The shape center of mass relative to the shape's origin.
|
||||
b3Vec3 center;
|
||||
|
||||
// The rotational inertia of the shape about the shape's center of mass.
|
||||
b3Mat33 I;
|
||||
};
|
||||
|
||||
class b3Shape
|
||||
{
|
||||
public:
|
||||
// A shape is created and initialized by an user and a body.
|
||||
b3Shape() { }
|
||||
virtual ~b3Shape() { }
|
||||
|
||||
@ -78,11 +82,7 @@ public:
|
||||
const b3Body* GetBody() const;
|
||||
b3Body* GetBody();
|
||||
|
||||
// Get the frame of the shape relative to the world.
|
||||
b3Transform GetTransform() const;
|
||||
|
||||
// Calculate the mass data for this shape given the shape density, that is,
|
||||
// the mass per unit volume.
|
||||
// Calculate the mass data for this shape given the shape density.
|
||||
virtual void ComputeMass(b3MassData* data, float32 density) const = 0;
|
||||
|
||||
// Compute the shape world AABB.
|
||||
@ -91,26 +91,40 @@ public:
|
||||
// Test if a point is contained inside this shape.
|
||||
virtual bool TestPoint(const b3Vec3& point, const b3Transform& xf) const = 0;
|
||||
|
||||
// Compute the ray intersection point, normal, and fraction.
|
||||
// Compute the ray intersection point, normal of surface, and fraction.
|
||||
virtual bool RayCast(b3RayCastOutput* output, const b3RayCastInput& input, const b3Transform& xf) const = 0;
|
||||
|
||||
bool IsSensor() const;
|
||||
void SetSensor(bool flag);
|
||||
// Set if this shape is a sensor.
|
||||
void SetSensor(bool bit);
|
||||
|
||||
// Is this shape a sensor?
|
||||
bool IsSensor() const;
|
||||
|
||||
// Get the shape density.
|
||||
float32 GetDensity() const;
|
||||
|
||||
// Set the shape density.
|
||||
void SetDensity(float32 density);
|
||||
|
||||
// Get the shape coefficient of restitution.
|
||||
float32 GetRestitution() const;
|
||||
|
||||
// Set the shape coefficient of restitution.
|
||||
// This is a value in the range [0, 1].
|
||||
void SetRestitution(float32 restitution);
|
||||
|
||||
// Get the shape coefficient of friction.
|
||||
float32 GetFriction() const;
|
||||
|
||||
// Set the shape coefficient of friction.
|
||||
// This is a value in the range [0, 1].
|
||||
void SetFriction(float32 friction);
|
||||
|
||||
// Get the user data associated with this shape.
|
||||
void* GetUserData() const;
|
||||
void SetUserData(void* data);
|
||||
|
||||
// Destroy the contacts associated with this shape.
|
||||
void DestroyContacts();
|
||||
// Set the user data associated with this shape.
|
||||
void SetUserData(void* data);
|
||||
|
||||
// Dump this shape to the log file.
|
||||
void Dump(i32 bodyIndex) const;
|
||||
@ -119,23 +133,31 @@ public:
|
||||
const b3Shape* GetNext() const;
|
||||
b3Shape* GetNext();
|
||||
|
||||
// Create a shape.
|
||||
float32 m_radius;
|
||||
protected:
|
||||
friend class b3World;
|
||||
friend class b3Body;
|
||||
friend class b3Contact;
|
||||
friend class b3ContactManager;
|
||||
friend class b3ContactSolver;
|
||||
friend class b3List1<b3Shape>;
|
||||
|
||||
static b3Shape* Create(const b3ShapeDef& def);
|
||||
|
||||
// Destroy a shape.
|
||||
static void Destroy(b3Shape* shape);
|
||||
|
||||
// Convenience function.
|
||||
// Destroy the contacts associated with this shape.
|
||||
void DestroyContacts();
|
||||
|
||||
b3ShapeType m_type;
|
||||
bool m_isSensor;
|
||||
void* m_userData;
|
||||
i32 m_broadPhaseID;
|
||||
|
||||
float32 m_radius;
|
||||
float32 m_density;
|
||||
float32 m_restitution;
|
||||
float32 m_friction;
|
||||
|
||||
// Contact edges for this shape.
|
||||
i32 m_broadPhaseID;
|
||||
|
||||
// Contact edges for this shape contact graph.
|
||||
b3List2<b3ContactEdge> m_contactEdges;
|
||||
|
||||
// The parent body of this shape.
|
||||
|
@ -19,7 +19,7 @@
|
||||
#ifndef B3_SPHERE_SHAPE_H
|
||||
#define B3_SPHERE_SHAPE_H
|
||||
|
||||
#include <bounce\dynamics\shapes\shape.h>
|
||||
#include <bounce/dynamics/shapes/shape.h>
|
||||
|
||||
class b3SphereShape : public b3Shape
|
||||
{
|
||||
|
@ -19,9 +19,9 @@
|
||||
#ifndef B3_TIME_STEP_H
|
||||
#define B3_TIME_STEP_H
|
||||
|
||||
#include <bounce\common\math\vec3.h>
|
||||
#include <bounce\common\math\mat33.h>
|
||||
#include <bounce\common\math\quat.h>
|
||||
#include <bounce/common/math/vec3.h>
|
||||
#include <bounce/common/math/mat33.h>
|
||||
#include <bounce/common/math/quat.h>
|
||||
|
||||
struct b3Position
|
||||
{
|
||||
|
@ -19,12 +19,12 @@
|
||||
#ifndef B3_WORLD_H
|
||||
#define B3_WORLD_H
|
||||
|
||||
#include <bounce\common\memory\stack_allocator.h>
|
||||
#include <bounce\common\memory\block_pool.h>
|
||||
#include <bounce\common\template\list.h>
|
||||
#include <bounce\dynamics\time_step.h>
|
||||
#include <bounce\dynamics\joint_manager.h>
|
||||
#include <bounce\dynamics\contact_manager.h>
|
||||
#include <bounce/common/memory/stack_allocator.h>
|
||||
#include <bounce/common/memory/block_pool.h>
|
||||
#include <bounce/common/template/list.h>
|
||||
#include <bounce/dynamics/time_step.h>
|
||||
#include <bounce/dynamics/joint_manager.h>
|
||||
#include <bounce/dynamics/contact_manager.h>
|
||||
|
||||
struct b3BodyDef;
|
||||
class b3Body;
|
||||
@ -34,18 +34,19 @@ class b3ContactListener;
|
||||
class b3ContactFilter;
|
||||
class b3Draw;
|
||||
|
||||
// Use a physics world to create/destroy rigid bodies, execute ray cast and AABB queries.
|
||||
// Use a physics world to create/destroy rigid bodies, execute ray cast and volume queries.
|
||||
class b3World
|
||||
{
|
||||
public:
|
||||
b3World();
|
||||
~b3World();
|
||||
|
||||
// Set the debug b3Draw interface.
|
||||
// Set the debug draw interface.
|
||||
// The user must implement this interface to tell the world to
|
||||
// b3Draw the physics entities.
|
||||
void SetDebugDraw(b3Draw* b3Draw);
|
||||
// draw the physics entities.
|
||||
void SetDebugDraw(b3Draw* draw);
|
||||
|
||||
// Get the debug draw interface.
|
||||
b3Draw* GetDebugDraw();
|
||||
|
||||
// The filter passed can tell the world to disallow the contact creation between
|
||||
@ -77,9 +78,9 @@ public:
|
||||
// Remove a joint from the world and deallocate it from the memory.
|
||||
void DestroyJoint(b3Joint* joint);
|
||||
|
||||
// Call the function below to simulate a physics step.
|
||||
// Simulate a physics step.
|
||||
// The function parameters are the ammount of time to simulate,
|
||||
// and the number of contact solver iterations.
|
||||
// and the number of constraint solver iterations.
|
||||
void Step(float32 dt, u32 velocityIterations, u32 positionIterations);
|
||||
|
||||
// Perform a ray cast with the world.
|
||||
@ -87,13 +88,13 @@ public:
|
||||
// in the world. The ray cast output is the intercepted shape, the intersection
|
||||
// point in world space, the face normal on the shape associated with the point,
|
||||
// and the intersection fraction.
|
||||
void CastRay(b3RayCastListener* listener, const b3Vec3& p1, const b3Vec3& p2) const;
|
||||
void RayCast(b3RayCastListener* listener, const b3Vec3& p1, const b3Vec3& p2) const;
|
||||
|
||||
// Perform a AABB cast with the world.
|
||||
// The query listener will be notified when two shape AABBs are overlapping.
|
||||
// If the listener returns false then the query is stopped immediately.
|
||||
// Otherwise, it continues searching for new overlapping shape AABBs.
|
||||
void CastAABB(b3QueryListener* listener, const b3AABB3& aabb) const;
|
||||
void QueryAABB(b3QueryListener* listener, const b3AABB3& aabb) const;
|
||||
|
||||
// Get the list of bodies in this world.
|
||||
const b3List2<b3Body>& GetBodyList() const;
|
||||
@ -110,7 +111,7 @@ public:
|
||||
// Get the time spent to finish executing each simulation module of the last physics step.
|
||||
const b3Profile& GetProfile() const;
|
||||
|
||||
// Tell the world to b3Draw the entities that belong to this world.
|
||||
// Tell the world to draw the entities that belong to this world.
|
||||
void DebugDraw() const;
|
||||
void DrawShape(const b3Transform& xf, const b3Shape* shape) const;
|
||||
void DrawJoint(const b3Joint* joint) const;
|
||||
|
@ -19,7 +19,7 @@
|
||||
#ifndef B3_WORLD_LISTENERS_H
|
||||
#define B3_WORLD_LISTENERS_H
|
||||
|
||||
#include <bounce\common\math\math.h>
|
||||
#include <bounce/common/math/math.h>
|
||||
|
||||
class b3Shape;
|
||||
class b3Contact;
|
||||
|
@ -19,8 +19,8 @@
|
||||
#ifndef QH_HULL_H
|
||||
#define QH_HULL_H
|
||||
|
||||
#include <bounce\common\geometry.h>
|
||||
#include <bounce\common\template\array.h>
|
||||
#include <bounce/common/geometry.h>
|
||||
#include <bounce/common/template/array.h>
|
||||
|
||||
template<class T>
|
||||
struct qhList
|
||||
|
@ -3,7 +3,7 @@
|
||||
template<class T>
|
||||
inline void qhList<T>::PushFront(T* link)
|
||||
{
|
||||
link->prev = nullptr;
|
||||
link->prev = NULL;
|
||||
link->next = head;
|
||||
if (head)
|
||||
{
|
||||
@ -31,8 +31,8 @@ inline T* qhList<T>::Remove(T* link)
|
||||
head = link->next;
|
||||
}
|
||||
|
||||
link->prev = nullptr;
|
||||
link->next = nullptr;
|
||||
link->prev = NULL;
|
||||
link->next = NULL;
|
||||
|
||||
--count;
|
||||
return next;
|
||||
@ -78,7 +78,7 @@ inline qhHalfEdge* qhFace::FindTwin(const qhVertex* tail, const qhVertex* head)
|
||||
e = e->next;
|
||||
} while (e != edge);
|
||||
|
||||
return nullptr;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
inline b3Vec3 b3Newell(const b3Vec3& a, const b3Vec3& b)
|
||||
@ -128,7 +128,7 @@ inline qhHalfEdge* qhHull::FindTwin(const qhVertex* tail, const qhVertex* head)
|
||||
}
|
||||
face = face->next;
|
||||
}
|
||||
return nullptr;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
inline u32 qhGetMemorySize(u32 V)
|
||||
|
@ -19,7 +19,7 @@
|
||||
#ifndef DEBUG_DRAW_H
|
||||
#define DEBUG_DRAW_H
|
||||
|
||||
#include <bounce\bounce.h>
|
||||
#include <bounce/bounce.h>
|
||||
#include "mat44.h"
|
||||
|
||||
struct DrawPoints;
|
||||
|
@ -19,7 +19,7 @@
|
||||
#ifndef MAT44_H
|
||||
#define MAT44_H
|
||||
|
||||
#include <bounce\bounce.h>
|
||||
#include <bounce/bounce.h>
|
||||
|
||||
struct Vec4
|
||||
{
|
||||
|
@ -45,7 +45,7 @@ public:
|
||||
|
||||
b3ShapeDef sdef;
|
||||
sdef.shape = &hs;
|
||||
sdef.userData = nullptr;
|
||||
sdef.userData = NULL;
|
||||
sdef.friction = 1.0f;
|
||||
|
||||
b3Shape* shape = body->CreateShape(sdef);
|
||||
@ -80,7 +80,7 @@ public:
|
||||
sdef.density = 0.5f;
|
||||
sdef.friction = 0.3f;
|
||||
sdef.shape = &hs;
|
||||
sdef.userData = nullptr;
|
||||
sdef.userData = NULL;
|
||||
|
||||
b3Shape* shape = body->CreateShape(sdef);
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
#ifndef CLUSTER_H
|
||||
#define CLUSTER_H
|
||||
|
||||
#include <bounce\dynamics\contacts\contact_cluster.h>
|
||||
#include <bounce/dynamics/contacts/contact_cluster.h>
|
||||
|
||||
extern DebugDraw* g_debugDraw;
|
||||
extern Camera g_camera;
|
||||
|
@ -19,7 +19,7 @@
|
||||
#ifndef QUADRIC_H
|
||||
#define QUADRIC_H
|
||||
|
||||
#include <testbed\tests\quickhull_test.h>
|
||||
#include <testbed/tests/quickhull_test.h>
|
||||
|
||||
extern DebugDraw* g_debugDraw;
|
||||
extern Camera g_camera;
|
||||
@ -113,6 +113,19 @@ public:
|
||||
|
||||
~Quadric()
|
||||
{
|
||||
{
|
||||
b3Free(m_coneHull.vertices);
|
||||
b3Free(m_coneHull.edges);
|
||||
b3Free(m_coneHull.faces);
|
||||
b3Free(m_coneHull.planes);
|
||||
}
|
||||
|
||||
{
|
||||
b3Free(m_cylinderHull.vertices);
|
||||
b3Free(m_cylinderHull.edges);
|
||||
b3Free(m_cylinderHull.faces);
|
||||
b3Free(m_cylinderHull.planes);
|
||||
}
|
||||
}
|
||||
|
||||
static Test* Create()
|
||||
|
@ -19,7 +19,7 @@
|
||||
#ifndef QHULL_H
|
||||
#define QHULL_H
|
||||
|
||||
#include <bounce\quickhull\qh_hull.h>
|
||||
#include <bounce/quickhull/qh_hull.h>
|
||||
|
||||
extern DebugDraw* g_debugDraw;
|
||||
extern Camera g_camera;
|
||||
@ -48,7 +48,7 @@ struct Map
|
||||
return pair;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
b3StackArray<Pair, 256> m_pairs;
|
||||
|
@ -89,7 +89,7 @@ public:
|
||||
sdef.density = 0.0f;
|
||||
sdef.friction = 0.0f;
|
||||
sdef.shape = &hs;
|
||||
sdef.userData = nullptr;
|
||||
sdef.userData = NULL;
|
||||
|
||||
b3Shape* shape = body->CreateShape(sdef);
|
||||
}
|
||||
@ -109,7 +109,7 @@ public:
|
||||
sdef.density = 0.0f;
|
||||
sdef.friction = 0.0f;
|
||||
sdef.shape = &hs;
|
||||
sdef.userData = nullptr;
|
||||
sdef.userData = NULL;
|
||||
|
||||
b3Shape* shape = body->CreateShape(sdef);
|
||||
}
|
||||
@ -129,7 +129,7 @@ public:
|
||||
sdef.density = 0.0f;
|
||||
sdef.friction = 0.0f;
|
||||
sdef.shape = &hs;
|
||||
sdef.userData = nullptr;
|
||||
sdef.userData = NULL;
|
||||
|
||||
b3Shape* shape = body->CreateShape(sdef);
|
||||
}
|
||||
@ -149,7 +149,7 @@ public:
|
||||
sdef.density = 0.0f;
|
||||
sdef.friction = 0.0f;
|
||||
sdef.shape = &hs;
|
||||
sdef.userData = nullptr;
|
||||
sdef.userData = NULL;
|
||||
|
||||
b3Shape* shape = body->CreateShape(sdef);
|
||||
}
|
||||
@ -169,7 +169,7 @@ public:
|
||||
sdef.density = 0.0f;
|
||||
sdef.friction = 0.0f;
|
||||
sdef.shape = &hs;
|
||||
sdef.userData = nullptr;
|
||||
sdef.userData = NULL;
|
||||
|
||||
b3Shape* shape = body->CreateShape(sdef);
|
||||
}
|
||||
@ -190,7 +190,7 @@ public:
|
||||
sdef.density = 0.0f;
|
||||
sdef.friction = 0.0f;
|
||||
sdef.shape = &hs;
|
||||
sdef.userData = nullptr;
|
||||
sdef.userData = NULL;
|
||||
|
||||
b3Shape* shape = body->CreateShape(sdef);
|
||||
}
|
||||
@ -206,35 +206,16 @@ public:
|
||||
{
|
||||
// Perform the ray cast
|
||||
RayCastListener listener;
|
||||
m_world.CastRay(&listener, p1, p2);
|
||||
|
||||
int hitId = listener.FindClosestHit();
|
||||
m_world.RayCast(&listener, p1, p2);
|
||||
|
||||
i32 hitId = listener.FindClosestHit();
|
||||
if (hitId >= 0)
|
||||
{
|
||||
// Hit
|
||||
// Replace current hit
|
||||
RayCastHit rayHit = listener.m_hits[hitId];
|
||||
|
||||
b3Shape* shape = rayHit.m_shape;
|
||||
|
||||
b3Body* bodyA = m_groundBody;
|
||||
b3Body* bodyB = shape->GetBody();
|
||||
|
||||
// Ray hit point in world space
|
||||
b3Vec3 worldPointA = rayHit.m_point;
|
||||
|
||||
// xf from world space to the local space of the shape
|
||||
b3Transform xf = shape->GetTransform();
|
||||
|
||||
// lp = xf^-1 * wp
|
||||
b3Vec3 localPointA = b3MulT(xf, worldPointA);
|
||||
|
||||
extern DebugDraw* g_debugDraw;
|
||||
|
||||
g_debugDraw->DrawSegment(p1, worldPointA, b3Color(0.0f, 1.0f, 0.0f));
|
||||
g_debugDraw->DrawPoint(worldPointA, b3Color(1.0f, 0.0f, 0.0f));
|
||||
g_debugDraw->DrawSegment(worldPointA, worldPointA + rayHit.m_normal, b3Color(1.0f, 1.0f, 1.0f));
|
||||
RayCastHit hit = listener.m_hits[hitId];
|
||||
g_debugDraw->DrawSegment(p1, hit.m_point, b3Color(0.0f, 1.0f, 0.0f));
|
||||
g_debugDraw->DrawPoint(hit.m_point, b3Color(1.0f, 0.0f, 0.0f));
|
||||
g_debugDraw->DrawSegment(hit.m_point, hit.m_point + hit.m_normal, b3Color(1.0f, 1.0f, 1.0f));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -19,10 +19,10 @@
|
||||
#ifndef TEST_H
|
||||
#define TEST_H
|
||||
|
||||
#include <glfw\glfw3.h>
|
||||
#include <imgui\imgui.h>
|
||||
#include "..\framework\debug_draw.h"
|
||||
#include <bounce\bounce.h>
|
||||
#include <glfw/glfw3.h>
|
||||
#include <imgui/imgui.h>
|
||||
#include "../framework/debug_draw.h"
|
||||
#include <bounce/bounce.h>
|
||||
|
||||
struct Settings
|
||||
{
|
||||
@ -199,7 +199,6 @@ public:
|
||||
b3Profile m_maxProfile;
|
||||
|
||||
RayCastHit m_rayHit;
|
||||
b3Body* m_groundBody;
|
||||
b3BoxHull m_groundHull;
|
||||
b3BoxHull m_boxHull;
|
||||
b3BoxHull m_tallHull;
|
||||
|
Reference in New Issue
Block a user