Molecule Viewer
 All Classes Functions Variables Enumerations Pages
Light.cpp
1 #include "Light.hpp"
2 
3 Light::Light() : SceneObject(), _position(new glm::vec3()), _projectionMatrix(new glm::mat4()) {
4  _rotation_x = 0;
5  _rotation_y = 0;
6 }
7 
8 
9 
11 
12  delete _position;
13  delete _projectionMatrix;
14 }
15 
16 const glm::vec3 Light::GetPosition() const {
17  return *_position;
18 }
19 
20 
21 void Light::Transform(glm::mat4 transformMatrix, glm::mat4 inverseTransformMatrix) {
22  SceneObject::Transform(transformMatrix, inverseTransformMatrix);
23  *_position = glm::vec3(*_modelMatrix * glm::vec4(0,0,0,1));
24 }
25 
26 void Light::Transform_world(glm::mat4 transformMatrix, glm::mat4 inverseTransformMatrix) {
27  SceneObject::Transform_world(transformMatrix, inverseTransformMatrix);
28  *_position = glm::vec3(*_modelMatrix * glm::vec4(0,0,0,1));
29 }
30 
31 void Light::RotateXY(float angle_x, float angle_y, float dist) {
32 
33  _rotation_x += angle_x;
34  if (abs(_rotation_x)>75)
35  _rotation_x = glm::sign(_rotation_x)*75;
36 
37  _rotation_y += angle_y;
38  if (abs(_rotation_y)>90)
39  _rotation_y = glm::sign(_rotation_y)*90;
40 
41 
42  glm::mat4 rot = glm::gtx::transform::rotate(_rotation_x,glm::vec3(1,0,0)) * glm::gtx::transform::rotate(_rotation_y,glm::vec3(0,1,0));;
43  glm::mat4 transl = glm::gtx::transform::translate(glm::vec3(0,0,dist));
44 
45 
46  *_modelMatrix = rot * transl;
47  *_inverseModelMatrix = glm::inverse(*_modelMatrix); //TODO
48  *_position = glm::vec3(*_modelMatrix * glm::vec4(0,0,0,1));
49 }
50 
51 
52 void Light::Reset(float nearPlane, float farPlane) {
54  *_position = glm::vec3(0,0,0);
55  *_projectionMatrix = glm::perspective(35.0f,1.0f, nearPlane, farPlane);
56 }
57 
58 const glm::mat4 * Light::GetProjectionMatrix() const {
59 
60  return _projectionMatrix;
61 }