Browse Source

Updated examples for new physac header-only

raysan5 9 years ago
parent
commit
3c1be60c66
2 changed files with 26 additions and 22 deletions
  1. 12 9
      examples/physics_basic_rigidbody.c
  2. 14 13
      examples/physics_forces.c

+ 12 - 9
examples/physics_basic_rigidbody.c

@@ -11,6 +11,9 @@
 
 
 #include "raylib.h"
 #include "raylib.h"
 
 
+#define PHYSAC_IMPLEMENTATION
+#include "physac.h"
+
 #define MOVE_VELOCITY    5
 #define MOVE_VELOCITY    5
 #define JUMP_VELOCITY    30
 #define JUMP_VELOCITY    30
 
 
@@ -22,35 +25,35 @@ int main()
     int screenHeight = 450;
     int screenHeight = 450;
 
 
     InitWindow(screenWidth, screenHeight, "raylib [physac] example - basic rigidbody");
     InitWindow(screenWidth, screenHeight, "raylib [physac] example - basic rigidbody");
-    InitPhysics((Vector2){ 0.0f, -9.81f/2 });      // Initialize physics module
     
     
-    SetTargetFPS(60);
+    InitPhysics((Vector2){ 0.0f, -9.81f/2 });      // Initialize physics module
     
     
     // Debug variables
     // Debug variables
     bool isDebug = false;
     bool isDebug = false;
     
     
     // Create rectangle physic object
     // Create rectangle physic object
-    PhysicObject rectangle = CreatePhysicObject((Vector2){ screenWidth*0.25f, screenHeight/2 }, 0.0f, (Vector2){ 75, 50 });
+    PhysicBody rectangle = CreatePhysicBody((Vector2){ screenWidth*0.25f, screenHeight/2 }, 0.0f, (Vector2){ 75, 50 });
     rectangle->rigidbody.enabled = true;       // Enable physic object rigidbody behaviour
     rectangle->rigidbody.enabled = true;       // Enable physic object rigidbody behaviour
     rectangle->rigidbody.applyGravity = true;
     rectangle->rigidbody.applyGravity = true;
     rectangle->rigidbody.friction = 0.1f;
     rectangle->rigidbody.friction = 0.1f;
     rectangle->rigidbody.bounciness = 6.0f;
     rectangle->rigidbody.bounciness = 6.0f;
     
     
     // Create square physic object
     // Create square physic object
-    PhysicObject square = CreatePhysicObject((Vector2){ screenWidth*0.75f, screenHeight/2 }, 0.0f, (Vector2){ 50, 50 });
+    PhysicBody square = CreatePhysicBody((Vector2){ screenWidth*0.75f, screenHeight/2 }, 0.0f, (Vector2){ 50, 50 });
     square->rigidbody.enabled = true;      // Enable physic object rigidbody behaviour
     square->rigidbody.enabled = true;      // Enable physic object rigidbody behaviour
     square->rigidbody.applyGravity = true;
     square->rigidbody.applyGravity = true;
     square->rigidbody.friction = 0.1f;
     square->rigidbody.friction = 0.1f;
     
     
     // Create walls physic objects
     // Create walls physic objects
-    PhysicObject floor = CreatePhysicObject((Vector2){ screenWidth/2, screenHeight*0.95f }, 0.0f, (Vector2){ screenWidth*0.9f, 100 });
-    PhysicObject leftWall = CreatePhysicObject((Vector2){ 0.0f, screenHeight/2 }, 0.0f, (Vector2){ screenWidth*0.1f, screenHeight });
-    PhysicObject rightWall = CreatePhysicObject((Vector2){ screenWidth, screenHeight/2 }, 0.0f, (Vector2){ screenWidth*0.1f, screenHeight });
-    PhysicObject roof = CreatePhysicObject((Vector2){ screenWidth/2, screenHeight*0.05f }, 0.0f, (Vector2){ screenWidth*0.9f, 100 });
+    PhysicBody floor = CreatePhysicBody((Vector2){ screenWidth/2, screenHeight*0.95f }, 0.0f, (Vector2){ screenWidth*0.9f, 100 });
+    PhysicBody leftWall = CreatePhysicBody((Vector2){ 0.0f, screenHeight/2 }, 0.0f, (Vector2){ screenWidth*0.1f, screenHeight });
+    PhysicBody rightWall = CreatePhysicBody((Vector2){ screenWidth, screenHeight/2 }, 0.0f, (Vector2){ screenWidth*0.1f, screenHeight });
+    PhysicBody roof = CreatePhysicBody((Vector2){ screenWidth/2, screenHeight*0.05f }, 0.0f, (Vector2){ screenWidth*0.9f, 100 });
     
     
     // Create pplatform physic object
     // Create pplatform physic object
-    PhysicObject platform = CreatePhysicObject((Vector2){ screenWidth/2, screenHeight*0.7f }, 0.0f, (Vector2){ screenWidth*0.25f, 20 });
+    PhysicBody platform = CreatePhysicBody((Vector2){ screenWidth/2, screenHeight*0.7f }, 0.0f, (Vector2){ screenWidth*0.25f, 20 });
     
     
+    SetTargetFPS(60);
     //--------------------------------------------------------------------------------------
     //--------------------------------------------------------------------------------------
 
 
     // Main game loop
     // Main game loop

+ 14 - 13
examples/physics_forces.c

@@ -10,15 +10,15 @@
 ********************************************************************************************/
 ********************************************************************************************/
 
 
 #include "raylib.h"
 #include "raylib.h"
-#include "math.h"
+
+#define PHYSAC_IMPLEMENTATION
+#include "physac.h"
 
 
 #define FORCE_AMOUNT        5.0f
 #define FORCE_AMOUNT        5.0f
 #define FORCE_RADIUS        150
 #define FORCE_RADIUS        150
 #define LINE_LENGTH         75
 #define LINE_LENGTH         75
 #define TRIANGLE_LENGTH     12
 #define TRIANGLE_LENGTH     12
 
 
-void DrawRigidbodyCircle(PhysicObject obj, Color color);
-
 int main()
 int main()
 {
 {
     // Initialization
     // Initialization
@@ -27,29 +27,28 @@ int main()
     int screenHeight = 450;
     int screenHeight = 450;
 
 
     InitWindow(screenWidth, screenHeight, "raylib [physac] example - forces");
     InitWindow(screenWidth, screenHeight, "raylib [physac] example - forces");
-    InitPhysics((Vector2){ 0.0f, -9.81f/2 });      // Initialize physics module
     
     
-    SetTargetFPS(60);
+    InitPhysics((Vector2){ 0.0f, -9.81f/2 });      // Initialize physics module
     
     
     // Global variables
     // Global variables
     Vector2 mousePosition;
     Vector2 mousePosition;
     bool isDebug = false;
     bool isDebug = false;
     
     
     // Create rectangle physic objects
     // Create rectangle physic objects
-    PhysicObject rectangles[3];
+    PhysicBody rectangles[3];
     for (int i = 0; i < 3; i++)
     for (int i = 0; i < 3; i++)
     {
     {
-        rectangles[i] = CreatePhysicObject((Vector2){ screenWidth/4*(i+1), (((i % 2) == 0) ? (screenHeight/3) : (screenHeight/1.5f)) }, 0.0f, (Vector2){ 50, 50 });
+        rectangles[i] = CreatePhysicBody((Vector2){ screenWidth/4*(i+1), (((i % 2) == 0) ? (screenHeight/3) : (screenHeight/1.5f)) }, 0.0f, (Vector2){ 50, 50 });
         rectangles[i]->rigidbody.enabled = true;       // Enable physic object rigidbody behaviour
         rectangles[i]->rigidbody.enabled = true;       // Enable physic object rigidbody behaviour
         rectangles[i]->rigidbody.friction = 0.1f;
         rectangles[i]->rigidbody.friction = 0.1f;
     }
     }
     
     
     // Create circles physic objects
     // Create circles physic objects
     // NOTE: when creating circle physic objects, transform.scale must be { 0, 0 } and object radius must be defined in collider.radius and use this value to draw the circle.
     // NOTE: when creating circle physic objects, transform.scale must be { 0, 0 } and object radius must be defined in collider.radius and use this value to draw the circle.
-    PhysicObject circles[3];
+    PhysicBody circles[3];
     for (int i = 0; i < 3; i++)
     for (int i = 0; i < 3; i++)
     {
     {
-        circles[i] = CreatePhysicObject((Vector2){ screenWidth/4*(i+1), (((i % 2) == 0) ? (screenHeight/1.5f) : (screenHeight/4)) }, 0.0f, (Vector2){ 0, 0 });
+        circles[i] = CreatePhysicBody((Vector2){ screenWidth/4*(i+1), (((i % 2) == 0) ? (screenHeight/1.5f) : (screenHeight/4)) }, 0.0f, (Vector2){ 0, 0 });
         circles[i]->rigidbody.enabled = true;       // Enable physic object rigidbody behaviour
         circles[i]->rigidbody.enabled = true;       // Enable physic object rigidbody behaviour
         circles[i]->rigidbody.friction = 0.1f;
         circles[i]->rigidbody.friction = 0.1f;
         circles[i]->collider.type = COLLIDER_CIRCLE;
         circles[i]->collider.type = COLLIDER_CIRCLE;
@@ -57,11 +56,12 @@ int main()
     }
     }
     
     
     // Create walls physic objects
     // Create walls physic objects
-    PhysicObject leftWall = CreatePhysicObject((Vector2){ -25, screenHeight/2 }, 0.0f, (Vector2){ 50, screenHeight });
-    PhysicObject rightWall = CreatePhysicObject((Vector2){ screenWidth + 25, screenHeight/2 }, 0.0f, (Vector2){ 50, screenHeight });
-    PhysicObject topWall = CreatePhysicObject((Vector2){ screenWidth/2, -25 }, 0.0f, (Vector2){ screenWidth, 50 });
-    PhysicObject bottomWall = CreatePhysicObject((Vector2){ screenWidth/2, screenHeight + 25 }, 0.0f, (Vector2){ screenWidth, 50 });
+    PhysicBody leftWall = CreatePhysicBody((Vector2){ -25, screenHeight/2 }, 0.0f, (Vector2){ 50, screenHeight });
+    PhysicBody rightWall = CreatePhysicBody((Vector2){ screenWidth + 25, screenHeight/2 }, 0.0f, (Vector2){ 50, screenHeight });
+    PhysicBody topWall = CreatePhysicBody((Vector2){ screenWidth/2, -25 }, 0.0f, (Vector2){ screenWidth, 50 });
+    PhysicBody bottomWall = CreatePhysicBody((Vector2){ screenWidth/2, screenHeight + 25 }, 0.0f, (Vector2){ screenWidth, 50 });
     
     
+    SetTargetFPS(60);
     //--------------------------------------------------------------------------------------
     //--------------------------------------------------------------------------------------
 
 
     // Main game loop
     // Main game loop
@@ -175,6 +175,7 @@ int main()
     // De-Initialization
     // De-Initialization
     //--------------------------------------------------------------------------------------
     //--------------------------------------------------------------------------------------
     ClosePhysics();       // Unitialize physics module
     ClosePhysics();       // Unitialize physics module
+    
     CloseWindow();        // Close window and OpenGL context
     CloseWindow();        // Close window and OpenGL context
     //--------------------------------------------------------------------------------------
     //--------------------------------------------------------------------------------------