Public Member Functions | Static Public Member Functions | Properties

ChipmunkBody Class Reference

Rigid bodies are the basic unit of simulation in Chipmunk. More...

#import <ChipmunkBody.h>

Inherits ChipmunkBaseObject-p.

List of all members.

Public Member Functions

(id) - initWithMass:andMoment:
 Initialize a rigid body with the given mass and moment of inertia.
(id) - initStaticBody
 Initialize a rigid body with infinite mass and moment.
(cpVect) - local2world:
 Convert from body local to world coordinates.
(cpVect) - world2local:
 Convert from world to body local Coordinates.
(void) - resetForces
 Reset force and torque.
(void) - applyForce:offset:
 Apply a force to a rigid body.
(void) - applyImpulse:offset:
 Apply an impulse to a rigid body.
(void) - activate
 Wake up the body if it's sleeping, or reset the idle timer if it's active.
(void) - activateStatic:
 Wake up any bodies touching a static body through shape filter Pass nil for to away all touching bodies.
(void) - sleepWithGroup:
 Force the body to sleep immediately.
(void) - sleep
 Equivalent to [ChipmunkBody sleepWithGroup:nil].
(NSArray *) - shapes
 Get a list of shapes that are attached to this body and currently added to a space.
(NSArray *) - constraints
 Get a list of constraints that are attached to this body and currently added to a space.
(typedef) - void
 Body/arbiter iterator callback block type.
(void) - eachArbiter:
 Call block once for each arbiter that is currently active on the body.
(void) - addToSpace:
 Implements the ChipmunkBaseObject protocol, not particularly useful outside of the library code.
(void) - removeFromSpace:
 Implements the ChipmunkBaseObject protocol, not particularly useful outside of the library code.
(CGAffineTransform) - affineTransform
 Get an affine transform to match this body.

Static Public Member Functions

(id) + bodyWithMass:andMoment:
 Create an autoreleased rigid body with the given mass and moment.
(id) + staticBody
 Create an autoreleased rigid body with infinite mass and moment.

Properties

cpFloat mass
 Mass of the rigid body. Mass does not have to be expressed in any particular units, but relative masses should be consistent.
cpFloat moment
 Moment of inertia of the body. The mass tells you how hard it is to push an object, the MoI tells you how hard it is to spin the object. Don't try to guess the MoI, use the cpMomentFor*() functions to try and estimate it.
cpVect pos
 The position of the rigid body's center of gravity.
cpVect vel
 The linear velocity of the rigid body.
cpVect force
 The linear force applied to the rigid body. Unlike in some physics engines, the force does not reset itself during each step. Make sure that you are reseting the force between frames if that is what you intended.
cpFloat angle
 The rotation angle of the rigid body in radians.
cpFloat angVel
 The angular velocity of the rigid body in radians per second.
cpFloat torque
 The torque being applied to the rigid body. Like force, this property is not reset every frame.
cpVect rot
 A unit length vector vector that stores the current rotation of the body as a 2D spinor or complex number. Can be used for fast rotation.
cpBody * body
 Returns a pointer to the underlying cpBody C struct.
id data
 An object that this constraint is associated with.
cpFloat velLimit
 Maximum velocity allowed for this body. Defaults to INFINITY.
cpFloat angVelLimit
 Maximum angular velocity allowed for this body. Defaults to INFINITY.
bool isSleeping
 Has the body been put to sleep by the space?
bool isRogue
 Has the body not been added to any spaces?
bool isStatic
 Is the body the static body associated with a space?
cpFloat kineticEnergy
 Get the kinetic energy of this body.

Detailed Description

Rigid bodies are the basic unit of simulation in Chipmunk.

They hold the physical properties of an object (mass, position, rotation, velocity, etc.). After creating a ChipmunkBody object, you can attach collision shapes (ChipmunkShape) and joints (ChipmunkConstraint) to it.


Member Function Documentation

- (void) applyForce: (cpVect)  force
offset: (cpVect)  offset 

Apply a force to a rigid body.

An offset of cpvzero is equivalent to adding directly to the force property.

Parameters:
force A force in expressed in absolute (word) coordinates.
offset An offset expressed in world coordinates. Note that it is still an offset, meaning that it's position is relative, but the rotation is not.
- (void) applyImpulse: (cpVect)  impulse
offset: (cpVect)  offset 

Apply an impulse to a rigid body.

Parameters:
impulse An impulse in expressed in absolute (word) coordinates.
offset An offset expressed in world coordinates. Note that it is still an offset, meaning that it's position is relative, but the rotation is not.
+ (id) bodyWithMass: (cpFloat)  mass
andMoment: (cpFloat)  moment 

Create an autoreleased rigid body with the given mass and moment.

Guessing the moment of inertia is usually a bad idea. Use the moment estimation functions (cpMomentFor*()).

- (id) initStaticBody  

Initialize a rigid body with infinite mass and moment.

This is most useful when you want to create a rogue body for controlling a moving platform or some other strictly controlled object.

- (id) initWithMass: (cpFloat)  mass
andMoment: (cpFloat)  moment 

Initialize a rigid body with the given mass and moment of inertia.

Guessing the moment of inertia is usually a bad idea. Use the moment estimation functions (cpMomentFor*()).

- (cpVect) local2world: (cpVect)  v  

Convert from body local to world coordinates.

Convert a point in world (absolute) coordinates to body local coordinates affected by the position and rotation of the rigid body.

- (void) resetForces  

Reset force and torque.

Set the force on this rigid body to cpvzero, and set the torque to 0.0.

- (void) sleep  

Equivalent to [ChipmunkBody sleepWithGroup:nil].

That is the object is forced to sleep immediately, but is not grouped with any other sleeping bodies.

- (void) sleepWithGroup: (ChipmunkBody *)  group  

Force the body to sleep immediately.

The body will be added to the same group as . When any object in a group is woken up, all of the bodies are woken up with it. If group is nil, then a new group is created and the body is added to it. It is an error pass a non-sleeping body as group. This is useful if you want an object to be inactive until something hits it such as a pile of boxes you want the player to plow through or a stalactite hanging from a cave ceiling. Make sure the body is fully set up before you call this. Adding this body or any shapes or constraints attached to it to a space, or modifying any of their properties automatically wake a body up.

+ (id) staticBody  

Create an autoreleased rigid body with infinite mass and moment.

This is most useful when you want to create a rogue body for controlling a moving platform or some other strictly controlled object.

- (cpVect) world2local: (cpVect)  v  

Convert from world to body local Coordinates.

Convert a point in body local coordinates coordinates to world (absolute) coordinates.


Property Documentation

- (id) data [read, write, assign]

An object that this constraint is associated with.

You can use this get a reference to your game object or controller object from within callbacks.

Attention:
Like most delegate properties this is a weak reference and does not call retain. This prevents reference cycles from occuring.

Reimplemented from <ChipmunkBaseObject>.


The documentation for this class was generated from the following file:
 All Classes Functions Properties