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 

Smooth Mouse (SDL) ;)

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



Joined: 02 Apr 2007
Posts: 3

PostPosted: Tue Apr 10, 2007 3:03 pm    Post subject: Smooth Mouse (SDL) ;) Reply with quote

last night i made this, to make a mouse cursor with smooth movement

the movement is based on the stick angle (aStickA), 0° = Right
now, you can add accleration in function of circle ray (aStickR)

Code:

int getSqrRadius(int X, int Y) {
   return sqrt((X * X) + (Y * Y));
}

SDL_ShowCursor(0);
SDL_WarpMouse(SCR_WIDTH / 2, SCR_HEIGHT / 2);

SDL_Surface* Mouse = SDL_LoadBMP("ms0:/PSP/GAME150/test/cursor.bmp");
SDL_SetColorKey(Mouse, SDL_SRCCOLORKEY, SDL_MapRGB(Mouse->format,255,255,255));
SDL_Rect coords;

SceCtrlData pad;
int aStickX = 0;
int aStickY = 0;
float aStickR;
float aStickA;
int x,y;
float Precision = 360.0f;
while (1) {
   
   //Deplacement de la souri
   SDL_GetMouseState(&x, &y);
   sceCtrlReadBufferPositive(&pad, 1);
   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;
      }
   }
   
   SDL_WarpMouse(x, y);
   coords.x = x;
   coords.y = y;
   SDL_BlitSurface(Mouse, NULL, Screen, &coords);
   SDL_Flip(Screen);
   sceKernelDelayThread(20000);
}
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