Controllers: Make deadzone circular
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user