|
@@ -4,7 +4,7 @@
|
|
|
*
|
|
|
* Basic functions to draw 2d Shapes and check collisions
|
|
|
*
|
|
|
-* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
|
|
+* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
|
|
|
*
|
|
|
* This software is provided "as-is", without any express or implied warranty. In no event
|
|
|
* will the authors be held liable for any damages arising from the use of this software.
|
|
@@ -25,9 +25,8 @@
|
|
|
|
|
|
#include "raylib.h"
|
|
|
|
|
|
-#include <stdlib.h> // Required for abs() function
|
|
|
-#include <math.h> // Math related functions, sin() and cos() used on DrawCircle*
|
|
|
- // sqrt() and pow() and abs() used on CheckCollision*
|
|
|
+#include <stdlib.h> // Required for: abs()
|
|
|
+#include <math.h> // Required for: sinf(), cosf(), sqrtf()
|
|
|
|
|
|
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2
|
|
|
|
|
@@ -331,8 +330,8 @@ void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color col
|
|
|
rlColor4ub(color.r, color.g, color.b, color.a);
|
|
|
|
|
|
rlVertex2f(0, 0);
|
|
|
- rlVertex2f(sin(DEG2RAD*i)*radius, cos(DEG2RAD*i)*radius);
|
|
|
- rlVertex2f(sin(DEG2RAD*(i + 360/sides))*radius, cos(DEG2RAD*(i + 360/sides))*radius);
|
|
|
+ rlVertex2f(sinf(DEG2RAD*i)*radius, cosf(DEG2RAD*i)*radius);
|
|
|
+ rlVertex2f(sinf(DEG2RAD*(i + 360/sides))*radius, cosf(DEG2RAD*(i + 360/sides))*radius);
|
|
|
}
|
|
|
rlEnd();
|
|
|
rlPopMatrix();
|
|
@@ -434,7 +433,7 @@ bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, floa
|
|
|
float dx = center2.x - center1.x; // X distance between centers
|
|
|
float dy = center2.y - center1.y; // Y distance between centers
|
|
|
|
|
|
- float distance = sqrt(dx*dx + dy*dy); // Distance between centers
|
|
|
+ float distance = sqrtf(dx*dx + dy*dy); // Distance between centers
|
|
|
|
|
|
if (distance <= (radius1 + radius2)) collision = true;
|
|
|
|
|
@@ -457,7 +456,7 @@ bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec)
|
|
|
if (dx <= (rec.width/2)) { return true; }
|
|
|
if (dy <= (rec.height/2)) { return true; }
|
|
|
|
|
|
- float cornerDistanceSq = pow(dx - rec.width/2, 2) + pow(dy - rec.height/2, 2);
|
|
|
+ float cornerDistanceSq = (dx - rec.width/2)*(dx - rec.width/2) + (dy - rec.height/2)*(dy - rec.height/2);
|
|
|
|
|
|
return (cornerDistanceSq <= (radius*radius));
|
|
|
}
|