-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameObject.hpp
More file actions
49 lines (37 loc) · 972 Bytes
/
GameObject.hpp
File metadata and controls
49 lines (37 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once
#include "Model.hpp"
#include <memory>
namespace engine {
struct Transform2DComponent {
glm::vec2 translation{};
glm::vec2 scale{ 1.f, 1.f };
float rotation;
glm::mat2 mat2() {
const float s = glm::sin(rotation);
const float c = glm::cos(rotation);
glm::mat2 rotMat{ {c,s}, {-s,c} };
glm::mat2 scaleMat{ {scale.x, .0f}, {.0f, scale.y} };
return rotMat*scaleMat;
};
};
class GameObject
{
public:
using id_t = unsigned int;
static GameObject createGameObject() {
static id_t currentId = 0;
return GameObject(currentId++);
}
const id_t getId() { return id; };
GameObject(const GameObject&) = delete;
GameObject& operator=(const GameObject&) = delete;
GameObject(GameObject&&) = default;
GameObject& operator=(GameObject&&) = default;
std::shared_ptr<Model> model{};
glm::vec3 color{};
Transform2DComponent transform2d{};
private:
GameObject(id_t objId) : id{ objId } {};
id_t id;
};
}