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)
|
||||
{
|
||||
sf::Vector2f newDirection = {value, directionVector.y};
|
||||
sf::Vector2f newDirection = sf::Vector2f(value, directionVector.y);
|
||||
set(newDirection);
|
||||
}
|
||||
|
||||
void Direction::setY(float value)
|
||||
{
|
||||
sf::Vector2f newDirection = {directionVector.x, value};
|
||||
sf::Vector2f newDirection = sf::Vector2f(directionVector.x, value);
|
||||
set(newDirection);
|
||||
}
|
||||
|
|
|
@ -83,15 +83,12 @@ void InputMapper::handleJoystickMovement(sf::Event::JoystickMoveEvent event)
|
|||
value = 0.f;
|
||||
}
|
||||
|
||||
if (axis == sf::Joystick::Axis::X ||
|
||||
axis == sf::Joystick::Axis::R ||
|
||||
axis == sf::Joystick::Axis::PovX)
|
||||
if (axis == sf::Joystick::Axis::X)
|
||||
{
|
||||
gamepadIdentity->direction.setX(value);
|
||||
} else if (axis == sf::Joystick::Axis::Y ||
|
||||
axis == sf::Joystick::Axis::U ||
|
||||
axis == sf::Joystick::Axis::PovY)
|
||||
} else if (axis == sf::Joystick::Axis::Y)
|
||||
{
|
||||
value *= -1; // Is inverted
|
||||
gamepadIdentity->direction.setY(value);
|
||||
}
|
||||
}
|
||||
|
@ -103,29 +100,29 @@ std::shared_ptr<InputIdentity> InputMapper::getInputIdentity(InputDeviceType dev
|
|||
case InputDeviceType::KEYBOARD:
|
||||
return keyboardIdentity;
|
||||
case InputDeviceType::GAMEPAD:
|
||||
if (InputMapper::gamepadIdentities.contains(gamepadId))
|
||||
if (!gamepadIdentities.contains(gamepadId))
|
||||
{
|
||||
// Create if it does not exist yet
|
||||
InputMapper::addGamepadIdentity(gamepadId);
|
||||
addGamepadIdentity(gamepadId);
|
||||
}
|
||||
return InputMapper::gamepadIdentities[gamepadId];
|
||||
return gamepadIdentities[gamepadId];
|
||||
default:
|
||||
return InputMapper::allIdentity;
|
||||
return allIdentity;
|
||||
}
|
||||
}
|
||||
|
||||
void InputMapper::addGamepadIdentity(unsigned int gamepadId)
|
||||
{
|
||||
// Exists already?
|
||||
if (InputMapper::gamepadIdentities.contains(gamepadId))
|
||||
if (gamepadIdentities.contains(gamepadId))
|
||||
{
|
||||
InputMapper::gamepadIdentities[gamepadId]->isActive = true;
|
||||
gamepadIdentities[gamepadId]->isActive = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// Does not exist yet, create new
|
||||
auto newIdentity = std::make_shared<InputIdentity>(InputDeviceType::GAMEPAD, gamepadId);
|
||||
InputMapper::gamepadIdentities[gamepadId] = newIdentity;
|
||||
gamepadIdentities[gamepadId] = newIdentity;
|
||||
}
|
||||
|
||||
void InputMapper::deactivateGamepadIdentity(unsigned int gamepadId)
|
||||
|
@ -137,7 +134,8 @@ void InputMapper::deactivateGamepadIdentity(unsigned int gamepadId)
|
|||
|
||||
std::shared_ptr<InputMapper> InputMapper::getInstance()
|
||||
{
|
||||
if (singletonInstance == nullptr) {
|
||||
if (singletonInstance == nullptr)
|
||||
{
|
||||
singletonInstance = std::make_shared<InputMapper>();
|
||||
}
|
||||
|
||||
|
@ -151,7 +149,7 @@ std::vector<std::shared_ptr<InputIdentity>> InputMapper::getAllInputIdentities()
|
|||
allIdentities.push_back(allIdentity);
|
||||
allIdentities.push_back(keyboardIdentity);
|
||||
|
||||
for (auto const& [key, val] : gamepadIdentities)
|
||||
for (auto const &[key, val]: gamepadIdentities)
|
||||
{
|
||||
allIdentities.push_back(val);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ void Player::update(Game *game)
|
|||
}
|
||||
|
||||
// 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();
|
||||
coordinates.move(moveDelta);
|
||||
circle->coordinates.set(coordinates);
|
||||
|
|
Loading…
Reference in a new issue