22 #include <Box2D/Common/b2Math.h> 23 #include <Box2D/Collision/Shapes/b2Shape.h> 169 const b2Vec2& GetPosition()
const;
173 float32 GetAngle()
const;
176 const b2Vec2& GetWorldCenter()
const;
179 const b2Vec2& GetLocalCenter()
const;
183 void SetLinearVelocity(
const b2Vec2& v);
187 const b2Vec2& GetLinearVelocity()
const;
191 void SetAngularVelocity(float32 omega);
195 float32 GetAngularVelocity()
const;
203 void ApplyForce(
const b2Vec2& force,
const b2Vec2& point,
bool wake);
208 void ApplyForceToCenter(
const b2Vec2& force,
bool wake);
214 void ApplyTorque(float32 torque,
bool wake);
222 void ApplyLinearImpulse(
const b2Vec2& impulse,
const b2Vec2& point,
bool wake);
227 void ApplyLinearImpulseToCenter(
const b2Vec2& impulse,
bool wake);
232 void ApplyAngularImpulse(float32 impulse,
bool wake);
236 float32 GetMass()
const;
240 float32 GetInertia()
const;
256 void ResetMassData();
281 b2Vec2 GetLinearVelocityFromWorldPoint(
const b2Vec2& worldPoint)
const;
286 b2Vec2 GetLinearVelocityFromLocalPoint(
const b2Vec2& localPoint)
const;
289 float32 GetLinearDamping()
const;
295 float32 GetAngularDamping()
const;
301 float32 GetGravityScale()
const;
304 void SetGravityScale(float32 scale);
307 void SetType(b2BodyType
type);
310 b2BodyType GetType()
const;
313 void SetBullet(
bool flag);
316 bool IsBullet()
const;
320 void SetSleepingAllowed(
bool flag);
323 bool IsSleepingAllowed()
const;
328 void SetAwake(
bool flag);
332 bool IsAwake()
const;
347 void SetActive(
bool flag);
350 bool IsActive()
const;
354 void SetFixedRotation(
bool flag);
357 bool IsFixedRotation()
const;
375 const b2Body* GetNext()
const;
378 void* GetUserData()
const;
381 void SetUserData(
void* data);
385 const b2World* GetWorld()
const;
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);
444 float32 m_angularVelocity;
454 int32 m_fixtureCount;
459 float32 m_mass, m_invMass;
464 float32 m_linearDamping;
465 float32 m_angularDamping;
466 float32 m_gravityScale;
500 return m_sweep.localCenter;
505 if (m_type == b2_staticBody)
510 if (b2Dot(v,v) > 0.0f)
515 m_linearVelocity = v;
520 return m_linearVelocity;
525 if (m_type == b2_staticBody)
535 m_angularVelocity = w;
540 return m_angularVelocity;
550 return m_I + m_mass * b2Dot(m_sweep.localCenter, m_sweep.localCenter);
556 data->
I = m_I + m_mass * b2Dot(m_sweep.localCenter, m_sweep.localCenter);
557 data->
center = m_sweep.localCenter;
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);
587 return GetLinearVelocityFromWorldPoint(GetWorldPoint(localPoint));
592 return m_linearDamping;
602 return m_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;
641 if ((m_flags & e_awakeFlag) == 0)
643 m_flags |= e_awakeFlag;
649 m_flags &= ~e_awakeFlag;
651 m_linearVelocity.SetZero();
652 m_angularVelocity = 0.0f;
660 return (m_flags & e_awakeFlag) == e_awakeFlag;
665 return (m_flags & e_activeFlag) == e_activeFlag;
670 return (m_flags & e_fixedRotationFlag) == e_fixedRotationFlag;
677 m_flags |= e_autoSleepFlag;
681 m_flags &= ~e_autoSleepFlag;
688 return (m_flags & e_autoSleepFlag) == e_autoSleepFlag;
693 return m_fixtureList;
698 return m_fixtureList;
713 return m_contactList;
718 return m_contactList;
743 if (m_type != b2_dynamicBody)
748 if (wake && (m_flags & e_awakeFlag) == 0)
754 if (m_flags & e_awakeFlag)
757 m_torque += b2Cross(point - m_sweep.c, force);
763 if (m_type != b2_dynamicBody)
768 if (wake && (m_flags & e_awakeFlag) == 0)
774 if (m_flags & e_awakeFlag)
782 if (m_type != b2_dynamicBody)
787 if (wake && (m_flags & e_awakeFlag) == 0)
793 if (m_flags & e_awakeFlag)
801 if (m_type != b2_dynamicBody)
806 if (wake && (m_flags & e_awakeFlag) == 0)
812 if (m_flags & e_awakeFlag)
814 m_linearVelocity += m_invMass * impulse;
815 m_angularVelocity += m_invI * b2Cross(point - m_sweep.c, impulse);
821 if (m_type != b2_dynamicBody)
826 if (wake && (m_flags & e_awakeFlag) == 0)
832 if (m_flags & e_awakeFlag)
834 m_linearVelocity += m_invMass * impulse;
840 if (m_type != b2_dynamicBody)
845 if (wake && (m_flags & e_awakeFlag) == 0)
851 if (m_flags & e_awakeFlag)
853 m_angularVelocity += m_invI * impulse;
857 inline void b2Body::SynchronizeTransform()
859 m_xf.q.Set(m_sweep.a);
860 m_xf.p = m_sweep.c - b2Mul(m_xf.q, m_sweep.localCenter);
863 inline void b2Body::Advance(float32 alpha)
866 m_sweep.Advance(alpha);
867 m_sweep.c = m_sweep.c0;
868 m_sweep.a = m_sweep.a0;
869 m_xf.q.Set(m_sweep.a);
870 m_xf.p = m_sweep.c - b2Mul(m_xf.q, m_sweep.localCenter);
b2BodyType type
Definition: b2Body.h:74
b2JointEdge * GetJointList()
Get the list of all joints attached to this body.
Definition: b2Body.h:701
float32 GetInertia() const
Definition: b2Body.h:548
const b2Vec2 & GetWorldCenter() const
Get the world position of the center of mass.
Definition: b2Body.h:493
Definition: b2RopeJoint.h:58
bool active
Does this body start out active?
Definition: b2Body.h:116
b2ContactEdge * GetContactList()
Definition: b2Body.h:711
bool IsSleepingAllowed() const
Is this body allowed to sleep.
Definition: b2Body.h:686
float32 angularDamping
Definition: b2Body.h:97
void SetGravityScale(float32 scale)
Set the gravity scale of the body.
Definition: b2Body.h:615
void SetAwake(bool flag)
Definition: b2Body.h:637
Definition: b2MotorJoint.h:59
void ApplyLinearImpulseToCenter(const b2Vec2 &impulse, bool wake)
Definition: b2Body.h:819
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 SetBullet(bool flag)
Should this body be treated like a bullet for continuous collision detection?
Definition: b2Body.h:620
void SetAngularDamping(float32 angularDamping)
Set the angular damping of the body.
Definition: b2Body.h:605
b2Body * GetNext()
Get the next body in the world's body list.
Definition: b2Body.h:721
void * userData
Use this to store application specific body data.
Definition: b2Body.h:119
b2Vec2 position
Definition: b2Body.h:78
bool bullet
Definition: b2Body.h:113
float32 GetAngle() const
Definition: b2Body.h:488
float32 GetLinearDamping() const
Get the linear damping of the body.
Definition: b2Body.h:590
void ApplyAngularImpulse(float32 impulse, bool wake)
Definition: b2Body.h:838
b2Vec2 GetLinearVelocityFromLocalPoint(const b2Vec2 &localPoint) const
Definition: b2Body.h:585
float32 linearDamping
Definition: b2Body.h:92
void SetLinearVelocity(const b2Vec2 &v)
Definition: b2Body.h:503
Definition: b2Joint.h:103
This holds the mass data computed for a shape.
Definition: b2Shape.h:27
b2Vec2 GetWorldPoint(const b2Vec2 &localPoint) const
Definition: b2Body.h:560
void SetUserData(void *data)
Set the user data. Use this to store your application specific data.
Definition: b2Body.h:731
Definition: b2PrismaticJoint.h:86
Definition: b2WeldJoint.h:62
Definition: b2MouseJoint.h:60
float32 gravityScale
Scale the gravity applied to this body.
Definition: b2Body.h:122
const b2Vec2 & GetPosition() const
Definition: b2Body.h:483
void Set(float32 x_, float32 y_)
Set this vector to some specified coordinates.
Definition: b2Math.h:65
Definition: b2Fixture.h:56
void ApplyForceToCenter(const b2Vec2 &force, bool wake)
Definition: b2Body.h:761
Definition: b2GearJoint.h:56
b2Fixture * GetFixtureList()
Get the list of all fixtures attached to this body.
Definition: b2Body.h:691
Definition: b2FrictionJoint.h:55
bool IsAwake() const
Definition: b2Body.h:658
bool awake
Is this body initially awake or sleeping?
Definition: b2Body.h:104
void GetMassData(b2MassData *data) const
Definition: b2Body.h:553
b2Vec2 GetLinearVelocityFromWorldPoint(const b2Vec2 &worldPoint) const
Definition: b2Body.h:580
float32 mass
The mass of the shape, usually in kilograms.
Definition: b2Shape.h:30
b2Vec2 center
The position of the shape's centroid relative to the shape's origin.
Definition: b2Shape.h:33
b2World * GetWorld()
Get the parent world of this body.
Definition: b2Body.h:873
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:799
void SetLinearDamping(float32 linearDamping)
Set the linear damping of the body.
Definition: b2Body.h:595
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:673
float32 angularVelocity
The angular velocity of the body.
Definition: b2Body.h:87
bool IsBullet() const
Is this body treated like a bullet for continuous collision detection?
Definition: b2Body.h:632
float32 GetAngularDamping() const
Get the angular damping of the body.
Definition: b2Body.h:600
A rigid body. These are created via b2World::CreateBody.
Definition: b2Body.h:126
void * GetUserData() const
Get the user data pointer that was provided in the body definition.
Definition: b2Body.h:736
const b2Vec2 & GetLocalCenter() const
Get the local position of the center of mass.
Definition: b2Body.h:498
This is an internal class.
Definition: b2Island.h:34
void ApplyForce(const b2Vec2 &force, const b2Vec2 &point, bool wake)
Definition: b2Body.h:741
const b2Vec2 & GetLinearVelocity() const
Definition: b2Body.h:518
b2Vec2 GetLocalVector(const b2Vec2 &worldVector) const
Definition: b2Body.h:575
void ApplyTorque(float32 torque, bool wake)
Definition: b2Body.h:780
A 2D column vector.
Definition: b2Math.h:53
b2BodyType GetType() const
Get the type of this body.
Definition: b2Body.h:473
bool IsFixedRotation() const
Does this body have fixed rotation?
Definition: b2Body.h:668
void SetAngularVelocity(float32 omega)
Definition: b2Body.h:523
float32 GetMass() const
Definition: b2Body.h:543
Definition: b2PulleyJoint.h:79
float32 GetGravityScale() const
Get the gravity scale of the body.
Definition: b2Body.h:610
bool IsActive() const
Get the active state of the body.
Definition: b2Body.h:663
Definition: b2WheelJoint.h:78
b2Vec2 GetWorldVector(const b2Vec2 &localVector) const
Definition: b2Body.h:565
float32 GetAngularVelocity() const
Definition: b2Body.h:538
bool allowSleep
Definition: b2Body.h:101
Definition: b2Fixture.h:107
b2Vec2 GetLocalPoint(const b2Vec2 &worldPoint) const
Definition: b2Body.h:570
const b2Transform & GetTransform() const
Definition: b2Body.h:478