12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- //
- // Created by jovian on 01/08/17.
- //
- #include "JoyPadCtrl.h"
- #define XBOX_BUT_X 0
- #define XBOX_BUT_Y 1
- #define XBOX_BUT_B 2
- #define XBOX_BUT_A 3
- #define XBOX_BUT_LB 4
- #define XBOX_BUT_RB 5
- #define XBOX_BUT_SELECT 6
- #define XBOX_BUT_START 7
- #define XBOX_AXE_1X 0
- #define XBOX_AXE_1Y 1
- #define XBOX_AXE_2X 3
- #define XBOX_AXE_2Y 4
- #define XBOX_AXE_RT 2
- #define XBOX_AXE_LT 5
- JoyPadCtrl::JoyPadCtrl(InputAndJoy *inputJoy, SDL_JoystickID id)
- : m_inputJoy(inputJoy), m_id(id),
- m_sqCeilMove(100000000.0f), m_sqCeilVisor(500000000.0f) {
- m_visor.x = 1.0f;
- }
- void JoyPadCtrl::refresh() {
- // Firing
- m_firing = m_inputJoy->getButtonPad(XBOX_BUT_X, m_id);
- // Shield activation
- m_shield = m_inputJoy->getButtonPad(XBOX_BUT_A, m_id);
- // Boosting
- m_boost = m_inputJoy->getButtonPad(XBOX_BUT_B, m_id);
- // Visor
- b2Vec2 newVisor;
- newVisor.x = (float) m_inputJoy->getAxeValue(XBOX_AXE_1X, m_id);
- newVisor.y = (float) m_inputJoy->getAxeValue(XBOX_AXE_1Y, m_id);
- if (newVisor.LengthSquared() > m_sqCeilVisor) {
- m_visor = newVisor;
- m_visor.Normalize();
- }
- // Acceleration
- int acc = 30000 + m_inputJoy->getAxeValue(XBOX_AXE_LT);
- if (acc < 30000)
- m_acceleration = 0.0f;
- else // todo Progressive
- m_acceleration = 1.0f;
- // Torque with buttons
- if (m_inputJoy->getButtonPad(XBOX_BUT_LB, m_id))
- m_torque = -1.0f;
- else if (m_inputJoy->getButtonPad(XBOX_BUT_RB, m_id))
- m_torque = 1.0f;
- else
- m_torque = 0.0f;
- // Zoom
- /*int axe(30000 + m_inputJoy->getAxeValue(2, m_id));
- if (axe > 0) {
- float scale((float) axe / 30000.0f);
- if (scale > m_zoomScale)
- m_zoomScale = scale;
- }
- axe = 30000 + m_inputJoy->getAxeValue(5, m_id);
- if (axe > 0) {
- float scale((float) 10000.0f / axe);
- if (scale < m_zoomScale)
- m_zoomScale = scale;
- }*/
- if (m_inputJoy->getButtonPad(XBOX_BUT_A))
- m_zoomScale += 0.05f;
- else if (m_inputJoy->getButtonPad(XBOX_BUT_B))
- m_zoomScale -= 0.05f;
- else if (m_inputJoy->getButtonPad(XBOX_BUT_Y))
- m_zoomScale = 1.0f;
- }
|