From abfbc42df703c382a56cf1e06e4302cadbfe3395 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 25 Sep 2018 12:53:31 +0200 Subject: PNG image size optimization --- examples/shapes/shapes_colors_palette.png | Bin 5230 -> 6591 bytes examples/text/resources/custom_alagard.png | Bin 37935 -> 45351 bytes examples/text/resources/custom_jupiter_crash.png | Bin 23596 -> 29128 bytes examples/text/resources/custom_mecha.png | Bin 26597 -> 32399 bytes examples/text/resources/fonts/alagard.png | Bin 4424 -> 3626 bytes examples/text/resources/fonts/alpha_beta.png | Bin 2442 -> 2424 bytes examples/text/resources/fonts/jupiter_crash.png | Bin 3478 -> 2975 bytes examples/text/resources/fonts/mecha.png | Bin 2399 -> 2355 bytes examples/text/resources/fonts/pixantiqua.png | Bin 3003 -> 2739 bytes examples/text/resources/fonts/pixelplay.png | Bin 2912 -> 2835 bytes examples/text/resources/fonts/romulus.png | Bin 2932 -> 2702 bytes examples/text/resources/fonts/setback.png | Bin 2539 -> 2517 bytes .../textures/resources/custom_jupiter_crash.png | Bin 23596 -> 29128 bytes examples/textures/resources/scarfy.png | Bin 33146 -> 10495 bytes 14 files changed, 0 insertions(+), 0 deletions(-) (limited to 'examples') diff --git a/examples/shapes/shapes_colors_palette.png b/examples/shapes/shapes_colors_palette.png index dd3cf4a5..4073b670 100644 Binary files a/examples/shapes/shapes_colors_palette.png and b/examples/shapes/shapes_colors_palette.png differ diff --git a/examples/text/resources/custom_alagard.png b/examples/text/resources/custom_alagard.png index c3eb63b7..63426555 100644 Binary files a/examples/text/resources/custom_alagard.png and b/examples/text/resources/custom_alagard.png differ diff --git a/examples/text/resources/custom_jupiter_crash.png b/examples/text/resources/custom_jupiter_crash.png index 451b591f..2deaaeff 100644 Binary files a/examples/text/resources/custom_jupiter_crash.png and b/examples/text/resources/custom_jupiter_crash.png differ diff --git a/examples/text/resources/custom_mecha.png b/examples/text/resources/custom_mecha.png index 59caab2c..a8c9e06e 100644 Binary files a/examples/text/resources/custom_mecha.png and b/examples/text/resources/custom_mecha.png differ diff --git a/examples/text/resources/fonts/alagard.png b/examples/text/resources/fonts/alagard.png index 3ac4bf1c..c0c54273 100644 Binary files a/examples/text/resources/fonts/alagard.png and b/examples/text/resources/fonts/alagard.png differ diff --git a/examples/text/resources/fonts/alpha_beta.png b/examples/text/resources/fonts/alpha_beta.png index c362bfb1..8a0c2733 100644 Binary files a/examples/text/resources/fonts/alpha_beta.png and b/examples/text/resources/fonts/alpha_beta.png differ diff --git a/examples/text/resources/fonts/jupiter_crash.png b/examples/text/resources/fonts/jupiter_crash.png index 1f5172fb..4972c02e 100644 Binary files a/examples/text/resources/fonts/jupiter_crash.png and b/examples/text/resources/fonts/jupiter_crash.png differ diff --git a/examples/text/resources/fonts/mecha.png b/examples/text/resources/fonts/mecha.png index 8022d18c..9213fa2d 100644 Binary files a/examples/text/resources/fonts/mecha.png and b/examples/text/resources/fonts/mecha.png differ diff --git a/examples/text/resources/fonts/pixantiqua.png b/examples/text/resources/fonts/pixantiqua.png index ce422e7e..17ad1ab7 100644 Binary files a/examples/text/resources/fonts/pixantiqua.png and b/examples/text/resources/fonts/pixantiqua.png differ diff --git a/examples/text/resources/fonts/pixelplay.png b/examples/text/resources/fonts/pixelplay.png index bf8f8818..fbf6430d 100644 Binary files a/examples/text/resources/fonts/pixelplay.png and b/examples/text/resources/fonts/pixelplay.png differ diff --git a/examples/text/resources/fonts/romulus.png b/examples/text/resources/fonts/romulus.png index 46ccc327..648aa8b0 100644 Binary files a/examples/text/resources/fonts/romulus.png and b/examples/text/resources/fonts/romulus.png differ diff --git a/examples/text/resources/fonts/setback.png b/examples/text/resources/fonts/setback.png index 086f3e27..1630a733 100644 Binary files a/examples/text/resources/fonts/setback.png and b/examples/text/resources/fonts/setback.png differ diff --git a/examples/textures/resources/custom_jupiter_crash.png b/examples/textures/resources/custom_jupiter_crash.png index 451b591f..2deaaeff 100644 Binary files a/examples/textures/resources/custom_jupiter_crash.png and b/examples/textures/resources/custom_jupiter_crash.png differ diff --git a/examples/textures/resources/scarfy.png b/examples/textures/resources/scarfy.png index beb5ffa0..4803ef77 100644 Binary files a/examples/textures/resources/scarfy.png and b/examples/textures/resources/scarfy.png differ -- cgit v1.2.3 From 35634f37c85ddc0e0f78b8e007250fa0acbd2365 Mon Sep 17 00:00:00 2001 From: Pablo Marcos Oltra Date: Sun, 23 Sep 2018 13:55:39 +0200 Subject: Fix physac's fixed time step --- examples/physac/physics_restitution.c | 3 ++ src/physac.h | 71 +++++++++++++++++------------------ 2 files changed, 37 insertions(+), 37 deletions(-) (limited to 'examples') diff --git a/examples/physac/physics_restitution.c b/examples/physac/physics_restitution.c index d2ec49db..197e6eb5 100644 --- a/examples/physac/physics_restitution.c +++ b/examples/physac/physics_restitution.c @@ -51,6 +51,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 diff --git a/src/physac.h b/src/physac.h index 38789a6d..ab975e28 100644 --- a/src/physac.h +++ b/src/physac.h @@ -96,8 +96,6 @@ #define PHYSAC_MAX_VERTICES 24 #define PHYSAC_CIRCLE_VERTICES 24 -#define PHYSAC_DESIRED_DELTATIME 1.0/60.0 -#define PHYSAC_MAX_TIMESTEP 0.02 #define PHYSAC_COLLISION_ITERATIONS 100 #define PHYSAC_PENETRATION_ALLOWANCE 0.05f #define PHYSAC_PENETRATION_CORRECTION 0.4f @@ -197,6 +195,7 @@ extern "C" { // Prevents name mangling of fun //---------------------------------------------------------------------------------- PHYSACDEF void InitPhysics(void); // Initializes physics values, pointers and creates physics loop thread PHYSACDEF void RunPhysicsStep(void); // Run physics step, to be used if PHYSICS_NO_THREADS is set in your main loop +PHYSACDEF void SetPhysicsTimeStep(double delta); // Sets physics fixed time step in milliseconds. 1.666666 by default PHYSACDEF bool IsPhysicsEnabled(void); // Returns true if physics thread is currently enabled PHYSACDEF void SetPhysicsGravity(float x, float y); // Sets physics global gravity force PHYSACDEF PhysicsBody CreatePhysicsBodyCircle(Vector2 pos, float radius, float density); // Creates a new circle physics body with generic parameters @@ -279,16 +278,15 @@ static pthread_t physicsThreadId; // Physics thread id #endif static unsigned int usedMemory = 0; // Total allocated dynamic memory static bool physicsThreadEnabled = false; // Physics thread enabled state - static double baseTime = 0.0; // Offset time for MONOTONIC clock static double startTime = 0.0; // Start time in milliseconds -static double deltaTime = 0.0; // Delta time used for physics steps +static double deltaTime = 1.0/60.0/10.0 * 1000; // Delta time used for physics steps, in milliseconds static double currentTime = 0.0; // Current time in milliseconds static uint64_t frequency = 0; // Hi-res clock frequency static double accumulator = 0.0; // Physics time step delta time accumulator static unsigned int stepsCount = 0; // Total physics steps processed -static Vector2 gravityForce = { 0.0f, 9.81f/1000 }; // Physics world gravity force +static Vector2 gravityForce = { 0.0f, 9.81f }; // Physics world gravity force static PhysicsBody bodies[PHYSAC_MAX_BODIES]; // Physics bodies pointers array static unsigned int physicsBodiesCount = 0; // Physics world current bodies counter static PhysicsManifold contacts[PHYSAC_MAX_MANIFOLDS]; // Physics bodies pointers array @@ -322,13 +320,12 @@ static bool BiasGreaterThan(float valueA, float valueB); static Vector2 TriangleBarycenter(Vector2 v1, Vector2 v2, Vector2 v3); // Returns the barycenter of a triangle given by 3 points static void InitTimer(void); // Initializes hi-resolution MONOTONIC timer -static uint64_t GetTimeCount(void); // Get hi-res MONOTONIC time measure in seconds -static double GetCurrentTime(void); // // Get hi-res MONOTONIC time measure in seconds +static uint64_t GetTimeCount(void); // Get hi-res MONOTONIC time measure in mseconds +static double GetCurrentTime(void); // Get current time measure in milliseconds static int GetRandomNumber(int min, int max); // Returns a random number between min and max (both included) // Math functions -static void MathClamp(double *value, double min, double max); // Clamp a value in a range static Vector2 MathCross(float value, Vector2 vector); // Returns the cross product of a vector and a value static float MathCrossVector2(Vector2 v1, Vector2 v2); // Returns the cross product of two vectors static float MathLenSqr(Vector2 vector); // Returns the len square root of a vector @@ -363,6 +360,8 @@ PHYSACDEF void InitPhysics(void) #if defined(PHYSAC_DEBUG) printf("[PHYSAC] physics module initialized successfully\n"); #endif + + accumulator = 0.0; } // Returns true if physics thread is currently enabled @@ -917,6 +916,18 @@ PHYSACDEF void ClosePhysics(void) #if !defined(PHYSAC_NO_THREADS) pthread_join(physicsThreadId, NULL); #endif + + // Unitialize physics manifolds dynamic memory allocations + for (int i = physicsManifoldsCount - 1; i >= 0; i--) DestroyPhysicsManifold(contacts[i]); + + // Unitialize physics bodies dynamic memory allocations + for (int i = physicsBodiesCount - 1; i >= 0; i--) DestroyPhysicsBody(bodies[i]); + + #if defined(PHYSAC_DEBUG) + if (physicsBodiesCount > 0 || usedMemory != 0) printf("[PHYSAC] physics module closed with %i still allocated bodies [MEMORY: %i bytes]\n", physicsBodiesCount, usedMemory); + else if (physicsManifoldsCount > 0 || usedMemory != 0) printf("[PHYSAC] physics module closed with %i still allocated manifolds [MEMORY: %i bytes]\n", physicsManifoldsCount, usedMemory); + else printf("[PHYSAC] physics module closed successfully\n"); + #endif } //---------------------------------------------------------------------------------- @@ -1011,7 +1022,6 @@ static void *PhysicsLoop(void *arg) // Initialize physics loop thread values physicsThreadEnabled = true; - accumulator = 0; // Physics update loop while (physicsThreadEnabled) @@ -1019,18 +1029,6 @@ static void *PhysicsLoop(void *arg) RunPhysicsStep(); } - // Unitialize physics manifolds dynamic memory allocations - for (int i = physicsManifoldsCount - 1; i >= 0; i--) DestroyPhysicsManifold(contacts[i]); - - // Unitialize physics bodies dynamic memory allocations - for (int i = physicsBodiesCount - 1; i >= 0; i--) DestroyPhysicsBody(bodies[i]); - - #if defined(PHYSAC_DEBUG) - if (physicsBodiesCount > 0 || usedMemory != 0) printf("[PHYSAC] physics module closed with %i still allocated bodies [MEMORY: %i bytes]\n", physicsBodiesCount, usedMemory); - else if (physicsManifoldsCount > 0 || usedMemory != 0) printf("[PHYSAC] physics module closed with %i still allocated manifolds [MEMORY: %i bytes]\n", physicsManifoldsCount, usedMemory); - else printf("[PHYSAC] physics module closed successfully\n"); - #endif - return NULL; } @@ -1147,17 +1145,18 @@ PHYSACDEF void RunPhysicsStep(void) currentTime = GetCurrentTime(); // Calculate current delta time - deltaTime = currentTime - startTime; + const double delta = currentTime - startTime; // Store the time elapsed since the last frame began - accumulator += deltaTime; - - // Clamp accumulator to max time step to avoid bad performance - MathClamp(&accumulator, 0.0, PHYSAC_MAX_TIMESTEP); + accumulator += delta; // Fixed time stepping loop - while (accumulator >= PHYSAC_DESIRED_DELTATIME) + while (accumulator >= deltaTime) { +#ifdef PHYSAC_DEBUG + //printf("currentTime %f, startTime %f, accumulator-pre %f, accumulator-post %f, delta %f, deltaTime %f\n", + // currentTime, startTime, accumulator, accumulator-deltaTime, delta, deltaTime); +#endif PhysicsStep(); accumulator -= deltaTime; } @@ -1166,6 +1165,11 @@ PHYSACDEF void RunPhysicsStep(void) startTime = currentTime; } +PHYSACDEF void SetPhysicsTimeStep(double delta) +{ + deltaTime = delta; +} + // Finds a valid index for a new manifold initialization static int FindAvailableManifoldIndex() { @@ -1557,8 +1561,8 @@ static void IntegratePhysicsForces(PhysicsBody body) if (body->useGravity) { - body->velocity.x += gravityForce.x*(deltaTime/2.0); - body->velocity.y += gravityForce.y*(deltaTime/2.0); + body->velocity.x += gravityForce.x*(deltaTime/1000/2.0); + body->velocity.y += gravityForce.y*(deltaTime/1000/2.0); } if (!body->freezeOrient) body->angularVelocity += body->torque*body->inverseInertia*(deltaTime/2.0); @@ -1592,7 +1596,7 @@ static void InitializePhysicsManifolds(PhysicsManifold manifold) // Determine if we should perform a resting collision or not; // The idea is if the only thing moving this object is gravity, then the collision should be performed without any restitution - if (MathLenSqr(radiusV) < (MathLenSqr((Vector2){ gravityForce.x*deltaTime, gravityForce.y*deltaTime }) + PHYSAC_EPSILON)) manifold->restitution = 0; + if (MathLenSqr(radiusV) < (MathLenSqr((Vector2){ gravityForce.x*deltaTime/1000, gravityForce.y*deltaTime/1000 }) + PHYSAC_EPSILON)) manifold->restitution = 0; } } @@ -1953,13 +1957,6 @@ static int GetRandomNumber(int min, int max) return (rand()%(abs(max - min) + 1) + min); } -// Clamp a value in a range -static inline void MathClamp(double *value, double min, double max) -{ - if (*value < min) *value = min; - else if (*value > max) *value = max; -} - // Returns the cross product of a vector and a value static inline Vector2 MathCross(float value, Vector2 vector) { -- cgit v1.2.3 From fa5cebdfd27f7081b37d54401624d2556a04a4d2 Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 19 Oct 2018 16:17:29 +0200 Subject: Comment tweak --- examples/models/models_yaw_pitch_roll.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/models/models_yaw_pitch_roll.c b/examples/models/models_yaw_pitch_roll.c index 0dcf8c70..88b0a610 100644 --- a/examples/models/models_yaw_pitch_roll.c +++ b/examples/models/models_yaw_pitch_roll.c @@ -5,8 +5,7 @@ * This example has been created using raylib 1.8 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * -* Example based on Berni work on Raspberry Pi: -* http://forum.raylib.com/index.php?p=/discussion/124/line-versus-triangle-drawing-order +* Example based on Berni work on Raspberry Pi. * * Copyright (c) 2017 Ramon Santamaria (@raysan5) * -- cgit v1.2.3 From 7a712d00e656f9e10846b8501bc10bc9760bd3be Mon Sep 17 00:00:00 2001 From: Berni8k Date: Sun, 21 Oct 2018 10:10:50 +0100 Subject: Added multitouch example --- examples/Makefile | 1 + examples/core/core_multitouch.c | 90 ++++++++++++++++++++++++++++++++++++++ examples/core/core_multitouch.png | Bin 0 -> 17177 bytes 3 files changed, 91 insertions(+) create mode 100644 examples/core/core_multitouch.c create mode 100644 examples/core/core_multitouch.png (limited to 'examples') diff --git a/examples/Makefile b/examples/Makefile index a7a85661..a26e0bbb 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -375,6 +375,7 @@ EXAMPLES = \ core/core_2d_camera \ core/core_world_screen \ core/core_vr_simulator \ + core/core_multitouch \ shapes/shapes_logo_raylib \ shapes/shapes_basic_shapes \ shapes/shapes_colors_palette \ diff --git a/examples/core/core_multitouch.c b/examples/core/core_multitouch.c new file mode 100644 index 00000000..c059ac03 --- /dev/null +++ b/examples/core/core_multitouch.c @@ -0,0 +1,90 @@ +/******************************************************************************************* +* +* raylib [core] example - Multitouch input +* +* This example has been created using raylib 2.1 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2014 Ramon Santamaria (@raysan5) +* Example by Berni +* +********************************************************************************************/ + +#include "raylib.h" +#include + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [core] example - multitouch input"); + + Vector2 ballPosition = { -100.0f, -100.0f }; + Color ballColor; + int PressedCounter = 0; + Vector2 TouchPos; + char Str[16]; + + SetTargetFPS(60); + //--------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + ballPosition = GetMousePosition(); + + ballColor = BEIGE; + + if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) ballColor = MAROON; + if (IsMouseButtonDown(MOUSE_MIDDLE_BUTTON)) ballColor = LIME; + if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) ballColor = DARKBLUE; + + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) PressedCounter = 10; + if (IsMouseButtonPressed(MOUSE_MIDDLE_BUTTON)) PressedCounter = 10; + if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) PressedCounter = 10; + if(PressedCounter > 0) + PressedCounter--; + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + // Multitouch + for (int i = 0; i < MAX_TOUCH_POINTS; ++i) + { + TouchPos = GetTouchPosition(i); // Get the touch point + + if( (TouchPos.x >= 0) && (TouchPos.y >= 0) ) // Make sure point is not (-1,-1) as this means there is no touch for it + { + DrawCircleV(TouchPos, 34, ORANGE); // Draw a circle there + + sprintf(Str,"%d",i); + DrawText(Str, TouchPos.x - 10, TouchPos.y - 70, 40, BLACK); // Also show its index number + } + } + + // Draw the normal mouse location + DrawCircleV(ballPosition, 30 + (PressedCounter * 3), ballColor); + + DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, DARKGRAY); + DrawText("touch the screen at multiple locations to get multiple balls", 10, 30, 20, DARKGRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} \ No newline at end of file diff --git a/examples/core/core_multitouch.png b/examples/core/core_multitouch.png new file mode 100644 index 00000000..74284f82 Binary files /dev/null and b/examples/core/core_multitouch.png differ -- cgit v1.2.3