Controllers: Make deadzone circular

This commit is contained in:
Connor McLaughlin
2022-10-21 21:14:27 +10:00
parent ca571f8a78
commit f5b7311a45
7 changed files with 133 additions and 17 deletions

View File

@ -230,3 +230,21 @@ std::string Controller::GetSettingsSection(u32 pad)
{
return fmt::format("Pad{}", pad + 1u);
}
bool Controller::InCircularDeadzone(float deadzone, float pos_x, float pos_y)
{
if (pos_x == 0.0f && pos_y == 0.0f)
return false;
// Compute the angle at the given position in the stick's square bounding box.
const float theta = std::atan2(pos_y, pos_x);
// Compute the position that the edge of the circle would be at, given the angle.
const float dz_x = std::cos(theta) * deadzone;
const float dz_y = std::sin(theta) * deadzone;
// We're in the deadzone if our position is less than the circle edge.
const bool in_x = (pos_x < 0.0f) ? (pos_x > dz_x) : (pos_x <= dz_x);
const bool in_y = (pos_y < 0.0f) ? (pos_y > dz_y) : (pos_y <= dz_y);
return (in_x && in_y);
}