diff options
| author | kotorifan <kotorifan05@gmail.com> | 2026-04-28 00:47:22 +0200 |
|---|---|---|
| committer | kotorifan <kotorifan05@gmail.com> | 2026-04-28 00:47:22 +0200 |
| commit | c176eedfb6de797c09acbff1f61cf62cf1f2c694 (patch) | |
| tree | 89bafd3d16712e72330b0a1f272285fc28ba998a /src/common.h | |
| parent | 1ff5ed07b840f4f5de81592f7a9b04debf38c447 (diff) | |
| download | trashbinphysics-c176eedfb6de797c09acbff1f61cf62cf1f2c694.tar.gz | |
Diffstat (limited to 'src/common.h')
| -rw-r--r-- | src/common.h | 71 |
1 files changed, 43 insertions, 28 deletions
diff --git a/src/common.h b/src/common.h index 7664233..9fafd78 100644 --- a/src/common.h +++ b/src/common.h @@ -7,34 +7,19 @@ #define COMMON_H #include <stdint.h> -typedef uint_least8_t u8; -typedef int_least8_t i8; -typedef uint_least16_t u16; -typedef int_least16_t i16; -typedef uint_least32_t u32; -typedef int_least32_t i32; - -typedef struct { - Color color; - float elast; - float frict; - float angle_vel; - float inertia; - Vector2 angle; - Vector2 pos; - Vector2 pos_prev; - Vector2 vel; - bool grabbed; - bool registered; - float mass; - Vector2* vertices; - Vector2* edges; - float line_thickness; - u32 vertex_n; // number of vertices - u32 edge_n; // number of edges -} object_t; +#include <raylib.h> +#include <raymath.h> +#include <math.h> +#define MIN_VERTICES 3 +#define MAX_VERTICES 16 +#define MIN_EDGES 3 +#define MAX_EDGES 16 +// how many times to run update_physics per frame +// should be balanced between accuracy and CPU load, the higher +// the number the more resource-intensive it is +#define ITER_PER_FRAME 8 // settings // UI @@ -43,9 +28,9 @@ typedef struct { #define WINDOW_Y 1000 // physics #define MAX_OBJECTS 100 -#define FORCE_RESITUTION_DEFAULT 0.8f +#define FORCE_RESITUTION_DEFAULT 0.7f #define FORCE_GRAVITY_DEFAULT 1000.0f -#define FORCE_LINEAR_DAMPING_DEFAULT 0.995f; +#define FORCE_LINEAR_DAMPING_DEFAULT 0.995f #define ARR_LEN(arr) (sizeof(arr)/sizeof(arr[0])) @@ -56,5 +41,35 @@ typedef struct { 255 \ }) +typedef uint_least8_t u8; +typedef int_least8_t i8; +typedef uint_least16_t u16; +typedef int_least16_t i16; +typedef uint_least32_t u32; +typedef int_least32_t i32; + +typedef struct { + Color color; + + float elast; // restitution + float frict; + float angle; + float angle_vel; + float mass; + float inertia; + + Vector2 pos; + Vector2 pos_prev; + Vector2 vel; + Vector2 vertices[MAX_VERTICES]; + Vector2 local_vertices[MAX_VERTICES]; + Vector2 edges[MAX_EDGES]; + + float line_thickness; + u32 vertex_n; // number of vertices + u32 edge_n; // number of edges + bool grabbed; + bool registered; +} object_t; #endif // COMMON_H |
