how to determine analog stick value for 8 direction?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
leenoi
Posts: 9
Joined: Fri Jul 08, 2005 4:35 pm

how to determine analog stick value for 8 direction?

Post by leenoi »

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: Select all

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 &#40;&#40;pad.Lx>=127&#41;&&&#40;pad.Ly<30&#41;&#41;
		&#123;
			printf&#40;" Go East \n"&#41;;
		&#125;else if &#40;&#40;pad.Ly<= -127&#41;&&&#40;pad.Lx<30&#41;&#41;
		&#123;
			printf&#40;" Go West \n"&#41;;
		&#125;else if &#40;&#40;pad.Ly<= -127&#41;&&&#40;pad.Lx<30&#41;&#41;
		&#123;
			printf&#40;" Go North \n"&#41;;
		&#125;else if &#40;&#40;pad.Lx>=127&#41;&&&#40;pad.Ly<120&#41;&#41;
		&#123;
			printf&#40;" Go South \n"&#41;;
		&#125;

	&#125;

	sceKernelExitGame&#40;&#41;;
	return 0;
&#125;
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

Last time i remember southeast - SE composed of south + east :P
i may be wrong but ...

Code: Select all

if &#40; &#40;pad.Lx>=127&#41;&&&#40;pad.Ly<30&#41; & &#40;pad.Lx>=127&#41;&&&#40;pad.Ly<120&#41; &#41; &#123;
      print&#40;"Southeast"&#41;;
&#125;
10011011 00101010 11010111 10001001 10111010
User avatar
Saotome
Posts: 182
Joined: Sat Apr 03, 2004 3:45 am

Post by Saotome »

thats my solution:
(for 16 directions)

Code: Select all

	// s16 aStickR, aStickX, aStickY;

	aStickX = pad.Ly - 128;
	aStickY = pad.Lx - 128;	
	
	if &#40;getSqrRadius&#40;aStickX, aStickY&#41; > 4500&#41; &#123;
		aStickR = &#40;&#40;atan2f&#40;aStickX, aStickY&#41; + M_PI&#41; / &#40;M_PI*2&#41;&#41; * 16.0f;
	&#125; else &#123;
		aStickR = -1;		
	&#125;
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
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

niiiicee :)

extra points for you
10011011 00101010 11010111 10001001 10111010
leenoi
Posts: 9
Joined: Fri Jul 08, 2005 4:35 pm

Post by leenoi »

thank you very much I will try it.

but Saotome how you check for other direction. (16 direction)
User avatar
Saotome
Posts: 182
Joined: Sat Apr 03, 2004 3:45 am

Post by Saotome »

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
leenoi
Posts: 9
Joined: Fri Jul 08, 2005 4:35 pm

Post by leenoi »

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.
Post Reply