Skip to content

Commit

Permalink
Fixed controller weirdness (Kenix3#464)
Browse files Browse the repository at this point in the history
Co-authored-by: KiritoDv <[email protected]>
  • Loading branch information
briaguya-ai and KiritoDv authored Apr 5, 2024
1 parent c3a6994 commit cdcb1f0
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/controller/controldevice/controller/ControllerStick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
#include <sstream>
#include <algorithm>

#define M_TAU 6.2831853071795864769252867665590057 // 2 * pi
#define MINIMUM_RADIUS_TO_MAP_NOTCH 0.9

// for some reason windows isn't seeing M_PI
// this is copied from my system's math.h
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

#define M_TAU 2 * M_PI
#define MINIMUM_RADIUS_TO_MAP_NOTCH 0.9

namespace LUS {
ControllerStick::ControllerStick(uint8_t portIndex, Stick stick)
: mPortIndex(portIndex), mStick(stick), mUseKeydownEventToCreateNewMapping(false),
Expand Down Expand Up @@ -230,11 +230,11 @@ float ControllerStick::GetAxisDirectionValue(Direction direction) {
}

void ControllerStick::Process(int8_t& x, int8_t& y) {
auto sx = GetAxisDirectionValue(RIGHT) - GetAxisDirectionValue(LEFT);
auto sy = GetAxisDirectionValue(UP) - GetAxisDirectionValue(DOWN);
double sx = GetAxisDirectionValue(RIGHT) - GetAxisDirectionValue(LEFT);
double sy = GetAxisDirectionValue(UP) - GetAxisDirectionValue(DOWN);

auto ux = fabs(sx) * mSensitivity;
auto uy = fabs(sy) * mSensitivity;
double ux = fabs(sx) * mSensitivity;
double uy = fabs(sy) * mSensitivity;

// create scaled circular dead-zone
auto len = sqrt(ux * ux + uy * uy);
Expand Down Expand Up @@ -265,11 +265,11 @@ void ControllerStick::Process(int8_t& x, int8_t& y) {

const double distance = std::sqrt((ux * ux) + (uy * uy)) / MAX_AXIS_RANGE;
if (distance >= MINIMUM_RADIUS_TO_MAP_NOTCH) {
auto angle = atan2(uy, ux) + M_TAU;
auto angle = std::atan2(uy, ux) + M_TAU;
auto newAngle = GetClosestNotch(angle, notchProximityValRadians);

ux = cos(newAngle) * distance * MAX_AXIS_RANGE;
uy = sin(newAngle) * distance * MAX_AXIS_RANGE;
ux = std::cos(newAngle) * distance * MAX_AXIS_RANGE;
uy = std::sin(newAngle) * distance * MAX_AXIS_RANGE;
}

// assign back to original sign
Expand Down

0 comments on commit cdcb1f0

Please sign in to comment.