diff --git a/src/gamepad/joystick_transformation.cpp b/src/gamepad/joystick_transformation.cpp index 225c2d1..07de716 100644 --- a/src/gamepad/joystick_transformation.cpp +++ b/src/gamepad/joystick_transformation.cpp @@ -34,9 +34,9 @@ std::pair Fisheye::get_value(std::pair value) { float y_abs = abs(y); float j = std::sqrt(m_radius * m_radius - 1.0 * 1.0); if (x_abs >= j && y_abs >= j) { - float theta = std::atan2(y_abs, x_abs); - x_abs *= m_radius / std::cos(abs(std::remainder(theta, 90))); - y_abs *= m_radius / std::cos(abs(std::remainder(theta, 90))); + float scale = std::hypot(std::min(x_abs / y_abs, y_abs / x_abs), 1.0) / m_radius; + x_abs *= scale; + y_abs *= scale; } x = std::copysign(std::min(1.0f, x_abs), x); y = std::copysign(std::min(1.0f, y_abs), y);