Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.23 KB | None | 0 0
  1. #include "Laborator3.h"
  2. // Lab3.cpp
  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. Mesh* soare = Object2D::CreateSquare("soare", corner, 100, glm::vec3(1, 0, 0), true);
  59. AddMeshToList(soare);
  60.  
  61. Mesh* pamant = Object2D::CreateSquare("pamant", corner, 50, glm::vec3(0, 1, 0));
  62. AddMeshToList(pamant);
  63.  
  64. Mesh* luna = Object2D::CreateSquare("luna", corner, 20, glm::vec3(0, 0, 1));
  65. AddMeshToList(luna);
  66.  
  67. }
  68.  
  69. void Laborator3::FrameStart()
  70. {
  71. // clears the color buffer (using the previously set color) and depth buffer
  72. glClearColor(0, 0, 0, 1);
  73. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  74.  
  75. glm::ivec2 resolution = window->GetResolution();
  76. // sets the screen area where to draw
  77. glViewport(0, 0, resolution.x, resolution.y);
  78. }
  79.  
  80.  
  81. float rotation = 0;
  82. float factorScale = 1;
  83. float translationX = 0;
  84. float scale = 1;
  85. float factor = 1;
  86.  
  87.  
  88. float rotationLuna = 0;
  89. float rotationPamant = 0;
  90. float xSoare = 640, ySoare = 360;
  91. float xPamant = 500, yPamant = 350;
  92. float xluna = 550, yluna = 350;
  93.  
  94. double i = 0;
  95.  
  96. void Laborator3::Update(float deltaTimeSeconds)
  97. {
  98. modelMatrix = glm::mat3(1);
  99. modelMatrix *= Transform2D::Translate(xSoare, ySoare);
  100. //modelMatrix *= Transform2D::Rotate(rotation);
  101. RenderMesh2D(meshes["soare"], shaders["VertexColor"], modelMatrix);
  102.  
  103. modelMatrix = glm::mat3(1);
  104. modelMatrix *= Transform2D::Translate(xPamant, yPamant);
  105. modelMatrix *= Transform2D::Rotate(rotation/3);
  106. RenderMesh2D(meshes["pamant"], shaders["VertexColor"], modelMatrix);
  107.  
  108. modelMatrix = glm::mat3(1);
  109. modelMatrix *= Transform2D::Translate(xluna, yluna);
  110. modelMatrix *= Transform2D::Rotate(rotation);
  111. RenderMesh2D(meshes["luna"], shaders["VertexColor"], modelMatrix);
  112.  
  113. if (i >= 2 * AI_MATH_PI_F)
  114. i = 0;
  115. else
  116. i += 1 * deltaTimeSeconds;
  117.  
  118. xluna = xPamant + 100 * cos(i * 3);
  119. yluna = yPamant + 100 * sin(i * 3);
  120.  
  121.  
  122. xPamant = xSoare + 200 * cos(i);
  123. yPamant = ySoare + 200 * sin(i);
  124.  
  125. //cout << xluna << endl << yluna;
  126. // TODO: update steps for translation, rotation, scale, in order to create animations
  127.  
  128. modelMatrix = glm::mat3(1);
  129. modelMatrix *= Transform2D::Translate(150, 250);
  130. modelMatrix *= Transform2D::Translate(translationX, 200);
  131. // TODO: create animations by multiplying current transform matrix with matrices from Transform 2D
  132.  
  133. //RenderMesh2D(meshes["square1"], shaders["VertexColor"], modelMatrix);
  134.  
  135. modelMatrix = glm::mat3(1);
  136. modelMatrix *= Transform2D::Translate(400, 250);
  137. modelMatrix *= Transform2D::Rotate(rotation);
  138. //TODO create animations by multiplying current transform matrix with matrices from Transform 2D
  139.  
  140. //RenderMesh2D(meshes["square2"], shaders["VertexColor"], modelMatrix);
  141.  
  142. modelMatrix = glm::mat3(1);
  143. modelMatrix *= Transform2D::Translate(650, 250);
  144. modelMatrix *= Transform2D::Scale(scale, scale);
  145.  
  146. translationX += factor * deltaTimeSeconds * 100;
  147. if (translationX >= 800 || translationX <= 0)
  148. factor *= -1;
  149.  
  150. rotation += deltaTimeSeconds;
  151.  
  152. scale += factorScale * deltaTimeSeconds;
  153. if (scale > 3 || scale < 0.1)
  154. factorScale *= -1;
  155.  
  156. //TODO create animations by multiplying current transform matrix with matrices from Transform 2D
  157. //RenderMesh2D(meshes["square3"], shaders["VertexColor"], modelMatrix);
  158. }
  159.  
  160. void Laborator3::FrameEnd()
  161. {
  162.  
  163. }
  164.  
  165. void Laborator3::OnInputUpdate(float deltaTime, int mods)
  166. {
  167.  
  168. }
  169.  
  170. void Laborator3::OnKeyPress(int key, int mods)
  171. {
  172. // add key press event
  173. }
  174.  
  175. void Laborator3::OnKeyRelease(int key, int mods)
  176. {
  177. // add key release event
  178. }
  179.  
  180. void Laborator3::OnMouseMove(int mouseX, int mouseY, int deltaX, int deltaY)
  181. {
  182. // add mouse move event
  183. }
  184.  
  185. void Laborator3::OnMouseBtnPress(int mouseX, int mouseY, int button, int mods)
  186. {
  187. // add mouse button press event
  188. }
  189.  
  190. void Laborator3::OnMouseBtnRelease(int mouseX, int mouseY, int button, int mods)
  191. {
  192. // add mouse button release event
  193. }
  194.  
  195. void Laborator3::OnMouseScroll(int mouseX, int mouseY, int offsetX, int offsetY)
  196. {
  197. }
  198.  
  199. void Laborator3::OnWindowResize(int width, int height)
  200. {
  201. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement