Analogue Pad

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

Moderators: cheriff, TyRaNiD

Post Reply
Energy
Posts: 133
Joined: Sat Mar 26, 2005 4:13 pm
Location: uk/beds/flitwick
Contact:

Analogue Pad

Post by Energy »

Hey,
I've been searching away at this, and got little or no sucsess. I'm jsut trying to work out how to use the bloody thing! Search on the forums will only let you view the 1st page of results :/

From what I know:
CtrlSetAnalogMode(1);
needs to be put at the beginning of your code if you plan to use the analogue stick.

if(pad.Buttons & PSP_CTRL_CIRCLE) <- returns a value, so I'm wodering do I just do this...

if(pad.Buttons & PSP_ANALOG_X == ???)
{
//....
}

Is that on the rightlines...
I'm so close to something that I consider releasable (in an early form). Just really polishing and sorting bugs and stuff :/
Thanks for any help.
User avatar
Saotome
Posts: 182
Joined: Sat Apr 03, 2004 3:45 am

Post by Saotome »

you should have a look at the pspsdk code in svn from time to time ;)
especially here

Code: Select all

/** Returned controller data */
typedef struct SceCtrlData &#123;
        /** The current read frame. */
        unsigned int TimeStamp;
        /** Bit mask containing zero or more of &#58;&#58;PspCtrlButtons. */
        unsigned int Buttons;
        /** Analogue stick, X axis. */
        unsigned char Lx;
        /** Analogue stick, Y axis. */
        unsigned char Ly;
        /** Reserved. */
        unsigned char Rsrv&#91;6&#93;;
&#125; SceCtrlData;
I think you can guess the rest :)

EDIT: if not, here's the sample from svn
infj
Energy
Posts: 133
Joined: Sat Mar 26, 2005 4:13 pm
Location: uk/beds/flitwick
Contact:

Post by Energy »

Saotome wrote:you should have a look at the pspsdk code in svn from time to time ;)
especially here

Code: Select all

/** Returned controller data */
typedef struct SceCtrlData &#123;
        /** The current read frame. */
        unsigned int TimeStamp;
        /** Bit mask containing zero or more of &#58;&#58;PspCtrlButtons. */
        unsigned int Buttons;
        /** Analogue stick, X axis. */
        unsigned char Lx;
        /** Analogue stick, Y axis. */
        unsigned char Ly;
        /** Reserved. */
        unsigned char Rsrv&#91;6&#93;;
&#125; SceCtrlData;
I think you can guess the rest :)

EDIT: if not, here's the sample from svn

Awww I'm sooo close now Thanks! :)
I got this:

Code: Select all

while&#40;1&#41;
&#123;
   		sceCtrlSetSamplingCycle&#40;0&#41;;
		sceCtrlSetSamplingMode&#40;1&#41;;
		sceCtrlReadBufferPositive&#40;&pad, 1&#41;;

		if&#40;pad.Lx > 132&#41;
		&#123;
			if&#40;pad.Lx < 192&#41;
			&#123;
				if&#40;player_x < 422&#41;
				&#123;
					player_x += 4;
				&#125;
			&#125;
			else
			&#123;
				if&#40;player_x < 417&#41;
				&#123;
					player_x += 9;
				&#125;
			&#125;
		&#125;
&#125;
Now my only issue is that the bloody thing doesn't stop moving. Yet it gives me control of it! :) Getting there slowly :D[/code]
User avatar
Saotome
Posts: 182
Joined: Sat Apr 03, 2004 3:45 am

Post by Saotome »

how about something like this (not tested but I'm using something similar):

Code: Select all

int xx,yy;
xx = &#40;int&#41;pad.Lx - 128;
yy = &#40;int&#41;pad.Ly - 128;
if &#40;&#40;xx * yy&#41; > 500&#41; //maybe some higher value
&#123;
    player_x += xx >> 4;
    player_y += yy >> 4;
&#125;
infj
Energy
Posts: 133
Joined: Sat Mar 26, 2005 4:13 pm
Location: uk/beds/flitwick
Contact:

Post by Energy »

That's a nice way of doing it... :)
Guess the code should actually be:

Code: Select all

int xx,yy;
xx = &#40;int&#41;pad.Lx - 128;
yy = &#40;int&#41;pad.Ly - 128;
if &#40;&#40;xx * yy&#41; > 500 || &#40;xx * yy&#41; < -500&#41; //maybe some higher value
&#123;
    player_x += xx >> 4;
    player_y += yy >> 4;
&#125;
That works quite well. Big thanks for your help.
Hoping to get something out by mid next week.

(only issue I see is if xx or yy equals 0 then you don't get anywhere. Should be easy to fix though.)
User avatar
Saotome
Posts: 182
Joined: Sat Apr 03, 2004 3:45 am

Post by Saotome »

Energy wrote:That's a nice way of doing it... :)
Guess the code should actually be...
Ah, yes that was not correct (it was still early in the morning ;)), sorry. But actually it should have been:

Code: Select all

int xx,yy;
xx = &#40;int&#41;pad.Lx - 128;
yy = &#40;int&#41;pad.Ly - 128;
if &#40;&#40;xx*xx + yy*yy&#41; > 500&#41; //maybe some higher value
&#123;
    player_x += xx >> 4;
    player_y += yy >> 4;
&#125;
(xx*xx+yy*yy) is the square-radius then.
That should fix your issue with "xx or yy equals 0"
infj
orphan frequently
Posts: 9
Joined: Thu Aug 11, 2005 1:52 pm

Post by orphan frequently »

When i talked to an official dev he said that the max X is 217 and the max Y is 218. True?
Mike3285: wtf is a palindrome
MaroonSand: no its not dude
memon
Posts: 63
Joined: Mon Oct 03, 2005 10:51 pm

Post by memon »

I remember getting the whole range in my psp controller tests. The only thing is that you really want to have small dead zone in the middle, something like +-18 (so yeah the effective range is something like 220). The reason is that when you release the analog stick it never really gets back to the center.
Post Reply