9f86c672705335ebe9f7bcaf0fbb929a61f807c9
[platform/core/uifw/dali-core.git] / dali / public-api / dynamics / dynamics-body-config.h
1 #ifndef __DALI_DYNAMICS_BODY_CONFIG_H__
2 #define __DALI_DYNAMICS_BODY_CONFIG_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <string>
23
24 // BASE CLASS INCLUDES
25 #include <dali/public-api/object/base-handle.h>
26
27 // INTERNAL INCLUDES
28 #include <dali/public-api/dynamics/dynamics-shape.h>
29
30 namespace Dali
31 {
32 class DynamicsWorld;
33 struct Vector3;
34
35 namespace Internal DALI_INTERNAL
36 {
37 class DynamicsBodyConfig;
38 } // namespace Internal
39
40 /**
41  * @brief Describes a DynamicsBody configuration.
42  *
43  * Use to create multiple instances of a DynamicsBody
44  */
45 class DALI_IMPORT_API DynamicsBodyConfig : public BaseHandle
46 {
47 public:
48
49   /**
50    * @brief Enumeration of the types of dynamics bodies.
51    */
52   enum BodyType
53   {
54     RIGID,                ///< May have mass and therefore be affected by gravity and have velocity
55     SOFT,                 ///< Has a deformable shape - implies RIGID
56   }; // enum BodyType
57
58   /**
59    * @brief Collision filtering flags.
60    *
61    * A DynamicsBody pair are considered for collision detection if a bitwise AND of
62    * the filter group from one DynamicsBody and the filter mask of the other DynamicsBody
63    * gives a non-zero result.@n
64    * Set the filter group with Dali::DynamicsBodyConfig::SetCollisionGroup and
65    * the filter mask with Dali::DynamicsBodyConfig::SetCollisionMask.@n
66    */
67   enum CollisionFilter
68   {
69     COLLISION_FILTER_DEFAULT =  (1 << 0),          ///< The default group filter
70     COLLISION_FILTER_STATIC  =  (1 << 1),          ///< The default group for static (zero mass) bodies
71     COLLISION_FILTER_ALL     =  (-1)               ///< The default mask
72   };
73
74 public:
75   /**
76    * @brief Create a new DynamicsBody configuration object.
77    *
78    * All values are set to default values...
79    * @pre Stage::InitializeDynamics() must have been called
80    * @return a handle to the new DynamicsBodyconfig.
81    */
82   static DynamicsBodyConfig New();
83
84   /**
85    * @brief Create an uninitialized handle.
86    *
87    * Initialize with one of the DynamicsBodyConfig New methods
88    */
89   DynamicsBodyConfig();
90
91   /**
92    * @brief Destructor
93    *
94    * This is non-virtual since derived Handle types must not contain data or virtual methods.
95    */
96   ~DynamicsBodyConfig();
97
98   /**
99    * @brief This copy constructor is required for (smart) pointer semantics.
100    *
101    * @param [in] handle A reference to the copied handle
102    */
103   DynamicsBodyConfig(const DynamicsBodyConfig& handle);
104
105   /**
106    * @brief This assignment operator is required for (smart) pointer semantics.
107    *
108    * @param [in] rhs  A reference to the copied handle
109    * @return A reference to this
110    */
111   DynamicsBodyConfig& operator=(const DynamicsBodyConfig& rhs);
112
113 public:
114   /**
115    * @brief Set the type of DynamicsBody.
116    *
117    * @param[in] type A member of BodyType enumeration.
118    */
119   void SetType( const BodyType type );
120
121   /**
122    * @brief Get the type of DynamicsBody specified by the Configuration.
123    *
124    * @return A member of BodyType enumeration.
125    */
126   BodyType GetType() const;
127
128   /**
129    * @brief Define the shape for the body.
130    *
131    * @param[in] type        The type of shape
132    * @param[in] dimensions  The parameters defining the shape ...
133    *                        - DynamicsShape::SPHERE
134    *                          - x radius
135    *                        - DynamicsShape::CUBE
136    *                          - x width of cube
137    *                          - y height of cube
138    *                          - z depth of cube
139    *                        - DynamicsShape::CYLINDER
140    *                          - x radius of ends
141    *                          - y length if cylinder
142    *                        - DynamicsShape::CAPSULE
143    *                          - x radius of end caps
144    *                          - y length of capsule
145    *                        - DynamicsShape::CONE
146    *                          - x radius of base
147    *                          - y length of cone
148    *                        - DynamicsShape::MESH
149    *                          - x width
150    *                          - y height
151    *                          - z number of extra division on x and y
152    */
153   void SetShape(const DynamicsShape::ShapeType type, const Vector3& dimensions);
154
155   /**
156    * @brief Set the shape for the body.
157    *
158    * @param[in] shape A DynamicsShape.
159    */
160   void SetShape( DynamicsShape shape );
161
162   /**
163    * @brief get the shape for the body.
164    *
165    * @return A DynamicsShape.
166    */
167   DynamicsShape GetShape() const;
168
169   /**
170    * @brief Set the mass for the body.
171    *
172    * @param[in] mass The mass for the body.
173    */
174   void SetMass( float mass);
175
176   /**
177    * @brief Get the mass that will be set on bodies created from this config.
178    *
179    * @return The mass that will be set on bodies created from this config
180    */
181   float GetMass() const;
182
183   /**
184    * @brief Get the @"elasticity@" of the body.
185    *
186    * @return The @"elasticity@".
187    *
188    * See @ref SetElasticity
189    */
190   float GetElasticity() const;
191
192   /**
193    * @brief Affects the @"elasticity@" of the body.
194    *
195    * This function sets the coefficient of restitution (COR) of an object.@n
196    * @param[in] elasticity The elasticity of the body.
197    *                       Assuming the other body in a collision has a elasticity factor of 1.
198    *                       Set elasticity == 0 to inhibit bouncing at impact, reduces the velocity of the body to 0.
199    *                       Set elasticity > 1 will increase the velocity of the object after impact
200    */
201   void SetElasticity(float elasticity);
202
203   /**
204    * @brief Get the friction coefficient for any DynamicsBody created from this DynamicsBodyConfig.
205    *
206    * @return The friction coefficient.
207    *
208    * See @ref SetFriction.
209    */
210   float GetFriction() const;
211
212   /**
213    * @brief Set the friction coefficient for any DynamicsBody created from this DynamicsBodyConfig.
214    *
215    * @param[in] friction The friction coefficient.
216    *                     This will be clamped between 0 and 1
217    */
218   void SetFriction(float friction);
219
220   /**
221    * @brief Get the linear damping coefficient for any DynamicsBody created from this DynamicsBodyConfig.
222    *
223    * @return The linear damping coefficient.
224    * See @ref SetLinearDamping.
225    */
226   float GetLinearDamping() const;
227
228   /**
229    * @brief Set the linear damping coefficient for any DynamicsBody created from this DynamicsBodyConfig.
230    *
231    * @param[in] damping The linear damping coefficient.
232    *                    This will be clamped between 0 and 1
233    */
234   void SetLinearDamping( float damping );
235
236   /**
237    * @brief Get the angular damping coefficient for any DynamicsBody created from this DynamicsBodyConfig.
238    *
239    * @return The angular damping coefficient.
240    *
241    * See @ref SetAngularDamping.
242    */
243   float GetAngularDamping() const;
244
245   /**
246    * @brief Set the angular damping coefficient for any DynamicsBody created from this DynamicsBodyConfig.
247    *
248    * @param[in] damping The angular damping coefficient.
249    *                    This will be clamped between 0 and 1
250    */
251   void SetAngularDamping(float damping);
252
253   /**
254    * @brief Get the linear velocity below which the DynamicsBody can be put to sleep by the simulation.
255    *
256    * @return The linear sleep velocity.
257    *
258    * See @ref SetLinearSleepVelocity, DynamicsBody::SetSleepEnabled.
259    */
260   float GetLinearSleepVelocity() const;
261
262   /**
263    * @brief Set the linear velocity below which the DynamicsBody can be put to sleep by the simulation.
264    *
265    * @param[in] sleepVelocity The linear sleep velocity.
266    *
267    * See @ref DynamicsBody::SetSleepEnabled.
268    */
269   void SetLinearSleepVelocity(float sleepVelocity);
270
271   /**
272    * @brief Get the angular velocity below which the DynamicsBody can be put to sleep by the simulation.
273    *
274    * @return The angular sleep velocity.
275    *
276    * See @ref SetAngularSleepVelocity, DynamicsBody::SetSleepEnabled.
277    */
278   float GetAngularSleepVelocity() const;
279
280   /**
281    * @brief Set the angular velocity below which the DynamicsBody can be put to sleep by the simulation.
282    *
283    * @param[in] sleepVelocity The angular sleep velocity.
284    *
285    * See @ref DynamicsBody::SetSleepEnabled.
286    */
287   void SetAngularSleepVelocity(float sleepVelocity);
288
289   /**
290    * @brief Get the collision filter group.@n
291    *
292    * See @ref CollisionFilter
293    * @return The collision filter group.@n
294    */
295   short int GetCollisionGroup() const;
296
297   /**
298    * @brief Set the collision filter group.
299    *
300    * See @ref CollisionFilter
301    * @param[in] collisionGroup The collision filter group
302    */
303   void SetCollisionGroup(const short int collisionGroup);
304
305   /**
306    * @brief Get the collision filter mask.@n
307    *
308    * See @ref CollisionFilter
309    * @return The collision filter mask.@n
310    */
311   short int GetCollisionMask() const;
312
313   /**
314    * @brief Set the collision filter mask.
315    *
316    * See @ref CollisionFilter
317    * @param[in] collisionMask The collision filter mask
318    */
319   void SetCollisionMask(const short int collisionMask);
320
321   /**
322    * @brief Get the stiffness coefficient for the soft body.
323    *
324    * See @ref SetStiffness
325    * @return The stiffness coefficient for the soft body.
326    */
327   float GetStiffness() const;
328
329   /**
330    * @brief Set the stiffness co-efficient for the soft body.
331    *
332    * @param[in] stiffness A value clamped between 0 and 1.
333    *                      Values closer to 1 make it more stiff.
334    */
335   void SetStiffness( float stiffness );
336
337   /**
338    * @brief Get the anchor hardness.@n
339    *
340    * See @ref SetAnchorHardness.
341    * @return The anchor hardness.
342    */
343   float GetAnchorHardness() const;
344
345   /**
346    * @brief Set the hardness of an anchor, or how much the anchor is allowed to drift.
347    *
348    * @param[in] hardness 0 means a soft anchor with no drift correction, 1 mean a hard anchor with full correction
349    *                 hardness will be clamped between 0 and 1.
350    */
351   void SetAnchorHardness( float hardness );
352
353   /**
354    * @brief Get the volume conservation coefficient.
355    *
356    * @return The volume conservation coefficient.
357    */
358   float GetVolumeConservation() const;
359
360   /**
361    * @brief Set the volume conservation coefficient.
362    *
363    * Defines the magnitude of the force used to conserve the volume of the body after DynamicsBody::ConserveVolume is invoked
364    * @param[in] conservation Range 0 <= conservation < +infinity
365    */
366   void SetVolumeConservation(float conservation);
367
368   /**
369    * @brief Get the shape conservation factor.
370    *
371    * @return The shape conservation factor.
372    */
373   float GetShapeConservation() const;
374
375   /**
376    * @brief Set the shape conservation factor.
377    *
378    * Defines the factor used to match the shape of the body when DynamicsBody::ConserveShape. is invoked
379    * @param[in] conservation Range 0 <= conservation < 1
380    */
381   void SetShapeConservation(float conservation);
382
383   // Not intended for application developers
384 private:
385   /**
386    * @brief This constructor is used internally by Dali.
387    *
388    * @param [in] internal A pointer to a newly allocated Dali resource
389    */
390   explicit DALI_INTERNAL DynamicsBodyConfig( Internal::DynamicsBodyConfig* internal );
391 }; // class DynamicsBodyConfig
392
393 } // namespace Dali
394
395 #endif /* __DALI_DYNAMICS_BODY_CONFIG_H__ */