Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code Suggestion
02-19-2014, 09:03 AM (This post was last modified: 02-19-2014 09:29 AM by Young.)
Post: #1
Code Suggestion
void PSPDpad::ProcessTouch(float x, float y, bool down) in GamepadEmu.cpp

.
.
.
bool fourWay = g_Config.bDisableDpadDiagonals || rad < 0.7f;
if (down) {
if (fourWay) {
/*int direction = (int)(floorf((atan2f(dy, dx) / (2 * M_PI) * 4) + 0.5f)) & 3;
switch (direction) {
case 0: ctrlMask |= CTRL_RIGHT; break;
case 1: ctrlMask |= CTRL_DOWN; break;
case 2: ctrlMask |= CTRL_LEFT; break;
case 3: ctrlMask |= CTRL_UP; break;
}*/

int maskL1Flag = CTRL_DOWN | CTRL_LEFT;
int maskL2Flag = CTRL_RIGHT | CTRL_DOWN;

if (dy < dx) maskL1Flag = CTRL_RIGHT | CTRL_UP;
if (dy < -dx) maskL2Flag = CTRL_LEFT | CTRL_UP;

ctrlMask = maskL1Flag & maskL2Flag;

// 4 way pad
} else {
// 8 way pad
/*int direction = (int)(floorf((atan2f(dy, dx) / (2 * M_PI) * 8) + 0.5f)) & 7;
switch (direction) {
case 0: ctrlMask |= CTRL_RIGHT; break;
case 1: ctrlMask |= CTRL_RIGHT | CTRL_DOWN; break;
case 2: ctrlMask |= CTRL_DOWN; break;
case 3: ctrlMask |= CTRL_DOWN | CTRL_LEFT; break;
case 4: ctrlMask |= CTRL_LEFT; break;
case 5: ctrlMask |= CTRL_UP | CTRL_LEFT; break;
case 6: ctrlMask |= CTRL_UP; break;
case 7: ctrlMask |= CTRL_UP | CTRL_RIGHT; break;
}*/

int maskL1Flag = CTRL_DOWN;
int maskL2Flag = CTRL_RIGHT;
int maskL3Flag = CTRL_LEFT;
int maskL4Flag = CTRL_DOWN;

if (dy < -dx * 0.41421356f) maskL1Flag = CTRL_UP; //tan 22.5(degree) = 0.4142135623730950488016887242097
if (dy < -dx * 2.41421436f) maskL2Flag = CTRL_LEFT; //tan 67.5(degree) = 2.4142135623730950488016887242097
if (dy < dx * 2.41421436f) maskL3Flag = CTRL_RIGHT;
if (dy < dx * 0.41421356f) maskL4Flag = CTRL_UP;

ctrlMask = (maskL1Flag & maskL4Flag) + (maskL2Flag & maskL3Flag);

}
}
.
.
.
i don't know how to use 'git' thing cuz i'm not a programmer
i'm just a math teacher
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Code Suggestion - Young - 02-19-2014 09:03 AM
RE: Code Suggestion - Raimoo - 02-19-2014, 09:46 AM
RE: Code Suggestion - Young - 02-19-2014, 06:27 PM
RE: Code Suggestion - Bigpet - 02-20-2014, 07:26 PM
RE: Code Suggestion - Apology11 - 02-25-2014, 06:24 PM

Forum Jump: