23 #include <Box2D/Common/b2Math.h>
24 #include <Box2D/Collision/Shapes/b2Shape.h>
413 e_islandFlag = 0x0001,
414 e_awakeFlag = 0x0002,
415 e_autoSleepFlag = 0x0004,
416 e_bulletFlag = 0x0008,
417 e_fixedRotationFlag = 0x0010,
418 e_activeFlag = 0x0020,
425 void SynchronizeFixtures();
426 void SynchronizeTransform();
430 bool ShouldCollide(
const b2Body* other)
const;
432 void Advance(float32 t);
445 float32 m_angularVelocity;
455 int32 m_fixtureCount;
460 float32 m_mass, m_invMass;
465 float32 m_linearDamping;
466 float32 m_angularDamping;
467 float32 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;
642 if ((m_flags & e_awakeFlag) == 0)
644 m_flags |= e_awakeFlag;
650 m_flags &= ~e_awakeFlag;
653 m_angularVelocity = 0.0f;
661 return (m_flags & e_awakeFlag) == e_awakeFlag;
666 return (m_flags & e_activeFlag) == e_activeFlag;
671 return (m_flags & e_fixedRotationFlag) == e_fixedRotationFlag;
678 m_flags |= e_autoSleepFlag;
682 m_flags &= ~e_autoSleepFlag;
689 return (m_flags & e_autoSleepFlag) == e_autoSleepFlag;
694 return m_fixtureList;
699 return m_fixtureList;
714 return m_contactList;
719 return m_contactList;
744 if (m_type != b2_dynamicBody)
749 if (wake && (m_flags & e_awakeFlag) == 0)
755 if (m_flags & e_awakeFlag)
758 m_torque += b2Cross(point - m_sweep.
c, force);
764 if (m_type != b2_dynamicBody)
769 if (wake && (m_flags & e_awakeFlag) == 0)
775 if (m_flags & e_awakeFlag)
783 if (m_type != b2_dynamicBody)
788 if (wake && (m_flags & e_awakeFlag) == 0)
794 if (m_flags & e_awakeFlag)
802 if (m_type != b2_dynamicBody)
807 if (wake && (m_flags & e_awakeFlag) == 0)
813 if (m_flags & e_awakeFlag)
815 m_linearVelocity += m_invMass * impulse;
816 m_angularVelocity += m_invI * b2Cross(point - m_sweep.
c, impulse);
822 if (m_type != b2_dynamicBody)
827 if (wake && (m_flags & e_awakeFlag) == 0)
833 if (m_flags & e_awakeFlag)
835 m_angularVelocity += m_invI * impulse;
839 inline void b2Body::SynchronizeTransform()
841 m_xf.q.
Set(m_sweep.
a);
842 m_xf.p = m_sweep.
c - b2Mul(m_xf.q, m_sweep.
localCenter);
845 inline void b2Body::Advance(float32 alpha)
849 m_sweep.
c = m_sweep.c0;
850 m_sweep.
a = m_sweep.a0;
851 m_xf.q.
Set(m_sweep.
a);
852 m_xf.p = m_sweep.
c - b2Mul(m_xf.q, m_sweep.
localCenter);
b2BodyType type
Definition: b2Body.h:75
void ResetMassData()
Definition: b2Body.cpp:287
b2JointEdge * GetJointList()
Get the list of all joints attached to this body.
Definition: b2Body.h:702
float32 GetInertia() const
Definition: b2Body.h:549
float32 GetAngularDamping() const
Get the angular damping of the body.
Definition: b2Body.h:601
float32 GetAngle() const
Definition: b2Body.h:489
void SetActive(bool flag)
Definition: b2Body.cpp:461
Definition: b2RopeJoint.h:58
bool active
Does this body start out active?
Definition: b2Body.h:117
b2ContactEdge * GetContactList()
Definition: b2Body.h:712
float32 GetAngularVelocity() const
Definition: b2Body.h:539
float32 angularDamping
Definition: b2Body.h:98
float32 GetGravityScale() const
Get the gravity scale of the body.
Definition: b2Body.h:611
void SetGravityScale(float32 scale)
Set the gravity scale of the body.
Definition: b2Body.h:616
void GetMassData(b2MassData *data) const
Definition: b2Body.h:554
void SetAwake(bool flag)
Definition: b2Body.h:638
Definition: b2MotorJoint.h:59
b2BodyType GetType() const
Get the type of this body.
Definition: b2Body.h:474
b2Vec2 GetWorldVector(const b2Vec2 &localVector) const
Definition: b2Body.h:566
float32 GetLinearDamping() const
Get the linear damping of the body.
Definition: b2Body.h:591
float32 I
The rotational inertia of the shape about the local origin.
Definition: b2Shape.h:37
bool fixedRotation
Should this body be prevented from rotating? Useful for characters.
Definition: b2Body.h:108
void SetTransform(const b2Vec2 &position, float32 angle)
Definition: b2Body.cpp:423
void SetBullet(bool flag)
Should this body be treated like a bullet for continuous collision detection?
Definition: b2Body.h:621
void SetAngularDamping(float32 angularDamping)
Set the angular damping of the body.
Definition: b2Body.h:606
b2Body * GetNext()
Get the next body in the world's body list.
Definition: b2Body.h:722
void * userData
Use this to store application specific body data.
Definition: b2Body.h:120
b2Vec2 position
Definition: b2Body.h:79
const b2Vec2 & GetLinearVelocity() const
Definition: b2Body.h:519
bool bullet
Definition: b2Body.h:114
b2Vec2 GetLinearVelocityFromLocalPoint(const b2Vec2 &localPoint) const
Definition: b2Body.h:586
Definition: b2ParticleSystem.h:189
void ApplyAngularImpulse(float32 impulse, bool wake)
Definition: b2Body.h:820
float32 linearDamping
Definition: b2Body.h:93
void SetLinearVelocity(const b2Vec2 &v)
Definition: b2Body.h:504
Definition: b2Joint.h:103
This holds the mass data computed for a shape.
Definition: b2Shape.h:28
void SetUserData(void *data)
Set the user data. Use this to store your application specific data.
Definition: b2Body.h:732
bool IsFixedRotation() const
Does this body have fixed rotation?
Definition: b2Body.h:669
void SetMassData(const b2MassData *data)
Definition: b2Body.cpp:359
b2Vec2 GetLocalVector(const b2Vec2 &worldVector) const
Definition: b2Body.h:576
float32 a
world angles
Definition: b2Math.h:456
Definition: b2PrismaticJoint.h:86
Definition: b2WeldJoint.h:62
void DestroyFixture(b2Fixture *fixture)
Definition: b2Body.cpp:216
Definition: b2MouseJoint.h:60
b2Fixture * CreateFixture(const b2FixtureDef *def)
Definition: b2Body.cpp:168
float32 GetMass() const
Definition: b2Body.h:544
float32 gravityScale
Scale the gravity applied to this body.
Definition: b2Body.h:123
bool IsActive() const
Get the active state of the body.
Definition: b2Body.h:664
void Set(float32 x_, float32 y_)
Set this vector to some specified coordinates.
Definition: b2Math.h:68
void SetZero()
Set this vector to all zeros.
Definition: b2Math.h:65
void SetType(b2BodyType type)
Set the type of this body. This may alter the mass and velocity.
Definition: b2Body.cpp:115
bool IsBullet() const
Is this body treated like a bullet for continuous collision detection?
Definition: b2Body.h:633
Definition: b2Fixture.h:57
void ApplyForceToCenter(const b2Vec2 &force, bool wake)
Definition: b2Body.h:762
Definition: b2GearJoint.h:56
b2Fixture * GetFixtureList()
Get the list of all fixtures attached to this body.
Definition: b2Body.h:692
Definition: b2FrictionJoint.h:55
A group of particles. b2ParticleGroup::CreateParticleGroup creates these.
Definition: b2ParticleGroup.h:134
void SetFixedRotation(bool flag)
Definition: b2Body.cpp:506
bool awake
Is this body initially awake or sleeping?
Definition: b2Body.h:105
float32 mass
The mass of the shape, usually in kilograms.
Definition: b2Shape.h:31
bool IsSleepingAllowed() const
Is this body allowed to sleep.
Definition: b2Body.h:687
b2Vec2 center
The position of the shape's centroid relative to the shape's origin.
Definition: b2Shape.h:34
b2Vec2 c
center world positions
Definition: b2Math.h:455
void * GetUserData() const
Get the user data pointer that was provided in the body definition.
Definition: b2Body.h:737
b2World * GetWorld()
Get the parent world of this body.
Definition: b2Body.h:855
b2Vec2 localCenter
local center of mass position
Definition: b2Math.h:454
Definition: b2DistanceJoint.h:67
b2BodyDef()
This constructor sets the body definition default values.
Definition: b2Body.h:55
void ApplyLinearImpulse(const b2Vec2 &impulse, const b2Vec2 &point, bool wake)
Definition: b2Body.h:800
void SetLinearDamping(float32 linearDamping)
Set the linear damping of the body.
Definition: b2Body.h:596
b2Vec2 GetWorldPoint(const b2Vec2 &localPoint) const
Definition: b2Body.h:561
float32 angle
The world angle of the body in radians.
Definition: b2Body.h:82
b2Vec2 linearVelocity
The linear velocity of the body's origin in world co-ordinates.
Definition: b2Body.h:85
Definition: b2RevoluteJoint.h:90
void SetSleepingAllowed(bool flag)
Definition: b2Body.h:674
float32 angularVelocity
The angular velocity of the body.
Definition: b2Body.h:88
A rigid body. These are created via b2World::CreateBody.
Definition: b2Body.h:127
This is an internal class.
Definition: b2Island.h:34
bool IsAwake() const
Definition: b2Body.h:659
const b2Transform & GetTransform() const
Definition: b2Body.h:479
const b2Vec2 & GetLocalCenter() const
Get the local position of the center of mass.
Definition: b2Body.h:499
void ApplyForce(const b2Vec2 &force, const b2Vec2 &point, bool wake)
Definition: b2Body.h:742
const b2Vec2 & GetPosition() const
Definition: b2Body.h:484
void ApplyTorque(float32 torque, bool wake)
Definition: b2Body.h:781
b2Vec2 GetLinearVelocityFromWorldPoint(const b2Vec2 &worldPoint) const
Definition: b2Body.h:581
A 2D column vector.
Definition: b2Math.h:56
void Advance(float32 alpha)
Definition: b2Math.h:768
void Set(float32 angle)
Set using an angle in radians.
Definition: b2Math.h:373
b2Vec2 GetLocalPoint(const b2Vec2 &worldPoint) const
Definition: b2Body.h:571
void SetAngularVelocity(float32 omega)
Definition: b2Body.h:524
Definition: b2PulleyJoint.h:79
Definition: b2WheelJoint.h:79
const b2Vec2 & GetWorldCenter() const
Get the world position of the center of mass.
Definition: b2Body.h:494
void Dump()
Dump this body to a log file.
Definition: b2Body.cpp:528
bool allowSleep
Definition: b2Body.h:102
Definition: b2Fixture.h:108