53127428bb7fabd02c3ac8fc0331a052a09fcab5
[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   /**
114    * @brief This method is defined to allow assignment of the NULL value,
115    * and will throw an exception if passed any other value.
116    *
117    * Assigning to NULL is an alias for Reset().
118    * @param [in] rhs  A NULL pointer
119    * @return A reference to this handle
120    */
121   DynamicsBodyConfig& operator=(BaseHandle::NullType* rhs);
122
123 public:
124   /**
125    * @brief Set the type of DynamicsBody.
126    *
127    * @param[in] type A member of BodyType enumeration.
128    */
129   void SetType( const BodyType type );
130
131   /**
132    * @brief Get the type of DynamicsBody specified by the Configuration.
133    *
134    * @return A member of BodyType enumeration.
135    */
136   BodyType GetType() const;
137
138   /**
139    * @brief Define the shape for the body.
140    *
141    * @param[in] type        The type of shape
142    * @param[in] dimensions  The parameters defining the shape ...
143    *                        - DynamicsShape::SPHERE
144    *                          - x radius
145    *                        - DynamicsShape::CUBE
146    *                          - x width of cube
147    *                          - y height of cube
148    *                          - z depth of cube
149    *                        - DynamicsShape::CYLINDER
150    *                          - x radius of ends
151    *                          - y length if cylinder
152    *                        - DynamicsShape::CAPSULE
153    *                          - x radius of end caps
154    *                          - y length of capsule
155    *                        - DynamicsShape::CONE
156    *                          - x radius of base
157    *                          - y length of cone
158    *                        - DynamicsShape::MESH
159    *                          - x width
160    *                          - y height
161    *                          - z number of extra division on x and y
162    */
163   void SetShape(const DynamicsShape::ShapeType type, const Vector3& dimensions);
164
165   /**
166    * @brief Set the shape for the body.
167    *
168    * @param[in] shape A DynamicsShape.
169    */
170   void SetShape( DynamicsShape shape );
171
172   /**
173    * @brief get the shape for the body.
174    *
175    * @return A DynamicsShape.
176    */
177   DynamicsShape GetShape() const;
178
179   /**
180    * @brief Set the mass for the body.
181    *
182    * @param[in] mass The mass for the body.
183    */
184   void SetMass( float mass);
185
186   /**
187    * @brief Get the mass that will be set on bodies created from this config.
188    *
189    * @return The mass that will be set on bodies created from this config
190    */
191   float GetMass() const;
192
193   /**
194    * @brief Get the @"elasticity@" of the body.
195    *
196    * @return The @"elasticity@".
197    *
198    * See @ref SetElasticity
199    */
200   float GetElasticity() const;
201
202   /**
203    * @brief Affects the @"elasticity@" of the body.
204    *
205    * This function sets the coefficient of restitution (COR) of an object.@n
206    * @param[in] elasticity The elasticity of the body.
207    *                       Assuming the other body in a collision has a elasticity factor of 1.
208    *                       Set elasticity == 0 to inhibit bouncing at impact, reduces the velocity of the body to 0.
209    *                       Set elasticity > 1 will increase the velocity of the object after impact
210    */
211   void SetElasticity(float elasticity);
212
213   /**
214    * @brief Get the friction coefficient for any DynamicsBody created from this DynamicsBodyConfig.
215    *
216    * @return The friction coefficient.
217    *
218    * See @ref SetFriction.
219    */
220   float GetFriction() const;
221
222   /**
223    * @brief Set the friction coefficient for any DynamicsBody created from this DynamicsBodyConfig.
224    *
225    * @param[in] friction The friction coefficient.
226    *                     This will be clamped between 0 and 1
227    */
228   void SetFriction(float friction);
229
230   /**
231    * @brief Get the linear damping coefficient for any DynamicsBody created from this DynamicsBodyConfig.
232    *
233    * @return The linear damping coefficient.
234    * See @ref SetLinearDamping.
235    */
236   float GetLinearDamping() const;
237
238   /**
239    * @brief Set the linear damping coefficient for any DynamicsBody created from this DynamicsBodyConfig.
240    *
241    * @param[in] damping The linear damping coefficient.
242    *                    This will be clamped between 0 and 1
243    */
244   void SetLinearDamping( float damping );
245
246   /**
247    * @brief Get the angular damping coefficient for any DynamicsBody created from this DynamicsBodyConfig.
248    *
249    * @return The angular damping coefficient.
250    *
251    * See @ref SetAngularDamping.
252    */
253   float GetAngularDamping() const;
254
255   /**
256    * @brief Set the angular damping coefficient for any DynamicsBody created from this DynamicsBodyConfig.
257    *
258    * @param[in] damping The angular damping coefficient.
259    *                    This will be clamped between 0 and 1
260    */
261   void SetAngularDamping(float damping);
262
263   /**
264    * @brief Get the linear velocity below which the DynamicsBody can be put to sleep by the simulation.
265    *
266    * @return The linear sleep velocity.
267    *
268    * See @ref SetLinearSleepVelocity, DynamicsBody::SetSleepEnabled.
269    */
270   float GetLinearSleepVelocity() const;
271
272   /**
273    * @brief Set the linear velocity below which the DynamicsBody can be put to sleep by the simulation.
274    *
275    * @param[in] sleepVelocity The linear sleep velocity.
276    *
277    * See @ref DynamicsBody::SetSleepEnabled.
278    */
279   void SetLinearSleepVelocity(float sleepVelocity);
280
281   /**
282    * @brief Get the angular velocity below which the DynamicsBody can be put to sleep by the simulation.
283    *
284    * @return The angular sleep velocity.
285    *
286    * See @ref SetAngularSleepVelocity, DynamicsBody::SetSleepEnabled.
287    */
288   float GetAngularSleepVelocity() const;
289
290   /**
291    * @brief Set the angular velocity below which the DynamicsBody can be put to sleep by the simulation.
292    *
293    * @param[in] sleepVelocity The angular sleep velocity.
294    *
295    * See @ref DynamicsBody::SetSleepEnabled.
296    */
297   void SetAngularSleepVelocity(float sleepVelocity);
298
299   /**
300    * @brief Get the collision filter group.@n
301    *
302    * See @ref CollisionFilter
303    * @return The collision filter group.@n
304    */
305   short int GetCollisionGroup() const;
306
307   /**
308    * @brief Set the collision filter group.
309    *
310    * See @ref CollisionFilter
311    * @param[in] collisionGroup The collision filter group
312    */
313   void SetCollisionGroup(const short int collisionGroup);
314
315   /**
316    * @brief Get the collision filter mask.@n
317    *
318    * See @ref CollisionFilter
319    * @return The collision filter mask.@n
320    */
321   short int GetCollisionMask() const;
322
323   /**
324    * @brief Set the collision filter mask.
325    *
326    * See @ref CollisionFilter
327    * @param[in] collisionMask The collision filter mask
328    */
329   void SetCollisionMask(const short int collisionMask);
330
331   /**
332    * @brief Get the stiffness coefficient for the soft body.
333    *
334    * See @ref SetStiffness
335    * @return The stiffness coefficient for the soft body.
336    */
337   float GetStiffness() const;
338
339   /**
340    * @brief Set the stiffness co-efficient for the soft body.
341    *
342    * @param[in] stiffness A value clamped between 0 and 1.
343    *                      Values closer to 1 make it more stiff.
344    */
345   void SetStiffness( float stiffness );
346
347   /**
348    * @brief Get the anchor hardness.@n
349    *
350    * See @ref SetAnchorHardness.
351    * @return The anchor hardness.
352    */
353   float GetAnchorHardness() const;
354
355   /**
356    * @brief Set the hardness of an anchor, or how much the anchor is allowed to drift.
357    *
358    * @param[in] hardness 0 means a soft anchor with no drift correction, 1 mean a hard anchor with full correction
359    *                 hardness will be clamped between 0 and 1.
360    */
361   void SetAnchorHardness( float hardness );
362
363   /**
364    * @brief Get the volume conservation coefficient.
365    *
366    * @return The volume conservation coefficient.
367    */
368   float GetVolumeConservation() const;
369
370   /**
371    * @brief Set the volume conservation coefficient.
372    *
373    * Defines the magnitude of the force used to conserve the volume of the body after DynamicsBody::ConserveVolume is invoked
374    * @param[in] conservation Range 0 <= conservation < +infinity
375    */
376   void SetVolumeConservation(float conservation);
377
378   /**
379    * @brief Get the shape conservation factor.
380    *
381    * @return The shape conservation factor.
382    */
383   float GetShapeConservation() const;
384
385   /**
386    * @brief Set the shape conservation factor.
387    *
388    * Defines the factor used to match the shape of the body when DynamicsBody::ConserveShape. is invoked
389    * @param[in] conservation Range 0 <= conservation < 1
390    */
391   void SetShapeConservation(float conservation);
392
393   // Not intended for application developers
394 private:
395   /**
396    * @brief This constructor is used internally by Dali.
397    *
398    * @param [in] internal A pointer to a newly allocated Dali resource
399    */
400   explicit DALI_INTERNAL DynamicsBodyConfig( Internal::DynamicsBodyConfig* internal );
401 }; // class DynamicsBodyConfig
402
403 } // namespace Dali
404
405 #endif /* __DALI_DYNAMICS_BODY_CONFIG_H__ */