23 #include <Box2D/Common/b2Math.h>
24 #include <Box2D/Collision/Shapes/b2Shape.h>
73 #if LIQUIDFUN_EXTERNAL_LANGUAGE_API
74 void SetPosition(float32 positionX, float32 positionY);
76 #endif // LIQUIDFUN_EXTERNAL_LANGUAGE_API
392 #if LIQUIDFUN_EXTERNAL_LANGUAGE_API
395 float32 GetPositionX()
const {
return GetPosition().x; }
398 float32 GetPositionY()
const {
return GetPosition().y; }
401 void SetTransform(float32 positionX, float32 positionY, float32 angle);
402 #endif // LIQUIDFUN_EXTERNAL_LANGUAGE_API
430 e_islandFlag = 0x0001,
431 e_awakeFlag = 0x0002,
432 e_autoSleepFlag = 0x0004,
433 e_bulletFlag = 0x0008,
434 e_fixedRotationFlag = 0x0010,
435 e_activeFlag = 0x0020,
442 void SynchronizeFixtures();
443 void SynchronizeTransform();
447 bool ShouldCollide(
const b2Body* other)
const;
449 void Advance(float32 t);
462 float32 m_angularVelocity;
472 int32 m_fixtureCount;
477 float32 m_mass, m_invMass;
482 float32 m_linearDamping;
483 float32 m_angularDamping;
484 float32 m_gravityScale;
523 if (m_type == b2_staticBody)
528 if (b2Dot(v,v) > 0.0f)
533 m_linearVelocity = v;
538 return m_linearVelocity;
543 if (m_type == b2_staticBody)
553 m_angularVelocity = w;
558 return m_angularVelocity;
580 return b2Mul(m_xf, localPoint);
585 return b2Mul(m_xf.q, localVector);
590 return b2MulT(m_xf, worldPoint);
595 return b2MulT(m_xf.q, worldVector);
600 return m_linearVelocity + b2Cross(m_angularVelocity, worldPoint - m_sweep.
c);
610 return m_linearDamping;
615 m_linearDamping = linearDamping;
620 return m_angularDamping;
625 m_angularDamping = angularDamping;
630 return m_gravityScale;
635 m_gravityScale = scale;
642 m_flags |= e_bulletFlag;
646 m_flags &= ~e_bulletFlag;
652 return (m_flags & e_bulletFlag) == e_bulletFlag;
659 if ((m_flags & e_awakeFlag) == 0)
661 m_flags |= e_awakeFlag;
667 m_flags &= ~e_awakeFlag;
670 m_angularVelocity = 0.0f;
678 return (m_flags & e_awakeFlag) == e_awakeFlag;
683 return (m_flags & e_activeFlag) == e_activeFlag;
688 return (m_flags & e_fixedRotationFlag) == e_fixedRotationFlag;
695 m_flags |= e_autoSleepFlag;
699 m_flags &= ~e_autoSleepFlag;
706 return (m_flags & e_autoSleepFlag) == e_autoSleepFlag;
711 return m_fixtureList;
716 return m_fixtureList;
731 return m_contactList;
736 return m_contactList;
761 if (m_type != b2_dynamicBody)
766 if (wake && (m_flags & e_awakeFlag) == 0)
772 if (m_flags & e_awakeFlag)
775 m_torque += b2Cross(point - m_sweep.
c, force);
781 if (m_type != b2_dynamicBody)
786 if (wake && (m_flags & e_awakeFlag) == 0)
792 if (m_flags & e_awakeFlag)
800 if (m_type != b2_dynamicBody)
805 if (wake && (m_flags & e_awakeFlag) == 0)
811 if (m_flags & e_awakeFlag)
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;
833 m_angularVelocity += m_invI * b2Cross(point - m_sweep.
c, impulse);
839 if (m_type != b2_dynamicBody)
844 if (wake && (m_flags & e_awakeFlag) == 0)
850 if (m_flags & e_awakeFlag)
852 m_angularVelocity += m_invI * impulse;
856 inline void b2Body::SynchronizeTransform()
858 m_xf.q.
Set(m_sweep.
a);
859 m_xf.p = m_sweep.
c - b2Mul(m_xf.q, m_sweep.
localCenter);
862 inline void b2Body::Advance(float32 alpha)
866 m_sweep.
c = m_sweep.c0;
867 m_sweep.
a = m_sweep.a0;
868 m_xf.q.
Set(m_sweep.
a);
869 m_xf.p = m_sweep.
c - b2Mul(m_xf.q, m_sweep.
localCenter);
882 #if LIQUIDFUN_EXTERNAL_LANGUAGE_API
883 inline void b2BodyDef::SetPosition(float32 positionX, float32 positionY)
892 #endif // LIQUIDFUN_EXTERNAL_LANGUAGE_API
b2BodyType type
Definition: b2Body.h:80
void ResetMassData()
Definition: b2Body.cpp:287
b2JointEdge * GetJointList()
Get the list of all joints attached to this body.
Definition: b2Body.h:719
float32 GetInertia() const
Definition: b2Body.h:566
float32 GetAngularDamping() const
Get the angular damping of the body.
Definition: b2Body.h:618
float32 GetAngle() const
Definition: b2Body.h:506
void SetActive(bool flag)
Definition: b2Body.cpp:461
Definition: b2RopeJoint.h:58
bool active
Does this body start out active?
Definition: b2Body.h:122
b2ContactEdge * GetContactList()
Definition: b2Body.h:729
float32 GetAngularVelocity() const
Definition: b2Body.h:556
float32 angularDamping
Definition: b2Body.h:103
float32 GetGravityScale() const
Get the gravity scale of the body.
Definition: b2Body.h:628
void SetGravityScale(float32 scale)
Set the gravity scale of the body.
Definition: b2Body.h:633
void GetMassData(b2MassData *data) const
Definition: b2Body.h:571
void SetAwake(bool flag)
Definition: b2Body.h:655
Definition: b2MotorJoint.h:59
b2BodyType GetType() const
Get the type of this body.
Definition: b2Body.h:491
b2Vec2 GetWorldVector(const b2Vec2 &localVector) const
Definition: b2Body.h:583
float32 GetLinearDamping() const
Get the linear damping of the body.
Definition: b2Body.h:608
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:113
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:638
void SetAngularDamping(float32 angularDamping)
Set the angular damping of the body.
Definition: b2Body.h:623
b2Body * GetNext()
Get the next body in the world's body list.
Definition: b2Body.h:739
void * userData
Use this to store application specific body data.
Definition: b2Body.h:125
b2Vec2 position
Definition: b2Body.h:84
const b2Vec2 & GetLinearVelocity() const
Definition: b2Body.h:536
bool bullet
Definition: b2Body.h:119
b2Vec2 GetLinearVelocityFromLocalPoint(const b2Vec2 &localPoint) const
Definition: b2Body.h:603
Definition: b2ParticleSystem.h:281
void ApplyAngularImpulse(float32 impulse, bool wake)
Definition: b2Body.h:837
float32 linearDamping
Definition: b2Body.h:98
void SetLinearVelocity(const b2Vec2 &v)
Definition: b2Body.h:521
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:749
bool IsFixedRotation() const
Does this body have fixed rotation?
Definition: b2Body.h:686
void SetMassData(const b2MassData *data)
Definition: b2Body.cpp:359
b2Vec2 GetLocalVector(const b2Vec2 &worldVector) const
Definition: b2Body.h:593
float32 a
world angles
Definition: b2Math.h:470
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:561
float32 gravityScale
Scale the gravity applied to this body.
Definition: b2Body.h:128
bool IsActive() const
Get the active state of the body.
Definition: b2Body.h:681
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:650
Definition: b2Fixture.h:57
void ApplyForceToCenter(const b2Vec2 &force, bool wake)
Definition: b2Body.h:779
Definition: b2GearJoint.h:56
b2Fixture * GetFixtureList()
Get the list of all fixtures attached to this body.
Definition: b2Body.h:709
Definition: b2FrictionJoint.h:55
A group of particles. b2ParticleGroup::CreateParticleGroup creates these.
Definition: b2ParticleGroup.h:172
void SetFixedRotation(bool flag)
Definition: b2Body.cpp:506
bool awake
Is this body initially awake or sleeping?
Definition: b2Body.h:110
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:704
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:469
void * GetUserData() const
Get the user data pointer that was provided in the body definition.
Definition: b2Body.h:754
b2World * GetWorld()
Get the parent world of this body.
Definition: b2Body.h:872
b2Vec2 localCenter
local center of mass position
Definition: b2Math.h:468
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:817
void SetLinearDamping(float32 linearDamping)
Set the linear damping of the body.
Definition: b2Body.h:613
b2Vec2 GetWorldPoint(const b2Vec2 &localPoint) const
Definition: b2Body.h:578
float32 angle
The world angle of the body in radians.
Definition: b2Body.h:87
b2Vec2 linearVelocity
The linear velocity of the body's origin in world co-ordinates.
Definition: b2Body.h:90
Definition: b2RevoluteJoint.h:90
void SetSleepingAllowed(bool flag)
Definition: b2Body.h:691
float32 angularVelocity
The angular velocity of the body.
Definition: b2Body.h:93
A rigid body. These are created via b2World::CreateBody.
Definition: b2Body.h:132
This is an internal class.
Definition: b2Island.h:34
bool IsAwake() const
Definition: b2Body.h:676
const b2Transform & GetTransform() const
Definition: b2Body.h:496
const b2Vec2 & GetLocalCenter() const
Get the local position of the center of mass.
Definition: b2Body.h:516
void ApplyForce(const b2Vec2 &force, const b2Vec2 &point, bool wake)
Definition: b2Body.h:759
const b2Vec2 & GetPosition() const
Definition: b2Body.h:501
void ApplyTorque(float32 torque, bool wake)
Definition: b2Body.h:798
b2Vec2 GetLinearVelocityFromWorldPoint(const b2Vec2 &worldPoint) const
Definition: b2Body.h:598
A 2D column vector.
Definition: b2Math.h:56
void Advance(float32 alpha)
Definition: b2Math.h:782
void Set(float32 angle)
Set using an angle in radians.
Definition: b2Math.h:373
b2Vec2 GetLocalPoint(const b2Vec2 &worldPoint) const
Definition: b2Body.h:588
void SetAngularVelocity(float32 omega)
Definition: b2Body.h:541
Definition: b2PulleyJoint.h:79
Definition: b2WheelJoint.h:79
const b2Vec2 & GetWorldCenter() const
Get the world position of the center of mass.
Definition: b2Body.h:511
void Dump()
Dump this body to a log file.
Definition: b2Body.cpp:528
bool allowSleep
Definition: b2Body.h:107
Definition: b2Fixture.h:108