Chipmunk2D Pro API Reference  7.0.0
 All Classes Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
cpBody.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 
27 
28 typedef enum cpBodyType {
41 } cpBodyType;
42 
44 typedef void (*cpBodyVelocityFunc)(cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt);
46 typedef void (*cpBodyPositionFunc)(cpBody *body, cpFloat dt);
47 
49 cpBody* cpBodyAlloc(void);
51 cpBody* cpBodyInit(cpBody *body, cpFloat mass, cpFloat moment);
53 cpBody* cpBodyNew(cpFloat mass, cpFloat moment);
54 
58 cpBody* cpBodyNewStatic(void);
59 
61 void cpBodyDestroy(cpBody *body);
63 void cpBodyFree(cpBody *body);
64 
65 // Defined in cpSpace.c
67 void cpBodyActivate(cpBody *body);
69 void cpBodyActivateStatic(cpBody *body, cpShape *filter);
70 
72 void cpBodySleep(cpBody *body);
74 void cpBodySleepWithGroup(cpBody *body, cpBody *group);
75 
77 cpBool cpBodyIsSleeping(const cpBody *body);
78 
82 void cpBodySetType(cpBody *body, cpBodyType type);
83 
85 cpSpace* cpBodyGetSpace(const cpBody *body);
86 
88 cpFloat cpBodyGetMass(const cpBody *body);
90 void cpBodySetMass(cpBody *body, cpFloat m);
91 
93 cpFloat cpBodyGetMoment(const cpBody *body);
95 void cpBodySetMoment(cpBody *body, cpFloat i);
96 
98 cpVect cpBodyGetPosition(const cpBody *body);
100 void cpBodySetPosition(cpBody *body, cpVect pos);
101 
105 void cpBodySetCenterOfGravity(cpBody *body, cpVect cog);
106 
108 cpVect cpBodyGetVelocity(const cpBody *body);
110 void cpBodySetVelocity(cpBody *body, cpVect velocity);
111 
113 cpVect cpBodyGetForce(const cpBody *body);
115 void cpBodySetForce(cpBody *body, cpVect force);
116 
118 cpFloat cpBodyGetAngle(const cpBody *body);
120 void cpBodySetAngle(cpBody *body, cpFloat a);
121 
125 void cpBodySetAngularVelocity(cpBody *body, cpFloat angularVelocity);
126 
128 cpFloat cpBodyGetTorque(const cpBody *body);
130 void cpBodySetTorque(cpBody *body, cpFloat torque);
131 
133 cpVect cpBodyGetRotation(const cpBody *body);
134 
138 void cpBodySetUserData(cpBody *body, cpDataPointer userData);
139 
141 void cpBodySetVelocityUpdateFunc(cpBody *body, cpBodyVelocityFunc velocityFunc);
144 void cpBodySetPositionUpdateFunc(cpBody *body, cpBodyPositionFunc positionFunc);
145 
147 void cpBodyUpdateVelocity(cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt);
149 void cpBodyUpdatePosition(cpBody *body, cpFloat dt);
150 
152 cpVect cpBodyLocalToWorld(const cpBody *body, const cpVect point);
154 cpVect cpBodyWorldToLocal(const cpBody *body, const cpVect point);
155 
157 void cpBodyApplyForceAtWorldPoint(cpBody *body, cpVect force, cpVect point);
159 void cpBodyApplyForceAtLocalPoint(cpBody *body, cpVect force, cpVect point);
160 
162 void cpBodyApplyImpulseAtWorldPoint(cpBody *body, cpVect impulse, cpVect point);
164 void cpBodyApplyImpulseAtLocalPoint(cpBody *body, cpVect impulse, cpVect point);
165 
170 
172 cpFloat cpBodyKineticEnergy(const cpBody *body);
173 
175 typedef void (*cpBodyShapeIteratorFunc)(cpBody *body, cpShape *shape, void *data);
177 void cpBodyEachShape(cpBody *body, cpBodyShapeIteratorFunc func, void *data);
178 
180 typedef void (*cpBodyConstraintIteratorFunc)(cpBody *body, cpConstraint *constraint, void *data);
182 void cpBodyEachConstraint(cpBody *body, cpBodyConstraintIteratorFunc func, void *data);
183 
185 typedef void (*cpBodyArbiterIteratorFunc)(cpBody *body, cpArbiter *arbiter, void *data);
187 void cpBodyEachArbiter(cpBody *body, cpBodyArbiterIteratorFunc func, void *data);
188