JoyPadCtrl.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // Created by jovian on 01/08/17.
  3. //
  4. #include "JoyPadCtrl.h"
  5. JoyPadCtrl::JoyPadCtrl(InputAndJoy *inputJoy, SDL_JoystickID id)
  6. : m_inputJoy(inputJoy), m_id(id),
  7. m_sqCeilMove(100000000.0f), m_sqCeilVisor(500000000.0f) {
  8. m_visor.x = 1.0f;
  9. }
  10. void JoyPadCtrl::refresh() {
  11. // Firing
  12. m_firing = m_inputJoy->getButtonPad(5, m_id);
  13. // Shield activation
  14. m_shield = m_inputJoy->getButtonPad(0, m_id);
  15. // Jumping
  16. m_jump = m_inputJoy->getButtonPad(4, m_id);
  17. // Movement
  18. m_move.x = (float) m_inputJoy->getAxeValue(0, m_id);
  19. m_move.y = (float) m_inputJoy->getAxeValue(1, m_id);
  20. if (m_move.LengthSquared() < m_sqCeilMove)
  21. m_move.SetZero();
  22. else
  23. m_move.Normalize();
  24. // Visor
  25. b2Vec2 newVisor;
  26. newVisor.x = (float) m_inputJoy->getAxeValue(3, m_id);
  27. newVisor.y = (float) m_inputJoy->getAxeValue(4, m_id);
  28. if (newVisor.LengthSquared() > m_sqCeilVisor) {
  29. m_visor = newVisor;
  30. m_visor.Normalize();
  31. }
  32. // Zoom
  33. int axe(30000 + m_inputJoy->getAxeValue(2, m_id));
  34. if (axe > 0) {
  35. float scale((float) axe / 30000.0f);
  36. if (scale > m_zoomScale)
  37. m_zoomScale = scale;
  38. }
  39. axe = 30000 + m_inputJoy->getAxeValue(5, m_id);
  40. if (axe > 0) {
  41. float scale((float) 10000.0f / axe);
  42. if (scale < m_zoomScale)
  43. m_zoomScale = scale;
  44. }
  45. }