Guest User

Untitled

a guest
Jan 21st, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. int main(int argc, char** argv)
  2. {
  3. /*
  4. INIT AND OTHER STUFF SNIPPED OUT
  5. */
  6.  
  7. double currentFrame = glfwGetTime();
  8. double lastFrame = currentFrame;
  9. double deltaTime;
  10.  
  11. double a=0;
  12. double speed = 0.6;
  13. //Main loop
  14. while(true)
  15. {
  16. a++;
  17.  
  18. currentFrame = glfwGetTime();
  19. deltaTime = currentFrame - lastFrame;
  20. lastFrame = currentFrame;
  21.  
  22. /** I know that delta time is around 0.016 at my framerate **/
  23. //deltaTime = 0.016;
  24.  
  25. x = sin( a * deltaTime * speed ) * 0.8f;
  26. y = cos( a * deltaTime * speed ) * 0.8f;
  27.  
  28. display();
  29.  
  30. if(glfwGetKey(GLFW_KEY_ESC) || !glfwGetWindowParam(GLFW_OPENED))
  31. break;
  32. }
  33.  
  34. glfwTerminate();
  35.  
  36. return 0;
  37. }
  38.  
  39. void display()
  40. {
  41. glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
  42. glClear(GL_COLOR_BUFFER_BIT);
  43.  
  44. glUseProgram(playerProgram);
  45.  
  46. glUniform3f(playerLocationUniform,x,y,z);
  47.  
  48. glBindBuffer(GL_ARRAY_BUFFER, playerVertexBufferObject);
  49.  
  50. glEnableVertexAttribArray(0);
  51. glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
  52. glDrawArrays(GL_TRIANGLES, 0, 3);
  53. glDisableVertexAttribArray(0);
  54.  
  55. glUseProgram(0);
  56. glfwSwapBuffers();
  57.  
  58. }
  59.  
  60. #define TAU (M_PI * 2.0)
  61.  
  62. currentFrame = glfwGetTime();
  63. deltaTime = currentFrame - lastFrame;
  64. lastFrame = currentFrame;
  65.  
  66. a += deltaTime * speed;
  67.  
  68. // Optional, keep the cycle bounded to reduce precision errors
  69. // if you plan to leave this running for a long time...
  70. if( a > TAU ) a -= TAU;
  71.  
  72. x = sin( a ) * 0.8f;
  73. y = cos( a ) * 0.8f;
Add Comment
Please, Sign In to add comment