-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPropellor.cpp
More file actions
86 lines (51 loc) · 2.43 KB
/
Propellor.cpp
File metadata and controls
86 lines (51 loc) · 2.43 KB
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
76
77
78
79
80
81
82
83
84
85
86
#include "Propellor.h"
#include "vertexArray.h"
#include "shaderProgram.h"
#include "texture.h"
Propellor::Propellor()
{
model = std::make_shared<vertexArray>("Models/prop/prop.obj");
modelTexture = std::make_shared<texture>("Models/prop/prop.png");
program = std::make_shared<shaderProgram>(shaderProgram::SHADERTYPE::SHADER_LIGHT);
position = glm::vec3(2.6f, 0.0f, 0.0f);
rotation = glm::vec3(0.0f, 0.0f, 0.0f);
modelMatrix = glm::translate(modelMatrix, position);
modelMatrix = glm::rotate(modelMatrix, glm::radians(rotation.x), glm::vec3(0, 1, 0));
modelMatrix = glm::rotate(modelMatrix, glm::radians(rotation.y), glm::vec3(1, 0, 0));
modelMatrix = glm::rotate(modelMatrix, glm::radians(rotation.z), glm::vec3(0, 0, 1));
projection = glm::perspective(glm::radians(60.0f), ((1.0f * 1920) / (1.0f * 1080)), 0.1f, 1000.0f);
}
void Propellor::draw(std::shared_ptr<orbitLight> _light)
{
glUseProgram(program->getId());
glBindVertexArray(model->getId());
program->update(projection, viewMatrix, modelMatrix, model, modelTexture->getId());
//program->update(projection, viewMatrix, modelMatrix, model, modelTexture->getId(), _light);
}
void Propellor::update(glm::vec3 _translation, glm::vec3 _rotation, glm::mat4 _viewMatrix)
{
modelMatrix = glm::mat4(1.0f);
position += _translation;
rotation += _rotation;
//rotation.y += 10;
modelMatrix = glm::rotate(modelMatrix, glm::radians(rotation.x), glm::vec3(0, 1, 0));
modelMatrix = glm::rotate(modelMatrix, glm::radians(rotation.y), glm::vec3(1, 0, 0));
modelMatrix = glm::rotate(modelMatrix, glm::radians(rotation.z + spinFactor), glm::vec3(0, 0, 1));
modelMatrix = glm::translate(modelMatrix, position);
//modelMatrix = glm::lookAt(position, position + _translation, glm::vec3(0, 1, 0));
viewMatrix = _viewMatrix;
}
void Propellor::setTransform(glm::vec3 _position, glm::vec3 _rotation, glm::mat4 _viewMatrix, float throttle)
{
modelMatrix = glm::mat4(1.0f);
spinFactor += 0.25f * throttle;
position = _position;
rotation = _rotation;
modelMatrix = glm::translate(modelMatrix, position);
modelMatrix = glm::rotate(modelMatrix, glm::radians(rotation.x), glm::vec3(0, 1, 0));
modelMatrix = glm::rotate(modelMatrix, glm::radians(rotation.y), glm::vec3(1, 0, 0));
modelMatrix = glm::rotate(modelMatrix, glm::radians(rotation.z), glm::vec3(0, 0, 1));
modelMatrix = glm::rotate(modelMatrix, spinFactor, glm::vec3(1,0,0));
viewMatrix = _viewMatrix;
//rotation += _ro;
}