diff options
| author | raysan5 <raysan5@gmail.com> | 2016-01-20 19:23:58 +0100 |
|---|---|---|
| committer | raysan5 <raysan5@gmail.com> | 2016-01-20 19:23:58 +0100 |
| commit | cf6c6fefd76135df0247339c9adc2712da6c2691 (patch) | |
| tree | 751d2c7303dc92780b027b122f26b09a4930e88b /src | |
| parent | c5663ca015e550ab8e2a43c10fa72db0aab7cac8 (diff) | |
| download | raylib-cf6c6fefd76135df0247339c9adc2712da6c2691.tar.gz raylib-cf6c6fefd76135df0247339c9adc2712da6c2691.zip | |
Review some function names for consistency with raymath
Diffstat (limited to 'src')
| -rw-r--r-- | src/physac.c | 26 | ||||
| -rw-r--r-- | src/physac.h | 4 |
2 files changed, 17 insertions, 13 deletions
diff --git a/src/physac.c b/src/physac.c index 6dfdbb49..891f0123 100644 --- a/src/physac.c +++ b/src/physac.c @@ -55,8 +55,8 @@ static bool collisionChecker = false; // Module specific Functions Declarations //---------------------------------------------------------------------------------- static float Vector2Length(Vector2 vector); -static float Vector2LengthPoints(Vector2 a, Vector2 b); -static Vector2 Vector2Normalize(Vector2 vector); +static float Vector2Distance(Vector2 a, Vector2 b); +static void Vector2Normalize(Vector2 *vector); //---------------------------------------------------------------------------------- // Module Functions Definitions @@ -277,7 +277,7 @@ void AddForceAtPosition(Vector2 position, float intensity, float radius) Vector2 pos = {colliders[i].bounds.x, colliders[i].bounds.y}; // Get distance between rigidbody position and target position - float distance = Vector2LengthPoints(position, pos); + float distance = Vector2Distance(position, pos); if(distance <= radius) { @@ -285,7 +285,7 @@ void AddForceAtPosition(Vector2 position, float intensity, float radius) Vector2 force = {colliders[i].bounds.x - position.x, colliders[i].bounds.y - position.y}; // Normalize the direction vector - force = Vector2Normalize(force); + Vector2Normalize(&force); // Invert y value force.y *= -1; @@ -323,20 +323,24 @@ static float Vector2Length(Vector2 vector) return sqrt((vector.x * vector.x) + (vector.y * vector.y)); } -static float Vector2LengthPoints(Vector2 a, Vector2 b) +static float Vector2Distance(Vector2 a, Vector2 b) { Vector2 vector = {b.x - a.x, b.y - a.y}; return sqrt((vector.x * vector.x) + (vector.y * vector.y)); } -static Vector2 Vector2Normalize(Vector2 vector) +static void Vector2Normalize(Vector2 *vector) { - float length = Vector2Length(vector); + float length = Vector2Length(*vector); - if(length != 0) + if (length != 0.0f) { - return (Vector2){vector.x / length, vector.y / length}; + vector->x /= length; + vector->y /= length; + } + else + { + vector->x = 0.0f; + vector->y = 0.0f; } - - return (Vector2){0, 0}; } diff --git a/src/physac.h b/src/physac.h index a1501ee3..12209987 100644 --- a/src/physac.h +++ b/src/physac.h @@ -66,8 +66,8 @@ typedef struct Rigidbody { typedef struct Collider { bool enabled; ColliderType type; - Rectangle bounds; // Just used for RectangleCollider type - int radius; // Just used for CircleCollider type + Rectangle bounds; // Used for COLLIDER_RECTANGLE and COLLIDER_CAPSULE + int radius; // Used for COLLIDER_CIRCLE and COLLIDER_CAPSULE } Collider; #ifdef __cplusplus |
