1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
3 | #pragma once |
4 | |
5 | #include "BsCorePrerequisites.h" |
6 | #include "Resources/BsResource.h" |
7 | |
8 | namespace bs |
9 | { |
10 | /** @addtogroup Physics |
11 | * @{ |
12 | */ |
13 | |
14 | /** |
15 | * Material that controls how two physical objects interact with each other. Materials of both objects are used during |
16 | * their interaction and their combined values are used. |
17 | */ |
18 | class BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:Physics) PhysicsMaterial : public Resource |
19 | { |
20 | public: |
21 | virtual ~PhysicsMaterial() = default; |
22 | |
23 | /** |
24 | * Controls friction when two in-contact objects are not moving lateral to each other (for example how difficult |
25 | * it is to get an object moving from a static state while it is in contact with other object(s)). |
26 | */ |
27 | BS_SCRIPT_EXPORT(n:StaticFriction,pr:setter) |
28 | virtual void setStaticFriction(float value) = 0; |
29 | |
30 | /** @copydoc setStaticFriction() */ |
31 | BS_SCRIPT_EXPORT(n:StaticFriction,pr:getter) |
32 | virtual float getStaticFriction() const = 0; |
33 | |
34 | /** |
35 | * Controls friction when two in-contact objects are moving lateral to each other (for example how quickly does an |
36 | * object slow down when sliding along another object). |
37 | */ |
38 | BS_SCRIPT_EXPORT(n:DynamicFriction,pr:setter) |
39 | virtual void setDynamicFriction(float value) = 0; |
40 | |
41 | /** @copydoc setDynamicFriction() */ |
42 | BS_SCRIPT_EXPORT(n:DynamicFriction,pr:getter) |
43 | virtual float getDynamicFriction() const = 0; |
44 | |
45 | /** |
46 | * Controls "bounciness" of an object during a collision. Value of 1 means the collision is elastic, and value of 0 |
47 | * means the value is inelastic. Must be in [0, 1] range. |
48 | */ |
49 | BS_SCRIPT_EXPORT(n:Restitution,pr:setter) |
50 | virtual void setRestitutionCoefficient(float value) = 0; |
51 | |
52 | /** @copydoc setRestitutionCoefficient() */ |
53 | BS_SCRIPT_EXPORT(n:Restitution,pr:getter) |
54 | virtual float getRestitutionCoefficient() const = 0; |
55 | |
56 | /** |
57 | * Creates a new physics material. |
58 | * |
59 | * @param[in] staticFriction Controls friction when two in-contact objects are not moving lateral to each other |
60 | * (for example how difficult is to get an object moving from a static state while it |
61 | * is in contact other object(s)). |
62 | * @param[in] dynamicFriction Sets dynamic friction of the material. Controls friction when two in-contact objects |
63 | * are moving lateral to each other (for example how quickly does an object slow down |
64 | * when sliding along another object). |
65 | * @param[in] restitution Controls "bounciness" of an object during a collision. Value of 1 means the |
66 | * collision is elastic, and value of 0 means the value is inelastic. Must be in |
67 | * [0, 1] range. |
68 | */ |
69 | BS_SCRIPT_EXPORT(ec:PhysicsMaterial) |
70 | static HPhysicsMaterial create(float staticFriction = 0.0f, float dynamicFriction = 0.0f, float restitution = 0.0f); |
71 | |
72 | /** @name Internal |
73 | * @{ |
74 | */ |
75 | |
76 | /** |
77 | * @copydoc create() |
78 | * |
79 | * For internal use. Requires manual initialization after creation. |
80 | */ |
81 | static SPtr<PhysicsMaterial> _createPtr(float staticFriction = 0.0f, float dynamicFriction = 0.0f, |
82 | float restitution = 0.0f); |
83 | |
84 | /** @} */ |
85 | |
86 | /************************************************************************/ |
87 | /* SERIALIZATION */ |
88 | /************************************************************************/ |
89 | public: |
90 | friend class PhysicsMaterialRTTI; |
91 | static RTTITypeBase* getRTTIStatic(); |
92 | RTTITypeBase* getRTTI() const override; |
93 | }; |
94 | |
95 | /** @} */ |
96 | } |