|
Box2D
2.4.1
A 2D physics engine for games
|
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;
163 void SetTransform(
const b2Vec2& position,
float angle);
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;
258 void ResetMassData();
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);
309 void SetType(b2BodyType type);
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;
348 void SetEnabled(
bool flag);
351 bool IsEnabled()
const;
355 void SetFixedRotation(
bool flag);
358 bool IsFixedRotation()
const;
376 const b2Body* GetNext()
const;
382 void SetUserData(
void* data);
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;
855 inline 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);
861 inline 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 2D column vector.
Definition: b2_math.h:41
void SetAngularDamping(float angularDamping)
Set the angular damping of the body.
Definition: b2_body.h:606
Definition: b2_friction_joint.h:60
bool IsAwake() const
Definition: b2_body.h:661
A rigid body. These are created via b2World::CreateBody.
Definition: b2_body.h:128
float linearDamping
Definition: b2_body.h:93
void GetMassData(b2MassData *data) const
Definition: b2_body.h:554
void SetBullet(bool flag)
Should this body be treated like a bullet for continuous collision detection?
Definition: b2_body.h:621
You can define this to inject whatever data you want in b2Body.
Definition: b2_settings.h:58
b2Fixture * GetFixtureList()
Get the list of all fixtures attached to this body.
Definition: b2_body.h:694
Definition: b2_distance_joint.h:76
b2Vec2 GetLocalPoint(const b2Vec2 &worldPoint) const
Definition: b2_body.h:571
const b2Transform & GetTransform() const
Definition: b2_body.h:479
b2JointEdge * GetJointList()
Get the list of all joints attached to this body.
Definition: b2_body.h:704
b2BodyType GetType() const
Get the type of this body.
Definition: b2_body.h:474
b2Vec2 GetWorldPoint(const b2Vec2 &localPoint) const
Definition: b2_body.h:561
b2Body * GetNext()
Get the next body in the world's body list.
Definition: b2_body.h:724
b2BodyUserData & GetUserData()
Get the user data pointer that was provided in the body definition.
Definition: b2_body.h:734
Definition: b2_math.h:368
b2Vec2 GetLinearVelocityFromWorldPoint(const b2Vec2 &worldPoint) const
Definition: b2_body.h:581
Definition: b2_prismatic_joint.h:91
float gravityScale
Scale the gravity applied to this body.
Definition: b2_body.h:124
bool fixedRotation
Should this body be prevented from rotating? Useful for characters.
Definition: b2_body.h:109
b2BodyDef()
This constructor sets the body definition default values.
Definition: b2_body.h:55
const b2Vec2 & GetLinearVelocity() const
Definition: b2_body.h:519
float angularDamping
Definition: b2_body.h:99
b2Vec2 GetLocalVector(const b2Vec2 &worldVector) const
Definition: b2_body.h:576
float angle
The world angle of the body in radians.
Definition: b2_body.h:81
void SetAngularVelocity(float omega)
Definition: b2_body.h:524
b2Vec2 c
center world positions
Definition: b2_math.h:383
void SetGravityScale(float scale)
Set the gravity scale of the body.
Definition: b2_body.h:616
float GetInertia() const
Definition: b2_body.h:549
void ApplyAngularImpulse(float impulse, bool wake)
Definition: b2_body.h:836
Definition: b2_wheel_joint.h:95
void SetSleepingAllowed(bool flag)
Definition: b2_body.h:676
bool IsBullet() const
Is this body treated like a bullet for continuous collision detection?
Definition: b2_body.h:633
bool IsSleepingAllowed() const
Is this body allowed to sleep.
Definition: b2_body.h:689
Definition: b2_fixture.h:61
Definition: b2_weld_joint.h:69
void SetLinearVelocity(const b2Vec2 &v)
Definition: b2_body.h:504
b2Vec2 GetWorldVector(const b2Vec2 &localVector) const
Definition: b2_body.h:566
void ApplyLinearImpulseToCenter(const b2Vec2 &impulse, bool wake)
Definition: b2_body.h:817
b2BodyType type
Definition: b2_body.h:74
b2World * GetWorld()
Get the parent world of this body.
Definition: b2_body.h:871
Definition: b2_fixture.h:116
b2Vec2 linearVelocity
The linear velocity of the body's origin in world co-ordinates.
Definition: b2_body.h:84
void Advance(float alpha)
Definition: b2_math.h:697
bool bullet
Definition: b2_body.h:115
float angularVelocity
The angular velocity of the body.
Definition: b2_body.h:87
float GetAngularDamping() const
Get the angular damping of the body.
Definition: b2_body.h:601
Definition: b2_revolute_joint.h:94
const b2Vec2 & GetWorldCenter() const
Get the world position of the center of mass.
Definition: b2_body.h:494
float GetAngle() const
Definition: b2_body.h:489
bool awake
Is this body initially awake or sleeping?
Definition: b2_body.h:106
bool allowSleep
Definition: b2_body.h:103
b2BodyUserData userData
Use this to store application specific body data.
Definition: b2_body.h:121
b2Vec2 GetLinearVelocityFromLocalPoint(const b2Vec2 &localPoint) const
Definition: b2_body.h:586
bool enabled
Does this body start out enabled?
Definition: b2_body.h:118
void SetLinearDamping(float linearDamping)
Set the linear damping of the body.
Definition: b2_body.h:596
bool IsEnabled() const
Get the active state of the body.
Definition: b2_body.h:666
b2ContactEdge * GetContactList()
Definition: b2_body.h:714
Definition: b2_joint.h:63
Definition: b2_motor_joint.h:64
float GetMass() const
Definition: b2_body.h:544
Definition: b2_world.h:46
float GetGravityScale() const
Get the gravity scale of the body.
Definition: b2_body.h:611
bool IsFixedRotation() const
Does this body have fixed rotation?
Definition: b2_body.h:671
void ApplyLinearImpulse(const b2Vec2 &impulse, const b2Vec2 &point, bool wake)
Definition: b2_body.h:797
Definition: b2_gear_joint.h:61
Definition: b2_shape.h:48
void Set(float angle)
Set using an angle in radians.
Definition: b2_math.h:300
This holds the mass data computed for a shape.
Definition: b2_shape.h:33
b2Vec2 center
The position of the shape's centroid relative to the shape's origin.
Definition: b2_shape.h:39
void SetAwake(bool flag)
Definition: b2_body.h:638
void SetZero()
Set this vector to all zeros.
Definition: b2_math.h:50
float mass
The mass of the shape, usually in kilograms.
Definition: b2_shape.h:36
void ApplyTorque(float torque, bool wake)
Definition: b2_body.h:778
Definition: b2_mouse_joint.h:65
Definition: b2_joint.h:110
const b2Vec2 & GetLocalCenter() const
Get the local position of the center of mass.
Definition: b2_body.h:499
b2Vec2 localCenter
local center of mass position
Definition: b2_math.h:382
const b2Vec2 & GetPosition() const
Definition: b2_body.h:484
float GetAngularVelocity() const
Definition: b2_body.h:539
float I
The rotational inertia of the shape about the local origin.
Definition: b2_shape.h:42
float GetLinearDamping() const
Get the linear damping of the body.
Definition: b2_body.h:591
void ApplyForce(const b2Vec2 &force, const b2Vec2 &point, bool wake)
Definition: b2_body.h:739
float a
world angles
Definition: b2_math.h:384
Definition: b2_pulley_joint.h:84
b2Vec2 position
Definition: b2_body.h:78
void ApplyForceToCenter(const b2Vec2 &force, bool wake)
Definition: b2_body.h:759