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);
115 * @brief Set the type of DynamicsBody.
117 * @param[in] type A member of BodyType enumeration.
119 void SetType( const BodyType type );
122 * @brief Get the type of DynamicsBody specified by the Configuration.
124 * @return A member of BodyType enumeration.
126 BodyType GetType() const;
129 * @brief Define the shape for the body.
131 * @param[in] type The type of shape
132 * @param[in] dimensions The parameters defining the shape ...
133 * - DynamicsShape::SPHERE
135 * - DynamicsShape::CUBE
139 * - DynamicsShape::CYLINDER
141 * - y length if cylinder
142 * - DynamicsShape::CAPSULE
143 * - x radius of end caps
144 * - y length of capsule
145 * - DynamicsShape::CONE
148 * - DynamicsShape::MESH
151 * - z number of extra division on x and y
153 void SetShape(const DynamicsShape::ShapeType type, const Vector3& dimensions);
156 * @brief Set the shape for the body.
158 * @param[in] shape A DynamicsShape.
160 void SetShape( DynamicsShape shape );
163 * @brief get the shape for the body.
165 * @return A DynamicsShape.
167 DynamicsShape GetShape() const;
170 * @brief Set the mass for the body.
172 * @param[in] mass The mass for the body.
174 void SetMass( float mass);
177 * @brief Get the mass that will be set on bodies created from this config.
179 * @return The mass that will be set on bodies created from this config
181 float GetMass() const;
184 * @brief Get the @"elasticity@" of the body.
186 * @return The @"elasticity@".
188 * See @ref SetElasticity
190 float GetElasticity() const;
193 * @brief Affects the @"elasticity@" of the body.
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
201 void SetElasticity(float elasticity);
204 * @brief Get the friction coefficient for any DynamicsBody created from this DynamicsBodyConfig.
206 * @return The friction coefficient.
208 * See @ref SetFriction.
210 float GetFriction() const;
213 * @brief Set the friction coefficient for any DynamicsBody created from this DynamicsBodyConfig.
215 * @param[in] friction The friction coefficient.
216 * This will be clamped between 0 and 1
218 void SetFriction(float friction);
221 * @brief Get the linear damping coefficient for any DynamicsBody created from this DynamicsBodyConfig.
223 * @return The linear damping coefficient.
224 * See @ref SetLinearDamping.
226 float GetLinearDamping() const;
229 * @brief Set the linear damping coefficient for any DynamicsBody created from this DynamicsBodyConfig.
231 * @param[in] damping The linear damping coefficient.
232 * This will be clamped between 0 and 1
234 void SetLinearDamping( float damping );
237 * @brief Get the angular damping coefficient for any DynamicsBody created from this DynamicsBodyConfig.
239 * @return The angular damping coefficient.
241 * See @ref SetAngularDamping.
243 float GetAngularDamping() const;
246 * @brief Set the angular damping coefficient for any DynamicsBody created from this DynamicsBodyConfig.
248 * @param[in] damping The angular damping coefficient.
249 * This will be clamped between 0 and 1
251 void SetAngularDamping(float damping);
254 * @brief Get the linear velocity below which the DynamicsBody can be put to sleep by the simulation.
256 * @return The linear sleep velocity.
258 * See @ref SetLinearSleepVelocity, DynamicsBody::SetSleepEnabled.
260 float GetLinearSleepVelocity() const;
263 * @brief Set the linear velocity below which the DynamicsBody can be put to sleep by the simulation.
265 * @param[in] sleepVelocity The linear sleep velocity.
267 * See @ref DynamicsBody::SetSleepEnabled.
269 void SetLinearSleepVelocity(float sleepVelocity);
272 * @brief Get the angular velocity below which the DynamicsBody can be put to sleep by the simulation.
274 * @return The angular sleep velocity.
276 * See @ref SetAngularSleepVelocity, DynamicsBody::SetSleepEnabled.
278 float GetAngularSleepVelocity() const;
281 * @brief Set the angular velocity below which the DynamicsBody can be put to sleep by the simulation.
283 * @param[in] sleepVelocity The angular sleep velocity.
285 * See @ref DynamicsBody::SetSleepEnabled.
287 void SetAngularSleepVelocity(float sleepVelocity);
290 * @brief Get the collision filter group.@n
292 * See @ref CollisionFilter
293 * @return The collision filter group.@n
295 short int GetCollisionGroup() const;
298 * @brief Set the collision filter group.
300 * See @ref CollisionFilter
301 * @param[in] collisionGroup The collision filter group
303 void SetCollisionGroup(const short int collisionGroup);
306 * @brief Get the collision filter mask.@n
308 * See @ref CollisionFilter
309 * @return The collision filter mask.@n
311 short int GetCollisionMask() const;
314 * @brief Set the collision filter mask.
316 * See @ref CollisionFilter
317 * @param[in] collisionMask The collision filter mask
319 void SetCollisionMask(const short int collisionMask);
322 * @brief Get the stiffness coefficient for the soft body.
324 * See @ref SetStiffness
325 * @return The stiffness coefficient for the soft body.
327 float GetStiffness() const;
330 * @brief Set the stiffness co-efficient for the soft body.
332 * @param[in] stiffness A value clamped between 0 and 1.
333 * Values closer to 1 make it more stiff.
335 void SetStiffness( float stiffness );
338 * @brief Get the anchor hardness.@n
340 * See @ref SetAnchorHardness.
341 * @return The anchor hardness.
343 float GetAnchorHardness() const;
346 * @brief Set the hardness of an anchor, or how much the anchor is allowed to drift.
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.
351 void SetAnchorHardness( float hardness );
354 * @brief Get the volume conservation coefficient.
356 * @return The volume conservation coefficient.
358 float GetVolumeConservation() const;
361 * @brief Set the volume conservation coefficient.
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
366 void SetVolumeConservation(float conservation);
369 * @brief Get the shape conservation factor.
371 * @return The shape conservation factor.
373 float GetShapeConservation() const;
376 * @brief Set the shape conservation factor.
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
381 void SetShapeConservation(float conservation);
383 // Not intended for application developers
386 * @brief This constructor is used internally by Dali.
388 * @param [in] internal A pointer to a newly allocated Dali resource
390 explicit DALI_INTERNAL DynamicsBodyConfig( Internal::DynamicsBodyConfig* internal );
391 }; // class DynamicsBodyConfig
395 #endif /* __DALI_DYNAMICS_BODY_CONFIG_H__ */