Updated physac to latest version
This commit is contained in:
parent
b4d28cc7a1
commit
3e082f1d62
70
src/physac.h
70
src/physac.h
@ -39,10 +39,11 @@
|
|||||||
* Otherwise it will include stdlib.h and use the C standard library malloc()/free() function.
|
* 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):
|
* Use the following code to compile:
|
||||||
* gcc -o $(NAME_PART).exe $(FILE_NAME) -s $(RAYLIB_DIR)\raylib\raylib_icon -static -lraylib -lpthread
|
* 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
|
* -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition
|
||||||
*
|
*
|
||||||
* VERY THANKS TO:
|
* VERY THANKS TO:
|
||||||
@ -51,7 +52,7 @@
|
|||||||
*
|
*
|
||||||
* LICENSE: zlib/libpng
|
* 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
|
* 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.
|
* will the authors be held liable for any damages arising from the use of this software.
|
||||||
@ -73,7 +74,7 @@
|
|||||||
#if !defined(PHYSAC_H)
|
#if !defined(PHYSAC_H)
|
||||||
#define PHYSAC_H
|
#define PHYSAC_H
|
||||||
|
|
||||||
#define PHYSAC_STATIC
|
// #define PHYSAC_STATIC
|
||||||
// #define PHYSAC_NO_THREADS
|
// #define PHYSAC_NO_THREADS
|
||||||
// #define PHYSAC_STANDALONE
|
// #define PHYSAC_STANDALONE
|
||||||
// #define PHYSAC_DEBUG
|
// #define PHYSAC_DEBUG
|
||||||
@ -250,6 +251,7 @@ PHYSACDEF void ClosePhysics(void);
|
|||||||
int __stdcall QueryPerformanceCounter(unsigned long long int *lpPerformanceCount);
|
int __stdcall QueryPerformanceCounter(unsigned long long int *lpPerformanceCount);
|
||||||
int __stdcall QueryPerformanceFrequency(unsigned long long int *lpFrequency);
|
int __stdcall QueryPerformanceFrequency(unsigned long long int *lpFrequency);
|
||||||
#elif defined(__linux__) || defined(PLATFORM_WEB)
|
#elif defined(__linux__) || defined(PLATFORM_WEB)
|
||||||
|
#define _DEFAULT_SOURCE // Enables BSD function definitions and C99 POSIX compliance
|
||||||
#include <sys/time.h> // Required for: timespec
|
#include <sys/time.h> // Required for: timespec
|
||||||
#include <time.h> // Required for: clock_gettime()
|
#include <time.h> // Required for: clock_gettime()
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@ -745,82 +747,74 @@ PHYSACDEF int GetPhysicsBodiesCount(void)
|
|||||||
// Returns a physics body of the bodies pool at a specific index
|
// Returns a physics body of the bodies pool at a specific index
|
||||||
PHYSACDEF PhysicsBody GetPhysicsBody(int index)
|
PHYSACDEF PhysicsBody GetPhysicsBody(int index)
|
||||||
{
|
{
|
||||||
|
PhysicsBody body = NULL;
|
||||||
|
|
||||||
if (index < physicsBodiesCount)
|
if (index < physicsBodiesCount)
|
||||||
{
|
{
|
||||||
PhysicsBody body = bodies[index];
|
body = bodies[index];
|
||||||
if (body != NULL) return body;
|
|
||||||
else
|
if (body == NULL)
|
||||||
{
|
{
|
||||||
#if defined(PHYSAC_DEBUG)
|
#if defined(PHYSAC_DEBUG)
|
||||||
printf("[PHYSAC] error when trying to get a null reference physics body");
|
printf("[PHYSAC] error when trying to get a null reference physics body");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if defined(PHYSAC_DEBUG)
|
#if defined(PHYSAC_DEBUG)
|
||||||
else
|
else printf("[PHYSAC] physics body index is out of bounds");
|
||||||
{
|
|
||||||
printf("[PHYSAC] physics body index is out of bounds");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the physics body shape type (PHYSICS_CIRCLE or PHYSICS_POLYGON)
|
// Returns the physics body shape type (PHYSICS_CIRCLE or PHYSICS_POLYGON)
|
||||||
PHYSACDEF int GetPhysicsShapeType(int index)
|
PHYSACDEF int GetPhysicsShapeType(int index)
|
||||||
{
|
{
|
||||||
|
int result = -1;
|
||||||
|
|
||||||
if (index < physicsBodiesCount)
|
if (index < physicsBodiesCount)
|
||||||
{
|
{
|
||||||
PhysicsBody body = bodies[index];
|
PhysicsBody body = bodies[index];
|
||||||
if (body != NULL) return body->shape.type;
|
|
||||||
|
if (body != NULL) result = body->shape.type;
|
||||||
#if defined(PHYSAC_DEBUG)
|
#if defined(PHYSAC_DEBUG)
|
||||||
else
|
else printf("[PHYSAC] error when trying to get a null reference physics body");
|
||||||
{
|
|
||||||
printf("[PHYSAC] error when trying to get a null reference physics body");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#if defined(PHYSAC_DEBUG)
|
#if defined(PHYSAC_DEBUG)
|
||||||
else
|
else printf("[PHYSAC] physics body index is out of bounds");
|
||||||
{
|
|
||||||
printf("[PHYSAC] physics body index is out of bounds");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the amount of vertices of a physics body shape
|
// Returns the amount of vertices of a physics body shape
|
||||||
PHYSACDEF int GetPhysicsShapeVerticesCount(int index)
|
PHYSACDEF int GetPhysicsShapeVerticesCount(int index)
|
||||||
{
|
{
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
if (index < physicsBodiesCount)
|
if (index < physicsBodiesCount)
|
||||||
{
|
{
|
||||||
PhysicsBody body = bodies[index];
|
PhysicsBody body = bodies[index];
|
||||||
|
|
||||||
if (body != NULL)
|
if (body != NULL)
|
||||||
{
|
{
|
||||||
switch (body->shape.type)
|
switch (body->shape.type)
|
||||||
{
|
{
|
||||||
case PHYSICS_CIRCLE: return PHYSAC_CIRCLE_VERTICES; break;
|
case PHYSICS_CIRCLE: result = PHYSAC_CIRCLE_VERTICES; break;
|
||||||
case PHYSICS_POLYGON: return body->shape.vertexData.vertexCount; break;
|
case PHYSICS_POLYGON: result = body->shape.vertexData.vertexCount; break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if defined(PHYSAC_DEBUG)
|
#if defined(PHYSAC_DEBUG)
|
||||||
else
|
else printf("[PHYSAC] error when trying to get a null reference physics body");
|
||||||
{
|
|
||||||
printf("[PHYSAC] error when trying to get a null reference physics body");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#if defined(PHYSAC_DEBUG)
|
#if defined(PHYSAC_DEBUG)
|
||||||
else
|
else printf("[PHYSAC] physics body index is out of bounds");
|
||||||
{
|
|
||||||
printf("[PHYSAC] physics body index is out of bounds");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns transformed position of a body shape (body position + vertex transformed position)
|
// Returns transformed position of a body shape (body position + vertex transformed position)
|
||||||
|
Loading…
Reference in New Issue
Block a user