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