Chipmunk2D Pro API Reference  7.0.0
ChipmunkBody.h
1 /* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to deal
5  * in the Software without restriction, including without limitation the rights
6  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7  * copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19  * SOFTWARE.
20  */
21 
22 @class ChipmunkShape;
23 @class ChipmunkConstraint;
24 
29 @interface ChipmunkBody : NSObject <ChipmunkBaseObject>
30 
33 +(ChipmunkBody *)bodyFromCPBody:(cpBody *)body;
34 
39 + (id)bodyWithMass:(cpFloat)mass andMoment:(cpFloat)moment;
40 
44 + (id)staticBody;
45 
49 + (id)kinematicBody;
50 
55 - (id)initWithMass:(cpFloat)mass andMoment:(cpFloat)moment;
56 
58 @property(nonatomic, assign) cpBodyType type;
59 
61 @property(nonatomic, assign) cpFloat mass;
62 
64 @property(nonatomic, assign) cpFloat moment;
65 
67 @property(nonatomic, assign) cpVect centerOfGravity;
68 
70 @property(nonatomic, assign) cpVect position;
71 
73 @property(nonatomic, assign) cpVect velocity;
74 
76 @property(nonatomic, assign) cpVect force;
77 
79 @property(nonatomic, assign) cpFloat angle;
80 
82 @property(nonatomic, assign) cpFloat angularVelocity;
83 
85 @property(nonatomic, assign) cpFloat torque;
86 
88 @property(nonatomic, readonly) cpTransform transform;
89 
91 @property(nonatomic, readonly) cpBody *body;
92 
97 @property(nonatomic, assign) id userData;
98 
100 @property(nonatomic, readonly) bool isSleeping;
101 
103 @property(nonatomic, readonly) cpFloat kineticEnergy;
104 
106 @property(nonatomic, readonly) ChipmunkSpace *space;
107 
112 - (cpVect)localToWorld:(cpVect)v;
113 
118 - (cpVect)worldToLocal:(cpVect)v;
119 
124 - (cpVect)velocityAtLocalPoint:(cpVect)p;
125 
130 - (cpVect)velocityAtWorldPoint:(cpVect)p;
131 
137 - (void)applyForce:(cpVect)force atLocalPoint:(cpVect)point;
138 - (void)applyForce:(cpVect)force atWorldPoint:(cpVect)point;
139 
145 - (void)applyImpulse:(cpVect)impulse atLocalPoint:(cpVect)point;
146 - (void)applyImpulse:(cpVect)impulse atWorldPoint:(cpVect)point;
147 
149 - (void)activate;
150 
152 - (void)activateStatic:(ChipmunkShape *)filter;
153 
160 - (void)sleepWithGroup:(ChipmunkBody *)group;
161 
165 - (void)sleep;
166 
168 - (NSArray *)shapes;
169 
171 - (NSArray *)constraints;
172 
174 typedef void (^ChipmunkBodyArbiterIteratorBlock)(cpArbiter *arbiter);
175 
177 - (void)eachArbiter:(ChipmunkBodyArbiterIteratorBlock)block;
178 
180 - (void)addToSpace:(ChipmunkSpace *)space;
182 - (void)removeFromSpace:(ChipmunkSpace *)space;
183 
186 -(void)updateVelocity:(cpFloat)dt gravity:(cpVect)gravity damping:(cpFloat)damping;
187 
190 -(void)updatePosition:(cpFloat)dt;
191 
192 @end
cpVect position
The position of the rigid body&#39;s center of gravity.
Definition: ChipmunkBody.h:70
cpBodyType type
Type of the body (dynamic, kinematic, static).
Definition: ChipmunkBody.h:58
cpVect centerOfGravity
Location of the body&#39;s center of gravity relative to it&#39;s position. Defaults to cpvzero.
Definition: ChipmunkBody.h:67
void activate()
Wake up the body if it&#39;s sleeping, or reset the idle timer if it&#39;s active.
NSArray * constraints()
Get a list of constraints that are attached to this body and currently added to a space...
cpBodyType
Definition: cpBody.h:28
void(^ ChipmunkBodyArbiterIteratorBlock)(cpArbiter *arbiter)
Body/arbiter iterator callback block type.
Definition: ChipmunkBody.h:174
Definition: chipmunk_private.h:80
cpFloat angularVelocity
The angular velocity of the rigid body in radians per second.
Definition: ChipmunkBody.h:82
NSArray * shapes()
Get a list of shapes that are attached to this body and currently added to a space.
Rigid bodies are the basic unit of simulation in Chipmunk.
Definition: ChipmunkBody.h:29
id staticBody()
Create an autoreleased static body.
double cpFloat
Chipmunk&#39;s floating point type.
Definition: chipmunk_types.h:83
Chipmunk spaces are simulation containers.
Definition: ChipmunkSpace.h:32
bool isSleeping
Has the body been put to sleep by the space?
Definition: ChipmunkBody.h:100
cpVect velocity
The linear velocity of the rigid body.
Definition: ChipmunkBody.h:73
Definition: chipmunk_types.h:271
Abstract base class for collsion shape types.
Definition: ChipmunkShape.h:27
cpFloat angle
The rotation angle of the rigid body in radians.
Definition: ChipmunkBody.h:79
cpFloat torque
The torque being applied to the rigid body. Like force, this property is not reset every frame...
Definition: ChipmunkBody.h:85
cpVect force
The linear force applied to the rigid body. Unlike in some physics engines, the force does not reset ...
Definition: ChipmunkBody.h:76
Definition: chipmunk_private.h:185
Constraints connect two ChipmunkBody objects together.
Definition: ChipmunkConstraint.h:33
ChipmunkSpace * space
Get the space the body is added to.
Definition: ChipmunkBody.h:106
cpTransform transform
The rigid transform of the body.
Definition: ChipmunkBody.h:88
cpFloat mass
Mass of the rigid body. Mass does not have to be expressed in any particular units, but relative masses should be consistent.
Definition: ChipmunkBody.h:61
id kinematicBody()
Create an autoreleased kinematic body.
cpFloat kineticEnergy
Get the kinetic energy of this body.
Definition: ChipmunkBody.h:103
id userData
An object that this constraint is associated with.
Definition: ChipmunkBody.h:97
Column major affine transform.
Definition: chipmunk_types.h:278
void sleep()
Equivalent to [ChipmunkBody sleepWithGroup:nil].
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&#39;t try to guess the MoI, use the cpMomentFor*() functions to try and estimate it.
Definition: ChipmunkBody.h:64