mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Updated to Box2D 2.2, added new joints, some other updates to match the API changes (still plenty more to go though)
--HG-- branch : box2d-update
This commit is contained in:
Regular → Executable
+30
-18
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com
|
||||
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
@@ -26,6 +26,7 @@
|
||||
class b2BlockAllocator;
|
||||
class b2Body;
|
||||
class b2BroadPhase;
|
||||
class b2Fixture;
|
||||
|
||||
/// This holds contact filtering data.
|
||||
struct b2Filter
|
||||
@@ -61,8 +62,6 @@ struct b2FixtureDef
|
||||
isSensor = false;
|
||||
}
|
||||
|
||||
virtual ~b2FixtureDef() {}
|
||||
|
||||
/// The shape, this must be set. The shape will be cloned, so you
|
||||
/// can create the shape on the stack.
|
||||
const b2Shape* shape;
|
||||
@@ -87,6 +86,14 @@ struct b2FixtureDef
|
||||
b2Filter filter;
|
||||
};
|
||||
|
||||
/// This proxy is used internally to connect fixtures to the broad-phase.
|
||||
struct b2FixtureProxy
|
||||
{
|
||||
b2AABB aabb;
|
||||
b2Fixture* fixture;
|
||||
int32 childIndex;
|
||||
int32 proxyId;
|
||||
};
|
||||
|
||||
/// A fixture is used to attach a shape to a body for collision detection. A fixture
|
||||
/// inherits its transform from its parent. Fixtures hold additional non-geometric data
|
||||
@@ -115,11 +122,15 @@ public:
|
||||
|
||||
/// Set the contact filtering data. This will not update contacts until the next time
|
||||
/// step when either parent body is active and awake.
|
||||
/// This automatically calls Refilter.
|
||||
void SetFilterData(const b2Filter& filter);
|
||||
|
||||
/// Get the contact filtering data.
|
||||
const b2Filter& GetFilterData() const;
|
||||
|
||||
/// Call this if you want to establish collision that was previously disabled by b2ContactFilter::ShouldCollide.
|
||||
void Refilter();
|
||||
|
||||
/// Get the parent body of this fixture. This is NULL if the fixture is not attached.
|
||||
/// @return the parent body.
|
||||
b2Body* GetBody();
|
||||
@@ -138,14 +149,13 @@ public:
|
||||
void SetUserData(void* data);
|
||||
|
||||
/// Test a point for containment in this fixture.
|
||||
/// @param xf the shape world transform.
|
||||
/// @param p a point in world coordinates.
|
||||
bool TestPoint(const b2Vec2& p) const;
|
||||
|
||||
/// Cast a ray against this shape.
|
||||
/// @param output the ray-cast results.
|
||||
/// @param input the ray-cast input parameters.
|
||||
bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input) const;
|
||||
bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input, int32 childIndex) const;
|
||||
|
||||
/// Get the mass data for this fixture. The mass data is based on the density and
|
||||
/// the shape. The rotational inertia is about the shape's origin. This operation
|
||||
@@ -162,19 +172,21 @@ public:
|
||||
/// Get the coefficient of friction.
|
||||
float32 GetFriction() const;
|
||||
|
||||
/// Set the coefficient of friction.
|
||||
/// Set the coefficient of friction. This will _not_ change the friction of
|
||||
/// existing contacts.
|
||||
void SetFriction(float32 friction);
|
||||
|
||||
/// Get the coefficient of restitution.
|
||||
float32 GetRestitution() const;
|
||||
|
||||
/// Set the coefficient of restitution.
|
||||
/// Set the coefficient of restitution. This will _not_ change the restitution of
|
||||
/// existing contacts.
|
||||
void SetRestitution(float32 restitution);
|
||||
|
||||
/// Get the fixture's AABB. This AABB may be enlarge and/or stale.
|
||||
/// If you need a more accurate AABB, compute it using the shape and
|
||||
/// the body transform.
|
||||
const b2AABB& GetAABB() const;
|
||||
const b2AABB& GetAABB(int32 childIndex) const;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -184,7 +196,6 @@ protected:
|
||||
friend class b2ContactManager;
|
||||
|
||||
b2Fixture();
|
||||
~b2Fixture();
|
||||
|
||||
// We need separation create/destroy functions from the constructor/destructor because
|
||||
// the destructor cannot access the allocator (no destructor arguments allowed by C++).
|
||||
@@ -192,13 +203,11 @@ protected:
|
||||
void Destroy(b2BlockAllocator* allocator);
|
||||
|
||||
// These support body activation/deactivation.
|
||||
void CreateProxy(b2BroadPhase* broadPhase, const b2Transform& xf);
|
||||
void DestroyProxy(b2BroadPhase* broadPhase);
|
||||
void CreateProxies(b2BroadPhase* broadPhase, const b2Transform& xf);
|
||||
void DestroyProxies(b2BroadPhase* broadPhase);
|
||||
|
||||
void Synchronize(b2BroadPhase* broadPhase, const b2Transform& xf1, const b2Transform& xf2);
|
||||
|
||||
b2AABB m_aabb;
|
||||
|
||||
float32 m_density;
|
||||
|
||||
b2Fixture* m_next;
|
||||
@@ -209,7 +218,9 @@ protected:
|
||||
float32 m_friction;
|
||||
float32 m_restitution;
|
||||
|
||||
int32 m_proxyId;
|
||||
b2FixtureProxy* m_proxies;
|
||||
int32 m_proxyCount;
|
||||
|
||||
b2Filter m_filter;
|
||||
|
||||
bool m_isSensor;
|
||||
@@ -308,9 +319,9 @@ inline bool b2Fixture::TestPoint(const b2Vec2& p) const
|
||||
return m_shape->TestPoint(m_body->GetTransform(), p);
|
||||
}
|
||||
|
||||
inline bool b2Fixture::RayCast(b2RayCastOutput* output, const b2RayCastInput& input) const
|
||||
inline bool b2Fixture::RayCast(b2RayCastOutput* output, const b2RayCastInput& input, int32 childIndex) const
|
||||
{
|
||||
return m_shape->RayCast(output, input, m_body->GetTransform());
|
||||
return m_shape->RayCast(output, input, m_body->GetTransform(), childIndex);
|
||||
}
|
||||
|
||||
inline void b2Fixture::GetMassData(b2MassData* massData) const
|
||||
@@ -318,9 +329,10 @@ inline void b2Fixture::GetMassData(b2MassData* massData) const
|
||||
m_shape->ComputeMass(massData, m_density);
|
||||
}
|
||||
|
||||
inline const b2AABB& b2Fixture::GetAABB() const
|
||||
inline const b2AABB& b2Fixture::GetAABB(int32 childIndex) const
|
||||
{
|
||||
return m_aabb;
|
||||
b2Assert(0 <= childIndex && childIndex < m_proxyCount);
|
||||
return m_proxies[childIndex].aabb;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user