JoyPadCtrl.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // Created by jovian on 01/08/17.
  3. //
  4. #include "JoyPadCtrl.h"
  5. #define XBOX_BUT_X 0
  6. #define XBOX_BUT_Y 1
  7. #define XBOX_BUT_B 2
  8. #define XBOX_BUT_A 3
  9. #define XBOX_BUT_LB 4
  10. #define XBOX_BUT_RB 5
  11. #define XBOX_BUT_SELECT 6
  12. #define XBOX_BUT_START 7
  13. #define XBOX_AXE_1X 0
  14. #define XBOX_AXE_1Y 1
  15. #define XBOX_AXE_2X 3
  16. #define XBOX_AXE_2Y 4
  17. #define XBOX_AXE_RT 2
  18. #define XBOX_AXE_LT 5
  19. JoyPadCtrl::JoyPadCtrl(InputAndJoy *inputJoy, SDL_JoystickID id)
  20. : m_inputJoy(inputJoy), m_id(id),
  21. m_sqCeilMove(100000000.0f), m_sqCeilVisor(500000000.0f) {
  22. m_visor.x = 1.0f;
  23. }
  24. void JoyPadCtrl::refresh() {
  25. // Firing
  26. m_firing = m_inputJoy->getButtonPad(XBOX_BUT_X, m_id);
  27. // Shield activation
  28. m_shield = m_inputJoy->getButtonPad(XBOX_BUT_A, m_id);
  29. // Boosting
  30. m_boost = m_inputJoy->getButtonPad(XBOX_BUT_B, m_id);
  31. // Visor
  32. b2Vec2 newVisor;
  33. newVisor.x = (float) m_inputJoy->getAxeValue(XBOX_AXE_1X, m_id);
  34. newVisor.y = (float) m_inputJoy->getAxeValue(XBOX_AXE_1Y, m_id);
  35. if (newVisor.LengthSquared() > m_sqCeilVisor) {
  36. m_visor = newVisor;
  37. m_visor.Normalize();
  38. }
  39. // Acceleration
  40. int acc = 30000 + m_inputJoy->getAxeValue(XBOX_AXE_LT);
  41. if (acc < 30000)
  42. m_acceleration = 0.0f;
  43. else // todo Progressive
  44. m_acceleration = 1.0f;
  45. // Torque with buttons
  46. if (m_inputJoy->getButtonPad(XBOX_BUT_LB, m_id))
  47. m_torque = -1.0f;
  48. else if (m_inputJoy->getButtonPad(XBOX_BUT_RB, m_id))
  49. m_torque = 1.0f;
  50. else
  51. m_torque = 0.0f;
  52. // Zoom
  53. /*int axe(30000 + m_inputJoy->getAxeValue(2, m_id));
  54. if (axe > 0) {
  55. float scale((float) axe / 30000.0f);
  56. if (scale > m_zoomScale)
  57. m_zoomScale = scale;
  58. }
  59. axe = 30000 + m_inputJoy->getAxeValue(5, m_id);
  60. if (axe > 0) {
  61. float scale((float) 10000.0f / axe);
  62. if (scale < m_zoomScale)
  63. m_zoomScale = scale;
  64. }*/
  65. if (m_inputJoy->getButtonPad(XBOX_BUT_A))
  66. m_zoomScale += 0.05f;
  67. else if (m_inputJoy->getButtonPad(XBOX_BUT_B))
  68. m_zoomScale -= 0.05f;
  69. else if (m_inputJoy->getButtonPad(XBOX_BUT_Y))
  70. m_zoomScale = 1.0f;
  71. }