22 #include <Box2D/Common/b2Math.h>
23 #include <Box2D/Collision/Shapes/b2Shape.h>
409 e_islandFlag = 0x0001,
410 e_awakeFlag = 0x0002,
411 e_autoSleepFlag = 0x0004,
412 e_bulletFlag = 0x0008,
413 e_fixedRotationFlag = 0x0010,
414 e_activeFlag = 0x0020,
421 void SynchronizeFixtures();
422 void SynchronizeTransform();
426 bool ShouldCollide(
const b2Body* other)
const;
428 void Advance(float32 t);
440 float32 m_angularVelocity;
450 int32 m_fixtureCount;
455 float32 m_mass, m_invMass;
460 float32 m_linearDamping;
461 float32 m_angularDamping;
462 float32 m_gravityScale;
501 if (m_type == b2_staticBody)
506 if (b2Dot(v,v) > 0.0f)
511 m_linearVelocity = v;
516 return m_linearVelocity;
521 if (m_type == b2_staticBody)
531 m_angularVelocity = w;
536 return m_angularVelocity;
558 return b2Mul(m_xf, localPoint);
563 return b2Mul(m_xf.q, localVector);
568 return b2MulT(m_xf, worldPoint);
573 return b2MulT(m_xf.q, worldVector);
578 return m_linearVelocity + b2Cross(m_angularVelocity, worldPoint - m_sweep.
c);
588 return m_linearDamping;
593 m_linearDamping = linearDamping;
598 return m_angularDamping;
603 m_angularDamping = angularDamping;
608 return m_gravityScale;
613 m_gravityScale = scale;
620 m_flags |= e_bulletFlag;
624 m_flags &= ~e_bulletFlag;
630 return (m_flags & e_bulletFlag) == e_bulletFlag;
637 if ((m_flags & e_awakeFlag) == 0)
639 m_flags |= e_awakeFlag;
645 m_flags &= ~e_awakeFlag;
648 m_angularVelocity = 0.0f;
656 return (m_flags & e_awakeFlag) == e_awakeFlag;
661 return (m_flags & e_activeFlag) == e_activeFlag;
666 return (m_flags & e_fixedRotationFlag) == e_fixedRotationFlag;
673 m_flags |= e_autoSleepFlag;
677 m_flags &= ~e_autoSleepFlag;
684 return (m_flags & e_autoSleepFlag) == e_autoSleepFlag;
689 return m_fixtureList;
694 return m_fixtureList;
709 return m_contactList;
714 return m_contactList;
739 if (m_type != b2_dynamicBody)
744 if (wake && (m_flags & e_awakeFlag) == 0)
750 if (m_flags & e_awakeFlag)
753 m_torque += b2Cross(point - m_sweep.
c, force);
759 if (m_type != b2_dynamicBody)
764 if (wake && (m_flags & e_awakeFlag) == 0)
770 if (m_flags & e_awakeFlag)
778 if (m_type != b2_dynamicBody)
783 if (wake && (m_flags & e_awakeFlag) == 0)
789 if (m_flags & e_awakeFlag)
797 if (m_type != b2_dynamicBody)
802 if (wake && (m_flags & e_awakeFlag) == 0)
808 if (m_flags & e_awakeFlag)
810 m_linearVelocity += m_invMass * impulse;
811 m_angularVelocity += m_invI * b2Cross(point - m_sweep.
c, impulse);
817 if (m_type != b2_dynamicBody)
822 if (wake && (m_flags & e_awakeFlag) == 0)
828 if (m_flags & e_awakeFlag)
830 m_angularVelocity += m_invI * impulse;
834 inline void b2Body::SynchronizeTransform()
836 m_xf.q.
Set(m_sweep.
a);
837 m_xf.p = m_sweep.
c - b2Mul(m_xf.q, m_sweep.
localCenter);
840 inline void b2Body::Advance(float32 alpha)
844 m_sweep.
c = m_sweep.c0;
845 m_sweep.
a = m_sweep.a0;
846 m_xf.q.
Set(m_sweep.
a);
847 m_xf.p = m_sweep.
c - b2Mul(m_xf.q, m_sweep.
localCenter);
b2BodyType type
Definition: b2Body.h:74
void ResetMassData()
Definition: b2Body.cpp:281
b2JointEdge * GetJointList()
Get the list of all joints attached to this body.
Definition: b2Body.h:697
float32 GetInertia() const
Definition: b2Body.h:544
float32 GetAngularDamping() const
Get the angular damping of the body.
Definition: b2Body.h:596
float32 GetAngle() const
Definition: b2Body.h:484
void SetActive(bool flag)
Definition: b2Body.cpp:454
Definition: b2RopeJoint.h:58
bool active
Does this body start out active?
Definition: b2Body.h:116
b2ContactEdge * GetContactList()
Definition: b2Body.h:707
float32 GetAngularVelocity() const
Definition: b2Body.h:534
float32 angularDamping
Definition: b2Body.h:97
float32 GetGravityScale() const
Get the gravity scale of the body.
Definition: b2Body.h:606
void SetGravityScale(float32 scale)
Set the gravity scale of the body.
Definition: b2Body.h:611
void GetMassData(b2MassData *data) const
Definition: b2Body.h:549
void SetAwake(bool flag)
Definition: b2Body.h:633
Definition: b2MotorJoint.h:59
b2BodyType GetType() const
Get the type of this body.
Definition: b2Body.h:469
b2Vec2 GetWorldVector(const b2Vec2 &localVector) const
Definition: b2Body.h:561
float32 GetLinearDamping() const
Get the linear damping of the body.
Definition: b2Body.h:586
float32 I
The rotational inertia of the shape about the local origin.
Definition: b2Shape.h:36
bool fixedRotation
Should this body be prevented from rotating? Useful for characters.
Definition: b2Body.h:107
void SetTransform(const b2Vec2 &position, float32 angle)
Definition: b2Body.cpp:417
void SetBullet(bool flag)
Should this body be treated like a bullet for continuous collision detection?
Definition: b2Body.h:616
void SetAngularDamping(float32 angularDamping)
Set the angular damping of the body.
Definition: b2Body.h:601
b2Body * GetNext()
Get the next body in the world's body list.
Definition: b2Body.h:717
void * userData
Use this to store application specific body data.
Definition: b2Body.h:119
b2Vec2 position
Definition: b2Body.h:78
const b2Vec2 & GetLinearVelocity() const
Definition: b2Body.h:514
bool bullet
Definition: b2Body.h:113
b2Vec2 GetLinearVelocityFromLocalPoint(const b2Vec2 &localPoint) const
Definition: b2Body.h:581
void ApplyAngularImpulse(float32 impulse, bool wake)
Definition: b2Body.h:815
float32 linearDamping
Definition: b2Body.h:92
void SetLinearVelocity(const b2Vec2 &v)
Definition: b2Body.h:499
Definition: b2Joint.h:103
This holds the mass data computed for a shape.
Definition: b2Shape.h:27
void SetUserData(void *data)
Set the user data. Use this to store your application specific data.
Definition: b2Body.h:727
bool IsFixedRotation() const
Does this body have fixed rotation?
Definition: b2Body.h:664
void SetMassData(const b2MassData *data)
Definition: b2Body.cpp:353
b2Vec2 GetLocalVector(const b2Vec2 &worldVector) const
Definition: b2Body.h:571
float32 a
world angles
Definition: b2Math.h:395
Definition: b2PrismaticJoint.h:86
Definition: b2WeldJoint.h:62
void DestroyFixture(b2Fixture *fixture)
Definition: b2Body.cpp:214
Definition: b2MouseJoint.h:60
b2Fixture * CreateFixture(const b2FixtureDef *def)
Definition: b2Body.cpp:166
float32 GetMass() const
Definition: b2Body.h:539
float32 gravityScale
Scale the gravity applied to this body.
Definition: b2Body.h:122
bool IsActive() const
Get the active state of the body.
Definition: b2Body.h:659
void Set(float32 x_, float32 y_)
Set this vector to some specified coordinates.
Definition: b2Math.h:65
void SetZero()
Set this vector to all zeros.
Definition: b2Math.h:62
void SetType(b2BodyType type)
Set the type of this body. This may alter the mass and velocity.
Definition: b2Body.cpp:113
bool IsBullet() const
Is this body treated like a bullet for continuous collision detection?
Definition: b2Body.h:628
Definition: b2Fixture.h:56
void ApplyForceToCenter(const b2Vec2 &force, bool wake)
Definition: b2Body.h:757
Definition: b2GearJoint.h:56
b2Fixture * GetFixtureList()
Get the list of all fixtures attached to this body.
Definition: b2Body.h:687
Definition: b2FrictionJoint.h:55
void SetFixedRotation(bool flag)
Definition: b2Body.cpp:499
bool awake
Is this body initially awake or sleeping?
Definition: b2Body.h:104
float32 mass
The mass of the shape, usually in kilograms.
Definition: b2Shape.h:30
bool IsSleepingAllowed() const
Is this body allowed to sleep.
Definition: b2Body.h:682
b2Vec2 center
The position of the shape's centroid relative to the shape's origin.
Definition: b2Shape.h:33
b2Vec2 c
center world positions
Definition: b2Math.h:394
void * GetUserData() const
Get the user data pointer that was provided in the body definition.
Definition: b2Body.h:732
b2World * GetWorld()
Get the parent world of this body.
Definition: b2Body.h:850
b2Vec2 localCenter
local center of mass position
Definition: b2Math.h:393
Definition: b2DistanceJoint.h:67
b2BodyDef()
This constructor sets the body definition default values.
Definition: b2Body.h:54
void ApplyLinearImpulse(const b2Vec2 &impulse, const b2Vec2 &point, bool wake)
Definition: b2Body.h:795
void SetLinearDamping(float32 linearDamping)
Set the linear damping of the body.
Definition: b2Body.h:591
b2Vec2 GetWorldPoint(const b2Vec2 &localPoint) const
Definition: b2Body.h:556
float32 angle
The world angle of the body in radians.
Definition: b2Body.h:81
b2Vec2 linearVelocity
The linear velocity of the body's origin in world co-ordinates.
Definition: b2Body.h:84
Definition: b2RevoluteJoint.h:90
void SetSleepingAllowed(bool flag)
Definition: b2Body.h:669
float32 angularVelocity
The angular velocity of the body.
Definition: b2Body.h:87
A rigid body. These are created via b2World::CreateBody.
Definition: b2Body.h:126
This is an internal class.
Definition: b2Island.h:34
bool IsAwake() const
Definition: b2Body.h:654
const b2Transform & GetTransform() const
Definition: b2Body.h:474
const b2Vec2 & GetLocalCenter() const
Get the local position of the center of mass.
Definition: b2Body.h:494
void ApplyForce(const b2Vec2 &force, const b2Vec2 &point, bool wake)
Definition: b2Body.h:737
const b2Vec2 & GetPosition() const
Definition: b2Body.h:479
void ApplyTorque(float32 torque, bool wake)
Definition: b2Body.h:776
b2Vec2 GetLinearVelocityFromWorldPoint(const b2Vec2 &worldPoint) const
Definition: b2Body.h:576
A 2D column vector.
Definition: b2Math.h:53
void Advance(float32 alpha)
Definition: b2Math.h:702
void Set(float32 angle)
Set using an angle in radians.
Definition: b2Math.h:312
b2Vec2 GetLocalPoint(const b2Vec2 &worldPoint) const
Definition: b2Body.h:566
void SetAngularVelocity(float32 omega)
Definition: b2Body.h:519
Definition: b2PulleyJoint.h:79
Definition: b2WheelJoint.h:79
const b2Vec2 & GetWorldCenter() const
Get the world position of the center of mass.
Definition: b2Body.h:489
void Dump()
Dump this body to a log file.
Definition: b2Body.cpp:521
bool allowSleep
Definition: b2Body.h:101
Definition: b2Fixture.h:107