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-2018 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 
32 
33 
37  Collidable(true), AABBCallback(nullptr), ContactCallback(nullptr)
38  {}
39 
41  Collidable(other.Collidable), AABBCallback(std::move(other.AABBCallback)),
42  ContactCallback(std::move(other.ContactCallback))
43  {}
44 
46  {
47  Collidable = other.Collidable;
48  AABBCallback = std::move(other.AABBCallback);
49  ContactCallback = std::move(other.ContactCallback);
50  return *this;
51  }
52 
58  DLLEXPORT inline PhysMaterialDataPair& SetCollidable(bool collidable)
59  {
60  Collidable = collidable;
61  return *this;
62  }
63 
64  // //! \brief Sets the softness of the material pair
65  // //!
66  // //! Recommended 1.f and below, default 0.15f, higher value is less soft)
67  // DLLEXPORT inline PhysMaterialDataPair& SetSoftness(const float& softness)
68  // {
69  // Softness = softness;
70  // return *this;
71  // }
72 
73  // //! \brief Sets the elasticity (restitution) of the material pair
74  // //!
75  // //! Recommended 1.f and below, default 0.4f, higher value might be more elasticity)
76  // DLLEXPORT inline PhysMaterialDataPair& SetElasticity(const float& elasticity)
77  // {
78  // Elasticity = elasticity;
79  // return *this;
80  // }
81 
82  // //! \brief Sets the friction between the materials
83  // //!
84  // //! default static is 0.9f and dynamic (sliding) 0.5f
85  // DLLEXPORT inline PhysMaterialDataPair& SetFriction(
86  // const float& staticfriction, const float& dynamicfriction)
87  // {
88  // DynamicFriction = dynamicfriction;
89  // StaticFriction = staticfriction;
90  // return *this;
91  // }
92 
96  {
97  AABBCallback = aabb;
98  ContactCallback = contact;
99  return *this;
100  }
101 
102  // ------------------------------------ //
104  // float Elasticity;
105  // float StaticFriction;
106  // float DynamicFriction;
107  // float Softness;
108 
109  // Callbacks //
112 };
113 
115  friend PhysicsMaterialManager;
116 
117 public:
119  DLLEXPORT PhysicalMaterial(const std::string& name, int id);
120  // DLLEXPORT PhysicalMaterial(std::shared_ptr<ObjectFileObject> fileobject);
122 
126 
128  inline auto* GetPairWith(int otherid) const
129  {
130  const auto found = InterractionsWith.find(otherid);
131 
132  if(found == InterractionsWith.end())
133  return static_cast<const PhysMaterialDataPair*>(nullptr);
134 
135  return &found->second;
136  }
137 
139  {
140  return ID;
141  }
142 
143  // \todo file loading function //
144 
145 
146  DLLEXPORT inline std::string GetName() const
147  {
148  return Name;
149  }
150 
151 private:
152  const std::string Name;
153  const int ID;
154 
156  std::unordered_map<int, PhysMaterialDataPair> InterractionsWith;
157 };
158 
159 } // namespace Leviathan
DLLEXPORT PhysMaterialDataPair & FormPairWith(const PhysicalMaterial &other)
Data pairing.
auto * GetPairWith(int otherid) const
Returns data for this material to interact with another.
PhysicsMaterialContactCallback ContactCallback
STL namespace.
Defines properties between two materials.
This is an instance of a collision body.
Definition: PhysicsBody.h:74
DLLEXPORT std::string GetName() const
DLLEXPORT PhysMaterialDataPair & SetCallbacks(const PhysicsMaterialAABBCallback aabb, const PhysicsMaterialContactCallback contact)
Sets the callback functions that are called when the material interacts.
void(*)(PhysicalWorld &world, PhysicsBody &, PhysicsBody &) PhysicsMaterialContactCallback
DLLEXPORT PhysicalMaterial(const std::string &name, int id)
DLLEXPORT PhysMaterialDataPair & operator=(PhysMaterialDataPair &&other)
Contains a material list for applying automatic properties to PhysicsBody and collision callbacks...
#define DLLEXPORT
Definition: Include.h:115
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)