Leviathan  0.8.0.0
Leviathan game engine
PhysicalMaterial.h
Go to the documentation of this file.
1 // Leviathan Game Engine
2 // Copyright (c) 2012-2019 Henri Hyyryläinen
3 #pragma once
4 #include "Define.h"
5 // ------------------------------------ //
6 #include "PhysicalWorld.h"
7 
9 
10 
11 namespace Leviathan {
12 
13 class PhysicsBody;
14 class PhysicalWorld;
15 
23 
24 
29 using PhysicsMaterialContactCallback = void (*)(
31 
35 using PhysicsMaterialManifoldCallback = void (*)(
36  PhysicalWorld& world, PhysicsBody&, PhysicsBody&, const btPersistentManifold&);
37 
38 
39 
43  Collidable(true), AABBCallback(nullptr), ContactCallback(nullptr)
44  {}
45 
47  Collidable(other.Collidable), AABBCallback(std::move(other.AABBCallback)),
48  ContactCallback(std::move(other.ContactCallback))
49  {}
50 
52  {
53  Collidable = other.Collidable;
54  AABBCallback = std::move(other.AABBCallback);
55  ContactCallback = std::move(other.ContactCallback);
56  return *this;
57  }
58 
64  DLLEXPORT inline PhysMaterialDataPair& SetCollidable(bool collidable)
65  {
66  Collidable = collidable;
67  return *this;
68  }
69 
70  // //! \brief Sets the softness of the material pair
71  // //!
72  // //! Recommended 1.f and below, default 0.15f, higher value is less soft)
73  // DLLEXPORT inline PhysMaterialDataPair& SetSoftness(const float& softness)
74  // {
75  // Softness = softness;
76  // return *this;
77  // }
78 
79  // //! \brief Sets the elasticity (restitution) of the material pair
80  // //!
81  // //! Recommended 1.f and below, default 0.4f, higher value might be more elasticity)
82  // DLLEXPORT inline PhysMaterialDataPair& SetElasticity(const float& elasticity)
83  // {
84  // Elasticity = elasticity;
85  // return *this;
86  // }
87 
88  // //! \brief Sets the friction between the materials
89  // //!
90  // //! default static is 0.9f and dynamic (sliding) 0.5f
91  // DLLEXPORT inline PhysMaterialDataPair& SetFriction(
92  // const float& staticfriction, const float& dynamicfriction)
93  // {
94  // DynamicFriction = dynamicfriction;
95  // StaticFriction = staticfriction;
96  // return *this;
97  // }
98 
101  const PhysicsMaterialContactCallback contact,
102  PhysicsMaterialManifoldCallback manifold = nullptr)
103  {
104  AABBCallback = aabb;
105  ContactCallback = contact;
106  ManifoldCallback = manifold;
107  return *this;
108  }
109 
110  // ------------------------------------ //
112  // float Elasticity;
113  // float StaticFriction;
114  // float DynamicFriction;
115  // float Softness;
116 
117  // Callbacks //
121 };
122 
124  friend PhysicsMaterialManager;
125 
126 public:
128  DLLEXPORT PhysicalMaterial(const std::string& name, int id);
129  // DLLEXPORT PhysicalMaterial(std::shared_ptr<ObjectFileObject> fileobject);
131 
135 
137  inline auto* GetPairWith(int otherid) const
138  {
139  const auto found = InterractionsWith.find(otherid);
140 
141  if(found == InterractionsWith.end())
142  return static_cast<const PhysMaterialDataPair*>(nullptr);
143 
144  return &found->second;
145  }
146 
148  {
149  return ID;
150  }
151 
152  // \todo file loading function //
153 
154 
155  DLLEXPORT inline std::string GetName() const
156  {
157  return Name;
158  }
159 
160 private:
161  const std::string Name;
162  const int ID;
163 
165  std::unordered_map<int, PhysMaterialDataPair> InterractionsWith;
166 };
167 
168 } // namespace Leviathan
void(*)(PhysicalWorld &world, PhysicsBody &, PhysicsBody &, const btPersistentManifold &) PhysicsMaterialManifoldCallback
DLLEXPORT PhysMaterialDataPair & FormPairWith(const PhysicalMaterial &other)
Data pairing.
auto * GetPairWith(int otherid) const
Returns data for this material to interact with another.
PhysicsMaterialContactCallback ContactCallback
Defines properties between two materials.
PhysicsMaterialManifoldCallback ManifoldCallback
This is an instance of a collision body.
Definition: PhysicsBody.h:77
DLLEXPORT std::string GetName() const
void(*)(PhysicalWorld &world, PhysicsBody &, PhysicsBody &) PhysicsMaterialContactCallback
DLLEXPORT PhysicalMaterial(const std::string &name, int id)
DLLEXPORT PhysMaterialDataPair & operator=(PhysMaterialDataPair &&other)
DLLEXPORT PhysMaterialDataPair & SetCallbacks(const PhysicsMaterialAABBCallback aabb, const PhysicsMaterialContactCallback contact, PhysicsMaterialManifoldCallback manifold=nullptr)
Sets the callback functions that are called when the material interacts.
Contains a material list for applying automatic properties to PhysicsBody and collision callbacks.
#define DLLEXPORT
Definition: Include.h:84
DLLEXPORT PhysMaterialDataPair & SetCollidable(bool collidable)
Sets the material pair to collide or not with each other.
PhysicsMaterialAABBCallback AABBCallback
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
bool(*)(PhysicalWorld &world, PhysicsBody &, PhysicsBody &) PhysicsMaterialAABBCallback
DLLEXPORT PhysMaterialDataPair(PhysMaterialDataPair &&other)