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;
386 const b2World* GetWorld()
const;
394 friend class b2Island;
396 friend class b2ContactSolver;
407 friend class b2RopeJoint;
414 e_islandFlag = 0x0001,
415 e_awakeFlag = 0x0002,
416 e_autoSleepFlag = 0x0004,
417 e_bulletFlag = 0x0008,
418 e_fixedRotationFlag = 0x0010,
419 e_enabledFlag = 0x0020,
426 void SynchronizeFixtures();
427 void SynchronizeTransform();
431 bool ShouldCollide(
const b2Body* other)
const;
433 void Advance(
float t);
445 float m_angularVelocity;
455 int32 m_fixtureCount;
460 float m_mass, m_invMass;
465 float m_linearDamping;
466 float m_angularDamping;
467 float m_gravityScale;
506 if (m_type == b2_staticBody)
511 if (b2Dot(v,v) > 0.0f)
516 m_linearVelocity = v;
521 return m_linearVelocity;
526 if (m_type == b2_staticBody)
536 m_angularVelocity = w;
541 return m_angularVelocity;
563 return b2Mul(m_xf, localPoint);
568 return b2Mul(m_xf.q, localVector);
573 return b2MulT(m_xf, worldPoint);
578 return b2MulT(m_xf.q, worldVector);
583 return m_linearVelocity + b2Cross(m_angularVelocity, worldPoint - m_sweep.
c);
593 return m_linearDamping;
598 m_linearDamping = linearDamping;
603 return m_angularDamping;
608 m_angularDamping = angularDamping;
613 return m_gravityScale;
618 m_gravityScale = scale;
625 m_flags |= e_bulletFlag;
629 m_flags &= ~e_bulletFlag;
635 return (m_flags & e_bulletFlag) == e_bulletFlag;
640 if (m_type == b2_staticBody)
647 m_flags |= e_awakeFlag;
652 m_flags &= ~e_awakeFlag;
655 m_angularVelocity = 0.0f;
663 return (m_flags & e_awakeFlag) == e_awakeFlag;
668 return (m_flags & e_enabledFlag) == e_enabledFlag;
673 return (m_flags & e_fixedRotationFlag) == e_fixedRotationFlag;
680 m_flags |= e_autoSleepFlag;
684 m_flags &= ~e_autoSleepFlag;
691 return (m_flags & e_autoSleepFlag) == e_autoSleepFlag;
696 return m_fixtureList;
701 return m_fixtureList;
716 return m_contactList;
721 return m_contactList;
741 if (m_type != b2_dynamicBody)
746 if (wake && (m_flags & e_awakeFlag) == 0)
752 if (m_flags & e_awakeFlag)
755 m_torque += b2Cross(point - m_sweep.
c, force);
761 if (m_type != b2_dynamicBody)
766 if (wake && (m_flags & e_awakeFlag) == 0)
772 if (m_flags & e_awakeFlag)
780 if (m_type != b2_dynamicBody)
785 if (wake && (m_flags & e_awakeFlag) == 0)
791 if (m_flags & e_awakeFlag)
799 if (m_type != b2_dynamicBody)
804 if (wake && (m_flags & e_awakeFlag) == 0)
810 if (m_flags & e_awakeFlag)
812 m_linearVelocity += m_invMass * impulse;
813 m_angularVelocity += m_invI * b2Cross(point - m_sweep.
c, impulse);
819 if (m_type != b2_dynamicBody)
824 if (wake && (m_flags & e_awakeFlag) == 0)
830 if (m_flags & e_awakeFlag)
832 m_linearVelocity += m_invMass * impulse;
838 if (m_type != b2_dynamicBody)
843 if (wake && (m_flags & e_awakeFlag) == 0)
849 if (m_flags & e_awakeFlag)
851 m_angularVelocity += m_invI * impulse;
855inline void b2Body::SynchronizeTransform()
857 m_xf.q.
Set(m_sweep.
a);
858 m_xf.p = m_sweep.
c - b2Mul(m_xf.q, m_sweep.
localCenter);
861inline void b2Body::Advance(
float alpha)
865 m_sweep.
c = m_sweep.c0;
866 m_sweep.
a = m_sweep.a0;
867 m_xf.q.
Set(m_sweep.
a);
868 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:666
void SetEnabled(bool flag)
bool IsFixedRotation() const
Does this body have fixed rotation?
Definition: b2_body.h:671
b2Vec2 GetLinearVelocityFromLocalPoint(const b2Vec2 &localPoint) const
Definition: b2_body.h:586
b2Vec2 GetLocalPoint(const b2Vec2 &worldPoint) const
Definition: b2_body.h:571
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:734
b2ContactEdge * GetContactList()
Definition: b2_body.h:714
float GetAngularDamping() const
Get the angular damping of the body.
Definition: b2_body.h:601
void ApplyAngularImpulse(float impulse, bool wake)
Definition: b2_body.h:836
void SetAngularVelocity(float omega)
Definition: b2_body.h:524
void SetSleepingAllowed(bool flag)
Definition: b2_body.h:676
void SetBullet(bool flag)
Should this body be treated like a bullet for continuous collision detection?
Definition: b2_body.h:621
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:494
void GetMassData(b2MassData *data) const
Definition: b2_body.h:554
void SetUserData(void *data)
Set the user data. Use this to store your application specific data.
b2JointEdge * GetJointList()
Get the list of all joints attached to this body.
Definition: b2_body.h:704
void SetMassData(const b2MassData *data)
b2Vec2 GetLinearVelocityFromWorldPoint(const b2Vec2 &worldPoint) const
Definition: b2_body.h:581
const b2Vec2 & GetLocalCenter() const
Get the local position of the center of mass.
Definition: b2_body.h:499
b2Fixture * GetFixtureList()
Get the list of all fixtures attached to this body.
Definition: b2_body.h:694
bool IsAwake() const
Definition: b2_body.h:661
float GetLinearDamping() const
Get the linear damping of the body.
Definition: b2_body.h:591
b2Vec2 GetWorldPoint(const b2Vec2 &localPoint) const
Definition: b2_body.h:561
float GetAngularVelocity() const
Definition: b2_body.h:539
const b2Vec2 & GetPosition() const
Definition: b2_body.h:484
void ApplyLinearImpulse(const b2Vec2 &impulse, const b2Vec2 &point, bool wake)
Definition: b2_body.h:797
void SetAngularDamping(float angularDamping)
Set the angular damping of the body.
Definition: b2_body.h:606
void SetLinearVelocity(const b2Vec2 &v)
Definition: b2_body.h:504
void DestroyFixture(b2Fixture *fixture)
float GetMass() const
Definition: b2_body.h:544
float GetGravityScale() const
Get the gravity scale of the body.
Definition: b2_body.h:611
const b2Vec2 & GetLinearVelocity() const
Definition: b2_body.h:519
void SetGravityScale(float scale)
Set the gravity scale of the body.
Definition: b2_body.h:616
void ApplyForce(const b2Vec2 &force, const b2Vec2 &point, bool wake)
Definition: b2_body.h:739
b2BodyType GetType() const
Get the type of this body.
Definition: b2_body.h:474
void SetLinearDamping(float linearDamping)
Set the linear damping of the body.
Definition: b2_body.h:596
b2Fixture * CreateFixture(const b2FixtureDef *def)
float GetAngle() const
Definition: b2_body.h:489
void ApplyForceToCenter(const b2Vec2 &force, bool wake)
Definition: b2_body.h:759
b2World * GetWorld()
Get the parent world of this body.
Definition: b2_body.h:871
void SetTransform(const b2Vec2 &position, float angle)
bool IsSleepingAllowed() const
Is this body allowed to sleep.
Definition: b2_body.h:689
void SetAwake(bool flag)
Definition: b2_body.h:638
void Dump()
Dump this body to a file.
void ApplyTorque(float torque, bool wake)
Definition: b2_body.h:778
b2Body * GetNext()
Get the next body in the world's body list.
Definition: b2_body.h:724
bool IsBullet() const
Is this body treated like a bullet for continuous collision detection?
Definition: b2_body.h:633
b2Vec2 GetWorldVector(const b2Vec2 &localVector) const
Definition: b2_body.h:566
float GetInertia() const
Definition: b2_body.h:549
b2Vec2 GetLocalVector(const b2Vec2 &worldVector) const
Definition: b2_body.h:576
void ApplyLinearImpulseToCenter(const b2Vec2 &impulse, bool wake)
Definition: b2_body.h:817
const b2Transform & GetTransform() const
Definition: b2_body.h:479
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:111
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_shape.h:49
Definition: b2_weld_joint.h:70
Definition: b2_wheel_joint.h:96
Definition: b2_world.h:47
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
Definition: b2_joint.h:64
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
Definition: b2_math.h:369
b2Vec2 c
center world positions
Definition: b2_math.h:383
void Advance(float alpha)
Definition: b2_math.h:697
b2Vec2 localCenter
local center of mass position
Definition: b2_math.h:382
float a
world angles
Definition: b2_math.h:384
A 2D column vector.
Definition: b2_math.h:42
void SetZero()
Set this vector to all zeros.
Definition: b2_math.h:50