使用 raylib 库在 C 中开发的 2D 物理游戏头文件库。
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.
The header file includes some tweakable define values to fit the results that the user wants with a minimal bad results. Most of those values are commented with a little explanation about their uses.
Note: The example code uses raylib programming library to create the program window and rendering framework.
Physac requires raylib. To get it, follow the next steps:
* Go to [raylib](https://www.github.com/raysan5/raylib) and clone the repository.
* Ensure to pull the last changes of 'master' branch.
* Use code inside examples header comments to compile and execute.The PhysicsBody struct contains all dynamics information and collision shape. The user should use the following structure components:
…The header contains a few customizable define values. I set the values that gived me the best results.
#define PHYSAC_MAX_BODIES 64
#define PHYSAC_MAX_MANIFOLDS 4096
#define PHYSAC_MAX_VERTICES 24
#define PHYSAC_CIRCLE_VERTICES 24
#define PHYSAC_COLLISION_ITERATIONS 100
#define PHYSAC_PENETRATION_ALLOWANCE 0.05f
#define PHYSAC_PENETRATION_CORRECTION 0.4fPhysac contains defines for memory management functions (malloc, free) to bring the user the opportunity to implement its own memory functions:
#define PHYSAC_MALLOC(size) malloc(size)
#define PHYSAC_FREE(ptr) free(ptr)The Physac API functions availables for the user are the following:
…Note: InitPhysics() needs to be called at program start and ClosePhysics() before the program ends. Closing and initializing Physac during the program flow doesn't affect or produces any error (useful as a 'reset' to destroy any created body by user in runtime).
Physac uses the following C libraries for memory management, math operations and some debug features:
It is independent to any graphics engine and prepared to use any graphics API and use the vertices information (look at examples Drawing logic) to draw lines or shapes in screen. For example, this vertices information can be use in OpenGL API glVertex2f().
By the way, I use raylib to create the examples. This videogames programming library is used to handle inputs, window management and graphics drawing (using OpenGL API).
暂无开放 Issues,或尚未同步最近议题。