57 position.Set(0.0f, 0.0f);
59 linearVelocity.Set(0.0f, 0.0f);
60 angularVelocity = 0.0f;
62 angularDamping = 0.0f;
65 fixedRotation =
false;
171 const b2Vec2& GetPosition()
const;
175 float GetAngle()
const;
178 const b2Vec2& GetWorldCenter()
const;
181 const b2Vec2& GetLocalCenter()
const;
185 void SetLinearVelocity(
const b2Vec2& v);
189 const b2Vec2& GetLinearVelocity()
const;
193 void SetAngularVelocity(
float omega);
197 float GetAngularVelocity()
const;
205 void ApplyForce(
const b2Vec2& force,
const b2Vec2& point,
bool wake);
210 void ApplyForceToCenter(
const b2Vec2& force,
bool wake);
216 void ApplyTorque(
float torque,
bool wake);
224 void ApplyLinearImpulse(
const b2Vec2& impulse,
const b2Vec2& point,
bool wake);
229 void ApplyLinearImpulseToCenter(
const b2Vec2& impulse,
bool wake);
234 void ApplyAngularImpulse(
float impulse,
bool wake);
238 float GetMass()
const;
242 float GetInertia()
const;
283 b2Vec2 GetLinearVelocityFromWorldPoint(
const b2Vec2& worldPoint)
const;
288 b2Vec2 GetLinearVelocityFromLocalPoint(
const b2Vec2& localPoint)
const;
291 float GetLinearDamping()
const;
294 void SetLinearDamping(
float linearDamping);
297 float GetAngularDamping()
const;
300 void SetAngularDamping(
float angularDamping);
303 float GetGravityScale()
const;
306 void SetGravityScale(
float scale);
312 b2BodyType GetType()
const;
315 void SetBullet(
bool flag);
318 bool IsBullet()
const;
322 void SetSleepingAllowed(
bool flag);
325 bool IsSleepingAllowed()
const;
330 void SetAwake(
bool flag);
334 bool IsAwake()
const;
351 bool IsEnabled()
const;
358 bool IsFixedRotation()
const;
376 const b2Body* GetNext()
const;
384 const b2World* GetWorld()
const;
392 friend class b2Island;
394 friend class b2ContactSolver;
411 e_islandFlag = 0x0001,
412 e_awakeFlag = 0x0002,
413 e_autoSleepFlag = 0x0004,
414 e_bulletFlag = 0x0008,
415 e_fixedRotationFlag = 0x0010,
416 e_enabledFlag = 0x0020,
423 void SynchronizeFixtures();
424 void SynchronizeTransform();
428 bool ShouldCollide(
const b2Body* other)
const;
430 void Advance(
float t);
442 float m_angularVelocity;
452 int32 m_fixtureCount;
457 float m_mass, m_invMass;
462 float m_linearDamping;
463 float m_angularDamping;
464 float m_gravityScale;
503 if (m_type == b2_staticBody)
508 if (b2Dot(v,v) > 0.0f)
513 m_linearVelocity = v;
518 return m_linearVelocity;
523 if (m_type == b2_staticBody)
533 m_angularVelocity = w;
538 return m_angularVelocity;
562 return b2Mul(m_xf, localPoint);
567 return b2Mul(m_xf.q, localVector);
572 return b2MulT(m_xf, worldPoint);
577 return b2MulT(m_xf.q, worldVector);
582 return m_linearVelocity + b2Cross(m_angularVelocity, worldPoint - m_sweep.
c);
592 return m_linearDamping;
597 m_linearDamping = linearDamping;
602 return m_angularDamping;
607 m_angularDamping = angularDamping;
612 return m_gravityScale;
617 m_gravityScale = scale;
624 m_flags |= e_bulletFlag;
628 m_flags &= ~e_bulletFlag;
634 return (m_flags & e_bulletFlag) == e_bulletFlag;
639 if (m_type == b2_staticBody)
646 m_flags |= e_awakeFlag;
651 m_flags &= ~e_awakeFlag;
654 m_angularVelocity = 0.0f;
662 return (m_flags & e_awakeFlag) == e_awakeFlag;
667 return (m_flags & e_enabledFlag) == e_enabledFlag;
672 return (m_flags & e_fixedRotationFlag) == e_fixedRotationFlag;
679 m_flags |= e_autoSleepFlag;
683 m_flags &= ~e_autoSleepFlag;
690 return (m_flags & e_autoSleepFlag) == e_autoSleepFlag;
695 return m_fixtureList;
700 return m_fixtureList;
715 return m_contactList;
720 return m_contactList;
745 if (m_type != b2_dynamicBody)
750 if (wake && (m_flags & e_awakeFlag) == 0)
756 if (m_flags & e_awakeFlag)
759 m_torque += b2Cross(point - m_sweep.
c, force);
765 if (m_type != b2_dynamicBody)
770 if (wake && (m_flags & e_awakeFlag) == 0)
776 if (m_flags & e_awakeFlag)
784 if (m_type != b2_dynamicBody)
789 if (wake && (m_flags & e_awakeFlag) == 0)
795 if (m_flags & e_awakeFlag)
803 if (m_type != b2_dynamicBody)
808 if (wake && (m_flags & e_awakeFlag) == 0)
814 if (m_flags & e_awakeFlag)
816 m_linearVelocity += m_invMass * impulse;
817 m_angularVelocity += m_invI * b2Cross(point - m_sweep.
c, impulse);
823 if (m_type != b2_dynamicBody)
828 if (wake && (m_flags & e_awakeFlag) == 0)
834 if (m_flags & e_awakeFlag)
836 m_linearVelocity += m_invMass * impulse;
842 if (m_type != b2_dynamicBody)
847 if (wake && (m_flags & e_awakeFlag) == 0)
853 if (m_flags & e_awakeFlag)
855 m_angularVelocity += m_invI * impulse;
859inline void b2Body::SynchronizeTransform()
861 m_xf.q.
Set(m_sweep.
a);
862 m_xf.p = m_sweep.
c - b2Mul(m_xf.q, m_sweep.
localCenter);
865inline void b2Body::Advance(
float alpha)
869 m_sweep.
c = m_sweep.c0;
870 m_sweep.
a = m_sweep.a0;
871 m_xf.q.
Set(m_sweep.
a);
872 m_xf.p = m_sweep.
c - b2Mul(m_xf.q, m_sweep.
localCenter);
A rigid body. These are created via b2World::CreateBody.
Definition b2_body.h:129
bool IsEnabled() const
Get the active state of the body.
Definition b2_body.h:665
void SetEnabled(bool flag)
bool IsFixedRotation() const
Does this body have fixed rotation?
Definition b2_body.h:670
b2Vec2 GetLinearVelocityFromLocalPoint(const b2Vec2 &localPoint) const
Definition b2_body.h:585
b2Vec2 GetLocalPoint(const b2Vec2 &worldPoint) const
Definition b2_body.h:570
b2Fixture * CreateFixture(const b2Shape *shape, float density)
b2BodyUserData & GetUserData()
Get the user data pointer that was provided in the body definition.
Definition b2_body.h:733
b2ContactEdge * GetContactList()
Definition b2_body.h:713
float GetAngularDamping() const
Get the angular damping of the body.
Definition b2_body.h:600
void ApplyAngularImpulse(float impulse, bool wake)
Definition b2_body.h:840
void SetAngularVelocity(float omega)
Definition b2_body.h:521
void SetSleepingAllowed(bool flag)
Definition b2_body.h:675
void SetBullet(bool flag)
Should this body be treated like a bullet for continuous collision detection?
Definition b2_body.h:620
void SetType(b2BodyType type)
Set the type of this body. This may alter the mass and velocity.
const b2Vec2 & GetWorldCenter() const
Get the world position of the center of mass.
Definition b2_body.h:491
b2JointEdge * GetJointList()
Get the list of all joints attached to this body.
Definition b2_body.h:703
void SetMassData(const b2MassData *data)
b2Vec2 GetLinearVelocityFromWorldPoint(const b2Vec2 &worldPoint) const
Definition b2_body.h:580
const b2Vec2 & GetLocalCenter() const
Get the local position of the center of mass.
Definition b2_body.h:496
b2Fixture * GetFixtureList()
Get the list of all fixtures attached to this body.
Definition b2_body.h:693
bool IsAwake() const
Definition b2_body.h:660
float GetLinearDamping() const
Get the linear damping of the body.
Definition b2_body.h:590
b2Vec2 GetWorldPoint(const b2Vec2 &localPoint) const
Definition b2_body.h:560
float GetAngularVelocity() const
Definition b2_body.h:536
const b2Vec2 & GetPosition() const
Definition b2_body.h:481
void ApplyLinearImpulse(const b2Vec2 &impulse, const b2Vec2 &point, bool wake)
Definition b2_body.h:801
void SetAngularDamping(float angularDamping)
Set the angular damping of the body.
Definition b2_body.h:605
void SetLinearVelocity(const b2Vec2 &v)
Definition b2_body.h:501
void DestroyFixture(b2Fixture *fixture)
float GetMass() const
Definition b2_body.h:541
b2MassData GetMassData() const
Definition b2_body.h:551
float GetGravityScale() const
Get the gravity scale of the body.
Definition b2_body.h:610
const b2Vec2 & GetLinearVelocity() const
Definition b2_body.h:516
void SetGravityScale(float scale)
Set the gravity scale of the body.
Definition b2_body.h:615
void ApplyForce(const b2Vec2 &force, const b2Vec2 &point, bool wake)
Definition b2_body.h:743
b2BodyType GetType() const
Get the type of this body.
Definition b2_body.h:471
void SetLinearDamping(float linearDamping)
Set the linear damping of the body.
Definition b2_body.h:595
b2Fixture * CreateFixture(const b2FixtureDef *def)
float GetAngle() const
Definition b2_body.h:486
void ApplyForceToCenter(const b2Vec2 &force, bool wake)
Definition b2_body.h:763
b2World * GetWorld()
Get the parent world of this body.
Definition b2_body.h:875
void SetTransform(const b2Vec2 &position, float angle)
bool IsSleepingAllowed() const
Is this body allowed to sleep.
Definition b2_body.h:688
void SetAwake(bool flag)
Definition b2_body.h:637
void Dump()
Dump this body to a file.
void ApplyTorque(float torque, bool wake)
Definition b2_body.h:782
b2Body * GetNext()
Get the next body in the world's body list.
Definition b2_body.h:723
bool IsBullet() const
Is this body treated like a bullet for continuous collision detection?
Definition b2_body.h:632
b2Vec2 GetWorldVector(const b2Vec2 &localVector) const
Definition b2_body.h:565
float GetInertia() const
Definition b2_body.h:546
b2Vec2 GetLocalVector(const b2Vec2 &worldVector) const
Definition b2_body.h:575
void ApplyLinearImpulseToCenter(const b2Vec2 &impulse, bool wake)
Definition b2_body.h:821
const b2Transform & GetTransform() const
Definition b2_body.h:476
void SetFixedRotation(bool flag)
Definition b2_distance_joint.h:77
Definition b2_fixture.h:117
Definition b2_friction_joint.h:61
Definition b2_gear_joint.h:62
Definition b2_joint.h:110
Definition b2_motor_joint.h:65
Definition b2_mouse_joint.h:66
Definition b2_prismatic_joint.h:92
Definition b2_pulley_joint.h:85
Definition b2_revolute_joint.h:95
Definition b2_weld_joint.h:70
Definition b2_wheel_joint.h:96
bool allowSleep
Definition b2_body.h:103
bool awake
Is this body initially awake or sleeping?
Definition b2_body.h:106
b2Vec2 linearVelocity
The linear velocity of the body's origin in world co-ordinates.
Definition b2_body.h:84
bool fixedRotation
Should this body be prevented from rotating? Useful for characters.
Definition b2_body.h:109
bool enabled
Does this body start out enabled?
Definition b2_body.h:118
b2Vec2 position
Definition b2_body.h:78
bool bullet
Definition b2_body.h:115
b2BodyDef()
This constructor sets the body definition default values.
Definition b2_body.h:55
b2BodyType type
Definition b2_body.h:74
float linearDamping
Definition b2_body.h:93
float angularVelocity
The angular velocity of the body.
Definition b2_body.h:87
float angle
The world angle of the body in radians.
Definition b2_body.h:81
float gravityScale
Scale the gravity applied to this body.
Definition b2_body.h:124
b2BodyUserData userData
Use this to store application specific body data.
Definition b2_body.h:121
float angularDamping
Definition b2_body.h:99
You can define this to inject whatever data you want in b2Body.
Definition b2_settings.h:59
Definition b2_fixture.h:62
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
float mass
The mass of the shape, usually in kilograms.
Definition b2_shape.h:36
float I
The rotational inertia of the shape about the local origin.
Definition b2_shape.h:42
void Set(float angle)
Set using an angle in radians.
Definition b2_math.h:300
b2Vec2 c
center world positions
Definition b2_math.h:385
void Advance(float alpha)
Definition b2_math.h:699
b2Vec2 localCenter
local center of mass position
Definition b2_math.h:384
float a
world angles
Definition b2_math.h:386
A 2D column vector.
Definition b2_math.h:42
void SetZero()
Set this vector to all zeros.
Definition b2_math.h:50