The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Box2D::b2Body - A rigid body.

SYNOPSIS

  my $body = $world->CreateBody( $body_def );

  my $fixture = $body->CreateFixture();

  my $position = $body->GetPosition();

  my $center = $body->GetWorldCenter();

  $body->SetAngularVelocity( $v );
  $body->SetLinearVelocity( Box2D::b2Vec2->new( $vx, $vy ) );

DESCRIPTION

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

METHODS

ApplyAngularImpulse( $impulse )

Apply an angular impulse.

Parameters:

  • float32 $impulse - the angular impulse in units of kg*m*m/s

ApplyForce( $force, $point )

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:

  • Box2D::b2Vec2 $force - the world force vector, usually in Newtons (N).

  • Box2D::b2Vec2 $point - the world position of the point of application.

ApplyLinearImpulse( $impulse, $point )

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:

  • Box2D::b2Vec2 $impulse - the world impulse vector, usually in N-seconds or kg-m/s.

  • Box2D::b2Vec2 $point - the world position of the point of application.

ApplyTorque( $torque )

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

Parameters:

  • float32 $torque - about the z-axis (out of the screen), usually in N-m.

CreateFixture( $shape, $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:

  • Box2D::b2Shape $shape - the shape to be cloned.

  • float32 $density - the shape density (set to zero for static bodies). Warning:This function is locked during callbacks.

Returns a Box2D::b2Fixture

CreateFixtureDef( $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:

  • Box2D::b2FixtureDef $def - the fixture definition. Warning:This function is locked during callbacks.

Returns a Box2D::b2Fixture

DestroyFixture( $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:

  • Box2D::b2Fixture $fixture - the fixture to be removed. Warning:This function is locked during callbacks.

GetAngle()

Get the angle in radians.

Returns a float32 - the current world rotation angle in radians.

GetAngularDamping()

Get the angular damping of the body.

Returns a float32

GetAngularVelocity()

Get the angular velocity.

Returns a float32 - the angular velocity in radians/second.

GetInertia()

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

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

GetLinearDamping()

Get the linear damping of the body.

Returns a float32

GetLinearVelocity()

Get the linear velocity of the center of mass.

Returns a Box2D::b2Vec2 - the linear velocity of the center of mass.

GetLinearVelocityFromLocalPoint( $localPoint )

Get the world velocity of a local point.

Parameters:

  • Box2D::b2Vec2 $localPoint

Returns a Box2D::b2Vec2 - the world velocity of a point.

GetLinearVelocityFromWorldPoint( $worldPoint )

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

Parameters:

  • Box2D::b2Vec2 $worldPoint

Returns a Box2D::b2Vec2 - the world velocity of a point.

GetLocalCenter()

Get the local position of the center of mass.

Returns a Box2D::b2Vec2

GetLocalPoint( $worldPoint )

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

Parameters:

  • Box2D::b2Vec2 $worldPoint

Returns a Box2D::b2Vec2 - the corresponding local point relative to the body's origin.

GetLocalVector( $worldVector )

Gets a local vector given a world vector.

Parameters:

  • Box2D::b2Vec2 $worldVector

Returns a Box2D::b2Vec2 - the corresponding local vector.

GetMass()

Get the total mass of the body.

Returns a float32 - the mass, usually in kilograms (kg).

GetNext()

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

Returns a Box2D::b2Body

GetPosition()

Get the world body origin position.

Returns a Box2D::b2Vec2 - the world position of the body's origin.

GetTransform()

Get the body transform for the body's origin.

Returns a Box2D::b2Transform - the world transform of the body's origin.

GetType()

Get the type of this body.

Returns a Box2D::b2BodyType

GetUserData()

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

Returns a scalar

GetWorld()

Get the parent world of this body.

Returns a Box2D::b2World

GetWorldCenter()

Get the world position of the center of mass.

Returns a Box2D::b2Vec2

GetWorldPoint( $localPoint )

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

Parameters:

  • Box2D::b2Vec2 $localPoint - a point on the body measured relative the the body's origin.

Returns a Box2D::b2Vec2 - the same point expressed in world coordinates.

GetWorldVector( $localVector )

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

Parameters:

  • Box2D::b2Vec2 $localVector - a vector fixed in the body.

Returns a Box2D::b2Vec2 - the same vector expressed in world coordinates.

IsActive()

Get the active state of the body.

Returns a bool

IsAwake()

Get the sleeping state of this body.

Returns a bool - true if the body is sleeping.

IsBullet()

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

Returns a bool

IsFixedRotation()

Does this body have fixed rotation?

Returns a bool

IsSleepingAllowed()

Is this body allowed to sleep.

Returns a bool

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.

SetActive( $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.

Parameters:

  • bool $flag

SetAngularDamping( $angularDamping )

Set the angular damping of the body.

Parameters:

  • float32 $angularDamping

SetAngularVelocity( $omega )

Set the angular velocity.

Parameters:

  • float32 $omega - the new angular velocity in radians/second.

SetAwake( $flag )

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

Parameters:

  • bool $flag - set to true to put body to sleep, false to wake it.

SetBullet( $flag )

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

Parameters:

  • bool $flag

SetFixedRotation( $flag )

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

Parameters:

  • bool $flag

SetLinearDamping( $linearDamping )

Set the linear damping of the body.

Parameters:

  • float32 $linearDamping

SetLinearVelocity( $v )

Set the linear velocity of the center of mass.

Parameters:

  • Box2D::b2Vec2 $v - the new linear velocity of the center of mass.

SetSleepingAllowed( $flag )

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

Parameters:

  • bool $flag

SetTransform( $position, $angle )

Set the position of the body's origin and rotation. This breaks any contacts and wakes the other bodies. Manipulating a body's transform may cause non-physical behavior.

Parameters:

  • Box2D::b2Vec2 $position - the world position of the body's local origin.

  • float32 $angle - the world rotation in radians.

SetType( $type )

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

Parameters:

  • Box2D::b2BodyType $type

SetUserData( $data )

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

Parameters:

  • scalar $data

SEE ALSO

BUGS

See "BUGS" in Box2D

AUTHORS

See "AUTHORS" in Box2D

COPYRIGHT & LICENSE

See "COPYRIGHT & LICENSE" in Box2D