Reviewed physics module
A deeper revision required, not clear enough for the user Key: Create a PhysicObjects pool
This commit is contained in:
parent
94c92a58a1
commit
ed19064405
5 changed files with 64 additions and 98 deletions
|
@ -2,10 +2,10 @@
|
|||
*
|
||||
* raylib [physac] physics example - Rigidbody forces
|
||||
*
|
||||
* This example has been created using raylib 1.3 (www.raylib.com)
|
||||
* This example has been created using raylib 1.4 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
* Copyright (c) 2016 Victor Fisac and Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
@ -26,15 +26,9 @@ int main()
|
|||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [physics] example - rigidbodies forces");
|
||||
|
||||
InitPhysics(); // Initialize internal physics values (max rigidbodies/colliders available: 1024)
|
||||
InitPhysics(MAX_OBJECTS + 1); // Initialize physics system with maximum physic objects
|
||||
|
||||
// Physics initialization
|
||||
Physics worldPhysics = {true, false, (Vector2){0, -9.81f}};
|
||||
|
||||
// Set internal physics settings
|
||||
SetPhysics(worldPhysics);
|
||||
|
||||
// Objects initialization
|
||||
// Physic Objects initialization
|
||||
Transform objects[MAX_OBJECTS];
|
||||
|
||||
for (int i = 0; i < MAX_OBJECTS; i++)
|
||||
|
@ -49,6 +43,8 @@ int main()
|
|||
Transform floor = (Transform){(Vector2){0, screenHeight * 0.8f}, 0.0f, (Vector2){screenWidth, screenHeight * 0.2f}};
|
||||
AddCollider(MAX_OBJECTS, (Collider){true, COLLIDER_RECTANGLE, (Rectangle){floor.position.x, floor.position.y, floor.scale.x, floor.scale.y}, 0});
|
||||
|
||||
bool physicsDebug = false;
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -72,14 +68,7 @@ int main()
|
|||
}
|
||||
|
||||
// Check debug mode toggle button input
|
||||
if (IsKeyPressed(KEY_P))
|
||||
{
|
||||
// Update program physics value
|
||||
worldPhysics.debug = !worldPhysics.debug;
|
||||
|
||||
// Update internal physics value
|
||||
SetPhysics(worldPhysics);
|
||||
}
|
||||
if (IsKeyPressed(KEY_P)) physicsDebug = !physicsDebug;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
|
@ -89,10 +78,10 @@ int main()
|
|||
ClearBackground(RAYWHITE);
|
||||
|
||||
// Check if debug mode is enabled
|
||||
if (worldPhysics.debug)
|
||||
if (physicsDebug)
|
||||
{
|
||||
// Draw every internal physics stored collider if it is active (floor included)
|
||||
for (int i = 0; i < MAX_OBJECTS + 1; i++)
|
||||
for (int i = 0; i < MAX_OBJECTS; i++)
|
||||
{
|
||||
if (GetCollider(i).enabled)
|
||||
{
|
||||
|
@ -136,7 +125,9 @@ int main()
|
|||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadPhysics(); // Unload physic objects
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue