]> git.localhorst.tv Git - blank.git/blob - src/model/CompositeModel.cpp
check for entities under crosshair
[blank.git] / src / model / CompositeModel.cpp
1 #include "CompositeModel.hpp"
2
3 #include "EntityModel.hpp"
4 #include "../graphics/DirectionalLighting.hpp"
5
6 #include <glm/gtx/quaternion.hpp>
7
8
9 namespace blank {
10
11 CompositeModel::CompositeModel()
12 : node_model(nullptr)
13 , position(0.0f)
14 , orientation(1.0f, 0.0f, 0.0f, 0.0f)
15 , parts() {
16
17 }
18
19
20 CompositeModel &CompositeModel::AddPart() {
21         parts.emplace_back();
22         parts.back().parent = this;
23         return parts.back();
24 }
25
26
27 glm::mat4 CompositeModel::LocalTransform() const noexcept {
28         glm::mat4 transform(toMat4(orientation));
29         transform[3].x = position.x;
30         transform[3].y = position.y;
31         transform[3].z = position.z;
32         return transform;
33 }
34
35 glm::mat4 CompositeModel::GlobalTransform() const noexcept {
36         if (HasParent()) {
37                 return Parent().GlobalTransform() * LocalTransform();
38         } else {
39                 return LocalTransform();
40         }
41 }
42
43
44 void CompositeModel::Render(const glm::mat4 &M, DirectionalLighting &prog) const {
45         glm::mat4 transform(M * LocalTransform());
46         if (HasNodeModel()) {
47                 prog.SetM(transform);
48                 NodeModel().Draw();
49         }
50         for (const CompositeModel &part : parts) {
51                 part.Render(transform, prog);
52         }
53 }
54
55 }