forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

how to determine analog stick value for 8 direction?

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
leenoi



Joined: 08 Jul 2005
Posts: 9

PostPosted: Tue Feb 20, 2007 1:57 pm    Post subject: how to determine analog stick value for 8 direction? Reply with quote

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
View user's profile Send private message
dot_blank



Joined: 28 Sep 2005
Posts: 498
Location: Brasil

PostPosted: Tue Feb 20, 2007 4:40 pm    Post subject: Reply with quote

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
View user's profile Send private message
Saotome



Joined: 03 Apr 2004
Posts: 182

PostPosted: Tue Feb 20, 2007 5:51 pm    Post subject: Reply with quote

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
View user's profile Send private message
dot_blank



Joined: 28 Sep 2005
Posts: 498
Location: Brasil

PostPosted: Tue Feb 20, 2007 8:38 pm    Post subject: Reply with quote

niiiicee :)

extra points for you
_________________
10011011 00101010 11010111 10001001 10111010
Back to top
View user's profile Send private message
leenoi



Joined: 08 Jul 2005
Posts: 9

PostPosted: Tue Feb 20, 2007 11:18 pm    Post subject: Reply with quote

thank you very much I will try it.

but Saotome how you check for other direction. (16 direction)
Back to top
View user's profile Send private message
Saotome



Joined: 03 Apr 2004
Posts: 182

PostPosted: Tue Feb 20, 2007 11:51 pm    Post subject: Reply with quote

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
View user's profile Send private message
leenoi



Joined: 08 Jul 2005
Posts: 9

PostPosted: Wed Feb 21, 2007 12:22 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group