Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "methods.h"
- //Image-Draw
- //Draws an image passing X and Y
- void DrawImageXY(const float x, const float y, const GRRLIB_texImg *tex){
- GRRLIB_DrawImg(x, y, tex, 0, 1, 1, 0xFFFFFFFF);
- }
- //Draws an image passing one scale
- void DrawImageScale(const float x, const float y, const GRRLIB_texImg *tex, const float degrees, const float scale, const u32 color){
- GRRLIB_DrawImg(x, y, tex, degrees, scale, scale, color);
- }
- //Center an image
- void CenterImage(GRRLIB_texImg *tex){
- GRRLIB_SetMidHandle(tex, true);
- }
- //Math
- //2 Power of a number
- float Pow2(float x){
- return x*x;
- }
- //Distance between 2 pixels
- float PtDistance(float x1, float y1, float x2, float y2){
- return sqrt( Pow2(x2-x1) + Pow2(y2-y1));
- }
- //If a circle is on a circle
- bool CircleCollision(float x1, float y1, float radius1, float x2, float y2, float radius2){
- if( PtDistance(x1, y1, x2, y2) <= (radius1+radius2) ) return true;
- return false;
- }
- //If a pixel is in a circle
- bool PtInCircle(float x1, float y1, float x2, float y2, float radius){
- if( PtDistance(x1, y1, x2, y2) <= radius ) return true;
- return false;
- }
- //Collision between a circle and a annulus
- bool CircleOnAnnulus(float x1, float y1, float r1, float x2, float y2, float r2_R, float r2_r){
- float distance = PtDistance(x1, y1, x2, y2);
- if( ( distance <= (r2_R + r1) ) && ( distance >= (r2_r - r1) ) ) return true;
- return false;
- }
- //Angle between 2 pixels
- float PtAngle(float x1, float y1, float x2, float y2){
- return toDeg(atan2(y2-y1, x2-x1));
- }
- //Simple degree to radian conversion
- float toRad(float angle){
- return angle*0.01745;
- }
- //Simple radian to degree conversion
- float toDeg(float angle){
- return angle*57.29578;
- }
- //Returns a random float between two floats
- float RandomFloat(float a, float b) {
- // float random = ((float) rand()) / (float) RAND_MAX;
- // float diff = b - a;
- // float r = random * diff;
- return a + (((float) rand()) / (float) RAND_MAX) * (b - a);
- }
- //Returns a random int between two int
- int RandomInt(int min, int max) {
- return min + (rand() % (int)(max - min + 1));
- }
- //Converts the negative angle system to the normal system
- float toNormalDeg(float deg){
- if( deg < 0) return ( 180 + ( 180 + deg));
- return deg;
- }
- //Wii
- //Returns de nunchuk angle
- float NunchukAng(int pad){
- WPADData *wmote_data;
- wmote_data = WPAD_Data(pad);
- float angle = -(90-wmote_data->exp.nunchuk.js.ang);
- if( isnan(angle) || wmote_data->exp.nunchuk.js.mag < 0.1) return 0;
- return angle;
- }
- //Returns de nunchuk magnitude
- float NunchukMag(int pad){
- WPADData *wmote_data;
- wmote_data = WPAD_Data(pad);
- return wmote_data->exp.nunchuk.js.mag;
- }
- //Gets de nunchuk angle and magnitude
- void NunchukAngMag(int pad, float *ang, float *mag){
- WPADData *wmote_data;
- wmote_data = WPAD_Data(pad);
- float angle = -(90-wmote_data->exp.nunchuk.js.ang);
- if(isnan(angle) || wmote_data->exp.nunchuk.js.mag < 0.1){
- *ang = 0;
- }else{
- *ang = -(90-wmote_data->exp.nunchuk.js.ang);
- }
- *mag = wmote_data->exp.nunchuk.js.mag;
- }
- //Returns if nunchunk joystick is moving
- bool NunJoyMoving(int pad){
- WPADData *wmote_data;
- wmote_data = WPAD_Data(pad);
- if(wmote_data->exp.nunchuk.js.mag > 0.1) return true;
- return false;
- }
- //Angle between wiimote ir and a plot
- float WiimoteIrAngle(int pad, float x, float y){
- WPADData *wmote_data;
- wmote_data = WPAD_Data(pad);
- return PtAngle(x, y, wmote_data->ir.x, wmote_data->ir.y);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement