Fixed inverted controller output
This commit is contained in:
parent
ddea927ce0
commit
bf47252b8a
3 changed files with 16 additions and 18 deletions
|
@ -155,12 +155,12 @@ void Direction::set(sf::Vector2f direction)
|
||||||
|
|
||||||
void Direction::setX(float value)
|
void Direction::setX(float value)
|
||||||
{
|
{
|
||||||
sf::Vector2f newDirection = {value, directionVector.y};
|
sf::Vector2f newDirection = sf::Vector2f(value, directionVector.y);
|
||||||
set(newDirection);
|
set(newDirection);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Direction::setY(float value)
|
void Direction::setY(float value)
|
||||||
{
|
{
|
||||||
sf::Vector2f newDirection = {directionVector.x, value};
|
sf::Vector2f newDirection = sf::Vector2f(directionVector.x, value);
|
||||||
set(newDirection);
|
set(newDirection);
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,15 +83,12 @@ void InputMapper::handleJoystickMovement(sf::Event::JoystickMoveEvent event)
|
||||||
value = 0.f;
|
value = 0.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (axis == sf::Joystick::Axis::X ||
|
if (axis == sf::Joystick::Axis::X)
|
||||||
axis == sf::Joystick::Axis::R ||
|
|
||||||
axis == sf::Joystick::Axis::PovX)
|
|
||||||
{
|
{
|
||||||
gamepadIdentity->direction.setX(value);
|
gamepadIdentity->direction.setX(value);
|
||||||
} else if (axis == sf::Joystick::Axis::Y ||
|
} else if (axis == sf::Joystick::Axis::Y)
|
||||||
axis == sf::Joystick::Axis::U ||
|
|
||||||
axis == sf::Joystick::Axis::PovY)
|
|
||||||
{
|
{
|
||||||
|
value *= -1; // Is inverted
|
||||||
gamepadIdentity->direction.setY(value);
|
gamepadIdentity->direction.setY(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,29 +100,29 @@ std::shared_ptr<InputIdentity> InputMapper::getInputIdentity(InputDeviceType dev
|
||||||
case InputDeviceType::KEYBOARD:
|
case InputDeviceType::KEYBOARD:
|
||||||
return keyboardIdentity;
|
return keyboardIdentity;
|
||||||
case InputDeviceType::GAMEPAD:
|
case InputDeviceType::GAMEPAD:
|
||||||
if (InputMapper::gamepadIdentities.contains(gamepadId))
|
if (!gamepadIdentities.contains(gamepadId))
|
||||||
{
|
{
|
||||||
// Create if it does not exist yet
|
// Create if it does not exist yet
|
||||||
InputMapper::addGamepadIdentity(gamepadId);
|
addGamepadIdentity(gamepadId);
|
||||||
}
|
}
|
||||||
return InputMapper::gamepadIdentities[gamepadId];
|
return gamepadIdentities[gamepadId];
|
||||||
default:
|
default:
|
||||||
return InputMapper::allIdentity;
|
return allIdentity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputMapper::addGamepadIdentity(unsigned int gamepadId)
|
void InputMapper::addGamepadIdentity(unsigned int gamepadId)
|
||||||
{
|
{
|
||||||
// Exists already?
|
// Exists already?
|
||||||
if (InputMapper::gamepadIdentities.contains(gamepadId))
|
if (gamepadIdentities.contains(gamepadId))
|
||||||
{
|
{
|
||||||
InputMapper::gamepadIdentities[gamepadId]->isActive = true;
|
gamepadIdentities[gamepadId]->isActive = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Does not exist yet, create new
|
// Does not exist yet, create new
|
||||||
auto newIdentity = std::make_shared<InputIdentity>(InputDeviceType::GAMEPAD, gamepadId);
|
auto newIdentity = std::make_shared<InputIdentity>(InputDeviceType::GAMEPAD, gamepadId);
|
||||||
InputMapper::gamepadIdentities[gamepadId] = newIdentity;
|
gamepadIdentities[gamepadId] = newIdentity;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputMapper::deactivateGamepadIdentity(unsigned int gamepadId)
|
void InputMapper::deactivateGamepadIdentity(unsigned int gamepadId)
|
||||||
|
@ -137,7 +134,8 @@ void InputMapper::deactivateGamepadIdentity(unsigned int gamepadId)
|
||||||
|
|
||||||
std::shared_ptr<InputMapper> InputMapper::getInstance()
|
std::shared_ptr<InputMapper> InputMapper::getInstance()
|
||||||
{
|
{
|
||||||
if (singletonInstance == nullptr) {
|
if (singletonInstance == nullptr)
|
||||||
|
{
|
||||||
singletonInstance = std::make_shared<InputMapper>();
|
singletonInstance = std::make_shared<InputMapper>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ void Player::update(Game *game)
|
||||||
}
|
}
|
||||||
|
|
||||||
// auto moveDirection = InputMapper::getInstance()->getInputIdentity(InputDeviceType::KEYBOARD)->direction.asVector();
|
// auto moveDirection = InputMapper::getInstance()->getInputIdentity(InputDeviceType::KEYBOARD)->direction.asVector();
|
||||||
auto moveDirection = gamepadIdentity->direction.asScreenVector();
|
auto moveDirection = gamepadIdentity->direction.asVector();
|
||||||
auto moveDelta = moveDirection * 30.0f * FRAME_TIME.asSeconds();
|
auto moveDelta = moveDirection * 30.0f * FRAME_TIME.asSeconds();
|
||||||
coordinates.move(moveDelta);
|
coordinates.move(moveDelta);
|
||||||
circle->coordinates.set(coordinates);
|
circle->coordinates.set(coordinates);
|
||||||
|
|
Loading…
Reference in a new issue