PDA

View Full Version : Noob Coding Question



thehumanidiot
November 12th, 2007, 22:38
how do i code analog stick movements??

yaustar
November 12th, 2007, 22:54
http://www.psp-programming.com/forums/index.php?topic=2321.0

thehumanidiot
November 13th, 2007, 12:08
thank you very much

thehumanidiot
November 14th, 2007, 21:49
how do i detect the movements???

yaustar
November 15th, 2007, 15:06
You already have an example and code in the topic I linked. What do you mean by movement?

dangee
November 15th, 2007, 17:53
2 perpendicular strips attach to the base of the stick with geared movement for precision.

Each strip connects to a potentiometer,whose resistance varies according to the position of the strip.

Changing voltage/current caused by varying resistance is digitised and stored in an 8 bit data register.

X,Y registers for the 2 strips are read from f/ware, and returned to a prog.

'movement' (velocity) is programmed, using the time between 2 reads,and the distance between the
positions that were read

thehumanidiot
November 15th, 2007, 21:41
yes yaustar, i typed that in my code but how do i use it??

dangee
November 18th, 2007, 00:14
Analog velocity's uncommon in games, except on the Wii.
Tiger Woods PGA tour 2004 (PS2) uses it for the golfers' clubswing.
It's an ambitious piece of coding to attempt.

More often, the Analog stick's used like a Dpad:

The range of (X,Y) positions are divided into sectors.
Each sector corresponds to a direction button.
When the Analog position read is inside a sector,it's treated as
a push of the corresponding button.
Central sector = no button push

e.g. (-127,0) = Apad LEFT ,(120,118) = Apad RIGHT+UP

thehumanidiot
November 18th, 2007, 14:21
ok, but i want to know how to use it, for example, to use dpad buttons you would type
if(pad.Buttons & PSP_CTRL_UP){
}

so what do i do for that analog stick??

dangee
November 18th, 2007, 15:27
Size and shape of the Apad centre(-off) sector has a
significant effect on performance and sensitivity.

A precise method uses a circle centred at (0,0) with a variable radius (R).
The value (R × R) is calculated (RSQ).
An Apad position (X,Y) is inside the centre-off sector if ((X × X) + (Y × Y)) is less than RSQ.

ex:
if (analogX^2+analogY^2)<rsquared {/* no analog i/p */}

RSQ effects sensitivity.
(RSQ = 32768) : disables the Apad
(RSQ = 1) : maximum sensitivity
(RSQ = 3698) : default

thehumanidiot
November 18th, 2007, 15:36
sorry, but i don't understand that, i just want to know how to use it, i was trying this

if(analogueX == -127){
speed += 1;
}

but it doesn't work, so what should i be doing?

dangee
November 18th, 2007, 17:04
Apad positions outside the centre-off sector are tested against each outer sector
using techniques similar to hit detection.

The easiest system to implement is a 3×3 grid of square sectors.

The size of the squares is the analog range divided by the grid size. (in this case, 256/3)

An RSQ of at least the default magnitude (3698) is used to make sure the central square is
totally inside the (circular) centre-off sector.

ex:
if (analogX>42)&&(analogY>42) {/* Apad RIGHT+DOWN */}

thehumanidiot
November 18th, 2007, 21:34
still doesn't work

dangee
November 18th, 2007, 23:05
A radial system has advantages over the 3x3 grid.
RSQ minimum = 1, Analog response is smoother.

Each of the outer sectors is defined by an arc, and bounded by the centre-off circle, and the analog range.
Eight 45-degree sectors are often used.

ex:

int lgxA,lgyA;
lgxA=abs(analogX);
lgyA=abs(analogY);
analogX+=analogX;
analogY+=analogY;
if (analogX>lgyA) {/* Apad RIGHT */};
if (analogX<-lgyA) {/* Apad LEFT */};
if (analogY>lgxA) {/* Apad DOWN */};
if (analogY<-lgxA) {/* Apad UP */};

thehumanidiot
November 19th, 2007, 02:00
still isn't working, here is the code i have( i copied and pasted from your tutorial on the other site)

/** Returned controller data */
typedef struct SceCtrlData {
/** The current read frame. */
unsigned int TimeStamp;
/** Bit mask containing zero or more of ::PspCtrlButtons. */
unsigned int Buttons;
/** Analogue stick, X axis. */
unsigned char Lx;
/** Analogue stick, Y axis. */
unsigned char Ly;
/** Reserved. */
unsigned char Rsrv[6];
} SceCtrlData;
const int ANALOGUE_PAD_OFFSET = -127;
sceCtrlReadBufferPositive(&pad, 1);
int analogueX = pad.Lx + ANALOGUE_PAD_OFFSET;
int analogueY = pad.Ly + ANALOGUE_PAD_OFFSET;
const int DEAD_ZONE_THRESHOLD = 5;
const int DEAD_ZONE_THRESHOLD_SQUARED = DEAD_ZONE_THRESHOLD * DEAD_ZONE_THRESHOLD;
int analogueMagnitudeSquared = ( analogueX * analogueX ) + ( analogueY * analogueY );
if( analogueMagnitudeSquared < DEAD_ZONE_THRESHOLD_SQUARED )
{
analogueX = 0;
analogueY = 0;
}
while(1){
if(frame == 2){
int lgxA,lgyA;
lgxA= +analogueX;
lgyA= +analogueY;
analogueX+=analogueX;
analogueY+=analogueY;
if (analogueX>lgyA) {
speed+=1;
}}
}

dangee
November 19th, 2007, 10:14
Software development problems can be helped by use of a:

BREAKPOINT(int argc, char *argv[])
{ /* print variables to screen,wait for a button push */ }