-
Notifications
You must be signed in to change notification settings - Fork 0
/
Object.cpp
75 lines (61 loc) · 1.96 KB
/
Object.cpp
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* Object.cpp
*
* Created on: 18 kwi 2020
* Author: andr
*/
#include "Object.h"
void Object::Draw(GLuint modelLoc)
{
GltfModel->Draw(modelLoc);
}
void Object::Tick(double time)
{
ModelMatrix = glm::mat4(1.0f);
ModelMatrix = glm::translate(ModelMatrix, Position);
ModelMatrix = glm::rotate(ModelMatrix, Rotation.x, glm::vec3(1.0f, 0.0f, 0.0f));
ModelMatrix = glm::rotate(ModelMatrix, Rotation.y, glm::vec3(0.0f, 1.0f, 0.0f));
ModelMatrix = glm::rotate(ModelMatrix, Rotation.z, glm::vec3(0.0f, 0.0f, 1.0f));
ModelMatrix = glm::scale(ModelMatrix, Scale);
GltfModel->Tick();
map<int, Model *>::iterator iter_mod = GltfModel->ModelsMap.begin();
while (iter_mod != GltfModel->ModelsMap.end())
{
Model * model = iter_mod->second;
int nodeid = iter_mod->first;
glm::mat4 modelMat = GltfModel->MatricesMap[nodeid];
modelMat = ModelMatrix * modelMat;
GltfModel->MatricesMap[nodeid] = modelMat;
iter_mod++;
}
map<int, Animation *>::iterator iter = Animations.CurrentAnimations.begin();
while (iter != Animations.CurrentAnimations.end())
{
Animation * anim = iter->second;
int nodeid = iter->first;
if (anim->function == "rotation")
{
glm::vec4 rot = Animations.GetInterpolatedValue4(nodeid, time);
glm::mat4 modelMatrix;
modelMatrix = glm::mat4(1.0f);
modelMatrix = glm::rotate(modelMatrix, rot.x, glm::vec3(1.0f, 0.0f, 0.0f));
modelMatrix = glm::rotate(modelMatrix, rot.y, glm::vec3(0.0f, 1.0f, 0.0f));
modelMatrix = glm::rotate(modelMatrix, rot.z, glm::vec3(0.0f, 0.0f, 1.0f));
glm::mat4 modelMat = GltfModel->MatricesMap[nodeid];
GltfModel->MatricesMap[nodeid] = modelMat*modelMatrix;
}
iter++;
}
// Rotation.y += 0.001f;
}
Object::Object()
{
}
Object::Object(ParsedObject * parsed)
{
GltfModel = new LoadGltfModel();
GltfModel->init_vao(parsed->type);
Scale = parsed->scale;
Rotation = parsed->rotate;
Position = parsed->position;
}