blob: 9fafd785deb99ee2cacf9fcd1aa3231017d213f3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
/**
* @file common.h
* @brief Functions and values used throughout most files
* @date 2026-04-27
*/
#ifndef COMMON_H
#define COMMON_H
#include <stdint.h>
#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
#define SCREEN_TITLE "physics"
#define WINDOW_X 1250
#define WINDOW_Y 1000
// physics
#define MAX_OBJECTS 100
#define FORCE_RESITUTION_DEFAULT 0.7f
#define FORCE_GRAVITY_DEFAULT 1000.0f
#define FORCE_LINEAR_DAMPING_DEFAULT 0.995f
#define ARR_LEN(arr) (sizeof(arr)/sizeof(arr[0]))
#define RANDOM_COLOR() ((Color) { \
GetRandomValue(0, 255), \
GetRandomValue(0, 255), \
GetRandomValue(0, 255), \
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
|