Guest User

Untitled

a guest
Jan 21st, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. float speed = 3.0f;
  2. float deadZone = 0.10f;
  3. glm::vec2 direction(0.0f);
  4.  
  5. while (!glfwWindowShouldClose(window))
  6. {
  7. currentTime = glfwGetTime();
  8. deltaTime = (currentTime - lastUpdate) * 1000.0f;
  9.  
  10. //Update logic
  11. inputHandler->tick(deltaTime);
  12.  
  13. float inputX, inputY;
  14. inputX = inputHandler->getGamepad(0)->getAxes(AXIS::HORIZONTAL);
  15. inputY = inputHandler->getGamepad(0)->getAxes(AXIS::VERTICAL);
  16.  
  17. float magnitude = sqrtf((inputX * inputX) + (inputY * inputY));
  18. if (magnitude > deadZone) //Radial dead zone detection
  19. {
  20. //Could the stutter be caused by type casting?
  21. direction.x += inputX * float((speed * deltaTime) / 1000.0f);
  22. direction.y += inputY * float((speed * deltaTime) / 1000.0f);
  23. }
  24.  
  25. ... //Set vertex values and UV coord
  26.  
  27. //Set the matrix values according to the joystick input
  28. glm::mat4 MVP(1.0f);
  29. MVP = glm::translate(MVP, glm::vec3(direction, 0.0f));
  30. glUniformMatrix4fv(mvpID, 1, GL_FALSE, glm::value_ptr(MVP));
  31.  
  32. glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
  33.  
  34. ...
  35. }
  36.  
  37. #version 150
  38.  
  39. in vec2 vertexPosition_modelspace;
  40. in vec2 UV;
  41.  
  42. uniform mat4 MVP;
  43.  
  44. out vec2 vUV;
  45.  
  46. void main() {
  47. vUV = UV;
  48. gl_Position = MVP * vec4(vertexPosition_modelspace, 0, 1);
  49. }
Add Comment
Please, Sign In to add comment