Advertisement
xerpi

Methods 7-2-12_pre-alpha1

Feb 7th, 2012
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.60 KB | None | 0 0
  1. #include "methods.h"
  2.  
  3. //Image-Draw
  4.     //Draws an image passing X and Y
  5.         void DrawImageXY(const float x, const float y, const GRRLIB_texImg *tex){
  6.             GRRLIB_DrawImg(x, y, tex, 0, 1, 1, 0xFFFFFFFF);
  7.         }
  8.     //Draws an image passing one scale
  9.         void DrawImageScale(const float x, const float y, const GRRLIB_texImg *tex, const float degrees, const float scale, const u32 color){
  10.             GRRLIB_DrawImg(x, y, tex, degrees, scale, scale, color);
  11.         }
  12.                        
  13.     //Center an image
  14.         void CenterImage(GRRLIB_texImg *tex){
  15.             GRRLIB_SetMidHandle(tex, true);
  16.         }
  17.  
  18. //Math
  19.     //2 Power of a number
  20.         float Pow2(float x){
  21.             return x*x;
  22.         }
  23.     //Distance between 2 pixels
  24.         float PtDistance(float x1, float y1, float x2, float y2){
  25.             return sqrt( Pow2(x2-x1) + Pow2(y2-y1));
  26.         }
  27.     //If a circle is on a circle
  28.         bool CircleCollision(float x1, float y1, float radius1, float x2, float y2, float radius2){
  29.             if( PtDistance(x1, y1, x2, y2) <= (radius1+radius2) ) return true;
  30.             return false;
  31.         }
  32.     //If a pixel is in a circle
  33.         bool PtInCircle(float x1, float y1, float x2, float y2, float radius){
  34.             if( PtDistance(x1, y1, x2, y2) <= radius ) return true;
  35.             return false;  
  36.         }
  37.     //Collision between a circle and a annulus
  38.         bool CircleOnAnnulus(float x1, float y1, float r1, float x2, float y2, float r2_R, float r2_r){
  39.             float distance = PtDistance(x1, y1, x2, y2);
  40.             if(  ( distance <= (r2_R + r1) )  && ( distance >= (r2_r - r1) ) ) return true;    
  41.             return false;
  42.         }
  43.     //Angle between 2 pixels
  44.         float PtAngle(float x1, float y1, float x2, float y2){
  45.             return toDeg(atan2(y2-y1, x2-x1));
  46.         }
  47.     //Simple degree to radian conversion
  48.         float toRad(float angle){
  49.             return angle*0.01745;
  50.         }
  51.     //Simple radian to degree conversion
  52.         float toDeg(float angle){
  53.             return angle*57.29578;
  54.         }
  55.     //Returns a random float between two floats
  56.         float RandomFloat(float a, float b) {
  57.             // float random = ((float) rand()) / (float) RAND_MAX;
  58.             // float diff = b - a;
  59.             // float r = random * diff;
  60.             return a + (((float) rand()) / (float) RAND_MAX) * (b - a);
  61.         }
  62.         //Returns a random int between two int
  63.         int RandomInt(int min, int max) {
  64.             return min + (rand() % (int)(max - min + 1));
  65.         }
  66.         //Converts the negative angle system to the normal system
  67.             float toNormalDeg(float deg){
  68.                 if( deg < 0)  return ( 180 +  ( 180 + deg));
  69.                 return deg;    
  70.             }
  71.        
  72. //Wii
  73.     //Returns de nunchuk angle
  74.         float NunchukAng(int pad){
  75.             WPADData *wmote_data;
  76.             wmote_data = WPAD_Data(pad);
  77.             float angle = -(90-wmote_data->exp.nunchuk.js.ang);
  78.             if( isnan(angle) || wmote_data->exp.nunchuk.js.mag < 0.1) return 0;
  79.             return angle;
  80.         }
  81.     //Returns de nunchuk magnitude
  82.         float NunchukMag(int pad){
  83.             WPADData *wmote_data;
  84.             wmote_data = WPAD_Data(pad);
  85.             return wmote_data->exp.nunchuk.js.mag;
  86.         }
  87.     //Gets de nunchuk angle and magnitude
  88.         void NunchukAngMag(int pad, float *ang, float *mag){
  89.             WPADData *wmote_data;
  90.             wmote_data = WPAD_Data(pad);
  91.             float angle = -(90-wmote_data->exp.nunchuk.js.ang);
  92.             if(isnan(angle) || wmote_data->exp.nunchuk.js.mag < 0.1){
  93.                 *ang = 0;
  94.             }else{
  95.                 *ang = -(90-wmote_data->exp.nunchuk.js.ang);
  96.             }
  97.             *mag = wmote_data->exp.nunchuk.js.mag;
  98.         }
  99.     //Returns if nunchunk joystick is moving
  100.         bool NunJoyMoving(int pad){
  101.             WPADData *wmote_data;
  102.             wmote_data = WPAD_Data(pad);
  103.             if(wmote_data->exp.nunchuk.js.mag > 0.1) return true;
  104.             return false;
  105.         }
  106.     //Angle between wiimote ir and a plot
  107.         float WiimoteIrAngle(int pad, float x, float y){
  108.             WPADData *wmote_data;
  109.             wmote_data = WPAD_Data(pad);
  110.             return PtAngle(x, y, wmote_data->ir.x, wmote_data->ir.y);          
  111.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement