[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-physics / third-party / chipmunk2d / include / chipmunk / 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
22 /// @defgroup cpBody cpBody
23 /// Chipmunk's rigid body type. Rigid bodies hold the physical properties of an object like
24 /// it's mass, and position and velocity of it's center of gravity. They don't have an shape on their own.
25 /// They are given a shape by creating collision shapes (cpShape) that point to the body.
26 /// @{
27
28 typedef enum cpBodyType {
29         /// A dynamic body is one that is affected by gravity, forces, and collisions.
30         /// This is the default body type.
31         CP_BODY_TYPE_DYNAMIC,
32         /// A kinematic body is an infinite mass, user controlled body that is not affected by gravity, forces or collisions.
33         /// Instead the body only moves based on it's velocity.
34         /// Dynamic bodies collide normally with kinematic bodies, though the kinematic body will be unaffected.
35         /// Collisions between two kinematic bodies, or a kinematic body and a static body produce collision callbacks, but no collision response.
36         CP_BODY_TYPE_KINEMATIC,
37         /// A static body is a body that never (or rarely) moves. If you move a static body, you must call one of the cpSpaceReindex*() functions.
38         /// Chipmunk uses this information to optimize the collision detection.
39         /// Static bodies do not produce collision callbacks when colliding with other static bodies.
40         CP_BODY_TYPE_STATIC,
41 } cpBodyType;
42
43 /// Rigid body velocity update function type.
44 typedef void (*cpBodyVelocityFunc)(cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt);
45 /// Rigid body position update function type.
46 typedef void (*cpBodyPositionFunc)(cpBody *body, cpFloat dt);
47
48 /// Allocate a cpBody.
49 CP_EXPORT cpBody* cpBodyAlloc(void);
50 /// Initialize a cpBody.
51 CP_EXPORT cpBody* cpBodyInit(cpBody *body, cpFloat mass, cpFloat moment);
52 /// Allocate and initialize a cpBody.
53 CP_EXPORT cpBody* cpBodyNew(cpFloat mass, cpFloat moment);
54
55 /// Allocate and initialize a cpBody, and set it as a kinematic body.
56 CP_EXPORT cpBody* cpBodyNewKinematic(void);
57 /// Allocate and initialize a cpBody, and set it as a static body.
58 CP_EXPORT cpBody* cpBodyNewStatic(void);
59
60 /// Destroy a cpBody.
61 CP_EXPORT void cpBodyDestroy(cpBody *body);
62 /// Destroy and free a cpBody.
63 CP_EXPORT void cpBodyFree(cpBody *body);
64
65 // Defined in cpSpace.c
66 /// Wake up a sleeping or idle body.
67 CP_EXPORT void cpBodyActivate(cpBody *body);
68 /// Wake up any sleeping or idle bodies touching a static body.
69 CP_EXPORT void cpBodyActivateStatic(cpBody *body, cpShape *filter);
70
71 /// Force a body to fall asleep immediately.
72 CP_EXPORT void cpBodySleep(cpBody *body);
73 /// Force a body to fall asleep immediately along with other bodies in a group.
74 CP_EXPORT void cpBodySleepWithGroup(cpBody *body, cpBody *group);
75
76 /// Returns true if the body is sleeping.
77 CP_EXPORT cpBool cpBodyIsSleeping(const cpBody *body);
78
79 // Returns true if the body is exceeding the sleep threshold
80 CP_EXPORT cpBool cpBodyIsSleepThresholdExceeded(const cpBody *body, const cpShape *shape);
81
82 /// Get the type of the body.
83 CP_EXPORT cpBodyType cpBodyGetType(cpBody *body);
84 /// Set the type of the body.
85 CP_EXPORT void cpBodySetType(cpBody *body, cpBodyType type);
86
87 /// Get the space this body is added to.
88 CP_EXPORT cpSpace* cpBodyGetSpace(const cpBody *body);
89
90 /// Get the mass of the body.
91 CP_EXPORT cpFloat cpBodyGetMass(const cpBody *body);
92 /// Set the mass of the body.
93 CP_EXPORT void cpBodySetMass(cpBody *body, cpFloat m);
94
95 /// Get the moment of inertia of the body.
96 CP_EXPORT cpFloat cpBodyGetMoment(const cpBody *body);
97 /// Set the moment of inertia of the body.
98 CP_EXPORT void cpBodySetMoment(cpBody *body, cpFloat i);
99
100 /// Set the position of a body.
101 CP_EXPORT cpVect cpBodyGetPosition(const cpBody *body);
102 /// Set the position of the body.
103 CP_EXPORT void cpBodySetPosition(cpBody *body, cpVect pos);
104
105 /// Get the offset of the center of gravity in body local coordinates.
106 CP_EXPORT cpVect cpBodyGetCenterOfGravity(const cpBody *body);
107 /// Set the offset of the center of gravity in body local coordinates.
108 CP_EXPORT void cpBodySetCenterOfGravity(cpBody *body, cpVect cog);
109
110 /// Get the velocity of the body.
111 CP_EXPORT cpVect cpBodyGetVelocity(const cpBody *body);
112 /// Set the velocity of the body.
113 CP_EXPORT void cpBodySetVelocity(cpBody *body, cpVect velocity);
114
115 /// Get the force applied to the body for the next time step.
116 CP_EXPORT cpVect cpBodyGetForce(const cpBody *body);
117 /// Set the force applied to the body for the next time step.
118 CP_EXPORT void cpBodySetForce(cpBody *body, cpVect force);
119
120 /// Get the angle of the body.
121 CP_EXPORT cpFloat cpBodyGetAngle(const cpBody *body);
122 /// Set the angle of a body.
123 CP_EXPORT void cpBodySetAngle(cpBody *body, cpFloat a);
124
125 /// Get the angular velocity of the body.
126 CP_EXPORT cpFloat cpBodyGetAngularVelocity(const cpBody *body);
127 /// Set the angular velocity of the body.
128 CP_EXPORT void cpBodySetAngularVelocity(cpBody *body, cpFloat angularVelocity);
129
130 /// Get the torque applied to the body for the next time step.
131 CP_EXPORT cpFloat cpBodyGetTorque(const cpBody *body);
132 /// Set the torque applied to the body for the next time step.
133 CP_EXPORT void cpBodySetTorque(cpBody *body, cpFloat torque);
134
135 /// Get the rotation vector of the body. (The x basis vector of it's transform.)
136 CP_EXPORT cpVect cpBodyGetRotation(const cpBody *body);
137
138 /// Get the user data pointer assigned to the body.
139 CP_EXPORT cpDataPointer cpBodyGetUserData(const cpBody *body);
140 /// Set the user data pointer assigned to the body.
141 CP_EXPORT void cpBodySetUserData(cpBody *body, cpDataPointer userData);
142
143 /// Get the 2nd user data pointer assigned to the body.
144 CP_EXPORT cpDataPointer cpBodyGetUserData2(const cpBody *body);
145 /// Set the 2nd user data pointer assigned to the body.
146 CP_EXPORT void cpBodySetUserData2(cpBody *body, cpDataPointer userData);
147
148 /// Set the callback used to update a body's velocity.
149 CP_EXPORT void cpBodySetVelocityUpdateFunc(cpBody *body, cpBodyVelocityFunc velocityFunc);
150 /// Set the callback used to update a body's position.
151 /// NOTE: It's not generally recommended to override this unless you call the default position update function.
152 CP_EXPORT void cpBodySetPositionUpdateFunc(cpBody *body, cpBodyPositionFunc positionFunc);
153
154 /// Default velocity integration function..
155 CP_EXPORT void cpBodyUpdateVelocity(cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt);
156 /// Default position integration function.
157 CP_EXPORT void cpBodyUpdatePosition(cpBody *body, cpFloat dt);
158
159 /// Convert body relative/local coordinates to absolute/world coordinates.
160 CP_EXPORT cpVect cpBodyLocalToWorld(const cpBody *body, const cpVect point);
161 /// Convert body absolute/world coordinates to  relative/local coordinates.
162 CP_EXPORT cpVect cpBodyWorldToLocal(const cpBody *body, const cpVect point);
163
164 /// Apply a force to a body. Both the force and point are expressed in world coordinates.
165 CP_EXPORT void cpBodyApplyForceAtWorldPoint(cpBody *body, cpVect force, cpVect point);
166 /// Apply a force to a body. Both the force and point are expressed in body local coordinates.
167 CP_EXPORT void cpBodyApplyForceAtLocalPoint(cpBody *body, cpVect force, cpVect point);
168
169 /// Apply an impulse to a body. Both the impulse and point are expressed in world coordinates.
170 CP_EXPORT void cpBodyApplyImpulseAtWorldPoint(cpBody *body, cpVect impulse, cpVect point);
171 /// Apply an impulse to a body. Both the impulse and point are expressed in body local coordinates.
172 CP_EXPORT void cpBodyApplyImpulseAtLocalPoint(cpBody *body, cpVect impulse, cpVect point);
173
174 /// Get the velocity on a body (in world units) at a point on the body in world coordinates.
175 CP_EXPORT cpVect cpBodyGetVelocityAtWorldPoint(const cpBody *body, cpVect point);
176 /// Get the velocity on a body (in world units) at a point on the body in local coordinates.
177 CP_EXPORT cpVect cpBodyGetVelocityAtLocalPoint(const cpBody *body, cpVect point);
178
179 /// Get the amount of kinetic energy contained by the body.
180 CP_EXPORT cpFloat cpBodyKineticEnergy(const cpBody *body);
181
182 /// Body/shape iterator callback function type. 
183 typedef void (*cpBodyShapeIteratorFunc)(cpBody *body, cpShape *shape, void *data);
184 /// Call @c func once for each shape attached to @c body and added to the space.
185 CP_EXPORT void cpBodyEachShape(cpBody *body, cpBodyShapeIteratorFunc func, void *data);
186
187 /// Body/constraint iterator callback function type. 
188 typedef void (*cpBodyConstraintIteratorFunc)(cpBody *body, cpConstraint *constraint, void *data);
189 /// Call @c func once for each constraint attached to @c body and added to the space.
190 CP_EXPORT void cpBodyEachConstraint(cpBody *body, cpBodyConstraintIteratorFunc func, void *data);
191
192 /// Body/arbiter iterator callback function type. 
193 typedef void (*cpBodyArbiterIteratorFunc)(cpBody *body, cpArbiter *arbiter, void *data);
194 /// Call @c func once for each arbiter that is currently active on the body.
195 CP_EXPORT void cpBodyEachArbiter(cpBody *body, cpBodyArbiterIteratorFunc func, void *data);
196
197 ///@}