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 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 // BASE CLASS INCLUDES
25 #include <dali/public-api/object/base-handle.h>
28 #include <dali/public-api/dynamics/dynamics-shape.h>
35 namespace Internal DALI_INTERNAL
37 class DynamicsBodyConfig;
38 } // namespace Internal
41 * @brief Describes a DynamicsBody configuration.
43 * Use to create multiple instances of a DynamicsBody
45 class DALI_IMPORT_API DynamicsBodyConfig : public BaseHandle
50 * @brief Enumeration of the types of dynamics bodies.
54 RIGID, ///< May have mass and therefore be affected by gravity and have velocity
55 SOFT, ///< Has a deformable shape - implies RIGID
59 * @brief Collision filtering flags.
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
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
76 * @brief Create a new DynamicsBody configuration object.
78 * All values are set to default values...
79 * @pre Stage::InitializeDynamics() must have been called
80 * @return a handle to the new DynamicsBodyconfig.
82 static DynamicsBodyConfig New();
85 * @brief Create an uninitialized handle.
87 * Initialize with one of the DynamicsBodyConfig New methods
94 * This is non-virtual since derived Handle types must not contain data or virtual methods.
96 ~DynamicsBodyConfig();
99 * @brief This copy constructor is required for (smart) pointer semantics.
101 * @param [in] handle A reference to the copied handle
103 DynamicsBodyConfig(const DynamicsBodyConfig& handle);
106 * @brief This assignment operator is required for (smart) pointer semantics.
108 * @param [in] rhs A reference to the copied handle
109 * @return A reference to this
111 DynamicsBodyConfig& operator=(const DynamicsBodyConfig& rhs);
114 * @brief This method is defined to allow assignment of the NULL value,
115 * and will throw an exception if passed any other value.
117 * Assigning to NULL is an alias for Reset().
118 * @param [in] rhs A NULL pointer
119 * @return A reference to this handle
121 DynamicsBodyConfig& operator=(BaseHandle::NullType* rhs);
125 * @brief Set the type of DynamicsBody.
127 * @param[in] type A member of BodyType enumeration.
129 void SetType( const BodyType type );
132 * @brief Get the type of DynamicsBody specified by the Configuration.
134 * @return A member of BodyType enumeration.
136 BodyType GetType() const;
139 * @brief Define the shape for the body.
141 * @param[in] type The type of shape
142 * @param[in] dimensions The parameters defining the shape ...
143 * - DynamicsShape::SPHERE
145 * - DynamicsShape::CUBE
149 * - DynamicsShape::CYLINDER
151 * - y length if cylinder
152 * - DynamicsShape::CAPSULE
153 * - x radius of end caps
154 * - y length of capsule
155 * - DynamicsShape::CONE
158 * - DynamicsShape::MESH
161 * - z number of extra division on x and y
163 void SetShape(const DynamicsShape::ShapeType type, const Vector3& dimensions);
166 * @brief Set the shape for the body.
168 * @param[in] shape A DynamicsShape.
170 void SetShape( DynamicsShape shape );
173 * @brief get the shape for the body.
175 * @return A DynamicsShape.
177 DynamicsShape GetShape() const;
180 * @brief Set the mass for the body.
182 * @param[in] mass The mass for the body.
184 void SetMass( float mass);
187 * @brief Get the mass that will be set on bodies created from this config.
189 * @return The mass that will be set on bodies created from this config
191 float GetMass() const;
194 * @brief Get the @"elasticity@" of the body.
196 * @return The @"elasticity@".
198 * See @ref SetElasticity
200 float GetElasticity() const;
203 * @brief Affects the @"elasticity@" of the body.
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
211 void SetElasticity(float elasticity);
214 * @brief Get the friction coefficient for any DynamicsBody created from this DynamicsBodyConfig.
216 * @return The friction coefficient.
218 * See @ref SetFriction.
220 float GetFriction() const;
223 * @brief Set the friction coefficient for any DynamicsBody created from this DynamicsBodyConfig.
225 * @param[in] friction The friction coefficient.
226 * This will be clamped between 0 and 1
228 void SetFriction(float friction);
231 * @brief Get the linear damping coefficient for any DynamicsBody created from this DynamicsBodyConfig.
233 * @return The linear damping coefficient.
234 * See @ref SetLinearDamping.
236 float GetLinearDamping() const;
239 * @brief Set the linear damping coefficient for any DynamicsBody created from this DynamicsBodyConfig.
241 * @param[in] damping The linear damping coefficient.
242 * This will be clamped between 0 and 1
244 void SetLinearDamping( float damping );
247 * @brief Get the angular damping coefficient for any DynamicsBody created from this DynamicsBodyConfig.
249 * @return The angular damping coefficient.
251 * See @ref SetAngularDamping.
253 float GetAngularDamping() const;
256 * @brief Set the angular damping coefficient for any DynamicsBody created from this DynamicsBodyConfig.
258 * @param[in] damping The angular damping coefficient.
259 * This will be clamped between 0 and 1
261 void SetAngularDamping(float damping);
264 * @brief Get the linear velocity below which the DynamicsBody can be put to sleep by the simulation.
266 * @return The linear sleep velocity.
268 * See @ref SetLinearSleepVelocity, DynamicsBody::SetSleepEnabled.
270 float GetLinearSleepVelocity() const;
273 * @brief Set the linear velocity below which the DynamicsBody can be put to sleep by the simulation.
275 * @param[in] sleepVelocity The linear sleep velocity.
277 * See @ref DynamicsBody::SetSleepEnabled.
279 void SetLinearSleepVelocity(float sleepVelocity);
282 * @brief Get the angular velocity below which the DynamicsBody can be put to sleep by the simulation.
284 * @return The angular sleep velocity.
286 * See @ref SetAngularSleepVelocity, DynamicsBody::SetSleepEnabled.
288 float GetAngularSleepVelocity() const;
291 * @brief Set the angular velocity below which the DynamicsBody can be put to sleep by the simulation.
293 * @param[in] sleepVelocity The angular sleep velocity.
295 * See @ref DynamicsBody::SetSleepEnabled.
297 void SetAngularSleepVelocity(float sleepVelocity);
300 * @brief Get the collision filter group.@n
302 * See @ref CollisionFilter
303 * @return The collision filter group.@n
305 short int GetCollisionGroup() const;
308 * @brief Set the collision filter group.
310 * See @ref CollisionFilter
311 * @param[in] collisionGroup The collision filter group
313 void SetCollisionGroup(const short int collisionGroup);
316 * @brief Get the collision filter mask.@n
318 * See @ref CollisionFilter
319 * @return The collision filter mask.@n
321 short int GetCollisionMask() const;
324 * @brief Set the collision filter mask.
326 * See @ref CollisionFilter
327 * @param[in] collisionMask The collision filter mask
329 void SetCollisionMask(const short int collisionMask);
332 * @brief Get the stiffness coefficient for the soft body.
334 * See @ref SetStiffness
335 * @return The stiffness coefficient for the soft body.
337 float GetStiffness() const;
340 * @brief Set the stiffness co-efficient for the soft body.
342 * @param[in] stiffness A value clamped between 0 and 1.
343 * Values closer to 1 make it more stiff.
345 void SetStiffness( float stiffness );
348 * @brief Get the anchor hardness.@n
350 * See @ref SetAnchorHardness.
351 * @return The anchor hardness.
353 float GetAnchorHardness() const;
356 * @brief Set the hardness of an anchor, or how much the anchor is allowed to drift.
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.
361 void SetAnchorHardness( float hardness );
364 * @brief Get the volume conservation coefficient.
366 * @return The volume conservation coefficient.
368 float GetVolumeConservation() const;
371 * @brief Set the volume conservation coefficient.
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
376 void SetVolumeConservation(float conservation);
379 * @brief Get the shape conservation factor.
381 * @return The shape conservation factor.
383 float GetShapeConservation() const;
386 * @brief Set the shape conservation factor.
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
391 void SetShapeConservation(float conservation);
393 // Not intended for application developers
396 * @brief This constructor is used internally by Dali.
398 * @param [in] internal A pointer to a newly allocated Dali resource
400 explicit DALI_INTERNAL DynamicsBodyConfig( Internal::DynamicsBodyConfig* internal );
401 }; // class DynamicsBodyConfig
405 #endif /* __DALI_DYNAMICS_BODY_CONFIG_H__ */