Chipmunk2D Pro API Reference  6.1.5
 All Classes Functions Variables Typedefs Properties Groups Pages
Public Types | Instance Methods | Class Methods | Properties | List of all members
ChipmunkBody Class Reference

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

#import <ChipmunkBody.h>

Inherits NSObject, and <ChipmunkBaseObject>.

Public Types

typedef void(^ ChipmunkBodyArbiterIteratorBlock )(cpArbiter *arbiter)
 Body/arbiter iterator callback block type.
 

Instance Methods

(id) - initWithMass:andMoment:
 Initialize a rigid body with the given mass and moment of inertia. More...
 
(id) - initStaticBody
 Initialize a rigid body with infinite mass and moment. More...
 
(cpVect- local2world:
 Convert from body local to world coordinates. More...
 
(cpVect- world2local:
 Convert from world to body local Coordinates. More...
 
(cpVect- velocityAtLocalPoint:
 Get the velocity of a point on a body. More...
 
(cpVect- velocityAtWorldPoint:
 Get the velocity of a point on a body. More...
 
(void) - resetForces
 Reset force and torque. More...
 
(void) - applyForce:offset:
 Apply a force to a rigid body. More...
 
(void) - applyImpulse:offset:
 Apply an impulse to a rigid body. More...
 
(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 filter to away all touching bodies.
 
(void) - sleepWithGroup:
 Force the body to sleep immediately. More...
 
(void) - sleep
 Equivalent to [ChipmunkBody sleepWithGroup:nil]. More...
 
(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.
 
(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.
 
(void) - updateVelocity:gravity:damping:
 Override this to change the way that the body's velocity is integrated. More...
 
(void) - updatePosition:
 OVerride this to change the way that the body's position is intgrated. More...
 
(CGAffineTransform) - affineTransform
 Get an affine transform to match this body.
 

Class Methods

(ChipmunkBody *) + bodyFromCPBody:
 Get the ChipmunkBody object associciated with a cpBody pointer. More...
 
(id) + bodyWithMass:andMoment:
 Create an autoreleased rigid body with the given mass and moment. More...
 
(id) + staticBody
 Create an autoreleased rigid body with infinite mass and moment. More...
 

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.
 
cpBodybody
 Returns a pointer to the underlying cpBody C struct.
 
id data
 An object that this constraint is associated with. More...
 
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.
 
ChipmunkSpacespace
 Get the space the body is added to.
 

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.

Method 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
forceA force in expressed in absolute (word) coordinates.
offsetAn 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
impulseAn impulse in expressed in absolute (word) coordinates.
offsetAn offset expressed in world coordinates. Note that it is still an offset, meaning that it's position is relative, but the rotation is not.
+ (ChipmunkBody *) bodyFromCPBody: (cpBody *)  body

Get the ChipmunkBody object associciated with a cpBody pointer.

Undefined if the cpBody wasn't created using Objective-Chipmunk.

+ (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 group. 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.

- (void) updatePosition: (cpFloat dt

OVerride this to change the way that the body's position is intgrated.

You should either understand how the cpBodyUpdatePosition() function works, or use the super method.

- (void) updateVelocity: (cpFloat dt
gravity: (cpVect gravity
damping: (cpFloat damping 

Override this to change the way that the body's velocity is integrated.

You should either understand how the cpBodyUpdateVelocity() function works, or use the super method.

- (cpVect) velocityAtLocalPoint: (cpVect p

Get the velocity of a point on a body.

Get the world (absolute) velocity of a point on a rigid body specified in body local coordinates.

- (cpVect) velocityAtWorldPoint: (cpVect p

Get the velocity of a point on a body.

Get the world (absolute) velocity of a point on a rigid body specified in world coordinates.

- (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
readwritenonatomicassign

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.

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