Rehti MMORPG  1.0.0
Rehti MMORPG is a free and open source MMORPG game.
BasicTypes.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #define GLM_FORCE_DEPTH_ZERO_TO_ONE
4 #include <glm/gtc/quaternion.hpp>
5 #include <glm/mat4x4.hpp>
6 #include <glm/vec3.hpp>
7 
8 #include <array>
9 #include <memory>
10 #include <vector>
11 
12 // If you get an error here, you might need to run ./scripts/generate_assets.sh
13 #include "../../../assets/generated/GeneratedAnimations.hpp"
14 
15 #pragma region Constants
16 
17 constexpr uint32_t BONES_PER_VERTEX = 4;
18 constexpr uint32_t MAX_BONES = 50;
19 
20 constexpr glm::vec3 GAMEOBJECT_MIN = glm::vec3(-0.5f, -0.1f, -0.5f);
21 constexpr glm::vec3 GAMEOBJECT_MAX = glm::vec3(0.5f, 1.f, 0.5f);
22 
23 constexpr glm::vec3 CHARACTER_MIN = glm::vec3(-0.5f, 0.0f, -0.5f);
24 constexpr glm::vec3 CHARACTER_MAX = glm::vec3(0.5f, 2.0f, 0.5f);
25 
26 constexpr size_t OBJECT_TYPE_COUNT = 4;
27 
28 enum ObjectType : uint32_t
29 {
34  UNDEFINED
35 };
36 
37 std::array<ObjectType, OBJECT_TYPE_COUNT> getObjectTypes();
38 
39 std::array<AnimationType, ANIMATION_TYPE_COUNT> getAnimationTypes();
40 
41 uint32_t getAnimIndex(AnimationType animType);
42 
43 #pragma endregion
44 
45 #pragma region AnimationTypes
46 // Animation node. The data stored can also represent any kind of transformation.
48 {
49  glm::vec3 position;
50  glm::quat rotation;
51  glm::vec3 scale;
52 
57  glm::mat4 getTransformationMatrix() const;
58 
66  static GfxOrientation interpolate(GfxOrientation first, GfxOrientation second, float factor);
67 };
68 
70 {
71  double time;
72  std::array<GfxOrientation, MAX_BONES> bones;
73 };
74 
78 struct Animation
79 {
80  double totalTicks;
81  double ticksPerSecond;
82  float duration;
83  std::vector<AnimationNode> animationNodes;
84 };
85 
87 {
88  AnimationType currentAnimation;
89  double currentTicks;
90  std::array<Animation, ANIMATION_TYPE_COUNT> animations;
91 };
92 
93 struct BoneNode
94 {
95  glm::mat4 boneOffset;
96  int parent;
97  std::vector<uint32_t> children;
98 };
99 
101 {
104  std::array<glm::mat4, MAX_BONES> boneTransformations{};
105  std::vector<BoneNode> bones;
107  void advanceAnimation(float dt);
108 };
109 
110 #pragma endregion
111 
112 #pragma region GraphicsObjectTypes
113 
118 {
119  alignas(16) glm::vec3 direction;
120  alignas(16) glm::vec3 color;
121  float intensity;
122 };
123 
128 {
129  alignas(16) glm::vec3 position;
130  alignas(16) glm::vec3 color;
131  float intensity;
132 };
133 
135 {
136  alignas(16) glm::vec3 ambient;
137  alignas(16) glm::vec3 diffuse;
138  alignas(16) glm::vec3 specular;
139  float shininess;
141 };
142 
147 {
148  alignas(16) glm::vec3 position;
149  alignas(16) glm::vec3 direction;
150 };
151 
152 struct Hit
153 {
154  int id;
156  glm::vec3 hitPoint;
157  int button;
158 };
159 
160 struct ImageData
161 {
162  unsigned char* pixels;
163  int width;
164  int height;
165 };
166 
168 {
169  glm::vec3 pos;
170  glm::vec3 normal;
171  glm::uvec4 boneIDs;
172  glm::vec4 boneWeights;
173  glm::vec2 texCoord;
174 };
175 
176 struct Vertex
177 {
178  glm::vec3 pos;
179  glm::vec3 normal;
180  glm::vec2 texCoord;
181 };
182 
184 {
185  glm::vec3 pos;
186  glm::vec3 color;
187 };
188 
190 {
191  glm::vec3 animationDirection = glm::vec3(0.f, 0.f, -1.f);
192  AnimationType animType;
193  float duration;
194  bool looping;
195 
196  bool operator==(const AnimationConfig& other) const
197  {
198  return animationDirection == other.animationDirection && animType == other.animType && duration == other.duration && looping == other.looping;
199  }
200  bool operator!=(const AnimationConfig& other) const
201  {
202  return !(*this == other);
203  }
204 };
constexpr glm::vec3 CHARACTER_MIN
Definition: BasicTypes.hpp:23
constexpr glm::vec3 CHARACTER_MAX
Definition: BasicTypes.hpp:24
ObjectType
Definition: BasicTypes.hpp:29
@ UNDEFINED
Definition: BasicTypes.hpp:34
@ AREA
Definition: BasicTypes.hpp:33
@ GAMEOBJECT
Definition: BasicTypes.hpp:31
@ CHARACTER
Definition: BasicTypes.hpp:30
@ TESTOBJECT
Definition: BasicTypes.hpp:32
constexpr size_t OBJECT_TYPE_COUNT
Definition: BasicTypes.hpp:26
constexpr uint32_t MAX_BONES
Definition: BasicTypes.hpp:18
std::array< AnimationType, ANIMATION_TYPE_COUNT > getAnimationTypes()
Definition: GraphicsTypes.cpp:96
constexpr glm::vec3 GAMEOBJECT_MIN
Definition: BasicTypes.hpp:20
constexpr glm::vec3 GAMEOBJECT_MAX
Definition: BasicTypes.hpp:21
constexpr uint32_t BONES_PER_VERTEX
Definition: BasicTypes.hpp:17
uint32_t getAnimIndex(AnimationType animType)
Definition: GraphicsTypes.cpp:106
std::array< ObjectType, OBJECT_TYPE_COUNT > getObjectTypes()
Definition: GraphicsTypes.cpp:86
Definition: BasicTypes.hpp:190
glm::vec3 animationDirection
Definition: BasicTypes.hpp:191
bool looping
Definition: BasicTypes.hpp:194
bool operator!=(const AnimationConfig &other) const
Definition: BasicTypes.hpp:200
float duration
Definition: BasicTypes.hpp:193
AnimationType animType
Definition: BasicTypes.hpp:192
bool operator==(const AnimationConfig &other) const
Definition: BasicTypes.hpp:196
Definition: BasicTypes.hpp:70
double time
time of this animation node in ticks
Definition: BasicTypes.hpp:71
std::array< GfxOrientation, MAX_BONES > bones
bone orientations
Definition: BasicTypes.hpp:72
Immutable animation data. Animations should be stored somewhere and requested when needed to be store...
Definition: BasicTypes.hpp:79
double totalTicks
total ticks in the animation
Definition: BasicTypes.hpp:80
float duration
duration of the animation in seconds
Definition: BasicTypes.hpp:82
double ticksPerSecond
ticks per second
Definition: BasicTypes.hpp:81
std::vector< AnimationNode > animationNodes
animation nodes
Definition: BasicTypes.hpp:83
Definition: BasicTypes.hpp:94
std::vector< uint32_t > children
indices of the children in bone array.
Definition: BasicTypes.hpp:97
int parent
index of the parent in bone array.
Definition: BasicTypes.hpp:96
glm::mat4 boneOffset
offset matrix of the bone
Definition: BasicTypes.hpp:95
Camera data used for shading.
Definition: BasicTypes.hpp:147
glm::vec3 position
Definition: BasicTypes.hpp:148
glm::vec3 direction
Definition: BasicTypes.hpp:149
Definition: BasicTypes.hpp:87
AnimationType currentAnimation
Definition: BasicTypes.hpp:88
std::array< Animation, ANIMATION_TYPE_COUNT > animations
Definition: BasicTypes.hpp:90
double currentTicks
Definition: BasicTypes.hpp:89
Definition: BasicTypes.hpp:101
CharacterAnimationData animationData
Definition: BasicTypes.hpp:106
GfxOrientation characterOrientation
orientation of the character
Definition: BasicTypes.hpp:102
std::vector< BoneNode > bones
Definition: BasicTypes.hpp:105
glm::mat4 inverseGlobalTransformation
inverse global transformation of the character
Definition: BasicTypes.hpp:103
std::array< glm::mat4, MAX_BONES > boneTransformations
bone transformation storage data
Definition: BasicTypes.hpp:104
void advanceAnimation(float dt)
Definition: GraphicsTypes.cpp:133
Definition: BasicTypes.hpp:168
glm::vec3 pos
Definition: BasicTypes.hpp:169
glm::uvec4 boneIDs
Definition: BasicTypes.hpp:171
glm::vec4 boneWeights
Definition: BasicTypes.hpp:172
glm::vec2 texCoord
Definition: BasicTypes.hpp:173
glm::vec3 normal
Definition: BasicTypes.hpp:170
Directional light struct representing a directional light.
Definition: BasicTypes.hpp:118
glm::vec3 color
color of the directional light
Definition: BasicTypes.hpp:120
glm::vec3 direction
direction of the directional light
Definition: BasicTypes.hpp:119
float intensity
intensity of the directional light
Definition: BasicTypes.hpp:121
Definition: BasicTypes.hpp:48
glm::vec3 scale
scale of the node
Definition: BasicTypes.hpp:51
glm::mat4 getTransformationMatrix() const
Compiles the transformation matrix of this orientation.
Definition: GraphicsTypes.cpp:111
glm::quat rotation
rotation of the node
Definition: BasicTypes.hpp:50
glm::vec3 position
position of the node
Definition: BasicTypes.hpp:49
static GfxOrientation interpolate(GfxOrientation first, GfxOrientation second, float factor)
Interpolates between two orientations linearly.
Definition: GraphicsTypes.cpp:122
Definition: BasicTypes.hpp:153
int id
Definition: BasicTypes.hpp:154
ObjectType objectType
Definition: BasicTypes.hpp:155
glm::vec3 hitPoint
Definition: BasicTypes.hpp:156
int button
The button that was pressed. For example GLFW_MOUSE_BUTTON_LEFT.
Definition: BasicTypes.hpp:157
Definition: BasicTypes.hpp:161
unsigned char * pixels
Definition: BasicTypes.hpp:162
int height
Definition: BasicTypes.hpp:164
int width
Definition: BasicTypes.hpp:163
Definition: BasicTypes.hpp:135
glm::vec3 diffuse
diffuse color of the material
Definition: BasicTypes.hpp:137
glm::vec3 specular
specular color of the material
Definition: BasicTypes.hpp:138
static PhongMaterial getDefaultMaterial()
Definition: GraphicsTypes.cpp:346
float shininess
shininess of the material
Definition: BasicTypes.hpp:139
glm::vec3 ambient
ambient color of the material
Definition: BasicTypes.hpp:136
Point light struct representing a point that shines light in all directions.
Definition: BasicTypes.hpp:128
glm::vec3 position
position of the point light
Definition: BasicTypes.hpp:129
glm::vec3 color
color of the point light
Definition: BasicTypes.hpp:130
float intensity
intensity of the point light
Definition: BasicTypes.hpp:131
Definition: BasicTypes.hpp:184
glm::vec3 color
Definition: BasicTypes.hpp:186
glm::vec3 pos
Definition: BasicTypes.hpp:185
Definition: MapObjLoader.hpp:10
glm::vec3 normal
Definition: BasicTypes.hpp:179
glm::vec2 texCoord
Definition: BasicTypes.hpp:180
glm::vec3 pos
Definition: BasicTypes.hpp:178