 |
Box2D
2.4.0
A 2D physics engine for games
|
61 position.Set(0.0f, 0.0f);
63 linearVelocity.Set(0.0f, 0.0f);
64 angularVelocity = 0.0f;
66 angularDamping = 0.0f;
69 fixedRotation =
false;
175 const b2Vec2& GetPosition()
const;
179 float GetAngle()
const;
182 const b2Vec2& GetWorldCenter()
const;
185 const b2Vec2& GetLocalCenter()
const;
189 void SetLinearVelocity(
const b2Vec2& v);
193 const b2Vec2& GetLinearVelocity()
const;
197 void SetAngularVelocity(
float omega);
201 float GetAngularVelocity()
const;
209 void ApplyForce(
const b2Vec2& force,
const b2Vec2& point,
bool wake);
214 void ApplyForceToCenter(
const b2Vec2& force,
bool wake);
220 void ApplyTorque(
float torque,
bool wake);
228 void ApplyLinearImpulse(
const b2Vec2& impulse,
const b2Vec2& point,
bool wake);
233 void ApplyLinearImpulseToCenter(
const b2Vec2& impulse,
bool wake);
238 void ApplyAngularImpulse(
float impulse,
bool wake);
242 float GetMass()
const;
246 float GetInertia()
const;
287 b2Vec2 GetLinearVelocityFromWorldPoint(
const b2Vec2& worldPoint)
const;
292 b2Vec2 GetLinearVelocityFromLocalPoint(
const b2Vec2& localPoint)
const;
295 float GetLinearDamping()
const;
298 void SetLinearDamping(
float linearDamping);
301 float GetAngularDamping()
const;
304 void SetAngularDamping(
float angularDamping);
307 float GetGravityScale()
const;
310 void SetGravityScale(
float scale);
316 b2BodyType GetType()
const;
319 void SetBullet(
bool flag);
322 bool IsBullet()
const;
326 void SetSleepingAllowed(
bool flag);
329 bool IsSleepingAllowed()
const;
334 void SetAwake(
bool flag);
338 bool IsAwake()
const;
355 bool IsEnabled()
const;
362 bool IsFixedRotation()
const;
380 const b2Body* GetNext()
const;
383 void* GetUserData()
const;
386 void SetUserData(
void* data);
390 const b2World* GetWorld()
const;
398 friend class b2Island;
400 friend class b2ContactSolver;
418 e_islandFlag = 0x0001,
419 e_awakeFlag = 0x0002,
420 e_autoSleepFlag = 0x0004,
421 e_bulletFlag = 0x0008,
422 e_fixedRotationFlag = 0x0010,
423 e_enabledFlag = 0x0020,
430 void SynchronizeFixtures();
431 void SynchronizeTransform();
435 bool ShouldCollide(
const b2Body* other)
const;
437 void Advance(
float t);
449 float m_angularVelocity;
459 int32 m_fixtureCount;
464 float m_mass, m_invMass;
469 float m_linearDamping;
470 float m_angularDamping;
471 float m_gravityScale;
510 if (m_type == b2_staticBody)
515 if (b2Dot(v,v) > 0.0f)
520 m_linearVelocity = v;
525 return m_linearVelocity;
530 if (m_type == b2_staticBody)
540 m_angularVelocity = w;
545 return m_angularVelocity;
567 return b2Mul(m_xf, localPoint);
572 return b2Mul(m_xf.q, localVector);
577 return b2MulT(m_xf, worldPoint);
582 return b2MulT(m_xf.q, worldVector);
587 return m_linearVelocity + b2Cross(m_angularVelocity, worldPoint - m_sweep.
c);
597 return m_linearDamping;
602 m_linearDamping = linearDamping;
607 return m_angularDamping;
612 m_angularDamping = angularDamping;
617 return m_gravityScale;
622 m_gravityScale = scale;
629 m_flags |= e_bulletFlag;
633 m_flags &= ~e_bulletFlag;
639 return (m_flags & e_bulletFlag) == e_bulletFlag;
644 if (m_type == b2_staticBody)
651 m_flags |= e_awakeFlag;
656 m_flags &= ~e_awakeFlag;
659 m_angularVelocity = 0.0f;
667 return (m_flags & e_awakeFlag) == e_awakeFlag;
672 return (m_flags & e_enabledFlag) == e_enabledFlag;
677 return (m_flags & e_fixedRotationFlag) == e_fixedRotationFlag;
684 m_flags |= e_autoSleepFlag;
688 m_flags &= ~e_autoSleepFlag;
695 return (m_flags & e_autoSleepFlag) == e_autoSleepFlag;
700 return m_fixtureList;
705 return m_fixtureList;
720 return m_contactList;
725 return m_contactList;
750 if (m_type != b2_dynamicBody)
755 if (wake && (m_flags & e_awakeFlag) == 0)
761 if (m_flags & e_awakeFlag)
764 m_torque += b2Cross(point - m_sweep.
c, force);
770 if (m_type != b2_dynamicBody)
775 if (wake && (m_flags & e_awakeFlag) == 0)
781 if (m_flags & e_awakeFlag)
789 if (m_type != b2_dynamicBody)
794 if (wake && (m_flags & e_awakeFlag) == 0)
800 if (m_flags & e_awakeFlag)
808 if (m_type != b2_dynamicBody)
813 if (wake && (m_flags & e_awakeFlag) == 0)
819 if (m_flags & e_awakeFlag)
821 m_linearVelocity += m_invMass * impulse;
822 m_angularVelocity += m_invI * b2Cross(point - m_sweep.
c, impulse);
828 if (m_type != b2_dynamicBody)
833 if (wake && (m_flags & e_awakeFlag) == 0)
839 if (m_flags & e_awakeFlag)
841 m_linearVelocity += m_invMass * impulse;
847 if (m_type != b2_dynamicBody)
852 if (wake && (m_flags & e_awakeFlag) == 0)
858 if (m_flags & e_awakeFlag)
860 m_angularVelocity += m_invI * impulse;
864 inline void b2Body::SynchronizeTransform()
866 m_xf.q.
Set(m_sweep.
a);
867 m_xf.p = m_sweep.
c - b2Mul(m_xf.q, m_sweep.
localCenter);
870 inline void b2Body::Advance(
float alpha)
874 m_sweep.
c = m_sweep.c0;
875 m_sweep.
a = m_sweep.a0;
876 m_xf.q.
Set(m_sweep.
a);
877 m_xf.p = m_sweep.
c - b2Mul(m_xf.q, m_sweep.
localCenter);
A 2D column vector.
Definition: b2_math.h:42
void SetAngularDamping(float angularDamping)
Set the angular damping of the body.
Definition: b2_body.h:610
Definition: b2_friction_joint.h:61
bool IsAwake() const
Definition: b2_body.h:665
A rigid body. These are created via b2World::CreateBody.
Definition: b2_body.h:133
float linearDamping
Definition: b2_body.h:97
void GetMassData(b2MassData *data) const
Definition: b2_body.h:558
void SetBullet(bool flag)
Should this body be treated like a bullet for continuous collision detection?
Definition: b2_body.h:625
void SetTransform(const b2Vec2 &position, float angle)
Definition: b2_distance_joint.h:70
b2Vec2 GetLocalPoint(const b2Vec2 &worldPoint) const
Definition: b2_body.h:575
const b2Transform & GetTransform() const
Definition: b2_body.h:483
b2BodyType GetType() const
Get the type of this body.
Definition: b2_body.h:478
b2Fixture * GetFixtureList()
Get the list of all fixtures attached to this body.
Definition: b2_body.h:698
b2Vec2 GetWorldPoint(const b2Vec2 &localPoint) const
Definition: b2_body.h:565
Definition: b2_math.h:369
b2Vec2 GetLinearVelocityFromWorldPoint(const b2Vec2 &worldPoint) const
Definition: b2_body.h:585
Definition: b2_prismatic_joint.h:92
float gravityScale
Scale the gravity applied to this body.
Definition: b2_body.h:128
bool fixedRotation
Should this body be prevented from rotating? Useful for characters.
Definition: b2_body.h:113
b2World * GetWorld()
Get the parent world of this body.
Definition: b2_body.h:880
b2BodyDef()
This constructor sets the body definition default values.
Definition: b2_body.h:58
const b2Vec2 & GetLinearVelocity() const
Definition: b2_body.h:523
void SetType(b2BodyType type)
Set the type of this body. This may alter the mass and velocity.
float angularDamping
Definition: b2_body.h:103
b2Vec2 GetLocalVector(const b2Vec2 &worldVector) const
Definition: b2_body.h:580
float angle
The world angle of the body in radians.
Definition: b2_body.h:85
void SetAngularVelocity(float omega)
Definition: b2_body.h:528
b2JointEdge * GetJointList()
Get the list of all joints attached to this body.
Definition: b2_body.h:708
b2Vec2 c
center world positions
Definition: b2_math.h:383
void SetGravityScale(float scale)
Set the gravity scale of the body.
Definition: b2_body.h:620
float GetInertia() const
Definition: b2_body.h:553
void * userData
Use this to store application specific body data.
Definition: b2_body.h:125
void ApplyAngularImpulse(float impulse, bool wake)
Definition: b2_body.h:845
Definition: b2_wheel_joint.h:96
void SetSleepingAllowed(bool flag)
Definition: b2_body.h:680
bool IsBullet() const
Is this body treated like a bullet for continuous collision detection?
Definition: b2_body.h:637
bool IsSleepingAllowed() const
Is this body allowed to sleep.
Definition: b2_body.h:693
void * GetUserData() const
Get the user data pointer that was provided in the body definition.
Definition: b2_body.h:743
b2Fixture * CreateFixture(const b2FixtureDef *def)
Definition: b2_fixture.h:62
Definition: b2_weld_joint.h:70
void SetLinearVelocity(const b2Vec2 &v)
Definition: b2_body.h:508
b2Vec2 GetWorldVector(const b2Vec2 &localVector) const
Definition: b2_body.h:570
void Dump()
Dump this body to a file.
void ApplyLinearImpulseToCenter(const b2Vec2 &impulse, bool wake)
Definition: b2_body.h:826
void SetUserData(void *data)
Set the user data. Use this to store your application specific data.
Definition: b2_body.h:738
b2BodyType type
Definition: b2_body.h:78
Definition: b2_fixture.h:113
b2Vec2 linearVelocity
The linear velocity of the body's origin in world co-ordinates.
Definition: b2_body.h:88
void Advance(float alpha)
Definition: b2_math.h:696
bool bullet
Definition: b2_body.h:119
float angularVelocity
The angular velocity of the body.
Definition: b2_body.h:91
float GetAngularDamping() const
Get the angular damping of the body.
Definition: b2_body.h:605
Definition: b2_revolute_joint.h:95
const b2Vec2 & GetWorldCenter() const
Get the world position of the center of mass.
Definition: b2_body.h:498
float GetAngle() const
Definition: b2_body.h:493
b2ContactEdge * GetContactList()
Definition: b2_body.h:718
bool awake
Is this body initially awake or sleeping?
Definition: b2_body.h:110
bool allowSleep
Definition: b2_body.h:107
b2Vec2 GetLinearVelocityFromLocalPoint(const b2Vec2 &localPoint) const
Definition: b2_body.h:590
bool enabled
Does this body start out enabled?
Definition: b2_body.h:122
void SetLinearDamping(float linearDamping)
Set the linear damping of the body.
Definition: b2_body.h:600
bool IsEnabled() const
Get the active state of the body.
Definition: b2_body.h:670
void SetEnabled(bool flag)
Definition: b2_joint.h:64
Definition: b2_motor_joint.h:65
float GetMass() const
Definition: b2_body.h:548
void DestroyFixture(b2Fixture *fixture)
b2Body * GetNext()
Get the next body in the world's body list.
Definition: b2_body.h:728
Definition: b2_world.h:47
float GetGravityScale() const
Get the gravity scale of the body.
Definition: b2_body.h:615
bool IsFixedRotation() const
Does this body have fixed rotation?
Definition: b2_body.h:675
void ApplyLinearImpulse(const b2Vec2 &impulse, const b2Vec2 &point, bool wake)
Definition: b2_body.h:806
Definition: b2_gear_joint.h:61
Definition: b2_shape.h:49
Definition: b2_rope_joint.h:64
void Set(float angle)
Set using an angle in radians.
Definition: b2_math.h:300
This holds the mass data computed for a shape.
Definition: b2_shape.h:34
b2Vec2 center
The position of the shape's centroid relative to the shape's origin.
Definition: b2_shape.h:39
void SetAwake(bool flag)
Definition: b2_body.h:642
void SetZero()
Set this vector to all zeros.
Definition: b2_math.h:50
float mass
The mass of the shape, usually in kilograms.
Definition: b2_shape.h:36
void SetMassData(const b2MassData *data)
void ApplyTorque(float torque, bool wake)
Definition: b2_body.h:787
Definition: b2_mouse_joint.h:66
void SetFixedRotation(bool flag)
Definition: b2_joint.h:112
const b2Vec2 & GetLocalCenter() const
Get the local position of the center of mass.
Definition: b2_body.h:503
b2Vec2 localCenter
local center of mass position
Definition: b2_math.h:382
const b2Vec2 & GetPosition() const
Definition: b2_body.h:488
float GetAngularVelocity() const
Definition: b2_body.h:543
float I
The rotational inertia of the shape about the local origin.
Definition: b2_shape.h:42
float GetLinearDamping() const
Get the linear damping of the body.
Definition: b2_body.h:595
void ApplyForce(const b2Vec2 &force, const b2Vec2 &point, bool wake)
Definition: b2_body.h:748
float a
world angles
Definition: b2_math.h:384
Definition: b2_pulley_joint.h:85
b2Fixture * CreateFixture(const b2Shape *shape, float density)
b2Vec2 position
Definition: b2_body.h:82
void ApplyForceToCenter(const b2Vec2 &force, bool wake)
Definition: b2_body.h:768