summaryrefslogtreecommitdiffhomepage
path: root/examples/src/physac
diff options
context:
space:
mode:
authorRay <[email protected]>2019-05-14 17:57:45 +0200
committerRay <[email protected]>2019-05-14 17:57:45 +0200
commit5a27bcaf7115e46a5123e9857007d940998f0650 (patch)
tree7179c6a1b4d700c9685dd51cc76cb2b2c90b9609 /examples/src/physac
parent423fdd699225ee9686c44a606bf83272b4c77802 (diff)
downloadraylib.com-5a27bcaf7115e46a5123e9857007d940998f0650.tar.gz
raylib.com-5a27bcaf7115e46a5123e9857007d940998f0650.zip
Review examples collection -WIP-
WARNING: Examples list has been reviewed but examples haven't been recompiled yet... that's not trivial...
Diffstat (limited to 'examples/src/physac')
-rw-r--r--examples/src/physac/physics_demo.c26
-rw-r--r--examples/src/physac/physics_friction.c11
-rw-r--r--examples/src/physac/physics_movement.c11
-rw-r--r--examples/src/physac/physics_restitution.c14
-rw-r--r--examples/src/physac/physics_shatter.c30
5 files changed, 63 insertions, 29 deletions
diff --git a/examples/src/physac/physics_demo.c b/examples/src/physac/physics_demo.c
index 1b54d51..a92bb9e 100644
--- a/examples/src/physac/physics_demo.c
+++ b/examples/src/physac/physics_demo.c
@@ -7,16 +7,18 @@
*
* Use the following line to compile:
*
-* gcc -o $(NAME_PART).exe $(FILE_NAME) -s $(RAYLIB_DIR)\raylib\raylib_icon -static -lraylib -lpthread
-* -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition
+* gcc -o $(NAME_PART).exe $(FILE_NAME) -s -static /
+* -lraylib -lpthread -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm /
+* -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition
*
-* Copyright (c) 2017 Victor Fisac
+* Copyright (c) 2016-2018 Victor Fisac
*
********************************************************************************************/
#include "raylib.h"
#define PHYSAC_IMPLEMENTATION
+#define PHYSAC_NO_THREADS
#include "physac.h"
int main()
@@ -32,6 +34,7 @@ int main()
// Physac logo drawing position
int logoX = screenWidth - MeasureText("Physac", 30) - 10;
int logoY = 15;
+ bool needsReset = false;
// Initialize physics and default physics bodies
InitPhysics();
@@ -52,15 +55,25 @@ int main()
{
// Update
//----------------------------------------------------------------------------------
- if (IsKeyPressed('R')) // Reset physics input
- {
- ResetPhysics();
+ // Delay initialization of variables due to physics reset async
+ RunPhysicsStep();
+ if (needsReset)
+ {
floor = CreatePhysicsBodyRectangle((Vector2){ screenWidth/2, screenHeight }, 500, 100, 10);
floor->enabled = false;
circle = CreatePhysicsBodyCircle((Vector2){ screenWidth/2, screenHeight/2 }, 45, 10);
circle->enabled = false;
+
+ needsReset = false;
+ }
+
+ // Reset physics input
+ if (IsKeyPressed('R'))
+ {
+ ResetPhysics();
+ needsReset = true;
}
// Physics body creation inputs
@@ -127,4 +140,3 @@ int main()
return 0;
}
-
diff --git a/examples/src/physac/physics_friction.c b/examples/src/physac/physics_friction.c
index 9472729..337a126 100644
--- a/examples/src/physac/physics_friction.c
+++ b/examples/src/physac/physics_friction.c
@@ -7,16 +7,18 @@
*
* Use the following line to compile:
*
-* gcc -o $(NAME_PART).exe $(FILE_NAME) -s $(RAYLIB_DIR)\raylib\raylib_icon -static -lraylib -lpthread
-* -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition
+* gcc -o $(NAME_PART).exe $(FILE_NAME) -s -static /
+* -lraylib -lpthread -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm /
+* -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition
*
-* Copyright (c) 2017 Victor Fisac
+* Copyright (c) 2016-2018 Victor Fisac
*
********************************************************************************************/
#include "raylib.h"
#define PHYSAC_IMPLEMENTATION
+#define PHYSAC_NO_THREADS
#include "physac.h"
int main()
@@ -71,6 +73,8 @@ int main()
{
// Update
//----------------------------------------------------------------------------------
+ RunPhysicsStep();
+
if (IsKeyPressed('R')) // Reset physics input
{
// Reset dynamic physics bodies position, velocity and rotation
@@ -141,4 +145,3 @@ int main()
return 0;
}
-
diff --git a/examples/src/physac/physics_movement.c b/examples/src/physac/physics_movement.c
index 4b2c9ab..e799eaa 100644
--- a/examples/src/physac/physics_movement.c
+++ b/examples/src/physac/physics_movement.c
@@ -7,16 +7,18 @@
*
* Use the following line to compile:
*
-* gcc -o $(NAME_PART).exe $(FILE_NAME) -s $(RAYLIB_DIR)\raylib\raylib_icon -static -lraylib -lpthread
-* -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition
+* gcc -o $(NAME_PART).exe $(FILE_NAME) -s -static /
+* -lraylib -lpthread -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm /
+* -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition
*
-* Copyright (c) 2017 Victor Fisac
+* Copyright (c) 2016-2018 Victor Fisac
*
********************************************************************************************/
#include "raylib.h"
#define PHYSAC_IMPLEMENTATION
+#define PHYSAC_NO_THREADS
#include "physac.h"
#define VELOCITY 0.5f
@@ -64,6 +66,8 @@ int main()
{
// Update
//----------------------------------------------------------------------------------
+ RunPhysicsStep();
+
if (IsKeyPressed('R')) // Reset physics input
{
// Reset movement physics body position, velocity and rotation
@@ -127,4 +131,3 @@ int main()
return 0;
}
-
diff --git a/examples/src/physac/physics_restitution.c b/examples/src/physac/physics_restitution.c
index 2be8f42..3231d0c 100644
--- a/examples/src/physac/physics_restitution.c
+++ b/examples/src/physac/physics_restitution.c
@@ -7,16 +7,18 @@
*
* Use the following line to compile:
*
-* gcc -o $(NAME_PART).exe $(FILE_NAME) -s $(RAYLIB_DIR)\raylib\raylib_icon -static -lraylib -lpthread
-* -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition
+* gcc -o $(NAME_PART).exe $(FILE_NAME) -s -static /
+* -lraylib -lpthread -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm /
+* -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition
*
-* Copyright (c) 2017 Victor Fisac
+* Copyright (c) 2016-2018 Victor Fisac
*
********************************************************************************************/
#include "raylib.h"
#define PHYSAC_IMPLEMENTATION
+#define PHYSAC_NO_THREADS
#include "physac.h"
int main()
@@ -50,6 +52,9 @@ int main()
circleC->restitution = 1;
SetTargetFPS(60);
+
+ // Restitution demo needs a very tiny physics time step for a proper simulation
+ SetPhysicsTimeStep(1.0/60.0/100 * 1000);
//--------------------------------------------------------------------------------------
// Main game loop
@@ -57,6 +62,8 @@ int main()
{
// Update
//----------------------------------------------------------------------------------
+ RunPhysicsStep();
+
if (IsKeyPressed('R')) // Reset physics input
{
// Reset circles physics bodies position and velocity
@@ -120,4 +127,3 @@ int main()
return 0;
}
-
diff --git a/examples/src/physac/physics_shatter.c b/examples/src/physac/physics_shatter.c
index 6b474cd..7478522 100644
--- a/examples/src/physac/physics_shatter.c
+++ b/examples/src/physac/physics_shatter.c
@@ -7,17 +7,19 @@
*
* Use the following line to compile:
*
-* gcc -o $(NAME_PART).exe $(FILE_NAME) -s $(RAYLIB_DIR)\raylib\raylib_icon -static -lraylib -lpthread
-* -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition
+* gcc -o $(NAME_PART).exe $(FILE_NAME) -s -static /
+* -lraylib -lpthread -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm /
+* -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition
*
-* Copyright (c) 2017 Victor Fisac
+* Copyright (c) 2016-2018 Victor Fisac
*
********************************************************************************************/
#include "raylib.h"
#define PHYSAC_IMPLEMENTATION
-#include "physac.h"
+#define PHYSAC_NO_THREADS
+#include "physac.h"
int main()
{
@@ -32,14 +34,15 @@ int main()
// Physac logo drawing position
int logoX = screenWidth - MeasureText("Physac", 30) - 10;
int logoY = 15;
+ bool needsReset = false;
// Initialize physics and default physics bodies
InitPhysics();
SetPhysicsGravity(0, 0);
// Create random polygon physics body to shatter
- PhysicsBody body = CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10);
-
+ CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10);
+
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
@@ -47,13 +50,21 @@ int main()
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
+ RunPhysicsStep();
+
//----------------------------------------------------------------------------------
+ // Delay initialization of variables due to physics reset asynchronous
+ if (needsReset)
+ {
+ // Create random polygon physics body to shatter
+ CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10);
+ needsReset = false;
+ }
+
if (IsKeyPressed('R')) // Reset physics input
{
ResetPhysics();
-
- // Create random polygon physics body to shatter
- body = CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10);
+ needsReset = true;
}
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) // Physics shatter input
@@ -112,4 +123,3 @@ int main()
return 0;
}
-