Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 KB | None | 0 0
  1. #include "Laborator4.h"
  2.  
  3. #include <vector>
  4. #include <string>
  5. #include <iostream>
  6.  
  7. #include <Core/Engine.h>
  8. #include "Transform3D.h"
  9.  
  10. using namespace std;
  11.  
  12. int cnt;
  13. float angle;
  14.  
  15. Laborator4::Laborator4()
  16. {
  17. }
  18.  
  19. Laborator4::~Laborator4()
  20. {
  21. }
  22.  
  23. void Laborator4::Init()
  24. {
  25. cnt = 0;
  26. angle = M_PI;
  27. polygonMode = GL_FILL;
  28.  
  29. Mesh* mesh = new Mesh("box");
  30. mesh->LoadMesh(RESOURCE_PATH::MODELS + "Primitives", "box.obj");
  31. meshes[mesh->GetMeshID()] = mesh;
  32.  
  33. // initialize tx, ty and tz (the translation steps)
  34. translateX = 0;
  35. translateY = 0;
  36. translateZ = 0;
  37.  
  38. // initialize sx, sy and sz (the scale factors)
  39. scaleX = 1;
  40. scaleY = 1;
  41. scaleZ = 1;
  42.  
  43. // initialize angularSteps
  44. angularStepOX = 0;
  45. angularStepOY = 0;
  46. angularStepOZ = 0;
  47. }
  48.  
  49. void Laborator4::FrameStart()
  50. {
  51. // clears the color buffer (using the previously set color) and depth buffer
  52. glClearColor(0, 0, 0, 1);
  53. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  54.  
  55. glm::ivec2 resolution = window->GetResolution();
  56. // sets the screen area where to draw
  57. glViewport(0, 0, resolution.x, resolution.y);
  58. }
  59.  
  60. void Laborator4::Update(float deltaTimeSeconds)
  61. {
  62. glLineWidth(3);
  63. glPointSize(5);
  64. glPolygonMode(GL_FRONT_AND_BACK, polygonMode);
  65.  
  66. modelMatrix = glm::mat4(1);
  67. modelMatrix *= Transform3D::Translate(-2.5f, 0.5f,-1.5f);
  68. modelMatrix *= Transform3D::Translate(translateX, translateY, translateZ);
  69. RenderMesh(meshes["box"], shaders["VertexNormal"], modelMatrix);
  70.  
  71. modelMatrix = glm::mat4(1);
  72. modelMatrix *= Transform3D::Translate(0.0f, 0.5f, -1.5f);
  73. modelMatrix *= Transform3D::Scale(scaleX, scaleY, scaleZ);
  74. RenderMesh(meshes["box"], shaders["Simple"], modelMatrix);
  75.  
  76. modelMatrix = glm::mat4(1);
  77. modelMatrix *= Transform3D::Translate(2.5f, 0.5f, -1.5f);
  78. modelMatrix *= Transform3D::RotateOX(angularStepOX);
  79. modelMatrix *= Transform3D::RotateOY(angularStepOY);
  80. modelMatrix *= Transform3D::RotateOZ(angularStepOZ);
  81. RenderMesh(meshes["box"], shaders["VertexNormal"], modelMatrix);
  82.  
  83. angle -= deltaTimeSeconds;
  84. if (angle <= 0) {
  85. angle = M_PI;
  86. cnt++;
  87. }
  88.  
  89. modelMatrix = glm::mat4(1);
  90. modelMatrix *= Transform3D::Translate(4*cnt, 0.5f, 0);
  91. modelMatrix *= Transform3D::RotateOZ(angle);
  92. modelMatrix *= Transform3D::Translate(2, 0, 0);
  93. RenderMesh(meshes["box"], shaders["VertexNormal"], modelMatrix);
  94. }
  95.  
  96. void Laborator4::FrameEnd()
  97. {
  98. DrawCoordinatSystem();
  99. }
  100.  
  101. void Laborator4::OnInputUpdate(float deltaTime, int mods)
  102. {
  103. // TODO
  104. if (window->KeyHold(GLFW_KEY_A)) {
  105. translateX -= 0.1;
  106. }
  107.  
  108. if (window->KeyHold(GLFW_KEY_D)) {
  109. translateX += 0.1;
  110. }
  111.  
  112. if (window->KeyHold(GLFW_KEY_W)) {
  113. translateY += 0.1;
  114. }
  115.  
  116. if (window->KeyHold(GLFW_KEY_S)) {
  117. translateY -= 0.1;
  118. }
  119.  
  120. if (window->KeyHold(GLFW_KEY_F)) {
  121. translateZ += 0.1;
  122. }
  123.  
  124. if (window->KeyHold(GLFW_KEY_R)) {
  125. translateZ -= 0.1;
  126. }
  127.  
  128. if (window->KeyHold(GLFW_KEY_1)) {
  129. scaleX += 0.1;
  130. scaleY += 0.1;
  131. scaleZ += 0.1;
  132. }
  133.  
  134. if (window->KeyHold(GLFW_KEY_2)) {
  135. scaleX -= 0.1;
  136. scaleY -= 0.1;
  137. scaleZ -= 0.1;
  138. }
  139.  
  140. if (window->KeyHold(GLFW_KEY_3)) {
  141. angularStepOX += 0.1;
  142. }
  143.  
  144. if (window->KeyHold(GLFW_KEY_4)) {
  145. angularStepOX -= 0.1;
  146. }
  147.  
  148. if (window->KeyHold(GLFW_KEY_5)) {
  149. angularStepOY += 0.1;
  150. }
  151.  
  152. if (window->KeyHold(GLFW_KEY_6)) {
  153. angularStepOY -= 0.1;
  154. }
  155.  
  156. if (window->KeyHold(GLFW_KEY_7)) {
  157. angularStepOZ += 0.1;
  158. }
  159.  
  160. if (window->KeyHold(GLFW_KEY_8)) {
  161. angularStepOZ -= 0.1;
  162. }
  163.  
  164. }
  165.  
  166. void Laborator4::OnKeyPress(int key, int mods)
  167. {
  168. // add key press event
  169. if (key == GLFW_KEY_SPACE)
  170. {
  171. switch (polygonMode)
  172. {
  173. case GL_POINT:
  174. polygonMode = GL_FILL;
  175. break;
  176. case GL_LINE:
  177. polygonMode = GL_POINT;
  178. break;
  179. default:
  180. polygonMode = GL_LINE;
  181. break;
  182. }
  183. }
  184. }
  185.  
  186. void Laborator4::OnKeyRelease(int key, int mods)
  187. {
  188. // add key release event
  189. }
  190.  
  191. void Laborator4::OnMouseMove(int mouseX, int mouseY, int deltaX, int deltaY)
  192. {
  193. // add mouse move event
  194. }
  195.  
  196. void Laborator4::OnMouseBtnPress(int mouseX, int mouseY, int button, int mods)
  197. {
  198. // add mouse button press event
  199. }
  200.  
  201. void Laborator4::OnMouseBtnRelease(int mouseX, int mouseY, int button, int mods)
  202. {
  203. // add mouse button release event
  204. }
  205.  
  206. void Laborator4::OnMouseScroll(int mouseX, int mouseY, int offsetX, int offsetY)
  207. {
  208. }
  209.  
  210. void Laborator4::OnWindowResize(int width, int height)
  211. {
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement