Molecule Viewer
 All Classes Functions Variables Enumerations Pages
SceneObject.cpp
1 #include "SceneObject.hpp"
2 
3 
4 SceneObject::SceneObject() : _modelMatrix(new glm::mat4()), _inverseModelMatrix(new glm::mat4())
5 {
6 }
7 
9 {
10  delete _modelMatrix;
11  delete _inverseModelMatrix;
12 }
13 
14 
15 glm::mat4 SceneObject::GetModelMatrix() const {
16  return *_modelMatrix;
17 }
18 
20  return *_inverseModelMatrix;
21 }
22 
23 
25 
26  delete _modelMatrix;
27  delete _inverseModelMatrix;
28 
29  _modelMatrix = new glm::mat4();
30  _inverseModelMatrix = new glm::mat4();
31 }
32 
33 
34 void SceneObject::Translate(float x, float y, float z)
35 {
36  glm::mat4 transformMatrix = glm::gtx::transform::translate(glm::vec3(x,y,z));
37  glm::mat4 inverseTransformMatrix = glm::gtx::transform::translate(glm::vec3(-x,-y,-z));
38  Transform(transformMatrix, inverseTransformMatrix);
39 }
40 
41 
42 
43 void SceneObject::RotateX_world(float angle)
44 {
45 
46 
47  glm::mat4 transformMatrix = glm::gtx::transform::rotate(angle,glm::vec3(1,0,0));
48  glm::mat4 inverseTransformMatrix = glm::gtx::transform::rotate(-angle,glm::vec3(1,0,0));
49  Transform_world(transformMatrix, inverseTransformMatrix);
50 }
51 
52 
53 
54 void SceneObject::RotateY_world(float angle)
55 {
56 
57  glm::mat4 transformMatrix = glm::gtx::transform::rotate(angle,glm::vec3(0,1,0));
58  glm::mat4 inverseTransformMatrix = glm::gtx::transform::rotate(-angle,glm::vec3(0,1,0));
59 
60  Transform_world(transformMatrix, inverseTransformMatrix);
61 
62 
63 }
64 
65 
66 
67 void SceneObject::RotateX(float angle)
68 {
69 
70 
71  glm::mat4 transformMatrix = glm::gtx::transform::rotate(angle,glm::vec3(1,0,0));
72  glm::mat4 inverseTransformMatrix = glm::gtx::transform::rotate(-angle,glm::vec3(1,0,0));
73  Transform(transformMatrix, inverseTransformMatrix);
74 }
75 
76 
77 void SceneObject::RotateY(float angle)
78 {
79 
80  glm::mat4 transformMatrix = glm::gtx::transform::rotate(angle,glm::vec3(0,1,0));
81  glm::mat4 inverseTransformMatrix = glm::gtx::transform::rotate(-angle,glm::vec3(0,1,0));
82  Transform(transformMatrix, inverseTransformMatrix);
83 }
84 
85 
86 
87 void SceneObject::Transform_world(glm::mat4 transformMatrix, glm::mat4 inverseTransformMatrix) {
88 
89 
90  *_modelMatrix = transformMatrix * (*_modelMatrix);
91  *_inverseModelMatrix = (*_inverseModelMatrix) * inverseTransformMatrix;
92 
93 }
94 
95 void SceneObject::Transform(glm::mat4 transformMatrix, glm::mat4 inverseTransformMatrix) {
96 
97  *_modelMatrix = (*_modelMatrix) * transformMatrix;
98  *_inverseModelMatrix = inverseTransformMatrix * (*_inverseModelMatrix) ;
99 
100 
101 }
102 
103