Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 KB | None | 0 0
  1. #include "Laborator3.h"
  2.  
  3. #include <vector>
  4. #include <iostream>
  5.  
  6. #include <Core/Engine.h>
  7. #include "Transform2D.h"
  8. #include "Object2D.h"
  9.  
  10. using namespace std;
  11.  
  12. Laborator3::Laborator3()
  13. {
  14. }
  15.  
  16. Laborator3::~Laborator3()
  17. {
  18. }
  19.  
  20. void Laborator3::Init()
  21. {
  22. glm::ivec2 resolution = window->GetResolution();
  23. auto camera = GetSceneCamera();
  24. camera->SetOrthographic(0, (float)resolution.x, 0, (float)resolution.y, 0.01f, 400);
  25. camera->SetPosition(glm::vec3(0, 0, 50));
  26. camera->SetRotation(glm::vec3(0, 0, 0));
  27. camera->Update();
  28. GetCameraInput()->SetActive(false);
  29.  
  30. glm::vec3 corner = glm::vec3(0, 0, 0);
  31. float squareSide = 100;
  32.  
  33. // compute coordinates of square center
  34. float cx = corner.x + squareSide / 2;
  35. float cy = corner.y + squareSide / 2;
  36.  
  37. // initialize tx and ty (the translation steps)
  38. translateX = 0;
  39. translateY = 0;
  40.  
  41. // initialize sx and sy (the scale factors)
  42. scaleX = 1;
  43. scaleY = 1;
  44.  
  45. // initialize angularStep
  46. angularStep = 0;
  47.  
  48.  
  49. Mesh* square1 = Object2D::CreateSquare("square1", corner, squareSide, glm::vec3(1, 0, 0), true);
  50. AddMeshToList(square1);
  51.  
  52. Mesh* square2 = Object2D::CreateSquare("square2", corner, squareSide, glm::vec3(0, 1, 0));
  53. AddMeshToList(square2);
  54.  
  55. Mesh* square3 = Object2D::CreateSquare("square3", corner, squareSide, glm::vec3(0, 0, 1));
  56. AddMeshToList(square3);
  57. }
  58.  
  59. void Laborator3::FrameStart()
  60. {
  61. // clears the color buffer (using the previously set color) and depth buffer
  62. glClearColor(0, 0, 0, 1);
  63. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  64.  
  65. glm::ivec2 resolution = window->GetResolution();
  66. // sets the screen area where to draw
  67. glViewport(0, 0, resolution.x, resolution.y);
  68. }
  69.  
  70. void Laborator3::Update(float deltaTimeSeconds)
  71. {
  72. // TODO: update steps for translation, rotation, scale, in order to create animations
  73. /*
  74. translateX += deltaTimeSeconds * 100;
  75. translateY += deltaTimeSeconds * 100;
  76. */
  77. angularStep += 1 * deltaTimeSeconds;
  78. modelMatrix = glm::mat3(1);
  79.  
  80. modelMatrix = glm::mat3(1);
  81. modelMatrix *= Transform2D::Translate(450, 450);
  82. modelMatrix *= Transform2D::Translate(50, 50);
  83. modelMatrix *= Transform2D::Rotate(angularStep);
  84. modelMatrix *= Transform2D::Translate(-50, -50);
  85.  
  86. RenderMesh2D(meshes["square1"], shaders["VertexColor"], modelMatrix);
  87. // TODO: create animations by multiplying current transform matrix with matrices from Transform 2D
  88. /*
  89. if (scaleX > 2) {
  90. scaleX -= deltaTimeSeconds;
  91. scaleY -= deltaTimeSeconds;
  92. flags = 0;
  93. }
  94. else if (scaleX < 0.5) {
  95. scaleX += deltaTimeSeconds;
  96. scaleY += deltaTimeSeconds;
  97. flags = 1;
  98. }
  99. else if(flags==0){
  100. scaleX -= deltaTimeSeconds;
  101. scaleY -= deltaTimeSeconds;
  102. }
  103. else if (flags == 1) {
  104. scaleX += deltaTimeSeconds;
  105. scaleY += deltaTimeSeconds;
  106. }
  107. */
  108. /*
  109. modelMatrix = glm::mat3(1);
  110. modelMatrix *= Transform2D::Scale(scaleX, scaleX);
  111. RenderMesh2D(meshes["square2"], shaders["VertexColor"], modelMatrix);
  112. //TODO create animations by multiplying current transform matrix with matrices from Transform 2D
  113. */
  114.  
  115. modelMatrix = glm::mat3(1);
  116. modelMatrix *= Transform2D::Translate(650, 450);
  117. modelMatrix *= Transform2D::Translate(-150, 50);
  118. modelMatrix *= Transform2D::Rotate(-angularStep);
  119. modelMatrix *= Transform2D::Translate(150,-50);
  120. RenderMesh2D(meshes["square3"], shaders["VertexColor"], modelMatrix);
  121.  
  122.  
  123.  
  124. modelMatrix *= Transform2D::Translate(150,0);
  125. modelMatrix *= Transform2D::Translate(-100, 50);
  126. modelMatrix *= Transform2D::Rotate(-angularStep);
  127. modelMatrix *= Transform2D::Translate(100, -50);
  128. //TODO create animations by multiplying current transform matrix with matrices from Transform 2D
  129. RenderMesh2D(meshes["square3"], shaders["VertexColor"], modelMatrix);
  130.  
  131. }
  132.  
  133. void Laborator3::FrameEnd()
  134. {
  135.  
  136. }
  137.  
  138. void Laborator3::OnInputUpdate(float deltaTime, int mods)
  139. {
  140.  
  141. }
  142.  
  143. void Laborator3::OnKeyPress(int key, int mods)
  144. {
  145. // add key press event
  146. }
  147.  
  148. void Laborator3::OnKeyRelease(int key, int mods)
  149. {
  150. // add key release event
  151. }
  152.  
  153. void Laborator3::OnMouseMove(int mouseX, int mouseY, int deltaX, int deltaY)
  154. {
  155. // add mouse move event
  156. }
  157.  
  158. void Laborator3::OnMouseBtnPress(int mouseX, int mouseY, int button, int mods)
  159. {
  160. // add mouse button press event
  161. }
  162.  
  163. void Laborator3::OnMouseBtnRelease(int mouseX, int mouseY, int button, int mods)
  164. {
  165. // add mouse button release event
  166. }
  167.  
  168. void Laborator3::OnMouseScroll(int mouseX, int mouseY, int offsetX, int offsetY)
  169. {
  170. }
  171.  
  172. void Laborator3::OnWindowResize(int width, int height)
  173. {
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement