Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
b2Body Class Reference

A rigid body. These are created via b2World::CreateBody. More...

#include <b2Body.h>

Public Member Functions

void ApplyAngularImpulse (float32 impulse, bool wake)
 
void ApplyForce (const b2Vec2 &force, const b2Vec2 &point, bool wake)
 
void ApplyForceToCenter (const b2Vec2 &force, bool wake)
 
void ApplyLinearImpulse (const b2Vec2 &impulse, const b2Vec2 &point, bool wake)
 
void ApplyTorque (float32 torque, bool wake)
 
b2FixtureCreateFixture (const b2FixtureDef *def)
 
b2FixtureCreateFixture (const b2Shape *shape, float32 density)
 
void DestroyFixture (b2Fixture *fixture)
 
void Dump ()
 Dump this body to a log file. More...
 
float32 GetAngle () const
 
float32 GetAngularDamping () const
 Get the angular damping of the body. More...
 
float32 GetAngularVelocity () const
 
b2ContactEdgeGetContactList ()
 
const b2ContactEdgeGetContactList () const
 
b2FixtureGetFixtureList ()
 Get the list of all fixtures attached to this body. More...
 
const b2FixtureGetFixtureList () const
 
float32 GetGravityScale () const
 Get the gravity scale of the body. More...
 
float32 GetInertia () const
 
b2JointEdgeGetJointList ()
 Get the list of all joints attached to this body. More...
 
const b2JointEdgeGetJointList () const
 
float32 GetLinearDamping () const
 Get the linear damping of the body. More...
 
const b2Vec2GetLinearVelocity () const
 
b2Vec2 GetLinearVelocityFromLocalPoint (const b2Vec2 &localPoint) const
 
b2Vec2 GetLinearVelocityFromWorldPoint (const b2Vec2 &worldPoint) const
 
const b2Vec2GetLocalCenter () const
 Get the local position of the center of mass. More...
 
b2Vec2 GetLocalPoint (const b2Vec2 &worldPoint) const
 
b2Vec2 GetLocalVector (const b2Vec2 &worldVector) const
 
float32 GetMass () const
 
void GetMassData (b2MassData *data) const
 
b2BodyGetNext ()
 Get the next body in the world's body list. More...
 
const b2BodyGetNext () const
 
const b2Vec2GetPosition () const
 
const b2TransformGetTransform () const
 
b2BodyType GetType () const
 Get the type of this body. More...
 
voidGetUserData () const
 Get the user data pointer that was provided in the body definition. More...
 
b2WorldGetWorld ()
 Get the parent world of this body. More...
 
const b2WorldGetWorld () const
 
const b2Vec2GetWorldCenter () const
 Get the world position of the center of mass. More...
 
b2Vec2 GetWorldPoint (const b2Vec2 &localPoint) const
 
b2Vec2 GetWorldVector (const b2Vec2 &localVector) const
 
bool IsActive () const
 Get the active state of the body. More...
 
bool IsAwake () const
 
bool IsBullet () const
 Is this body treated like a bullet for continuous collision detection? More...
 
bool IsFixedRotation () const
 Does this body have fixed rotation? More...
 
bool IsSleepingAllowed () const
 Is this body allowed to sleep. More...
 
void ResetMassData ()
 
void SetActive (bool flag)
 
void SetAngularDamping (float32 angularDamping)
 Set the angular damping of the body. More...
 
void SetAngularVelocity (float32 omega)
 
void SetAwake (bool flag)
 
void SetBullet (bool flag)
 Should this body be treated like a bullet for continuous collision detection? More...
 
void SetFixedRotation (bool flag)
 
void SetGravityScale (float32 scale)
 Set the gravity scale of the body. More...
 
void SetLinearDamping (float32 linearDamping)
 Set the linear damping of the body. More...
 
void SetLinearVelocity (const b2Vec2 &v)
 
void SetMassData (const b2MassData *data)
 
void SetSleepingAllowed (bool flag)
 
void SetTransform (const b2Vec2 &position, float32 angle)
 
void SetType (b2BodyType type)
 Set the type of this body. This may alter the mass and velocity. More...
 
void SetUserData (void *data)
 Set the user data. Use this to store your application specific data. More...
 

Private Types

enum  {
  e_islandFlag = 0x0001, e_awakeFlag = 0x0002, e_autoSleepFlag = 0x0004, e_bulletFlag = 0x0008,
  e_fixedRotationFlag = 0x0010, e_activeFlag = 0x0020, e_toiFlag = 0x0040
}
 

Private Member Functions

void Advance (float32 t)
 
 b2Body (const b2BodyDef *bd, b2World *world)
 
bool ShouldCollide (const b2Body *other) const
 
void SynchronizeFixtures ()
 
void SynchronizeTransform ()
 
 ~b2Body ()
 

Private Attributes

float32 m_angularDamping
 
float32 m_angularVelocity
 
b2ContactEdgem_contactList
 
int32 m_fixtureCount
 
b2Fixturem_fixtureList
 
uint16 m_flags
 
b2Vec2 m_force
 
float32 m_gravityScale
 
float32 m_I
 
float32 m_invI
 
float32 m_invMass
 
int32 m_islandIndex
 
b2JointEdgem_jointList
 
float32 m_linearDamping
 
b2Vec2 m_linearVelocity
 
float32 m_mass
 
b2Bodym_next
 
b2Bodym_prev
 
float32 m_sleepTime
 
b2Sweep m_sweep
 
float32 m_torque
 
b2BodyType m_type
 
voidm_userData
 
b2Worldm_world
 
b2Transform m_xf
 

Friends

class b2Contact
 
class b2ContactManager
 
class b2ContactSolver
 
class b2DistanceJoint
 
class b2FrictionJoint
 
class b2GearJoint
 
class b2Island
 
class b2MotorJoint
 
class b2MouseJoint
 
class b2PrismaticJoint
 
class b2PulleyJoint
 
class b2RevoluteJoint
 
class b2RopeJoint
 
class b2WeldJoint
 
class b2WheelJoint
 
class b2World
 

Detailed Description

A rigid body. These are created via b2World::CreateBody.

Definition at line 126 of file b2Body.h.

Member Enumeration Documentation

anonymous enum
private
Enumerator
e_islandFlag 
e_awakeFlag 
e_autoSleepFlag 
e_bulletFlag 
e_fixedRotationFlag 
e_activeFlag 
e_toiFlag 

Definition at line 407 of file b2Body.h.

Constructor & Destructor Documentation

b2Body::b2Body ( const b2BodyDef bd,
b2World world 
)
private

Definition at line 25 of file b2Body.cpp.

b2Body::~b2Body ( )
private

Definition at line 108 of file b2Body.cpp.

Member Function Documentation

void b2Body::Advance ( float32  t)
inlineprivate

Definition at line 840 of file b2Body.h.

void b2Body::ApplyAngularImpulse ( float32  impulse,
bool  wake 
)
inline

Apply an angular impulse.

Parameters
impulsethe angular impulse in units of kg*m*m/s
wakealso wake up the body

Definition at line 815 of file b2Body.h.

void b2Body::ApplyForce ( const b2Vec2 force,
const b2Vec2 point,
bool  wake 
)
inline

Apply a force at a world point. If the force is not applied at the center of mass, it will generate a torque and affect the angular velocity. This wakes up the body.

Parameters
forcethe world force vector, usually in Newtons (N).
pointthe world position of the point of application.
wakealso wake up the body

Definition at line 737 of file b2Body.h.

void b2Body::ApplyForceToCenter ( const b2Vec2 force,
bool  wake 
)
inline

Apply a force to the center of mass. This wakes up the body.

Parameters
forcethe world force vector, usually in Newtons (N).
wakealso wake up the body

Definition at line 757 of file b2Body.h.

void b2Body::ApplyLinearImpulse ( const b2Vec2 impulse,
const b2Vec2 point,
bool  wake 
)
inline

Apply an impulse at a point. This immediately modifies the velocity. It also modifies the angular velocity if the point of application is not at the center of mass. This wakes up the body.

Parameters
impulsethe world impulse vector, usually in N-seconds or kg-m/s.
pointthe world position of the point of application.
wakealso wake up the body

Definition at line 795 of file b2Body.h.

void b2Body::ApplyTorque ( float32  torque,
bool  wake 
)
inline

Apply a torque. This affects the angular velocity without affecting the linear velocity of the center of mass. This wakes up the body.

Parameters
torqueabout the z-axis (out of the screen), usually in N-m.
wakealso wake up the body

Definition at line 776 of file b2Body.h.

b2Fixture * b2Body::CreateFixture ( const b2FixtureDef def)

Creates a fixture and attach it to this body. Use this function if you need to set some fixture parameters, like friction. Otherwise you can create the fixture directly from a shape. If the density is non-zero, this function automatically updates the mass of the body. Contacts are not created until the next time step.

Parameters
defthe fixture definition.
Warning
This function is locked during callbacks.

Definition at line 166 of file b2Body.cpp.

b2Fixture * b2Body::CreateFixture ( const b2Shape shape,
float32  density 
)

Creates a fixture from a shape and attach it to this body. This is a convenience function. Use b2FixtureDef if you need to set parameters like friction, restitution, user data, or filtering. If the density is non-zero, this function automatically updates the mass of the body.

Parameters
shapethe shape to be cloned.
densitythe shape density (set to zero for static bodies).
Warning
This function is locked during callbacks.

Definition at line 205 of file b2Body.cpp.

void b2Body::DestroyFixture ( b2Fixture fixture)

Destroy a fixture. This removes the fixture from the broad-phase and destroys all contacts associated with this fixture. This will automatically adjust the mass of the body if the body is dynamic and the fixture has positive density. All fixtures attached to a body are implicitly destroyed when the body is destroyed.

Parameters
fixturethe fixture to be removed.
Warning
This function is locked during callbacks.

Definition at line 214 of file b2Body.cpp.

void b2Body::Dump ( )

Dump this body to a log file.

Definition at line 521 of file b2Body.cpp.

float32 b2Body::GetAngle ( ) const
inline

Get the angle in radians.

Returns
the current world rotation angle in radians.

Definition at line 484 of file b2Body.h.

float32 b2Body::GetAngularDamping ( ) const
inline

Get the angular damping of the body.

Definition at line 596 of file b2Body.h.

float32 b2Body::GetAngularVelocity ( ) const
inline

Get the angular velocity.

Returns
the angular velocity in radians/second.

Definition at line 534 of file b2Body.h.

b2ContactEdge * b2Body::GetContactList ( )
inline

Get the list of all contacts attached to this body.

Warning
this list changes during the time step and you may miss some collisions if you don't use b2ContactListener.

Definition at line 707 of file b2Body.h.

const b2ContactEdge * b2Body::GetContactList ( ) const
inline

Definition at line 712 of file b2Body.h.

b2Fixture * b2Body::GetFixtureList ( )
inline

Get the list of all fixtures attached to this body.

Definition at line 687 of file b2Body.h.

const b2Fixture * b2Body::GetFixtureList ( ) const
inline

Definition at line 692 of file b2Body.h.

float32 b2Body::GetGravityScale ( ) const
inline

Get the gravity scale of the body.

Definition at line 606 of file b2Body.h.

float32 b2Body::GetInertia ( ) const
inline

Get the rotational inertia of the body about the local origin.

Returns
the rotational inertia, usually in kg-m^2.

Definition at line 544 of file b2Body.h.

b2JointEdge * b2Body::GetJointList ( )
inline

Get the list of all joints attached to this body.

Definition at line 697 of file b2Body.h.

const b2JointEdge * b2Body::GetJointList ( ) const
inline

Definition at line 702 of file b2Body.h.

float32 b2Body::GetLinearDamping ( ) const
inline

Get the linear damping of the body.

Definition at line 586 of file b2Body.h.

const b2Vec2 & b2Body::GetLinearVelocity ( ) const
inline

Get the linear velocity of the center of mass.

Returns
the linear velocity of the center of mass.

Definition at line 514 of file b2Body.h.

b2Vec2 b2Body::GetLinearVelocityFromLocalPoint ( const b2Vec2 localPoint) const
inline

Get the world velocity of a local point.

Parameters
apoint in local coordinates.
Returns
the world velocity of a point.

Definition at line 581 of file b2Body.h.

b2Vec2 b2Body::GetLinearVelocityFromWorldPoint ( const b2Vec2 worldPoint) const
inline

Get the world linear velocity of a world point attached to this body.

Parameters
apoint in world coordinates.
Returns
the world velocity of a point.

Definition at line 576 of file b2Body.h.

const b2Vec2 & b2Body::GetLocalCenter ( ) const
inline

Get the local position of the center of mass.

Definition at line 494 of file b2Body.h.

b2Vec2 b2Body::GetLocalPoint ( const b2Vec2 worldPoint) const
inline

Gets a local point relative to the body's origin given a world point.

Parameters
apoint in world coordinates.
Returns
the corresponding local point relative to the body's origin.

Definition at line 566 of file b2Body.h.

b2Vec2 b2Body::GetLocalVector ( const b2Vec2 worldVector) const
inline

Gets a local vector given a world vector.

Parameters
avector in world coordinates.
Returns
the corresponding local vector.

Definition at line 571 of file b2Body.h.

float32 b2Body::GetMass ( ) const
inline

Get the total mass of the body.

Returns
the mass, usually in kilograms (kg).

Definition at line 539 of file b2Body.h.

void b2Body::GetMassData ( b2MassData data) const
inline

Get the mass data of the body.

Returns
a struct containing the mass, inertia and center of the body.

Definition at line 549 of file b2Body.h.

b2Body * b2Body::GetNext ( )
inline

Get the next body in the world's body list.

Definition at line 717 of file b2Body.h.

const b2Body * b2Body::GetNext ( ) const
inline

Definition at line 722 of file b2Body.h.

const b2Vec2 & b2Body::GetPosition ( ) const
inline

Get the world body origin position.

Returns
the world position of the body's origin.

Definition at line 479 of file b2Body.h.

const b2Transform & b2Body::GetTransform ( ) const
inline

Get the body transform for the body's origin.

Returns
the world transform of the body's origin.

Definition at line 474 of file b2Body.h.

b2BodyType b2Body::GetType ( ) const
inline

Get the type of this body.

Definition at line 469 of file b2Body.h.

void * b2Body::GetUserData ( ) const
inline

Get the user data pointer that was provided in the body definition.

Definition at line 732 of file b2Body.h.

b2World * b2Body::GetWorld ( )
inline

Get the parent world of this body.

Definition at line 850 of file b2Body.h.

const b2World * b2Body::GetWorld ( ) const
inline

Definition at line 855 of file b2Body.h.

const b2Vec2 & b2Body::GetWorldCenter ( ) const
inline

Get the world position of the center of mass.

Definition at line 489 of file b2Body.h.

b2Vec2 b2Body::GetWorldPoint ( const b2Vec2 localPoint) const
inline

Get the world coordinates of a point given the local coordinates.

Parameters
localPointa point on the body measured relative the the body's origin.
Returns
the same point expressed in world coordinates.

Definition at line 556 of file b2Body.h.

b2Vec2 b2Body::GetWorldVector ( const b2Vec2 localVector) const
inline

Get the world coordinates of a vector given the local coordinates.

Parameters
localVectora vector fixed in the body.
Returns
the same vector expressed in world coordinates.

Definition at line 561 of file b2Body.h.

bool b2Body::IsActive ( ) const
inline

Get the active state of the body.

Definition at line 659 of file b2Body.h.

bool b2Body::IsAwake ( ) const
inline

Get the sleeping state of this body.

Returns
true if the body is awake.

Definition at line 654 of file b2Body.h.

bool b2Body::IsBullet ( ) const
inline

Is this body treated like a bullet for continuous collision detection?

Definition at line 628 of file b2Body.h.

bool b2Body::IsFixedRotation ( ) const
inline

Does this body have fixed rotation?

Definition at line 664 of file b2Body.h.

bool b2Body::IsSleepingAllowed ( ) const
inline

Is this body allowed to sleep.

Definition at line 682 of file b2Body.h.

void b2Body::ResetMassData ( )

This resets the mass properties to the sum of the mass properties of the fixtures. This normally does not need to be called unless you called SetMassData to override the mass and you later want to reset the mass.

Definition at line 281 of file b2Body.cpp.

void b2Body::SetActive ( bool  flag)

Set the active state of the body. An inactive body is not simulated and cannot be collided with or woken up. If you pass a flag of true, all fixtures will be added to the broad-phase. If you pass a flag of false, all fixtures will be removed from the broad-phase and all contacts will be destroyed. Fixtures and joints are otherwise unaffected. You may continue to create/destroy fixtures and joints on inactive bodies. Fixtures on an inactive body are implicitly inactive and will not participate in collisions, ray-casts, or queries. Joints connected to an inactive body are implicitly inactive. An inactive body is still owned by a b2World object and remains in the body list.

Definition at line 454 of file b2Body.cpp.

void b2Body::SetAngularDamping ( float32  angularDamping)
inline

Set the angular damping of the body.

Definition at line 601 of file b2Body.h.

void b2Body::SetAngularVelocity ( float32  omega)
inline

Set the angular velocity.

Parameters
omegathe new angular velocity in radians/second.

Definition at line 519 of file b2Body.h.

void b2Body::SetAwake ( bool  flag)
inline

Set the sleep state of the body. A sleeping body has very low CPU cost.

Parameters
flagset to true to wake the body, false to put it to sleep.

Definition at line 633 of file b2Body.h.

void b2Body::SetBullet ( bool  flag)
inline

Should this body be treated like a bullet for continuous collision detection?

Definition at line 616 of file b2Body.h.

void b2Body::SetFixedRotation ( bool  flag)

Set this body to have fixed rotation. This causes the mass to be reset.

Definition at line 499 of file b2Body.cpp.

void b2Body::SetGravityScale ( float32  scale)
inline

Set the gravity scale of the body.

Definition at line 611 of file b2Body.h.

void b2Body::SetLinearDamping ( float32  linearDamping)
inline

Set the linear damping of the body.

Definition at line 591 of file b2Body.h.

void b2Body::SetLinearVelocity ( const b2Vec2 v)
inline

Set the linear velocity of the center of mass.

Parameters
vthe new linear velocity of the center of mass.

Definition at line 499 of file b2Body.h.

void b2Body::SetMassData ( const b2MassData data)

Set the mass properties to override the mass properties of the fixtures. Note that this changes the center of mass position. Note that creating or destroying fixtures can also alter the mass. This function has no effect if the body isn't dynamic.

Parameters
massDatathe mass properties.

Definition at line 353 of file b2Body.cpp.

void b2Body::SetSleepingAllowed ( bool  flag)
inline

You can disable sleeping on this body. If you disable sleeping, the body will be woken.

Definition at line 669 of file b2Body.h.

void b2Body::SetTransform ( const b2Vec2 position,
float32  angle 
)

Set the position of the body's origin and rotation. Manipulating a body's transform may cause non-physical behavior. Note: contacts are updated on the next call to b2World::Step.

Parameters
positionthe world position of the body's local origin.
anglethe world rotation in radians.

Definition at line 417 of file b2Body.cpp.

void b2Body::SetType ( b2BodyType  type)

Set the type of this body. This may alter the mass and velocity.

Definition at line 113 of file b2Body.cpp.

void b2Body::SetUserData ( void data)
inline

Set the user data. Use this to store your application specific data.

Definition at line 727 of file b2Body.h.

bool b2Body::ShouldCollide ( const b2Body other) const
private

Definition at line 394 of file b2Body.cpp.

void b2Body::SynchronizeFixtures ( )
private

Definition at line 441 of file b2Body.cpp.

void b2Body::SynchronizeTransform ( )
inlineprivate

Definition at line 834 of file b2Body.h.

Friends And Related Function Documentation

friend class b2Contact
friend

Definition at line 392 of file b2Body.h.

friend class b2ContactManager
friend

Definition at line 390 of file b2Body.h.

friend class b2ContactSolver
friend

Definition at line 391 of file b2Body.h.

friend class b2DistanceJoint
friend

Definition at line 394 of file b2Body.h.

friend class b2FrictionJoint
friend

Definition at line 395 of file b2Body.h.

friend class b2GearJoint
friend

Definition at line 396 of file b2Body.h.

friend class b2Island
friend

Definition at line 389 of file b2Body.h.

friend class b2MotorJoint
friend

Definition at line 397 of file b2Body.h.

friend class b2MouseJoint
friend

Definition at line 398 of file b2Body.h.

friend class b2PrismaticJoint
friend

Definition at line 399 of file b2Body.h.

friend class b2PulleyJoint
friend

Definition at line 400 of file b2Body.h.

friend class b2RevoluteJoint
friend

Definition at line 401 of file b2Body.h.

friend class b2RopeJoint
friend

Definition at line 402 of file b2Body.h.

friend class b2WeldJoint
friend

Definition at line 403 of file b2Body.h.

friend class b2WheelJoint
friend

Definition at line 404 of file b2Body.h.

friend class b2World
friend

Definition at line 388 of file b2Body.h.

Member Data Documentation

float32 b2Body::m_angularDamping
private

Definition at line 461 of file b2Body.h.

float32 b2Body::m_angularVelocity
private

Definition at line 440 of file b2Body.h.

b2ContactEdge* b2Body::m_contactList
private

Definition at line 453 of file b2Body.h.

int32 b2Body::m_fixtureCount
private

Definition at line 450 of file b2Body.h.

b2Fixture* b2Body::m_fixtureList
private

Definition at line 449 of file b2Body.h.

uint16 b2Body::m_flags
private

Definition at line 432 of file b2Body.h.

b2Vec2 b2Body::m_force
private

Definition at line 442 of file b2Body.h.

float32 b2Body::m_gravityScale
private

Definition at line 462 of file b2Body.h.

float32 b2Body::m_I
private

Definition at line 458 of file b2Body.h.

float32 b2Body::m_invI
private

Definition at line 458 of file b2Body.h.

float32 b2Body::m_invMass
private

Definition at line 455 of file b2Body.h.

int32 b2Body::m_islandIndex
private

Definition at line 434 of file b2Body.h.

b2JointEdge* b2Body::m_jointList
private

Definition at line 452 of file b2Body.h.

float32 b2Body::m_linearDamping
private

Definition at line 460 of file b2Body.h.

b2Vec2 b2Body::m_linearVelocity
private

Definition at line 439 of file b2Body.h.

float32 b2Body::m_mass
private

Definition at line 455 of file b2Body.h.

b2Body* b2Body::m_next
private

Definition at line 447 of file b2Body.h.

b2Body* b2Body::m_prev
private

Definition at line 446 of file b2Body.h.

float32 b2Body::m_sleepTime
private

Definition at line 464 of file b2Body.h.

b2Sweep b2Body::m_sweep
private

Definition at line 437 of file b2Body.h.

float32 b2Body::m_torque
private

Definition at line 443 of file b2Body.h.

b2BodyType b2Body::m_type
private

Definition at line 430 of file b2Body.h.

void* b2Body::m_userData
private

Definition at line 466 of file b2Body.h.

b2World* b2Body::m_world
private

Definition at line 445 of file b2Body.h.

b2Transform b2Body::m_xf
private

Definition at line 436 of file b2Body.h.


The documentation for this class was generated from the following files:


mvsim
Author(s):
autogenerated on Fri May 7 2021 03:05:52