[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-physics / third-party / chipmunk2d / objectivec / include / ObjectiveChipmunk / 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
25 /**
26         Rigid bodies are the basic unit of simulation in Chipmunk.
27         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.
28 */
29 @interface ChipmunkBody : NSObject <ChipmunkBaseObject>
30
31 /// Get the ChipmunkBody object associciated with a cpBody pointer.
32 /// Undefined if the cpBody wasn't created using Objective-Chipmunk.
33 +(ChipmunkBody *)bodyFromCPBody:(cpBody *)body;
34
35 /**
36   Create an autoreleased rigid body with the given mass and moment.
37   Guessing the moment of inertia is usually a bad idea. Use the moment estimation functions (cpMomentFor*()).
38 */
39 + (id)bodyWithMass:(cpFloat)mass andMoment:(cpFloat)moment;
40
41 /**
42   Create an autoreleased static body.
43 */
44 + (id)staticBody;
45
46 /**
47   Create an autoreleased kinematic body.
48 */
49 + (id)kinematicBody;
50
51 /**
52   Initialize a rigid body with the given mass and moment of inertia.
53   Guessing the moment of inertia is usually a bad idea. Use the moment estimation functions (cpMomentFor*()).
54 */
55 - (id)initWithMass:(cpFloat)mass andMoment:(cpFloat)moment;
56
57 /// Type of the body (dynamic, kinematic, static).
58 @property(nonatomic, assign) cpBodyType type;
59
60 /// Mass of the rigid body. Mass does not have to be expressed in any particular units, but relative masses should be consistent.
61 @property(nonatomic, assign) cpFloat mass;
62
63 /// 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.
64 @property(nonatomic, assign) cpFloat moment;
65
66 /// Location of the body's center of gravity relative to it's position. Defaults to @c cpvzero.
67 @property(nonatomic, assign) cpVect centerOfGravity;
68
69 /// The position of the rigid body's center of gravity.
70 @property(nonatomic, assign) cpVect position;
71
72 /// The linear velocity of the rigid body.
73 @property(nonatomic, assign) cpVect velocity;
74
75 /// 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.
76 @property(nonatomic, assign) cpVect force;
77
78 /// The rotation angle of the rigid body in radians.
79 @property(nonatomic, assign) cpFloat angle;
80
81 /// The angular velocity of the rigid body in radians per second.
82 @property(nonatomic, assign) cpFloat angularVelocity;
83
84 /// The torque being applied to the rigid body. Like force, this property is not reset every frame.
85 @property(nonatomic, assign) cpFloat torque;
86
87 /// The rigid transform of the body.
88 @property(nonatomic, readonly) cpTransform transform;
89
90 /// Returns a pointer to the underlying cpBody C struct.
91 @property(nonatomic, readonly) cpBody *body;
92
93 /**
94         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.
95         @attention Like most @c delegate properties this is a weak reference and does not call @c retain. This prevents reference cycles from occuring.
96 */
97 @property(nonatomic, assign) id userData;
98
99 /// Has the body been put to sleep by the space?
100 @property(nonatomic, readonly) bool isSleeping;
101
102 /// Get the kinetic energy of this body.
103 @property(nonatomic, readonly) cpFloat kineticEnergy;
104
105 /// Get the space the body is added to.
106 @property(nonatomic, readonly) ChipmunkSpace *space;
107
108 /**
109   Convert from body local to world coordinates.
110   Convert a point in world (absolute) coordinates to body local coordinates affected by the position and rotation of the rigid body.
111 */
112 - (cpVect)localToWorld:(cpVect)v;
113
114 /**
115   Convert from world to body local Coordinates.
116   Convert a point in body local coordinates coordinates to world (absolute) coordinates.
117 */
118 - (cpVect)worldToLocal:(cpVect)v;
119
120 /**
121         Get the velocity of a point on a body.
122         Get the world (absolute) velocity of a point on a rigid body specified in body local coordinates.
123 */
124 - (cpVect)velocityAtLocalPoint:(cpVect)p;
125
126 /**
127         Get the velocity of a point on a body.
128         Get the world (absolute) velocity of a point on a rigid body specified in world coordinates.
129 */
130 - (cpVect)velocityAtWorldPoint:(cpVect)p;
131
132 /**
133   Apply a force to a rigid body. An offset of cpvzero is equivalent to adding directly to the force property.
134   @param force A force in expressed in absolute (word) coordinates.
135         @param 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.
136 */
137 - (void)applyForce:(cpVect)force atLocalPoint:(cpVect)point;
138 - (void)applyForce:(cpVect)force atWorldPoint:(cpVect)point;
139
140 /**
141   Apply an impulse to a rigid body.
142   @param impulse An impulse in expressed in absolute (word) coordinates.
143         @param 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.
144 */
145 - (void)applyImpulse:(cpVect)impulse atLocalPoint:(cpVect)point;
146 - (void)applyImpulse:(cpVect)impulse atWorldPoint:(cpVect)point;
147
148 /// Wake up the body if it's sleeping, or reset the idle timer if it's active.
149 - (void)activate;
150
151 /// Wake up any bodies touching a static body through shape @c filter Pass @c nil for @c filter to away all touching bodies.
152 - (void)activateStatic:(ChipmunkShape *)filter;
153
154 /**
155         Force the body to sleep immediately. The body will be added to the same group as @c group. When any object in a group is woken up, all of the bodies are woken up with it.
156         If @c 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 @c group.
157         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.
158         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.
159 */
160 - (void)sleepWithGroup:(ChipmunkBody *)group;
161
162 /**
163         Equivalent to [ChipmunkBody sleepWithGroup:nil]. That is the object is forced to sleep immediately, but is not grouped with any other sleeping bodies.
164 */
165 - (void)sleep;
166
167 /// Get a list of shapes that are attached to this body and currently added to a space.
168 - (NSArray *)shapes;
169
170 /// Get a list of constraints that are attached to this body and currently added to a space.
171 - (NSArray *)constraints;
172
173 /// Body/arbiter iterator callback block type.
174 typedef void (^ChipmunkBodyArbiterIteratorBlock)(cpArbiter *arbiter);
175
176 /// Call @c block once for each arbiter that is currently active on the body.
177 - (void)eachArbiter:(ChipmunkBodyArbiterIteratorBlock)block;
178
179 /// Implements the ChipmunkBaseObject protocol, not particularly useful outside of the library code
180 - (void)addToSpace:(ChipmunkSpace *)space;
181 /// Implements the ChipmunkBaseObject protocol, not particularly useful outside of the library code
182 - (void)removeFromSpace:(ChipmunkSpace *)space;
183
184 /// Override this to change the way that the body's velocity is integrated.
185 /// You should either understand how the cpBodyUpdateVelocity() function works, or use the super method.
186 -(void)updateVelocity:(cpFloat)dt gravity:(cpVect)gravity damping:(cpFloat)damping;
187
188 /// OVerride this to change the way that the body's position is intgrated.
189 /// You should either understand how the cpBodyUpdatePosition() function works, or use the super method.
190 -(void)updatePosition:(cpFloat)dt;
191
192 @end