Wise&mystical  1.0
Project about Europe
Loading...
Searching...
No Matches
physac.h File Reference

Go to the source code of this file.

Classes

struct  Vector2
 
struct  Matrix2x2
 
struct  PhysicsVertexData
 
struct  PhysicsShape
 
struct  PhysicsBodyData
 
struct  PhysicsManifoldData
 

Macros

#define PHYSACDEF
 Physac v1.1 - 2D Physics library for videogames. More...
 
#define PHYSAC_MALLOC(size)   malloc(size)
 
#define PHYSAC_CALLOC(size, n)   calloc(size, n)
 
#define PHYSAC_FREE(ptr)   free(ptr)
 
#define PHYSAC_MAX_BODIES   64
 
#define PHYSAC_MAX_MANIFOLDS   4096
 
#define PHYSAC_MAX_VERTICES   24
 
#define PHYSAC_DEFAULT_CIRCLE_VERTICES   24
 
#define PHYSAC_COLLISION_ITERATIONS   100
 
#define PHYSAC_PENETRATION_ALLOWANCE   0.05f
 
#define PHYSAC_PENETRATION_CORRECTION   0.4f
 
#define PHYSAC_PI   3.14159265358979323846f
 
#define PHYSAC_DEG2RAD   (PHYSAC_PI/180.0f)
 

Typedefs

typedef enum PhysicsShapeType PhysicsShapeType
 
typedef struct PhysicsBodyDataPhysicsBody
 
typedef struct Vector2 Vector2
 
typedef struct Matrix2x2 Matrix2x2
 
typedef struct PhysicsVertexData PhysicsVertexData
 
typedef struct PhysicsShape PhysicsShape
 
typedef struct PhysicsBodyData PhysicsBodyData
 
typedef struct PhysicsManifoldData PhysicsManifoldData
 
typedef struct PhysicsManifoldDataPhysicsManifold
 

Enumerations

enum  PhysicsShapeType { PHYSICS_CIRCLE = 0 , PHYSICS_POLYGON }
 

Functions

PHYSACDEF void InitPhysics (void)
 
PHYSACDEF void UpdatePhysics (void)
 
PHYSACDEF void ResetPhysics (void)
 
PHYSACDEF void ClosePhysics (void)
 
PHYSACDEF void SetPhysicsTimeStep (double delta)
 
PHYSACDEF void SetPhysicsGravity (float x, float y)
 
PHYSACDEF PhysicsBody CreatePhysicsBodyCircle (Vector2 pos, float radius, float density)
 
PHYSACDEF PhysicsBody CreatePhysicsBodyRectangle (Vector2 pos, float width, float height, float density)
 
PHYSACDEF PhysicsBody CreatePhysicsBodyPolygon (Vector2 pos, float radius, int sides, float density)
 
PHYSACDEF void DestroyPhysicsBody (PhysicsBody body)
 
PHYSACDEF void PhysicsAddForce (PhysicsBody body, Vector2 force)
 
PHYSACDEF void PhysicsAddTorque (PhysicsBody body, float amount)
 
PHYSACDEF void PhysicsShatter (PhysicsBody body, Vector2 position, float force)
 
PHYSACDEF void SetPhysicsBodyRotation (PhysicsBody body, float radians)
 
PHYSACDEF PhysicsBody GetPhysicsBody (int index)
 
PHYSACDEF int GetPhysicsBodiesCount (void)
 
PHYSACDEF int GetPhysicsShapeType (int index)
 
PHYSACDEF int GetPhysicsShapeVerticesCount (int index)
 
PHYSACDEF Vector2 GetPhysicsShapeVertex (PhysicsBody body, int vertex)
 

Macro Definition Documentation

◆ PHYSAC_CALLOC

#define PHYSAC_CALLOC (   size,
 
)    calloc(size, n)

Definition at line 94 of file physac.h.

◆ PHYSAC_COLLISION_ITERATIONS

#define PHYSAC_COLLISION_ITERATIONS   100

Definition at line 108 of file physac.h.

◆ PHYSAC_DEFAULT_CIRCLE_VERTICES

#define PHYSAC_DEFAULT_CIRCLE_VERTICES   24

Definition at line 106 of file physac.h.

◆ PHYSAC_DEG2RAD

#define PHYSAC_DEG2RAD   (PHYSAC_PI/180.0f)

Definition at line 113 of file physac.h.

◆ PHYSAC_FREE

#define PHYSAC_FREE (   ptr)    free(ptr)

Definition at line 97 of file physac.h.

◆ PHYSAC_MALLOC

#define PHYSAC_MALLOC (   size)    malloc(size)

Definition at line 91 of file physac.h.

◆ PHYSAC_MAX_BODIES

#define PHYSAC_MAX_BODIES   64

Definition at line 103 of file physac.h.

◆ PHYSAC_MAX_MANIFOLDS

#define PHYSAC_MAX_MANIFOLDS   4096

Definition at line 104 of file physac.h.

◆ PHYSAC_MAX_VERTICES

#define PHYSAC_MAX_VERTICES   24

Definition at line 105 of file physac.h.

◆ PHYSAC_PENETRATION_ALLOWANCE

#define PHYSAC_PENETRATION_ALLOWANCE   0.05f

Definition at line 109 of file physac.h.

◆ PHYSAC_PENETRATION_CORRECTION

#define PHYSAC_PENETRATION_CORRECTION   0.4f

Definition at line 110 of file physac.h.

◆ PHYSAC_PI

#define PHYSAC_PI   3.14159265358979323846f

Definition at line 112 of file physac.h.

◆ PHYSACDEF

#define PHYSACDEF

Physac v1.1 - 2D Physics library for videogames.

DESCRIPTION:

Physac is a small 2D physics engine written in pure C. The engine uses a fixed time-step thread loop to simulate 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 or source files without problems. But only ONE file should hold the implementation.

#define PHYSAC_DEBUG Show debug traces log messages about physic bodies creation/destruction, physic system errors, some calculations results and NULL reference exceptions.

#define PHYSAC_AVOID_TIMMING_SYSTEM Disables internal timming system, used by UpdatePhysics() to launch timmed physic steps, it allows just running UpdatePhysics() automatically on a separate thread at a desired time step. In case physics steps update needs to be controlled by user with a custom timming mechanism, just define this flag and the internal timming mechanism will be avoided, in that case, timming libraries are neither required by the module.

#define PHYSAC_MALLOC() #define PHYSAC_CALLOC() #define PHYSAC_FREE() 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.

COMPILATION:

Use the following code to compile with GCC: gcc -o .exe -s -static -lraylib -lopengl32 -lgdi32 -lwinmm -std=c99

VERSIONS HISTORY: 1.1 (20-Jan-2021) @raysan5: Library general revision Removed threading system (up to the user) Support MSVC C++ compilation using CLITERAL() Review DEBUG mechanism for TRACELOG() and all TRACELOG() messages Review internal variables/functions naming for consistency Allow option to avoid internal timming system, to allow app manage the steps 1.0 (12-Jun-2017) First release of the library

LICENSE: zlib/libpng

Copyright (c) 2016-2022 Victor Fisac (@victorfisac) and Ramon Santamaria (@raysan5)

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.

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  3. This notice may not be removed or altered from any source distribution.

Definition at line 86 of file physac.h.

Typedef Documentation

◆ Matrix2x2

typedef struct Matrix2x2 Matrix2x2

◆ PhysicsBody

typedef struct PhysicsBodyData* PhysicsBody

Definition at line 125 of file physac.h.

◆ PhysicsBodyData

◆ PhysicsManifold

◆ PhysicsManifoldData

◆ PhysicsShape

typedef struct PhysicsShape PhysicsShape

◆ PhysicsShapeType

◆ PhysicsVertexData

◆ Vector2

typedef struct Vector2 Vector2

Enumeration Type Documentation

◆ PhysicsShapeType

Enumerator
PHYSICS_CIRCLE 
PHYSICS_POLYGON 

Definition at line 122 of file physac.h.

Function Documentation

◆ ClosePhysics()

PHYSACDEF void ClosePhysics ( void  )

◆ CreatePhysicsBodyCircle()

PHYSACDEF PhysicsBody CreatePhysicsBodyCircle ( Vector2  pos,
float  radius,
float  density 
)

◆ CreatePhysicsBodyPolygon()

PHYSACDEF PhysicsBody CreatePhysicsBodyPolygon ( Vector2  pos,
float  radius,
int  sides,
float  density 
)

◆ CreatePhysicsBodyRectangle()

PHYSACDEF PhysicsBody CreatePhysicsBodyRectangle ( Vector2  pos,
float  width,
float  height,
float  density 
)

◆ DestroyPhysicsBody()

PHYSACDEF void DestroyPhysicsBody ( PhysicsBody  body)

◆ GetPhysicsBodiesCount()

PHYSACDEF int GetPhysicsBodiesCount ( void  )

◆ GetPhysicsBody()

PHYSACDEF PhysicsBody GetPhysicsBody ( int  index)

◆ GetPhysicsShapeType()

PHYSACDEF int GetPhysicsShapeType ( int  index)

◆ GetPhysicsShapeVertex()

PHYSACDEF Vector2 GetPhysicsShapeVertex ( PhysicsBody  body,
int  vertex 
)

◆ GetPhysicsShapeVerticesCount()

PHYSACDEF int GetPhysicsShapeVerticesCount ( int  index)

◆ InitPhysics()

PHYSACDEF void InitPhysics ( void  )

◆ PhysicsAddForce()

PHYSACDEF void PhysicsAddForce ( PhysicsBody  body,
Vector2  force 
)

◆ PhysicsAddTorque()

PHYSACDEF void PhysicsAddTorque ( PhysicsBody  body,
float  amount 
)

◆ PhysicsShatter()

PHYSACDEF void PhysicsShatter ( PhysicsBody  body,
Vector2  position,
float  force 
)

◆ ResetPhysics()

PHYSACDEF void ResetPhysics ( void  )

◆ SetPhysicsBodyRotation()

PHYSACDEF void SetPhysicsBodyRotation ( PhysicsBody  body,
float  radians 
)

◆ SetPhysicsGravity()

PHYSACDEF void SetPhysicsGravity ( float  x,
float  y 
)

◆ SetPhysicsTimeStep()

PHYSACDEF void SetPhysicsTimeStep ( double  delta)

◆ UpdatePhysics()

PHYSACDEF void UpdatePhysics ( void  )