1 #ifndef __DALI_DYNAMICS_BODY_CONFIG_H__
2 #define __DALI_DYNAMICS_BODY_CONFIG_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 // http://floralicense.org/license/
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.
23 // BASE CLASS INCLUDES
24 #include <dali/public-api/object/base-handle.h>
27 #include <dali/public-api/dynamics/dynamics-shape.h>
29 namespace Dali DALI_IMPORT_API
34 namespace Internal DALI_INTERNAL
36 class DynamicsBodyConfig;
37 } // namespace Internal
40 * @brief Describes a DynamicsBody configuration.
42 * Use to create multiple instances of a DynamicsBody
44 class DynamicsBodyConfig : public BaseHandle
49 * @brief Enumeration of the types of dynamics bodies.
53 RIGID, ///< May have mass and therefore be affected by gravity and have velocity
54 SOFT, ///< Has a deformable shape - implies RIGID
58 * @brief Collision filtering flags.
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
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
75 * @brief Create a new DynamicsBody configuration object.
77 * All values are set to default values...
78 * @pre Stage::InitializeDynamics() must have been called
79 * @return a handle to the new DynamicsBodyconfig.
81 static DynamicsBodyConfig New();
84 * @brief Create an uninitialized handle.
86 * Initialize with one of the DynamicsBodyConfig New methods
91 * @brief Virtual destructor.
93 virtual ~DynamicsBodyConfig();
96 * @copydoc Dali::BaseHandle::operator=
98 using BaseHandle::operator=;
102 * @brief Set the type of DynamicsBody.
104 * @param[in] type A member of BodyType enumeration.
106 void SetType( const BodyType type );
109 * @brief Get the type of DynamicsBody specified by the Configuration.
111 * @return A member of BodyType enumeration.
113 BodyType GetType() const;
116 * @brief Define the shape for the body.
118 * @param[in] type The type of shape
119 * @param[in] dimensions The parameters defining the shape ...
120 * - DynamicsShape::SPHERE
122 * - DynamicsShape::CUBE
126 * - DynamicsShape::CYLINDER
128 * - y length if cylinder
129 * - DynamicsShape::CAPSULE
130 * - x radius of end caps
131 * - y length of capsule
132 * - DynamicsShape::CONE
135 * - DynamicsShape::MESH
138 * - z number of extra division on x and y
140 void SetShape(const DynamicsShape::ShapeType type, const Vector3& dimensions);
143 * @brief Set the shape for the body.
145 * @param[in] shape A DynamicsShape.
147 void SetShape( DynamicsShape shape );
150 * @brief get the shape for the body.
152 * @return A DynamicsShape.
154 DynamicsShape GetShape() const;
157 * @brief Set the mass for the body.
159 * @param[in] mass The mass for the body.
161 void SetMass( const float mass);
164 * @brief Get the mass that will be set on bodies created from this config.
166 * @return The mass that will be set on bodies created from this config
168 float GetMass() const;
171 * @brief Get the @"elasticity@" of the body.
173 * @return The @"elasticity@".
175 * See @ref SetElasticity
177 float GetElasticity() const;
180 * @brief Affects the @"elasticity@" of the body.
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
188 void SetElasticity(const float elasticity);
191 * @brief Get the friction coefficient for any DynamicsBody created from this DynamicsBodyConfig.
193 * @return The friction coefficient.
195 * See @ref SetFriction.
197 float GetFriction() const;
200 * @brief Set the friction coefficient for any DynamicsBody created from this DynamicsBodyConfig.
202 * @param[in] friction The friction coefficient.
203 * This will be clamped between 0 and 1
205 void SetFriction(const float friction);
208 * @brief Get the linear damping coefficient for any DynamicsBody created from this DynamicsBodyConfig.
210 * @return The linear damping coefficient.
211 * See @ref SetLinearDamping.
213 float GetLinearDamping() const;
216 * @brief Set the linear damping coefficient for any DynamicsBody created from this DynamicsBodyConfig.
218 * @param[in] damping The linear damping coefficient.
219 * This will be clamped between 0 and 1
221 void SetLinearDamping( const float damping );
224 * @brief Get the angular damping coefficient for any DynamicsBody created from this DynamicsBodyConfig.
226 * @return The angular damping coefficient.
228 * See @ref SetAngularDamping.
230 float GetAngularDamping() const;
233 * @brief Set the angular damping coefficient for any DynamicsBody created from this DynamicsBodyConfig.
235 * @param[in] damping The angular damping coefficient.
236 * This will be clamped between 0 and 1
238 void SetAngularDamping(const float damping);
241 * @brief Get the linear velocity below which the DynamicsBody can be put to sleep by the simulation.
243 * @return The linear sleep velocity.
245 * See @ref SetLinearSleepVelocity, DynamicsBody::SetSleepEnabled.
247 float GetLinearSleepVelocity() const;
250 * @brief Set the linear velocity below which the DynamicsBody can be put to sleep by the simulation.
252 * @param[in] sleepVelocity The linear sleep velocity.
254 * See @ref DynamicsBody::SetSleepEnabled.
256 void SetLinearSleepVelocity(const float sleepVelocity);
259 * @brief Get the angular velocity below which the DynamicsBody can be put to sleep by the simulation.
261 * @return The angular sleep velocity.
263 * See @ref SetAngularSleepVelocity, DynamicsBody::SetSleepEnabled.
265 float GetAngularSleepVelocity() const;
268 * @brief Set the angular velocity below which the DynamicsBody can be put to sleep by the simulation.
270 * @param[in] sleepVelocity The angular sleep velocity.
272 * See @ref DynamicsBody::SetSleepEnabled.
274 void SetAngularSleepVelocity(const float sleepVelocity);
277 * @brief Get the collision filter group.@n
279 * See @ref CollisionFilter
280 * @return The collision filter group.@n
282 short int GetCollisionGroup() const;
285 * @brief Set the collision filter group.
287 * See @ref CollisionFilter
288 * @param[in] collisionGroup The collision filter group
290 void SetCollisionGroup(const short int collisionGroup);
293 * @brief Get the collision filter mask.@n
295 * See @ref CollisionFilter
296 * @return The collision filter mask.@n
298 short int GetCollisionMask() const;
301 * @brief Set the collision filter mask.
303 * See @ref CollisionFilter
304 * @param[in] collisionMask The collision filter mask
306 void SetCollisionMask(const short int collisionMask);
309 * @brief Get the stiffness coefficient for the soft body.
311 * See @ref SetStiffness
312 * @return The stiffness coefficient for the soft body.
314 float GetStiffness() const;
317 * @brief Set the stiffness co-efficient for the soft body.
319 * @param[in] stiffness A value clamped between 0 and 1.
320 * Values closer to 1 make it more stiff.
322 void SetStiffness( const float stiffness );
325 * @brief Get the anchor hardness.@n
327 * See @ref SetAnchorHardness.
328 * @return The anchor hardness.
330 float GetAnchorHardness() const;
333 * @brief Set the hardness of an anchor, or how much the anchor is allowed to drift.
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.
338 void SetAnchorHardness( const float hardness );
341 * @brief Get the volume conservation coefficient.
343 * @return The volume conservation coefficient.
345 float GetVolumeConservation() const;
348 * @brief Set the volume conservation coefficient.
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
353 void SetVolumeConservation(const float conservation);
356 * @brief Get the shape conservation factor.
358 * @return The shape conservation factor.
360 float GetShapeConservation() const;
363 * @brief Set the shape conservation factor.
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
368 void SetShapeConservation(const float conservation);
370 // Not intended for application developers
373 * @brief This constructor is used internally by Dali.
375 * @param [in] internal A pointer to a newly allocated Dali resource
377 explicit DALI_INTERNAL DynamicsBodyConfig( Internal::DynamicsBodyConfig* internal );
378 }; // class DynamicsBodyConfig
382 #endif /* __DALI_DYNAMICS_BODY_CONFIG_H__ */