Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. #ifndef CAMERA_H
  2. #define CAMERA_H
  3.  
  4. #pragma once
  5. #include "stdafx.h"
  6. #include "3rd\glm\glm.hpp"
  7. #include "3rd\glm\gtc\matrix_transform.hpp"
  8.  
  9. class Camera
  10. {
  11.  
  12. glm::vec3 up;
  13. glm::vec3 position;
  14. glm::vec3 lookAt;
  15. glm::mat4x4 View;
  16. glm::mat4x4 Projection;
  17. float width;
  18. float height;
  19.  
  20. public:
  21. Camera(){}
  22.  
  23. Camera(float Width, float Height)
  24. :width(Width), height(Height), position(glm::vec3(0,0.5f,-2.0f)), lookAt(glm::vec3(0.0f,0.0f,0.0f))
  25. {
  26. width = Width;
  27. height = Height;
  28. up = glm::vec3(0,1,0);
  29. View = glm::lookAt(position, lookAt, up );
  30. Projection = glm::perspective(45.0f,Width/Height,0.1f, 100.0f);
  31. }
  32. Camera(glm::vec3 Position, glm::vec3 Target, float Width, float Height)
  33. :width(Width), height(Height), position(Position), lookAt(Target)
  34. {
  35. width = Width;
  36. height = Height;
  37. up = glm::vec3(0,1,0);
  38. View = glm::lookAt(position, lookAt, up);
  39. Projection = glm::perspective(45.0f,Width/Height,0.1f, 100.0f);
  40. }
  41.  
  42. glm::mat4x4 getView()
  43. {
  44. View = glm::lookAt(position, lookAt, up);
  45. return View;
  46. }
  47.  
  48. glm::mat4x4 getProjection()
  49. {
  50. return Projection;
  51. }
  52.  
  53. glm::mat4x4 getViewProjection()
  54. {
  55. View = glm::lookAt(position, lookAt, up);
  56. return Projection*View;
  57. }
  58.  
  59. void setPosition(glm::vec3 Position)
  60. {
  61. position = Position;
  62. }
  63.  
  64. void setTarget(glm::vec3 Target)
  65. {
  66. lookAt = Target;
  67. }
  68.  
  69. glm::vec3 getPosition()
  70. {
  71. return position;
  72. }
  73.  
  74. glm::vec3 getTarget()
  75. {
  76. return lookAt;
  77. }
  78.  
  79. void setFOV(float fov)
  80. {
  81. Projection = glm::perspective(fov,width/height,0.1f, 100.0f);
  82. }
  83.  
  84. void setUp(glm::vec3 upv)
  85. {
  86. up = upv;
  87. }
  88.  
  89. };
  90.  
  91. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement