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 "Reflection/BsRTTIType.h" |
7 | #include "Physics/BsPhysicsMaterial.h" |
8 | |
9 | namespace bs |
10 | { |
11 | /** @cond RTTI */ |
12 | /** @addtogroup RTTI-Impl-Core |
13 | * @{ |
14 | */ |
15 | |
16 | class BS_CORE_EXPORT PhysicsMaterialRTTI : public RTTIType<PhysicsMaterial, Resource, PhysicsMaterialRTTI> |
17 | { |
18 | private: |
19 | float& getStaticFriction(PhysicsMaterial* obj) |
20 | { |
21 | return mStaticFriction; |
22 | } |
23 | |
24 | void setStaticFriction(PhysicsMaterial* obj, float& size) { obj->setStaticFriction(size); } |
25 | |
26 | float& getDynamicFriction(PhysicsMaterial* obj) |
27 | { |
28 | return mDynamicFriction; |
29 | } |
30 | |
31 | void setDynamicFriction(PhysicsMaterial* obj, float& size) { obj->setDynamicFriction(size); } |
32 | |
33 | float& getRestitutionCoefficient(PhysicsMaterial* obj) |
34 | { |
35 | return mRestitutionCoefficient; |
36 | } |
37 | |
38 | void setRestitutionCoefficient(PhysicsMaterial* obj, float& size) { obj->setRestitutionCoefficient(size); } |
39 | |
40 | public: |
41 | PhysicsMaterialRTTI() |
42 | { |
43 | addPlainField("staticFriction" , 0, &PhysicsMaterialRTTI::getStaticFriction, &PhysicsMaterialRTTI::setStaticFriction); |
44 | addPlainField("dynamicFriction" , 1, &PhysicsMaterialRTTI::getDynamicFriction, &PhysicsMaterialRTTI::setDynamicFriction); |
45 | addPlainField("restitutionCoefficient" , 2, &PhysicsMaterialRTTI::getRestitutionCoefficient, &PhysicsMaterialRTTI::setRestitutionCoefficient); |
46 | } |
47 | |
48 | void onSerializationStarted(IReflectable* obj, SerializationContext* context) override |
49 | { |
50 | PhysicsMaterial* material = static_cast<PhysicsMaterial*>(obj); |
51 | |
52 | mStaticFriction = material->getStaticFriction(); |
53 | mDynamicFriction = material->getDynamicFriction(); |
54 | mRestitutionCoefficient = material->getRestitutionCoefficient(); |
55 | } |
56 | |
57 | const String& getRTTIName() override |
58 | { |
59 | static String name = "PhysicsMaterial" ; |
60 | return name; |
61 | } |
62 | |
63 | UINT32 getRTTIId() override |
64 | { |
65 | return TID_PhysicsMaterial; |
66 | } |
67 | |
68 | SPtr<IReflectable> newRTTIObject() override |
69 | { |
70 | return PhysicsMaterial::_createPtr(); |
71 | } |
72 | |
73 | private: |
74 | float mStaticFriction; |
75 | float mDynamicFriction; |
76 | float mRestitutionCoefficient; |
77 | }; |
78 | |
79 | /** @} */ |
80 | /** @endcond */ |
81 | } |