 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
kuat
Joined: 09 Mar 2009 Posts: 5
|
Posted: Fri Mar 13, 2009 9:44 pm Post subject: Limitation of analogic speed |
|
|
Hi there!
Is there anyway to limit speed of analogic incrementation of pad.Lx and pad.Ly?
Thx |
|
| Back to top |
|
 |
Art
Joined: 09 Nov 2005 Posts: 647
|
Posted: Fri Mar 13, 2009 9:46 pm Post subject: |
|
|
Well there are easy software ways to achieve the same thing,
ie. time the increment of another var till it reaches the lx/y value. _________________ If not actually, then potentially. |
|
| Back to top |
|
 |
Torch

Joined: 28 May 2008 Posts: 842
|
Posted: Fri Mar 13, 2009 10:31 pm Post subject: |
|
|
| It just reports the x,y coordinates at that moment in time. If you want acceleration/deceleration effects then that is up to you to implement in your software. |
|
| Back to top |
|
 |
jean

Joined: 05 Jan 2008 Posts: 489
|
Posted: Sat Mar 14, 2009 12:51 am Post subject: |
|
|
You can use a simple follower derived from PID controller: for each axis,
where:
ca = computed axis (the one you will use)
ra = real axis (the position you readed from hw)
k = a constant between 0 and 1 (the lower, the slower)
each of the members need to be float or more precise floating point types.
A fast fixed point implementation is possible if you plan to make heavy use of this (like I do :P ) |
|
| Back to top |
|
 |
kuat
Joined: 09 Mar 2009 Posts: 5
|
Posted: Sat Mar 14, 2009 10:35 am Post subject: |
|
|
Well!
Thankyou guys, that was a lot of help!! |
|
| Back to top |
|
 |
sauron_le_noir
Joined: 05 Jul 2008 Posts: 229
|
Posted: Sat Mar 14, 2009 11:11 pm Post subject: |
|
|
look at this it is taken from the mouse part of the allegro library for psp
the function static void psp_mouse_timer_poll(void) do all the job
you have auto accelration in all the position thx to the real good code of Nekuz0r
| Code: |
/* ______ ___ ___
* /\ _ \ /\_ \ /\_ \
* \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
* \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
* \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
* \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
* \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
* /\____/
* \_/__/
*
* PSP mouse driver.
* TODO:.
*
* By sauron_le_noir some part of psp_mouse_timer_poll based on
* the sdl code of Nekuz0r
*
* See readme.txt for copyright information.
*/
#include "allegro.h"
#include "allegro/internal/aintern.h"
#include "allegro/platform/aintpsp.h"
#include "math.h"
#include <pspctrl.h>
#ifndef ALLEGRO_PSP
#error something is wrong with the makefile
#endif
static int psp_mouse_init(void);
static void psp_mouse_exit(void);
static void psp_mouse_position(int, int);
static void psp_mouse_set_range(int, int, int, int);
static void psp_mouse_get_mickeys(int *, int *);
static void psp_mouse_timer_poll(void);
MOUSE_DRIVER mouse_psp =
{
MOUSE_PSP,
empty_string,
empty_string,
"psp mouse",
psp_mouse_init,
psp_mouse_exit,
NULL, // AL_METHOD(void, poll, (void));
psp_mouse_timer_poll, // AL_METHOD(void, timer_poll, (void));
psp_mouse_position,
psp_mouse_set_range,
NULL, // AL_METHOD(void, set_speed, (int xspeed, int yspeed));
psp_mouse_get_mickeys,
NULL, // AL_METHOD(int, analyse_data, (AL_CONST char *buffer, int size));
NULL, // AL_METHOD(void, enable_hardware_cursor, (AL_CONST int mode));
NULL // AL_METHOD(int, select_system_cursor, (AL_CONST int cursor));
};
static int mouse_minx = 0;
static int mouse_miny = 0;
static int mouse_maxx = 479; /* 0 to 479 = 480 */
static int mouse_maxy = 271; /* 0 to 272 = 272 */ /* 480x272 is the resolution of the psp display */
static int mymickey_x = 0;
static int mymickey_y = 0;
static SceCtrlData pad;
static int aStickX = 0;
static int aStickY = 0;
static float aStickR;
static float aStickA;
static int x,y;
static float Precision = 360.0f;
static int getSqrRadius(int X, int Y)
{
return sqrt((X * X) + (Y * Y));
}
static int psp_mouse_init(void)
{
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
}
static void psp_mouse_timer_poll(void)
{
sceCtrlPeekBufferPositive(&pad, 1);
if (pad.Buttons != 0)
{
sceCtrlReadBufferPositive(&pad, 1);
_mouse_b = 0;
if (pad.Buttons & PSP_CTRL_LTRIGGER) _mouse_b = 1;
if (pad.Buttons & PSP_CTRL_RTRIGGER) _mouse_b = 2;
if ( (pad.Buttons & PSP_CTRL_LTRIGGER) && (pad.Buttons & PSP_CTRL_RTRIGGER)) _mouse_b = 4;
}
aStickX = pad.Ly - 128;
aStickY = pad.Lx - 128;
aStickR = getSqrRadius(aStickX, aStickY);
if (aStickR > 100) {
if (getSqrRadius(aStickX, aStickY) > 30) {
aStickA = ((atan2f(aStickX, -aStickY) + M_PI) / (M_PI * 2)) * Precision;
} else {
aStickA = -1;
}
//1° a 89°
if (aStickA >= 1 && aStickA <= (89 * (Precision / 360.0f))) {
x += (10 * (1 - (aStickA / (Precision / 360.0f) / 90)));
y -= (10 * (0 + (aStickA / (Precision / 360.0f) / 90)));
}
else if (aStickA >= (91 * (Precision / 360.0f)) && aStickA <= (179 * (Precision / 360.0f))) {
x -= (10 * (0 + (((aStickA / (Precision / 360.0f)) - 89) / 90)));
y -= (10 * (1 - (((aStickA / (Precision / 360.0f)) - 89) / 90)));
}
else if (aStickA >= (181 * (Precision / 360.0f)) && aStickA <= (269 * (Precision / 360.0f))) {
x -= (10 * (1 - (((aStickA / (Precision / 360.0f)) - 179) / 90)));
y += (10 * (0 + (((aStickA / (Precision / 360.0f)) - 179) / 90)));
}
else if (aStickA >= (271 * (Precision / 360.0f)) && aStickA <= (359 * (Precision / 360.0f))) {
x += (10 * (0 + (((aStickA / (Precision / 360.0f)) - 269) / 90)));
y += (10 * (1 - (((aStickA / (Precision / 360.0f)) - 269) / 90)));
}
else if (aStickA == 0) {
x += 10;
}
else if (aStickA == (90 * (Precision / 360.0f))) {
y -= 10;
}
else if (aStickA == (180 * (Precision / 360.0f))) {
x -= 10;
}
else if (aStickR == (270 * (Precision / 360.0f))) {
y += 10;
}
}
_mouse_x = x;
if (_mouse_x < mouse_minx) _mouse_x = 0;
if (_mouse_x > mouse_maxx) _mouse_x = mouse_maxx;
_mouse_y = y;
if (_mouse_y < mouse_miny) _mouse_y = 0;
if (_mouse_y > mouse_maxy) _mouse_y = mouse_maxy;
}
static void psp_mouse_position(int x, int y)
{
_mouse_x = x;
if (_mouse_x < mouse_minx) _mouse_x = 0;
if (_mouse_x > mouse_maxx) _mouse_x = mouse_maxx;
_mouse_y = y;
if (_mouse_y < mouse_miny) _mouse_y = 0;
if (_mouse_y > mouse_maxy) _mouse_y = mouse_maxy;
}
static void psp_mouse_set_range(int x1, int y1, int x2, int y2)
{
}
static void psp_mouse_get_mickeys(int *mickeyx, int *mickeyy)
{
*mickeyx = 0;
*mickeyy = 0;
}
static void psp_mouse_exit(void)
{
}
|
|
|
| Back to top |
|
 |
|
|
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
|