Updated physics examples with new module changes
This commit is contained in:
parent
5625c11e99
commit
6a2bbae521
2 changed files with 2 additions and 63 deletions
|
@ -13,12 +13,10 @@
|
||||||
|
|
||||||
#define PHYSAC_IMPLEMENTATION
|
#define PHYSAC_IMPLEMENTATION
|
||||||
#include "physac.h"
|
#include "physac.h"
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
#define MOVE_VELOCITY 5
|
#define MOVE_VELOCITY 5
|
||||||
#define JUMP_VELOCITY 30
|
#define JUMP_VELOCITY 30
|
||||||
|
|
||||||
void* PhysicsThread(void *arg);
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
@ -28,7 +26,6 @@ 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
|
InitPhysics((Vector2){ 0.0f, -9.81f/2 }); // Initialize physics module
|
||||||
|
|
||||||
// Debug variables
|
// Debug variables
|
||||||
|
@ -56,10 +53,6 @@ int main()
|
||||||
// Create pplatform physic object
|
// Create pplatform physic object
|
||||||
PhysicBody platform = CreatePhysicBody((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 });
|
||||||
|
|
||||||
// Create physics thread
|
|
||||||
pthread_t tid;
|
|
||||||
pthread_create(&tid, NULL, &PhysicsThread, NULL);
|
|
||||||
|
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -123,32 +116,9 @@ int main()
|
||||||
|
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
pthread_cancel(tid); // Destroy physics thread
|
|
||||||
|
|
||||||
ClosePhysics(); // Unitialize physics (including all loaded objects)
|
ClosePhysics(); // Unitialize physics (including all loaded objects)
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* PhysicsThread(void *arg)
|
|
||||||
{
|
|
||||||
// Initialize time variables
|
|
||||||
double currentTime = GetTime();
|
|
||||||
double previousTime = currentTime;
|
|
||||||
|
|
||||||
// Physics update loop
|
|
||||||
while (!WindowShouldClose())
|
|
||||||
{
|
|
||||||
currentTime = GetTime();
|
|
||||||
double deltaTime = (double)(currentTime - previousTime);
|
|
||||||
previousTime = currentTime;
|
|
||||||
|
|
||||||
// Delta time value needs to be inverse multiplied by physics time step value (1/target fps)
|
|
||||||
UpdatePhysics(deltaTime/PHYSICS_TIMESTEP);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
|
@ -13,15 +13,12 @@
|
||||||
|
|
||||||
#define PHYSAC_IMPLEMENTATION
|
#define PHYSAC_IMPLEMENTATION
|
||||||
#include "physac.h"
|
#include "physac.h"
|
||||||
#include <pthread.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* PhysicsThread(void *arg);
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// Initialization
|
// Initialization
|
||||||
|
@ -30,7 +27,6 @@ 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
|
InitPhysics((Vector2){ 0.0f, -9.81f/2 }); // Initialize physics module
|
||||||
|
|
||||||
// Global variables
|
// Global variables
|
||||||
|
@ -64,10 +60,6 @@ int main()
|
||||||
PhysicBody topWall = CreatePhysicBody((Vector2){ screenWidth/2, -25 }, 0.0f, (Vector2){ screenWidth, 50 });
|
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 });
|
PhysicBody bottomWall = CreatePhysicBody((Vector2){ screenWidth/2, screenHeight + 25 }, 0.0f, (Vector2){ screenWidth, 50 });
|
||||||
|
|
||||||
// Create physics thread
|
|
||||||
pthread_t tid;
|
|
||||||
pthread_create(&tid, NULL, &PhysicsThread, NULL);
|
|
||||||
|
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -180,32 +172,9 @@ int main()
|
||||||
|
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
pthread_cancel(tid); // Destroy physics thread
|
|
||||||
|
|
||||||
ClosePhysics(); // Unitialize physics module
|
ClosePhysics(); // Unitialize physics module
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* PhysicsThread(void *arg)
|
|
||||||
{
|
|
||||||
// Initialize time variables
|
|
||||||
double currentTime = GetTime();
|
|
||||||
double previousTime = currentTime;
|
|
||||||
|
|
||||||
// Physics update loop
|
|
||||||
while (!WindowShouldClose())
|
|
||||||
{
|
|
||||||
currentTime = GetTime();
|
|
||||||
double deltaTime = (double)(currentTime - previousTime);
|
|
||||||
previousTime = currentTime;
|
|
||||||
|
|
||||||
// Delta time value needs to be inverse multiplied by physics time step value (1/target fps)
|
|
||||||
UpdatePhysics(deltaTime/PHYSICS_TIMESTEP);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue