Skip to content

Commit

Permalink
improve pointer response to diagonal stick directions
Browse files Browse the repository at this point in the history
  • Loading branch information
rsn8887 committed Sep 9, 2018
1 parent 9f4c4fe commit fe6a372
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 9 deletions.
4 changes: 4 additions & 0 deletions README.MD
Expand Up @@ -283,6 +283,10 @@ Basilisk II Key Codes

Changelog
-----------
0.33f

- improve pointer response to diagonal stick directions

0.33e

- remove bluetooth mouse lag
Expand Down
61 changes: 52 additions & 9 deletions src/PSP2/video_psp.cpp
Expand Up @@ -1181,18 +1181,61 @@ void handle_menu(SceCtrlData pad)
void rescaleAnalog(int *x, int *y, int dead) {
//radial and scaled deadzone
//http://www.third-helix.com/2013/04/12/doing-thumbstick-dead-zones-right.html
//input and output values go from -32767...+32767;

//the maximum is adjusted to account for SCE_CTRL_MODE_DIGITALANALOG_WIDE
//where a reported maximum axis value corresponds to 80% of the full range
//of motion of the analog stick

if (dead == 0) return;
if (dead >= 32767){
*x = 0;
*y = 0;
return;
}

const float maxAxis = 32767.0f;
float analogX = (float) *x;
float analogY = (float) *y;
float deadZone = (float) dead;

float analogX = *x;
float analogY = *y;
float deadZone = dead;
float maximum = 32768.0f;
float magnitude = sqrt(analogX * analogX + analogY * analogY);
if (magnitude >= deadZone)
{
if (magnitude >= deadZone){
//adjust maximum magnitude
float absAnalogX = fabs(analogX);
float absAnalogY = fabs(analogY);
float maxX;
float maxY;
if (absAnalogX > absAnalogY){
maxX = maxAxis;
maxY = (maxAxis * analogY) / absAnalogX;
}else{
maxX = (maxAxis * analogX) / absAnalogY;
maxY = maxAxis;
}
float maximum = sqrt(maxX * maxX + maxY * maxY);
if (maximum > 1.25f * maxAxis) maximum = 1.25f * maxAxis;
if (maximum < magnitude) maximum = magnitude;

// find scaled axis values with magnitudes between zero and maximum
float scalingFactor = maximum / magnitude * (magnitude - deadZone) / (maximum - deadZone);
*x = (int) analogX * scalingFactor;
*y = (int) analogY * scalingFactor;
} else {
analogX = (analogX * scalingFactor);
analogY = (analogY * scalingFactor);

// clamp to ensure results will never exceed the maxAxis value
float clampingFactor = 1.0f;
absAnalogX = fabs(analogX);
absAnalogY = fabs(analogY);
if (absAnalogX > maxAxis || absAnalogY > maxAxis){
if (absAnalogX > absAnalogY)
clampingFactor = maxAxis / absAnalogX;
else
clampingFactor = maxAxis / absAnalogY;
}

*x = (int) (clampingFactor * analogX);
*y = (int) (clampingFactor * analogY);
}else{
*x = 0;
*y = 0;
}
Expand Down

0 comments on commit fe6a372

Please sign in to comment.