12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- //
- // Created by jovian on 01/08/17.
- //
- #include "JoyPadCtrl.h"
- 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(5, m_id);
- // Shield activation
- m_shield = m_inputJoy->getButtonPad(0, m_id);
- // Jumping
- m_jump = m_inputJoy->getButtonPad(4, m_id);
- // Movement
- m_move.x = (float) m_inputJoy->getAxeValue(0, m_id);
- m_move.y = (float) m_inputJoy->getAxeValue(1, m_id);
- if (m_move.LengthSquared() < m_sqCeilMove)
- m_move.SetZero();
- else
- m_move.Normalize();
- // Visor
- b2Vec2 newVisor;
- newVisor.x = (float) m_inputJoy->getAxeValue(3, m_id);
- newVisor.y = (float) m_inputJoy->getAxeValue(4, m_id);
- if (newVisor.LengthSquared() > m_sqCeilVisor) {
- m_visor = newVisor;
- m_visor.Normalize();
- }
- // 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;
- }
- }
|