From 7128ef686d9c09d0ec3b413c07bb1cc24f03d219 Mon Sep 17 00:00:00 2001 From: victorfisac Date: Wed, 16 Mar 2016 12:45:01 +0100 Subject: physac module redesign (2/3) physac module base almost finished. All collisions are now resolved properly and some force functions was added. COLLIDER_CAPSULE removed for now because in 2D everything is composed by rectangle and circle colliders... The last step is move physics update loop into another thread and update it in a fixed time step based on fps. --- src/physac.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/physac.h') diff --git a/src/physac.h b/src/physac.h index fc5502c4..852a7e4a 100644 --- a/src/physac.h +++ b/src/physac.h @@ -40,7 +40,7 @@ typedef struct Vector2 { float y; } Vector2; -typedef enum { COLLIDER_CIRCLE, COLLIDER_RECTANGLE, COLLIDER_CAPSULE } ColliderType; +typedef enum { COLLIDER_CIRCLE, COLLIDER_RECTANGLE } ColliderType; typedef struct Transform { Vector2 position; @@ -56,7 +56,7 @@ typedef struct Rigidbody { bool applyGravity; bool isGrounded; float friction; // Normalized value - float bounciness; // Normalized value + float bounciness; } Rigidbody; typedef struct Collider { @@ -81,13 +81,16 @@ extern "C" { // Prevents name mangling of functions //---------------------------------------------------------------------------------- // Module Functions Declaration //---------------------------------------------------------------------------------- -void InitPhysics(); // Initializes pointers array (just pointers, fixed size) +void InitPhysics(Vector2 gravity); // Initializes pointers array (just pointers, fixed size) void UpdatePhysics(); // Update physic objects, calculating physic behaviours and collisions detection void ClosePhysics(); // Unitialize all physic objects and empty the objects pool PhysicObject *CreatePhysicObject(Vector2 position, float rotation, Vector2 scale); // Create a new physic object dinamically, initialize it and add to pool void DestroyPhysicObject(PhysicObject *pObj); // Destroy a specific physic object and take it out of the list +void ApplyForce(PhysicObject *pObj, Vector2 force); // Apply directional force to a physic object +void ApplyForceAtPosition(Vector2 position, float force, float radius); // Apply radial force to all physic objects in range + Rectangle TransformToRectangle(Transform transform); // Convert Transform data type to Rectangle (position and scale) void DrawPhysicObjectInfo(PhysicObject *pObj, Vector2 position, int fontSize); // Draw physic object information at screen position -- cgit v1.2.3 From 0caf925d5dc32e03852e3bf3d5fc5e31bc065f03 Mon Sep 17 00:00:00 2001 From: victorfisac Date: Wed, 16 Mar 2016 12:48:30 +0100 Subject: Updated headers --- src/physac.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/physac.h') diff --git a/src/physac.h b/src/physac.h index 852a7e4a..c70dbbe2 100644 --- a/src/physac.h +++ b/src/physac.h @@ -62,8 +62,8 @@ typedef struct Rigidbody { typedef struct Collider { bool enabled; ColliderType type; - Rectangle bounds; // Used for COLLIDER_RECTANGLE and COLLIDER_CAPSULE - int radius; // Used for COLLIDER_CIRCLE and COLLIDER_CAPSULE + Rectangle bounds; // Used for COLLIDER_RECTANGLE + int radius; // Used for COLLIDER_CIRCLE } Collider; typedef struct PhysicObject { -- cgit v1.2.3