2021-11-30 21:29:18 -06:00
|
|
|
#ifndef TWODPHYSICS_H
|
|
|
|
#define TWODPHYSICS_H
|
|
|
|
|
2022-01-21 11:26:22 -06:00
|
|
|
#include <chipmunk/chipmunk.h>
|
2023-01-11 16:57:34 -06:00
|
|
|
#include "script.h"
|
2021-11-30 21:29:18 -06:00
|
|
|
|
|
|
|
extern float phys2d_gravity;
|
|
|
|
extern int physOn;
|
|
|
|
extern cpSpace *space;
|
|
|
|
|
2023-01-18 10:45:43 -06:00
|
|
|
extern float dbg_color[3];
|
|
|
|
extern float trigger_color[3];
|
|
|
|
extern float disabled_color[3];
|
|
|
|
extern float dynamic_color[3];
|
|
|
|
extern float kinematic_color[3];
|
|
|
|
extern float static_color[3];
|
|
|
|
|
|
|
|
|
2021-11-30 21:29:18 -06:00
|
|
|
struct phys2d_shape {
|
|
|
|
cpShape *shape;
|
2023-01-12 17:41:54 -06:00
|
|
|
int go;
|
2023-01-13 08:05:36 -06:00
|
|
|
void *data;
|
|
|
|
void (*debugdraw)(void *data);
|
2021-11-30 21:29:18 -06:00
|
|
|
};
|
|
|
|
|
2023-01-25 21:32:58 -06:00
|
|
|
/* Circles are the fastest collier type */
|
2021-11-30 21:29:18 -06:00
|
|
|
struct phys2d_circle {
|
|
|
|
float radius;
|
2023-01-19 18:30:23 -06:00
|
|
|
cpVect offset;
|
2021-11-30 21:29:18 -06:00
|
|
|
struct phys2d_shape shape;
|
|
|
|
};
|
|
|
|
|
2023-01-25 21:32:58 -06:00
|
|
|
/* A single segment */
|
2021-11-30 21:29:18 -06:00
|
|
|
struct phys2d_segment {
|
|
|
|
float a[2];
|
|
|
|
float b[2];
|
|
|
|
float thickness;
|
|
|
|
struct phys2d_shape shape;
|
|
|
|
};
|
|
|
|
|
2023-01-25 21:32:58 -06:00
|
|
|
/* A convex polygon; defined as the convex hull around the given set of points */
|
|
|
|
struct phys2d_poly {
|
|
|
|
cpVect *points;
|
|
|
|
float radius;
|
|
|
|
struct phys2d_shape shape;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* A box shape; a type of a polygon collider */
|
2021-11-30 21:29:18 -06:00
|
|
|
struct phys2d_box {
|
|
|
|
float w;
|
|
|
|
float h;
|
|
|
|
float offset[2];
|
2023-01-25 21:32:58 -06:00
|
|
|
float rotation;
|
2022-08-17 00:01:51 -05:00
|
|
|
float r;
|
2021-11-30 21:29:18 -06:00
|
|
|
struct phys2d_shape shape;
|
|
|
|
};
|
|
|
|
|
2023-01-25 21:32:58 -06:00
|
|
|
/* An edge with no volume. Cannot collide with each other. Join to make levels. */
|
2021-11-30 21:29:18 -06:00
|
|
|
struct phys2d_edge {
|
2023-01-25 21:32:58 -06:00
|
|
|
cpVect *points;
|
2021-11-30 21:29:18 -06:00
|
|
|
float thickness;
|
|
|
|
cpShape **shapes;
|
2023-01-25 21:32:58 -06:00
|
|
|
int closed; /* True if the first and last points should be connected */
|
2021-11-30 21:29:18 -06:00
|
|
|
struct phys2d_shape shape;
|
2023-01-25 21:32:58 -06:00
|
|
|
int draws;
|
2021-11-30 21:29:18 -06:00
|
|
|
};
|
|
|
|
|
2023-01-12 17:41:54 -06:00
|
|
|
struct phys2d_circle *Make2DCircle(int go);
|
2022-08-28 22:34:33 -05:00
|
|
|
void phys2d_circledel(struct phys2d_circle *c);
|
2021-11-30 21:29:18 -06:00
|
|
|
void phys2d_applycircle(struct phys2d_circle *circle);
|
|
|
|
void phys2d_dbgdrawcircle(struct phys2d_circle *circle);
|
2022-08-12 14:03:56 -05:00
|
|
|
void circle_gui(struct phys2d_circle *circle);
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2023-01-12 17:41:54 -06:00
|
|
|
struct phys2d_box *Make2DBox(int go);
|
2022-08-28 22:34:33 -05:00
|
|
|
void phys2d_boxdel(struct phys2d_box *box);
|
2021-11-30 21:29:18 -06:00
|
|
|
void phys2d_applybox(struct phys2d_box *box);
|
|
|
|
void phys2d_dbgdrawbox(struct phys2d_box *box);
|
2022-08-12 14:03:56 -05:00
|
|
|
void box_gui(struct phys2d_box *box);
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2023-01-12 17:41:54 -06:00
|
|
|
struct phys2d_poly *Make2DPoly(int go);
|
2022-08-28 22:34:33 -05:00
|
|
|
void phys2d_polydel(struct phys2d_poly *poly);
|
2021-11-30 21:29:18 -06:00
|
|
|
void phys2d_applypoly(struct phys2d_poly *poly);
|
|
|
|
void phys2d_dbgdrawpoly(struct phys2d_poly *poly);
|
|
|
|
void phys2d_polyaddvert(struct phys2d_poly *poly);
|
2023-01-25 21:32:58 -06:00
|
|
|
void phys2d_poly_setverts(struct phys2d_poly *poly, cpVect *verts);
|
2022-08-12 14:03:56 -05:00
|
|
|
void poly_gui(struct phys2d_poly *poly);
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2023-01-12 17:41:54 -06:00
|
|
|
struct phys2d_edge *Make2DEdge(int go);
|
2022-08-28 22:34:33 -05:00
|
|
|
void phys2d_edgedel(struct phys2d_edge *edge);
|
2021-11-30 21:29:18 -06:00
|
|
|
void phys2d_applyedge(struct phys2d_edge *edge);
|
|
|
|
void phys2d_dbgdrawedge(struct phys2d_edge *edge);
|
|
|
|
void phys2d_edgeaddvert(struct phys2d_edge *edge);
|
2023-01-25 21:32:58 -06:00
|
|
|
void phys2d_edge_rmvert(struct phys2d_edge *edge, int index);
|
2022-08-12 14:03:56 -05:00
|
|
|
void edge_gui(struct phys2d_edge *edge);
|
2023-02-02 17:52:15 -06:00
|
|
|
void phys2d_edge_setvert(struct phys2d_edge *edge, int index, cpVect val);
|
2021-11-30 21:29:18 -06:00
|
|
|
|
|
|
|
void phys2d_init();
|
|
|
|
void phys2d_update(float deltaT);
|
2023-02-02 17:52:15 -06:00
|
|
|
cpShape *phys2d_query_pos(cpVect pos);
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2023-01-11 16:57:34 -06:00
|
|
|
struct phys_cbs {
|
|
|
|
struct callee begin;
|
|
|
|
struct callee separate;
|
|
|
|
};
|
|
|
|
|
2023-01-12 17:41:54 -06:00
|
|
|
void phys2d_add_handler_type(int cmd, int go, struct callee c);
|
2023-01-11 16:57:34 -06:00
|
|
|
void register_collide(void *sym);
|
2023-01-10 17:23:11 -06:00
|
|
|
void phys2d_set_gravity(cpVect v);
|
2022-12-20 08:16:26 -06:00
|
|
|
|
2023-01-17 15:09:14 -06:00
|
|
|
void shape_enabled(struct phys2d_shape *shape, int enabled);
|
2023-01-18 10:45:43 -06:00
|
|
|
int shape_is_enabled(struct phys2d_shape *shape);
|
2023-01-17 15:09:14 -06:00
|
|
|
void shape_set_sensor(struct phys2d_shape *shape, int sensor);
|
2023-01-18 10:45:43 -06:00
|
|
|
int shape_get_sensor(struct phys2d_shape *shape);
|
2023-01-16 17:18:09 -06:00
|
|
|
|
2023-01-16 02:16:39 -06:00
|
|
|
struct color {
|
|
|
|
unsigned char r;
|
|
|
|
unsigned char g;
|
|
|
|
unsigned char b;
|
|
|
|
};
|
|
|
|
|
2023-01-18 10:45:43 -06:00
|
|
|
void color2float(struct color, float *fcolor);
|
|
|
|
struct color float2color(float *fcolor);
|
2023-01-16 02:16:39 -06:00
|
|
|
|
2022-08-12 14:03:56 -05:00
|
|
|
void shape_gui(struct phys2d_shape *shape);
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-12-21 19:24:59 -06:00
|
|
|
void phys2d_reindex_body(cpBody *body);
|
|
|
|
|
2021-11-30 21:29:18 -06:00
|
|
|
#endif
|