| View previous topic :: View next topic |
| Author |
Message |
leenoi
Joined: 08 Jul 2005 Posts: 9
|
Posted: Tue Feb 20, 2007 1:57 pm Post subject: how to determine analog stick value for 8 direction? |
|
|
I want to determine analog stick value to determine 8 direction.
(S,SE,E,EN,N,NW,W,WS )
This is my code I edit from SDK 's example.
Thank you very much
| Code: | int main(void)
{
SceCtrlData pad;
pspDebugScreenInit();
SetupCallbacks();
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
while(!done){
pspDebugScreenSetXY(0, 2);
sceCtrlReadBufferPositive(&pad, 1);
printf("Analog X = %d ", pad.Lx);
printf("Analog Y = %d \n", pad.Ly);
if ((pad.Lx>=127)&&(pad.Ly<30))
{
printf(" Go East \n");
}else if ((pad.Ly<= -127)&&(pad.Lx<30))
{
printf(" Go West \n");
}else if ((pad.Ly<= -127)&&(pad.Lx<30))
{
printf(" Go North \n");
}else if ((pad.Lx>=127)&&(pad.Ly<120))
{
printf(" Go South \n");
}
}
sceKernelExitGame();
return 0;
}
|
|
|
| Back to top |
|
 |
dot_blank

Joined: 28 Sep 2005 Posts: 498 Location: Brasil
|
Posted: Tue Feb 20, 2007 4:40 pm Post subject: |
|
|
Last time i remember southeast - SE composed of south + east :P
i may be wrong but ...
| Code: | if ( (pad.Lx>=127)&&(pad.Ly<30) & (pad.Lx>=127)&&(pad.Ly<120) ) {
print("Southeast");
} |
_________________ 10011011 00101010 11010111 10001001 10111010 |
|
| Back to top |
|
 |
Saotome

Joined: 03 Apr 2004 Posts: 182
|
Posted: Tue Feb 20, 2007 5:51 pm Post subject: |
|
|
thats my solution:
(for 16 directions)
| Code: |
// s16 aStickR, aStickX, aStickY;
aStickX = pad.Ly - 128;
aStickY = pad.Lx - 128;
if (getSqrRadius(aStickX, aStickY) > 4500) {
aStickR = ((atan2f(aStickX, aStickY) + M_PI) / (M_PI*2)) * 16.0f;
} else {
aStickR = -1;
}
|
getSqrRadius = x˛+y˛ ;)
aStickR is -1 if the stick is not pulled in any direction (if the radius˛ is lower than 4500)
P.S.: I'm using it for a radial menu to choose 1 of 16 options ;) _________________ infj |
|
| Back to top |
|
 |
dot_blank

Joined: 28 Sep 2005 Posts: 498 Location: Brasil
|
Posted: Tue Feb 20, 2007 8:38 pm Post subject: |
|
|
niiiicee :)
extra points for you _________________ 10011011 00101010 11010111 10001001 10111010 |
|
| Back to top |
|
 |
leenoi
Joined: 08 Jul 2005 Posts: 9
|
Posted: Tue Feb 20, 2007 11:18 pm Post subject: |
|
|
thank you very much I will try it.
but Saotome how you check for other direction. (16 direction) |
|
| Back to top |
|
 |
Saotome

Joined: 03 Apr 2004 Posts: 182
|
Posted: Tue Feb 20, 2007 11:51 pm Post subject: |
|
|
dot_blank: thanks for the extra points :)
leenoi: the result in aStickR is a value from 0 to 15 (16 different values) depending on the direction you pull the stick in. if it's -1, it means that it's not pulled in any direction (relatively) depending on the threshold value (4500).
if you change the 16.0f in the code to 8.0f then you get 8 different values (0..7). _________________ infj |
|
| Back to top |
|
 |
leenoi
Joined: 08 Jul 2005 Posts: 9
|
Posted: Wed Feb 21, 2007 12:22 pm Post subject: |
|
|
| Saotome wrote: | dot_blank: thanks for the extra points :)
leenoi: the result in aStickR is a value from 0 to 15 (16 different values) depending on the direction you pull the stick in. if it's -1, it means that it's not pulled in any direction (relatively) depending on the threshold value (4500).
if you change the 16.0f in the code to 8.0f then you get 8 different values (0..7). |
Ohh I understand now Thank you very much. |
|
| Back to top |
|
 |
|