-
Notifications
You must be signed in to change notification settings - Fork 0
/
object.cpp
43 lines (34 loc) · 946 Bytes
/
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
#include "object.h"
Object::Object( const Geometry& geometry) : geometry(geometry), position(glm::vec3()), modelMatrix(glm::mat4()), axis(glm::vec3(0,1,0))
{
}
Object::Object( const Geometry& geometry, glm::vec3 position) : geometry(geometry), position(position), modelMatrix(glm::mat4()), axis(glm::vec3(0,1,0))
{
}
const glm::mat4& Object::getModelMatrix()
{
updateModelMatrix();
return modelMatrix;
}
void Object::updateModelMatrix()
{
modelMatrix = glm::translate(glm::mat4(), position) * rotationMatrix;
}
const Geometry& Object::getGeometry()
{
return geometry;
}
const glm::vec3& Object::getPosition()
{
return position;
}
void Object::tumble(float degrees)
{
glm::mat4 rotationMat = glm::rotate(glm::mat4(), degrees, glm::vec3(1.0, 0.2, 0.5));
axis = glm::vec3(rotationMat * glm::vec4(axis, 1.0));
rotate(degrees*20);
}
void Object::rotate(float degrees)
{
rotationMatrix = glm::rotate(rotationMatrix, degrees, axis);
}