From f88a94341891b1969ba58dd7ab88e6b3c69cabf2 Mon Sep 17 00:00:00 2001 From: victorfisac Date: Mon, 6 Mar 2017 09:58:28 +0100 Subject: Fix bug in isGrounded state calculations --- src/physac.h | 80 +++++++++--------------------------------------------------- 1 file changed, 12 insertions(+), 68 deletions(-) (limited to 'src/physac.h') diff --git a/src/physac.h b/src/physac.h index cb0e3f3c..a6b529bc 100644 --- a/src/physac.h +++ b/src/physac.h @@ -361,70 +361,6 @@ PHYSACDEF PhysicsBody CreatePhysicsBodyCircle(Vector2 pos, float radius, float d { PhysicsBody newBody = CreatePhysicsBodyPolygon(pos, radius, PHYSAC_CIRCLE_VERTICES, density); return newBody; - - /*PhysicsBody newBody = (PhysicsBody)PHYSAC_MALLOC(sizeof(PhysicsBodyData)); - usedMemory += sizeof(PhysicsBodyData); - - int newId = -1; - for (int i = 0; i < PHYSAC_MAX_BODIES; i++) - { - int currentId = i; - - // Check if current id already exist in other physics body - for (int k = 0; k < physicsBodiesCount; k++) - { - if (bodies[k]->id == currentId) - { - currentId++; - break; - } - } - - // If it is not used, use it as new physics body id - if (currentId == i) - { - newId = i; - break; - } - } - - if (newId != -1) - { - // Initialize new body with generic values - newBody->id = newId; - newBody->enabled = true; - newBody->position = pos; - newBody->velocity = (Vector2){ 0 }; - newBody->force = (Vector2){ 0 }; - newBody->angularVelocity = 0; - newBody->torque = 0; - newBody->orient = 0; - newBody->mass = PHYSAC_PI*radius*radius*density; - newBody->inverseMass = ((newBody->mass != 0.0f) ? 1.0f/newBody->mass : 0.0f); - newBody->inertia = newBody->mass*radius*radius; - newBody->inverseInertia = ((newBody->inertia != 0.0f) ? 1.0f/newBody->inertia : 0.0f); - newBody->staticFriction = 0; - newBody->dynamicFriction = 0; - newBody->restitution = 0; - newBody->useGravity = true; - newBody->freezeOrient = false; - newBody->shape.type = PHYSICS_CIRCLE; - newBody->shape.body = newBody; - newBody->shape.radius = radius; - - // Add new body to bodies pointers array and update bodies count - bodies[physicsBodiesCount] = newBody; - physicsBodiesCount++; - - #if defined(PHYSAC_DEBUG) - printf("[PHYSAC] created circle physics body id %i\n", newBody->id); - #endif - } - #if defined(PHYSAC_DEBUG) - else printf("[PHYSAC] new physics body creation failed because there is any available id to use\n"); - #endif - - return newBody;*/ } // Creates a new rectangle physics body with generic parameters @@ -1130,6 +1066,7 @@ static void *PhysicsLoop(void *arg) // Physics steps calculations (dynamics, collisions and position corrections) static void PhysicsStep(void) { + // Update current steps count stepsCount++; // Clear previous generated collisions information @@ -1138,6 +1075,13 @@ static void PhysicsStep(void) PhysicsManifold manifold = contacts[i]; if (manifold != NULL) DestroyPhysicsManifold(manifold); } + + // Reset physics bodies grounded state + for (int i = 0; i < physicsBodiesCount; i++) + { + PhysicsBody body = bodies[i]; + body->isGrounded = false; + } // Generate new collision information for (int i = 0; i < physicsBodiesCount; i++) @@ -1347,9 +1291,9 @@ static void SolvePhysicsManifold(PhysicsManifold manifold) } break; default: break; } - - // Update physics body grounded state if normal direction is downside - manifold->bodyB->isGrounded = (manifold->normal.y < 0); + + // Update physics body grounded state if normal direction is down and grounded state is not set yet in previous manifolds + if (!manifold->bodyB->isGrounded) manifold->bodyB->isGrounded = (manifold->normal.y < 0); } // Solves collision between two circle shape physics bodies @@ -1388,7 +1332,7 @@ static void SolveCircleToCircle(PhysicsManifold manifold) } // Update physics body grounded state if normal direction is down - if (manifold->normal.y < 0) bodyA->isGrounded = true; + if (!bodyA->isGrounded) bodyA->isGrounded = (manifold->normal.y < 0); } // Solves collision between a circle to a polygon shape physics bodies -- cgit v1.2.3 From c964559bc966292a7d70f00559ea80c224aab96d Mon Sep 17 00:00:00 2001 From: victorfisac Date: Mon, 6 Mar 2017 22:57:33 +0100 Subject: Update physac source and examples with new changes --- examples/physics_demo.c | 7 +++++-- examples/physics_friction.c | 7 +++++-- examples/physics_movement.c | 7 +++++-- examples/physics_restitution.c | 7 +++++-- examples/physics_shatter.c | 7 +++++-- src/physac.h | 9 ++++++++- 6 files changed, 33 insertions(+), 11 deletions(-) (limited to 'src/physac.h') diff --git a/examples/physics_demo.c b/examples/physics_demo.c index de8d515e..b12ac708 100644 --- a/examples/physics_demo.c +++ b/examples/physics_demo.c @@ -3,9 +3,12 @@ * Physac - Physics demo * * NOTE: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations. -* The file pthreadGC2.dll is required to run the program; you can find it in 'src\external' * -* Copyright (c) 2016 Victor Fisac +* Use the following code to compile (-static -lpthread): +* 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 +* +* Copyright (c) 2017 Victor Fisac * ********************************************************************************************/ diff --git a/examples/physics_friction.c b/examples/physics_friction.c index a4baad53..db1b5f4c 100644 --- a/examples/physics_friction.c +++ b/examples/physics_friction.c @@ -3,9 +3,12 @@ * Physac - Physics friction * * NOTE: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations. -* The file pthreadGC2.dll is required to run the program; you can find it in 'src\external' * -* Copyright (c) 2016 Victor Fisac +* Use the following code to compile (-static -lpthread): +* 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 +* +* Copyright (c) 2017 Victor Fisac * ********************************************************************************************/ diff --git a/examples/physics_movement.c b/examples/physics_movement.c index ee97845f..3345404d 100644 --- a/examples/physics_movement.c +++ b/examples/physics_movement.c @@ -3,9 +3,12 @@ * Physac - Physics movement * * NOTE: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations. -* The file pthreadGC2.dll is required to run the program; you can find it in 'src\external' * -* Copyright (c) 2016 Victor Fisac +* Use the following code to compile (-static -lpthread): +* 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 +* +* Copyright (c) 2017 Victor Fisac * ********************************************************************************************/ diff --git a/examples/physics_restitution.c b/examples/physics_restitution.c index 378f6f24..534d125e 100644 --- a/examples/physics_restitution.c +++ b/examples/physics_restitution.c @@ -3,9 +3,12 @@ * Physac - Physics restitution * * NOTE: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations. -* The file pthreadGC2.dll is required to run the program; you can find it in 'src\external' * -* Copyright (c) 2016 Victor Fisac +* Use the following code to compile (-static -lpthread): +* 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 +* +* Copyright (c) 2017 Victor Fisac * ********************************************************************************************/ diff --git a/examples/physics_shatter.c b/examples/physics_shatter.c index 637a163e..fac90714 100644 --- a/examples/physics_shatter.c +++ b/examples/physics_shatter.c @@ -3,9 +3,12 @@ * Physac - Body shatter * * NOTE: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations. -* The file pthreadGC2.dll is required to run the program; you can find it in 'src\external' * -* Copyright (c) 2016 Victor Fisac +* Use the following code to compile (-static -lpthread): +* 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 +* +* Copyright (c) 2017 Victor Fisac * ********************************************************************************************/ diff --git a/src/physac.h b/src/physac.h index a6b529bc..ff56615d 100644 --- a/src/physac.h +++ b/src/physac.h @@ -38,13 +38,20 @@ * You can define your own malloc/free implementation replacing stdlib.h malloc()/free() functions. * Otherwise it will include stdlib.h and use the C standard library malloc()/free() function. * +* +* NOTE: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations. +* +* Use the following code to compile (-static -lpthread): +* 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 +* * VERY THANKS TO: * Ramón Santamaria (@raysan5) * * * LICENSE: zlib/libpng * -* Copyright (c) 2016 Victor Fisac +* Copyright (c) 2017 Victor Fisac * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. -- cgit v1.2.3 From 9875198a56263b5e282c016c67221ddfcfb51d31 Mon Sep 17 00:00:00 2001 From: RDR8 Date: Fri, 24 Mar 2017 01:20:24 -0500 Subject: c99 fix, some linux housekeeping --- examples/Makefile | 31 +++++++++++++++---------------- src/Makefile | 16 ++++++++++------ src/core.c | 10 +++++----- src/gestures.h | 4 ++-- src/physac.h | 6 +++--- 5 files changed, 35 insertions(+), 32 deletions(-) (limited to 'src/physac.h') diff --git a/examples/Makefile b/examples/Makefile index 98129990..e271355d 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -40,7 +40,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) else UNAMEOS:=$(shell uname) ifeq ($(UNAMEOS),Linux) - PLATFORM_OS=LINUX + PLATFORM_OS=linux LIBPATH=linux else ifeq ($(UNAMEOS),Darwin) @@ -73,7 +73,9 @@ endif ifeq ($(PLATFORM),PLATFORM_RPI) CFLAGS = -O2 -s -Wall -std=gnu99 -fgnu89-inline else - CFLAGS = -O2 -s -Wall -std=c99 + ifeq ($(PLATFORM_OS),LINUX) + CFLAGS = -O2 -s -Wall -std=c99 --D_DEFAULT_SOURCE + endif endif ifeq ($(PLATFORM),PLATFORM_WEB) CFLAGS = -O1 -Wall -std=c99 -s USE_GLFW=3 -s ASSERTIONS=1 --preload-file resources @@ -88,7 +90,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(PLATFORM_OS),WINDOWS) RAYLIB_PATH = ../release/win32/mingw32 endif - ifeq ($(PLATFORM_OS),LINUX) + ifeq ($(PLATFORM_OS),linux) RAYLIB_PATH = ../release/linux endif ifeq ($(PLATFORM_OS),OSX) @@ -110,7 +112,7 @@ ifeq ($(PLATFORM),PLATFORM_RPI) endif ifeq ($(PLATFORM),PLATFORM_DESKTOP) # add standard directories for GNU/Linux - ifeq ($(PLATFORM_OS),LINUX) + ifeq ($(PLATFORM_OS),linux) INCLUDES += -I/usr/local/include/raylib/ else ifeq ($(PLATFORM_OS),WINDOWS) # external libraries headers @@ -141,7 +143,7 @@ endif # define any libraries to link into executable # if you want to link libraries (libname.so or libname.a), use the -lname ifeq ($(PLATFORM),PLATFORM_DESKTOP) - ifeq ($(PLATFORM_OS),LINUX) + ifeq ($(PLATFORM_OS),linux) # libraries for Debian GNU/Linux desktop compiling # requires the following packages: # libglfw3-dev libopenal-dev libegl1-mesa-dev @@ -185,6 +187,11 @@ ifeq ($(PLATFORM_OS),WINDOWS) WINFLAGS = ../src/resources -Wl,--subsystem,windows endif +# Linux Fix to timespect from +ifeq ($(PLATFORM_OS),linux) + CFLAGS += -D_DEFAULT_SOURCE + endif + ifeq ($(PLATFORM),PLATFORM_WEB) EXT = .html endif @@ -207,7 +214,6 @@ EXAMPLES = \ core_3d_camera_first_person \ core_2d_camera \ core_world_screen \ - core_oculus_rift \ shapes_logo_raylib \ shapes_basic_shapes \ shapes_colors_palette \ @@ -338,8 +344,8 @@ core_world_screen: core_world_screen.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) # compile [core] example - oculus rift -core_oculus_rift: core_oculus_rift.c - $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) +#core_oculus_rift: core_oculus_rift.c +# $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) # compile [shapes] example - raylib logo (with basic shapes) shapes_logo_raylib: shapes_logo_raylib.c @@ -497,13 +503,6 @@ audio_module_playing: audio_module_playing.c audio_raw_stream: audio_raw_stream.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) -# Linux Fix to timespect from -ifeq ($(PLATFORM),PLATFORM_DESKTOP) - ifeq ($(PLATFORM_OS),LINUX) - CFLAGS += -D_POSIX_C_SOURCE=199309L - endif -endif - # compile [physac] example - physics demo physics_demo: physics_demo.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -lpthread -D$(PLATFORM) $(WINFLAGS) @@ -537,7 +536,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) find . -type f -perm +ugo+x -delete rm -f *.o else - ifeq ($(PLATFORM_OS),LINUX) + ifeq ($(PLATFORM_OS),linux) find -type f -executable | xargs file -i | grep -E 'x-object|x-archive|x-sharedlib|x-executable' | rev | cut -d ':' -f 2- | rev | xargs rm -f else del *.o *.exe diff --git a/src/Makefile b/src/Makefile index 4c2278f5..eeb0ce35 100644 --- a/src/Makefile +++ b/src/Makefile @@ -60,7 +60,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) else UNAMEOS:=$(shell uname) ifeq ($(UNAMEOS),Linux) - PLATFORM_OS=LINUX + PLATFORM_OS=linux else ifeq ($(UNAMEOS),Darwin) PLATFORM_OS=OSX @@ -153,12 +153,16 @@ endif # define compiler flags: # -O1 defines optimization level +# -Og enable debugging # -Wall turns on most, but not all, compiler warnings # -std=c99 defines C language mode (standard C from 1999 revision) # -std=gnu99 defines C language mode (GNU C from 1999 revision) # -fgnu89-inline declaring inline functions support (GCC optimized) # -Wno-missing-braces ignore invalid warning (GCC bug 53119) -CFLAGS = -O1 -Wall -std=gnu99 -fgnu89-inline -Wno-missing-braces +# -D_DEFAULT_SOURCE use with -std=c99 on Linux to enable timespec and audio +#CFLAGS = -O1 -Wall -std=gnu99 -fgnu89-inline -Wno-missing-braces +CFLAGS = -O1 -Wall -std=c99 -D_DEFAULT_SOURCE + # if shared library required, make sure code is compiled as position independent ifeq ($(SHARED),YES) @@ -213,7 +217,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(PLATFORM_OS),WINDOWS) OUTPUT_PATH = ../release/win32/mingw32 endif - ifeq ($(PLATFORM_OS),LINUX) + ifeq ($(PLATFORM_OS),linux) OUTPUT_PATH = ../release/linux endif ifeq ($(PLATFORM_OS),OSX) @@ -264,7 +268,7 @@ ifeq ($(PLATFORM),PLATFORM_WEB) @echo "libraylib.bc generated (web version)!" else ifeq ($(SHARED),YES) - ifeq ($(PLATFORM_OS),LINUX) + ifeq ($(PLATFORM_OS),linux) # compile raylib to shared library version for GNU/Linux. # WARNING: you should type "make clean" before doing this target $(CC) -shared -o $(OUTPUT_PATH)/libraylib.so $(OBJS) @@ -333,7 +337,7 @@ utils.o : utils.c utils.h # TODO: add other platforms. install : ifeq ($(ROOT),root) - ifeq ($(PLATFORM_OS),LINUX) + ifeq ($(PLATFORM_OS),linux) # On GNU/Linux there are some standard directories that contain # libraries and header files. These directory (/usr/local/lib and # /usr/local/include/) are for libraries that are installed @@ -356,7 +360,7 @@ endif # TODO: see 'install' target. unistall : ifeq ($(ROOT),root) - ifeq ($(PLATFORM_OS),LINUX) + ifeq ($(PLATFORM_OS),linux) rm --force /usr/local/include/raylib.h ifeq ($(SHARED),YES) rm --force /usr/local/lib/libraylib.so diff --git a/src/core.c b/src/core.c index 1423cf7c..1a0e5a66 100644 --- a/src/core.c +++ b/src/core.c @@ -105,7 +105,7 @@ #include // Required for: strcmp() //#include // Macros for reporting and retrieving error conditions through error codes -#if defined __linux || defined(PLATFORM_WEB) +#if defined __linux__ || defined(PLATFORM_WEB) #include // Required for: timespec, nanosleep(), select() - POSIX #elif defined __APPLE__ #include // Required for: usleep() @@ -115,7 +115,7 @@ //#define GLFW_INCLUDE_NONE // Disable the standard OpenGL header inclusion on GLFW3 #include // GLFW3 library: Windows, OpenGL context and Input management - #ifdef __linux + #ifdef __linux__ #define GLFW_EXPOSE_NATIVE_X11 // Linux specific definitions for getting #define GLFW_EXPOSE_NATIVE_GLX // native functions like glfwGetX11Window #include // which are required for hiding mouse @@ -641,7 +641,7 @@ int GetScreenHeight(void) void ShowCursor() { #if defined(PLATFORM_DESKTOP) - #ifdef __linux + #ifdef __linux__ XUndefineCursor(glfwGetX11Display(), glfwGetX11Window(window)); #else glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); @@ -654,7 +654,7 @@ void ShowCursor() void HideCursor() { #if defined(PLATFORM_DESKTOP) - #ifdef __linux + #ifdef __linux__ XColor col; const char nil[] = {0}; @@ -2036,7 +2036,7 @@ static void Wait(float ms) #else #if defined _WIN32 Sleep(ms); - #elif defined __linux || defined(PLATFORM_WEB) + #elif defined __linux__ || defined(PLATFORM_WEB) struct timespec req = { 0 }; time_t sec = (int)(ms/1000.0f); ms -= (sec*1000); diff --git a/src/gestures.h b/src/gestures.h index 42ced889..c97871e5 100644 --- a/src/gestures.h +++ b/src/gestures.h @@ -147,7 +147,7 @@ float GetGesturePinchAngle(void); // Get gesture pinch ang // Functions required to query time on Windows int __stdcall QueryPerformanceCounter(unsigned long long int *lpPerformanceCount); int __stdcall QueryPerformanceFrequency(unsigned long long int *lpFrequency); -#elif defined(__linux) +#elif defined(__linux__) #include // Required for: timespec #include // Required for: clock_gettime() #endif @@ -517,7 +517,7 @@ static double GetCurrentTime(void) time = (double)currentTime/clockFrequency*1000.0f; // Time in miliseconds #endif -#if defined(__linux) +#if defined(__linux__) // NOTE: Only for Linux-based systems struct timespec now; clock_gettime(CLOCK_MONOTONIC, &now); diff --git a/src/physac.h b/src/physac.h index ff56615d..1aa0adee 100644 --- a/src/physac.h +++ b/src/physac.h @@ -249,7 +249,7 @@ PHYSACDEF void ClosePhysics(void); // Functions required to query time on Windows int __stdcall QueryPerformanceCounter(unsigned long long int *lpPerformanceCount); int __stdcall QueryPerformanceFrequency(unsigned long long int *lpFrequency); -#elif defined(__linux) || defined(PLATFORM_WEB) +#elif defined(__linux__) || defined(PLATFORM_WEB) #include // Required for: timespec #include // Required for: clock_gettime() #include @@ -277,7 +277,7 @@ PHYSACDEF void ClosePhysics(void); static unsigned int usedMemory = 0; // Total allocated dynamic memory static bool physicsThreadEnabled = false; // Physics thread enabled state static double currentTime = 0; // Current time in milliseconds -#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) || defined(__linux) || defined(PLATFORM_WEB) +#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) || defined(__linux__) || defined(PLATFORM_WEB) static double baseTime = 0; // Android and RPI platforms base time #endif static double startTime = 0; // Start time in milliseconds @@ -1906,7 +1906,7 @@ static double GetCurrentTime(void) time = (double)((double)currentTime/clockFrequency)*1000; #endif - #if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) || defined(__linux) || defined(PLATFORM_WEB) + #if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) || defined(__linux__) || defined(PLATFORM_WEB) struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); uint64_t temp = (uint64_t)ts.tv_sec*1000000000LLU + (uint64_t)ts.tv_nsec; -- cgit v1.2.3 From 3e082f1d6251e366d7be6019d0950ea7a9e6b5b4 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sun, 16 Apr 2017 19:08:34 +0200 Subject: Updated physac to latest version --- src/physac.h | 104 ++++++++++++++++++++++++++++------------------------------- 1 file changed, 49 insertions(+), 55 deletions(-) (limited to 'src/physac.h') diff --git a/src/physac.h b/src/physac.h index 1aa0adee..cec3afc9 100644 --- a/src/physac.h +++ b/src/physac.h @@ -2,22 +2,22 @@ * * Physac v1.0 - 2D Physics library for videogames * -* DESCRIPTION: +* DESCRIPTION: * -* Physac is a small 2D physics engine written in pure C. The engine uses a fixed time-step thread loop -* to simluate physics. A physics step contains the following phases: get collision information, -* apply dynamics, collision solving and position correction. It uses a very simple struct for physic +* Physac is a small 2D physics engine written in pure C. The engine uses a fixed time-step thread loop +* to simluate physics. A physics step contains the following phases: get collision information, +* apply dynamics, collision solving and position correction. It uses a very simple struct for physic * bodies with a position vector to be used in any 3D rendering API. -* +* * CONFIGURATION: -* +* * #define PHYSAC_IMPLEMENTATION * Generates the implementation of the library into the included file. -* If not defined, the library is in header only mode and can be included in other headers +* If not defined, the library is in header only mode and can be included in other headers * or source files without problems. But only ONE file should hold the implementation. * * #define PHYSAC_STATIC (defined by default) -* The generated implementation will stay private inside implementation file and all +* The generated implementation will stay private inside implementation file and all * internal symbols and functions will only be visible inside that file. * * #define PHYSAC_NO_THREADS @@ -30,7 +30,7 @@ * the user (check library implementation for further details). * * #define PHYSAC_DEBUG -* Traces log messages when creating and destroying physics bodies and detects errors in physics +* Traces log messages when creating and destroying physics bodies and detects errors in physics * calculations and reference exceptions; it is useful for debug purposes * * #define PHYSAC_MALLOC() @@ -39,10 +39,11 @@ * Otherwise it will include stdlib.h and use the C standard library malloc()/free() function. * * -* NOTE: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations. +* NOTE 1: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations. +* NOTE 2: Physac requires static C library linkage to avoid dependency on MinGW DLL (-static -lpthread) * -* Use the following code to compile (-static -lpthread): -* gcc -o $(NAME_PART).exe $(FILE_NAME) -s $(RAYLIB_DIR)\raylib\raylib_icon -static -lraylib -lpthread +* Use the following code to compile: +* gcc -o physac_sample.exe physac_sample.c -s $(RAYLIB_DIR)\raylib\raylib_icon -static -lraylib -lpthread \ * -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition * * VERY THANKS TO: @@ -51,7 +52,7 @@ * * LICENSE: zlib/libpng * -* Copyright (c) 2017 Victor Fisac +* Copyright (c) 2016-2017 Victor Fisac * * This software is provided "as-is", without any express or implied warranty. In no event * will the authors be held liable for any damages arising from the use of this software. @@ -73,7 +74,7 @@ #if !defined(PHYSAC_H) #define PHYSAC_H -#define PHYSAC_STATIC +// #define PHYSAC_STATIC // #define PHYSAC_NO_THREADS // #define PHYSAC_STANDALONE // #define PHYSAC_DEBUG @@ -250,6 +251,7 @@ PHYSACDEF void ClosePhysics(void); int __stdcall QueryPerformanceCounter(unsigned long long int *lpPerformanceCount); int __stdcall QueryPerformanceFrequency(unsigned long long int *lpFrequency); #elif defined(__linux__) || defined(PLATFORM_WEB) + #define _DEFAULT_SOURCE // Enables BSD function definitions and C99 POSIX compliance #include // Required for: timespec #include // Required for: clock_gettime() #include @@ -404,7 +406,7 @@ PHYSACDEF PhysicsBody CreatePhysicsBodyRectangle(Vector2 pos, float width, float // Initialize new body with generic values newBody->id = newId; newBody->enabled = true; - newBody->position = pos; + newBody->position = pos; newBody->velocity = (Vector2){ 0 }; newBody->force = (Vector2){ 0 }; newBody->angularVelocity = 0; @@ -512,7 +514,7 @@ PHYSACDEF PhysicsBody CreatePhysicsBodyPolygon(Vector2 pos, float radius, int si // Initialize new body with generic values newBody->id = newId; newBody->enabled = true; - newBody->position = pos; + newBody->position = pos; newBody->velocity = (Vector2){ 0 }; newBody->force = (Vector2){ 0 }; newBody->angularVelocity = 0; @@ -745,82 +747,74 @@ PHYSACDEF int GetPhysicsBodiesCount(void) // Returns a physics body of the bodies pool at a specific index PHYSACDEF PhysicsBody GetPhysicsBody(int index) { + PhysicsBody body = NULL; + if (index < physicsBodiesCount) { - PhysicsBody body = bodies[index]; - if (body != NULL) return body; - else + body = bodies[index]; + + if (body == NULL) { #if defined(PHYSAC_DEBUG) printf("[PHYSAC] error when trying to get a null reference physics body"); #endif - - return NULL; } } #if defined(PHYSAC_DEBUG) - else - { - printf("[PHYSAC] physics body index is out of bounds"); - return NULL; - } + else printf("[PHYSAC] physics body index is out of bounds"); #endif + + return body; } // Returns the physics body shape type (PHYSICS_CIRCLE or PHYSICS_POLYGON) PHYSACDEF int GetPhysicsShapeType(int index) { + int result = -1; + if (index < physicsBodiesCount) { PhysicsBody body = bodies[index]; - if (body != NULL) return body->shape.type; + + if (body != NULL) result = body->shape.type; #if defined(PHYSAC_DEBUG) - else - { - printf("[PHYSAC] error when trying to get a null reference physics body"); - return -1; - } + else printf("[PHYSAC] error when trying to get a null reference physics body"); #endif } #if defined(PHYSAC_DEBUG) - else - { - printf("[PHYSAC] physics body index is out of bounds"); - return -1; - } + else printf("[PHYSAC] physics body index is out of bounds"); #endif + + return result; } // Returns the amount of vertices of a physics body shape PHYSACDEF int GetPhysicsShapeVerticesCount(int index) { + int result = 0; + if (index < physicsBodiesCount) { PhysicsBody body = bodies[index]; + if (body != NULL) { switch (body->shape.type) { - case PHYSICS_CIRCLE: return PHYSAC_CIRCLE_VERTICES; break; - case PHYSICS_POLYGON: return body->shape.vertexData.vertexCount; break; + case PHYSICS_CIRCLE: result = PHYSAC_CIRCLE_VERTICES; break; + case PHYSICS_POLYGON: result = body->shape.vertexData.vertexCount; break; default: break; } } #if defined(PHYSAC_DEBUG) - else - { - printf("[PHYSAC] error when trying to get a null reference physics body"); - return 0; - } + else printf("[PHYSAC] error when trying to get a null reference physics body"); #endif } #if defined(PHYSAC_DEBUG) - else - { - printf("[PHYSAC] physics body index is out of bounds"); - return 0; - } + else printf("[PHYSAC] physics body index is out of bounds"); #endif + + return result; } // Returns transformed position of a body shape (body position + vertex transformed position) @@ -1082,7 +1076,7 @@ static void PhysicsStep(void) PhysicsManifold manifold = contacts[i]; if (manifold != NULL) DestroyPhysicsManifold(manifold); } - + // Reset physics bodies grounded state for (int i = 0; i < physicsBodiesCount; i++) { @@ -1208,7 +1202,7 @@ static PhysicsManifold CreatePhysicsManifold(PhysicsBody a, PhysicsBody b) } if (newId != -1) - { + { // Initialize new manifold with generic values newManifold->id = newId; newManifold->bodyA = a; @@ -1298,7 +1292,7 @@ static void SolvePhysicsManifold(PhysicsManifold manifold) } break; default: break; } - + // Update physics body grounded state if normal direction is down and grounded state is not set yet in previous manifolds if (!manifold->bodyB->isGrounded) manifold->bodyB->isGrounded = (manifold->normal.y < 0); } @@ -1395,7 +1389,7 @@ static void SolveCircleToPolygon(PhysicsManifold manifold) manifold->penetration = bodyA->shape.radius - separation; if (dot1 <= 0) // Closest to v1 - { + { if (DistSqr(center, v1) > bodyA->shape.radius*bodyA->shape.radius) return; manifold->contactsCount = 1; @@ -1600,7 +1594,7 @@ static void IntegratePhysicsImpulses(PhysicsManifold manifold) // Early out and positional correct if both objects have infinite mass if (fabs(bodyA->inverseMass + bodyB->inverseMass) <= PHYSAC_EPSILON) { - bodyA->velocity = (Vector2){ 0 }; + bodyA->velocity = (Vector2){ 0 }; bodyB->velocity = (Vector2){ 0 }; return; } @@ -1629,7 +1623,7 @@ static void IntegratePhysicsImpulses(PhysicsManifold manifold) // Calculate impulse scalar value float impulse = -(1.0f + manifold->restitution)*contactVelocity; - impulse /= inverseMassSum; + impulse /= inverseMassSum; impulse /= (float)manifold->contactsCount; // Apply impulse to each physics body -- cgit v1.2.3 From fd5c36fc322fe8796f90dc19908c48a8aaec66f4 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 11 May 2017 17:22:25 +0200 Subject: Avoid math function duplicates --- src/physac.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/physac.h') diff --git a/src/physac.h b/src/physac.h index cec3afc9..b71f2877 100644 --- a/src/physac.h +++ b/src/physac.h @@ -274,13 +274,13 @@ PHYSACDEF void ClosePhysics(void); // Global Variables Definition //---------------------------------------------------------------------------------- #if !defined(PHYSAC_NO_THREADS) - static pthread_t physicsThreadId; // Physics thread id +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 currentTime = 0; // Current time in milliseconds #if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) || defined(__linux__) || defined(PLATFORM_WEB) - static double baseTime = 0; // Android and RPI platforms base time +static double baseTime = 0; // Android and RPI platforms base time #endif static double startTime = 0; // Start time in milliseconds static double deltaTime = 0; // Delta time used for physics steps @@ -316,10 +316,12 @@ static void FindIncidentFace(Vector2 *v0, Vector2 *v1, PhysicsShape ref, Physics static int Clip(Vector2 normal, float clip, Vector2 *faceA, Vector2 *faceB); // Calculates clipping based on a normal and two faces static bool BiasGreaterThan(float valueA, float valueB); // Check if values are between bias range 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 timer static double GetCurrentTime(void); // Get current time 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 @@ -327,8 +329,10 @@ static float MathLenSqr(Vector2 vector); static float MathDot(Vector2 v1, Vector2 v2); // Returns the dot product of two vectors static inline float DistSqr(Vector2 v1, Vector2 v2); // Returns the square root of distance between two vectors static void MathNormalize(Vector2 *vector); // Returns the normalized values of a vector +#if defined(PHYSAC_STANDALONE) static Vector2 Vector2Add(Vector2 v1, Vector2 v2); // Returns the sum of two given vectors static Vector2 Vector2Subtract(Vector2 v1, Vector2 v2); // Returns the subtract of two given vectors +#endif static Mat2 Mat2Radians(float radians); // Creates a matrix 2x2 from a given radians value static void Mat2Set(Mat2 *matrix, float radians); // Set values from radians to a created matrix 2x2 @@ -1978,6 +1982,7 @@ static void MathNormalize(Vector2 *vector) vector->y *= ilength; } +#if defined(PHYSAC_STANDALONE) // Returns the sum of two given vectors static inline Vector2 Vector2Add(Vector2 v1, Vector2 v2) { @@ -1988,7 +1993,7 @@ static inline Vector2 Vector2Add(Vector2 v1, Vector2 v2) static inline Vector2 Vector2Subtract(Vector2 v1, Vector2 v2) { return (Vector2){ v1.x - v2.x, v1.y - v2.y }; -} +#endif // Creates a matrix 2x2 from a given radians value static inline Mat2 Mat2Radians(float radians) -- cgit v1.2.3 From a5bfd7db228b90b5ddc183a03e1f0630d7321091 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 16 May 2017 15:23:01 +0200 Subject: Some reviews for RPI --- docs/examples/src/shaders/shaders_postprocessing.c | 89 +++++++++++++++++++-- .../web/shaders/shaders_postprocessing.png | Bin 237145 -> 193424 bytes examples/Makefile | 15 ++-- examples/models/models_mesh_picking.c | 26 +++--- examples/shaders/shaders_postprocessing.png | Bin 237145 -> 193424 bytes examples/text/text_ttf_loading.c | 10 ++- src/physac.h | 4 +- 7 files changed, 113 insertions(+), 31 deletions(-) (limited to 'src/physac.h') diff --git a/docs/examples/src/shaders/shaders_postprocessing.c b/docs/examples/src/shaders/shaders_postprocessing.c index 43d1af72..bb239efa 100644 --- a/docs/examples/src/shaders/shaders_postprocessing.c +++ b/docs/examples/src/shaders/shaders_postprocessing.c @@ -18,6 +18,48 @@ #include "raylib.h" +#if defined(PLATFORM_DESKTOP) + #define GLSL_VERSION 330 + #define DEFAULT_VERTEX_SHADER "resources/shaders/glsl330/base.vs" +#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB + #define GLSL_VERSION 100 + #define DEFAULT_VERTEX_SHADER "resources/shaders/glsl100/base.vs" +#endif + +#define MAX_POSTPRO_SHADERS 12 + +typedef enum { + FX_GRAYSCALE = 0, + FX_POSTERIZATION, + FX_DREAM_VISION, + FX_PIXELIZER, + FX_CROSS_HATCHING, + FX_CROSS_STITCHING, + FX_PREDATOR_VIEW, + FX_SCANLINES, + FX_FISHEYE, + FX_SOBEL, + FX_BLOOM, + FX_BLUR, + //FX_FXAA +} PostproShader; + +static const char *postproShaderText[] = { + "GRAYSCALE", + "POSTERIZATION", + "DREAM_VISION", + "PIXELIZER", + "CROSS_HATCHING", + "CROSS_STITCHING", + "PREDATOR_VIEW", + "SCANLINES", + "FISHEYE", + "SOBEL", + "BLOOM", + "BLUR", + //"FXAA" +}; + int main() { // Initialization @@ -38,8 +80,25 @@ int main() Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position - Shader shader = LoadShader("resources/shaders/glsl330/base.vs", - "resources/shaders/glsl330/bloom.fs"); // Load postpro shader + // Load all postpro shaders + // NOTE 1: All postpro shader use the base vertex shader (DEFAULT_VERTEX_SHADER) + // NOTE 2: We load the correct shader depending on GLSL version + Shader shaders[MAX_POSTPRO_SHADERS]; + + shaders[FX_GRAYSCALE] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/grayscale.fs", GLSL_VERSION)); + shaders[FX_POSTERIZATION] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/posterization.fs", GLSL_VERSION)); + shaders[FX_DREAM_VISION] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/dream_vision.fs", GLSL_VERSION)); + shaders[FX_PIXELIZER] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/pixelizer.fs", GLSL_VERSION)); + shaders[FX_CROSS_HATCHING] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/cross_hatching.fs", GLSL_VERSION)); + shaders[FX_CROSS_STITCHING] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/cross_stitching.fs", GLSL_VERSION)); + shaders[FX_PREDATOR_VIEW] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/predator.fs", GLSL_VERSION)); + shaders[FX_SCANLINES] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/scanlines.fs", GLSL_VERSION)); + shaders[FX_FISHEYE] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/fisheye.fs", GLSL_VERSION)); + shaders[FX_SOBEL] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/sobel.fs", GLSL_VERSION)); + shaders[FX_BLOOM] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/bloom.fs", GLSL_VERSION)); + shaders[FX_BLUR] = LoadShader(DEFAULT_VERTEX_SHADER, FormatText("resources/shaders/glsl%i/blur.fs", GLSL_VERSION)); + + int currentShader = FX_GRAYSCALE; // Create a RenderTexture2D to be used for render to texture RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight); @@ -56,6 +115,12 @@ int main() // Update //---------------------------------------------------------------------------------- UpdateCamera(&camera); // Update camera + + if (IsKeyPressed(KEY_RIGHT)) currentShader++; + else if (IsKeyPressed(KEY_LEFT)) currentShader--; + + if (currentShader >= MAX_POSTPRO_SHADERS) currentShader = 0; + else if (currentShader < 0) currentShader = MAX_POSTPRO_SHADERS - 1; //---------------------------------------------------------------------------------- // Draw @@ -73,21 +138,26 @@ int main() DrawGrid(10, 1.0f); // Draw a grid End3dMode(); - - DrawText("HELLO POSTPROCESSING!", 70, 190, 50, RED); EndTextureMode(); // End drawing to texture (now we have a texture available for next passes) - BeginShaderMode(shader); + // Render previously generated texture using selected postpro shader + BeginShaderMode(shaders[currentShader]); // NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom) DrawTextureRec(target.texture, (Rectangle){ 0, 0, target.texture.width, -target.texture.height }, (Vector2){ 0, 0 }, WHITE); EndShaderMode(); + DrawRectangle(0, 9, 580, 30, Fade(LIGHTGRAY, 0.7f)); + DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, DARKGRAY); - - DrawFPS(10, 10); + + DrawText("CURRENT POSTPRO SHADER:", 10, 15, 20, BLACK); + DrawText(postproShaderText[currentShader], 330, 15, 20, RED); + DrawText("< >", 540, 10, 30, DARKBLUE); + + DrawFPS(700, 15); EndDrawing(); //---------------------------------------------------------------------------------- @@ -95,7 +165,10 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - UnloadShader(shader); // Unload shader + + // Unload all postpro shaders + for (int i = 0; i < MAX_POSTPRO_SHADERS; i++) UnloadShader(shaders[i]); + UnloadTexture(texture); // Unload texture UnloadModel(dwarf); // Unload model UnloadRenderTexture(target); // Unload render texture diff --git a/docs/examples/web/shaders/shaders_postprocessing.png b/docs/examples/web/shaders/shaders_postprocessing.png index 684cbd41..628ab810 100644 Binary files a/docs/examples/web/shaders/shaders_postprocessing.png and b/docs/examples/web/shaders/shaders_postprocessing.png differ diff --git a/examples/Makefile b/examples/Makefile index c3728b3b..969edd0c 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -162,9 +162,9 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(PLATFORM_OS),WINDOWS) # external libraries to link with # GLFW3 - LFLAGS += -L$(RAYLIB_PATH)/src/external/glfw3/lib/$(LIBPATH) + LFLAGS += -L$(RAYLIB_PATH)/src/external/glfw3/lib/$(LIBPATH) # OpenAL Soft - LFLAGS += -L$(RAYLIB_PATH)/src/external/openal_soft/lib/$(LIBPATH) + LFLAGS += -L$(RAYLIB_PATH)/src/external/openal_soft/lib/$(LIBPATH) endif endif @@ -195,6 +195,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) else LIBS += -lopenal32dll endif + PHYSAC_LIBS = -static -lpthread endif endif endif @@ -524,23 +525,23 @@ audio/audio_raw_stream: audio/audio_raw_stream.c # compile [physac] example - physics demo physac/physics_demo: physac/physics_demo.c - $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -static -lpthread -D$(PLATFORM) $(WINFLAGS) + $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) $(PHYSAC_LIBS) -D$(PLATFORM) $(WINFLAGS) # compile [physac] example - physics friction physac/physics_friction: physac/physics_friction.c - $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -static -lpthread -D$(PLATFORM) $(WINFLAGS) + $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) $(PHYSAC_LIBS) -D$(PLATFORM) $(WINFLAGS) # compile [physac] example - physics movement physac/physics_movement: physac/physics_movement.c - $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -static -lpthread -D$(PLATFORM) $(WINFLAGS) + $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) $(PHYSAC_LIBS) -D$(PLATFORM) $(WINFLAGS) # compile [physac] example - physics restitution physac/physics_restitution: physac/physics_restitution.c - $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -static -lpthread -D$(PLATFORM) $(WINFLAGS) + $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) $(PHYSAC_LIBS) -D$(PLATFORM) $(WINFLAGS) # compile [physac] example - physics shatter physac/physics_shatter: physac/physics_shatter.c - $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -static -lpthread -D$(PLATFORM) $(WINFLAGS) + $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) $(PHYSAC_LIBS) -D$(PLATFORM) $(WINFLAGS) ifeq ($(PLATFORM),PLATFORM_ANDROID) external/native_app_glue.o : native_app_glue.c native_app_glue.h diff --git a/examples/models/models_mesh_picking.c b/examples/models/models_mesh_picking.c index 0b5247ec..ec151599 100644 --- a/examples/models/models_mesh_picking.c +++ b/examples/models/models_mesh_picking.c @@ -89,7 +89,7 @@ int main() cursorColor = PURPLE; hitObjectName = "Triangle"; - bary = VectorBarycenter(nearestHit.hitPosition, ta, tb, tc); + bary = VectorBarycenter(nearestHit.position, ta, tb, tc); hitTriangle = true; } else hitTriangle = false; @@ -136,15 +136,15 @@ int main() // If we hit something, draw the cursor at the hit point if (nearestHit.hit) { - DrawCube(nearestHit.hitPosition, 0.3, 0.3, 0.3, cursorColor); - DrawCubeWires(nearestHit.hitPosition, 0.3, 0.3, 0.3, RED); + DrawCube(nearestHit.position, 0.3, 0.3, 0.3, cursorColor); + DrawCubeWires(nearestHit.position, 0.3, 0.3, 0.3, RED); Vector3 normalEnd; - normalEnd.x = nearestHit.hitPosition.x + nearestHit.hitNormal.x; - normalEnd.y = nearestHit.hitPosition.y + nearestHit.hitNormal.y; - normalEnd.z = nearestHit.hitPosition.z + nearestHit.hitNormal.z; + normalEnd.x = nearestHit.position.x + nearestHit.normal.x; + normalEnd.y = nearestHit.position.y + nearestHit.normal.y; + normalEnd.z = nearestHit.position.z + nearestHit.normal.z; - DrawLine3D(nearestHit.hitPosition, normalEnd, RED); + DrawLine3D(nearestHit.position, normalEnd, RED); } DrawRay(ray, MAROON); @@ -163,14 +163,14 @@ int main() DrawText(FormatText("Distance: %3.2f", nearestHit.distance), 10, ypos, 10, BLACK); DrawText(FormatText("Hit Pos: %3.2f %3.2f %3.2f", - nearestHit.hitPosition.x, - nearestHit.hitPosition.y, - nearestHit.hitPosition.z), 10, ypos + 15, 10, BLACK); + nearestHit.position.x, + nearestHit.position.y, + nearestHit.position.z), 10, ypos + 15, 10, BLACK); DrawText(FormatText("Hit Norm: %3.2f %3.2f %3.2f", - nearestHit.hitNormal.x, - nearestHit.hitNormal.y, - nearestHit.hitNormal.z), 10, ypos + 30, 10, BLACK); + nearestHit.normal.x, + nearestHit.normal.y, + nearestHit.normal.z), 10, ypos + 30, 10, BLACK); if (hitTriangle) DrawText(FormatText("Barycenter: %3.2f %3.2f %3.2f", bary.x, bary.y, bary.z), 10, ypos + 45, 10, BLACK); } diff --git a/examples/shaders/shaders_postprocessing.png b/examples/shaders/shaders_postprocessing.png index 684cbd41..628ab810 100644 Binary files a/examples/shaders/shaders_postprocessing.png and b/examples/shaders/shaders_postprocessing.png differ diff --git a/examples/text/text_ttf_loading.c b/examples/text/text_ttf_loading.c index 02b7f95f..c9c2fb27 100644 --- a/examples/text/text_ttf_loading.c +++ b/examples/text/text_ttf_loading.c @@ -38,8 +38,11 @@ int main() SetTextureFilter(font.texture, FILTER_POINT); int currentFontFilter = 0; // FILTER_POINT + // NOTE: Drag and drop support only available for desktop platforms: Windows, Linux, OSX +#if defined(PLATFORM_DESKTOP) int count = 0; char **droppedFiles; +#endif SetTargetFPS(60); //-------------------------------------------------------------------------------------- @@ -74,6 +77,7 @@ int main() if (IsKeyDown(KEY_LEFT)) fontPosition.x -= 10; else if (IsKeyDown(KEY_RIGHT)) fontPosition.x += 10; +#if defined(PLATFORM_DESKTOP) // Load a dropped TTF file dynamically (at current fontSize) if (IsFileDropped()) { @@ -86,6 +90,7 @@ int main() ClearDroppedFiles(); } } +#endif //---------------------------------------------------------------------------------- // Draw @@ -119,10 +124,11 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- +#if defined(PLATFORM_DESKTOP) + ClearDroppedFiles(); // Clear internal buffers +#endif UnloadSpriteFont(font); // SpriteFont unloading - ClearDroppedFiles(); // Clear internal buffers - CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/src/physac.h b/src/physac.h index b71f2877..d3fdaca4 100644 --- a/src/physac.h +++ b/src/physac.h @@ -246,12 +246,14 @@ PHYSACDEF void ClosePhysics(void); #include // Required for: malloc(), free(), srand(), rand() #include // Required for: cosf(), sinf(), fabs(), sqrtf() +#include "raymath.h" // Required for: Vector2Add(), Vector2Subtract() + #if defined(_WIN32) // Functions required to query time on Windows int __stdcall QueryPerformanceCounter(unsigned long long int *lpPerformanceCount); int __stdcall QueryPerformanceFrequency(unsigned long long int *lpFrequency); #elif defined(__linux__) || defined(PLATFORM_WEB) - #define _DEFAULT_SOURCE // Enables BSD function definitions and C99 POSIX compliance + //#define _DEFAULT_SOURCE // Enables BSD function definitions and C99 POSIX compliance #include // Required for: timespec #include // Required for: clock_gettime() #include -- cgit v1.2.3