prosperon/source/engine/2dphysics.h

151 lines
4.2 KiB
C
Raw Normal View History

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
2023-02-28 09:40:53 -06:00
struct gameobject;
2021-11-30 21:29:18 -06:00
extern float phys2d_gravity;
extern int physOn;
extern cpSpace *space;
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;
void *data;
void (*debugdraw)(void *data);
float (*moi)(void *data, float mass);
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-02-17 13:15:56 -06:00
/* An edge with no volume. Cannot collide with each other. Join to make levels. Static only. */
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);
float phys2d_circle_moi(struct phys2d_circle *c, float m);
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);
float phys2d_box_moi(struct phys2d_box *box, float m);
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);
float phys2d_poly_moi(struct phys2d_poly *poly, float m);
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);
float phys2d_edge_moi(struct phys2d_edge *edge, float m);
2023-02-08 15:30:12 -06:00
void phys2d_edge_setvert(struct phys2d_edge *edge, int index, cpVect val);
2023-02-08 15:30:12 -06:00
void phys2d_edge_clearverts(struct phys2d_edge *edge);
void phys2d_edge_addverts(struct phys2d_edge *edge, cpVect *verts);
void phys2d_edge_set_sensor(struct phys2d_edge *edge, int sensor);
void phys2d_edge_set_enabled(struct phys2d_edge *edge, int enabled);
2021-11-30 21:29:18 -06:00
void phys2d_init();
void phys2d_update(float deltaT);
cpShape *phys2d_query_pos(cpVect pos);
2023-02-05 17:42:36 -06:00
int *phys2d_query_box(cpVect pos, cpVect wh);
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-02-17 01:16:52 -06:00
struct shape_cb {
2023-03-10 13:13:48 -06:00
struct phys2d_shape *shape;
2023-02-17 01:16:52 -06:00
struct phys_cbs cbs;
};
2023-03-10 13:13:48 -06:00
void fire_hits();
void phys2d_rm_go_handlers(int go);
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);
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);
int shape_get_sensor(struct phys2d_shape *shape);
2023-01-16 02:16:39 -06:00
struct color {
unsigned char r;
unsigned char g;
unsigned char b;
};
void color2float(struct color, float *fcolor);
struct color float2color(float *fcolor);
2023-03-17 10:25:35 -05:00
struct color shape_color_s(cpShape *shape);
2023-01-16 02:16:39 -06:00
2022-08-12 14:03:56 -05:00
void shape_gui(struct phys2d_shape *shape);
2023-03-10 13:13:48 -06:00
void phys2d_setup_handlers(int go);
2023-03-13 09:27:32 -05:00
int *phys2d_query_shape(struct phys2d_shape *shape);
2023-03-19 20:33:05 -05:00
int *phys2d_query_box_points(cpVect pos, cpVect wh, cpVect *points, int n);
2021-11-30 21:29:18 -06:00
void phys2d_reindex_body(cpBody *body);
2023-02-20 11:10:03 -06:00
cpVect world2go(struct gameobject *go, cpVect worldpos);
cpVect go2world(struct gameobject *go, cpVect gopos);
2023-03-10 13:13:48 -06:00
extern unsigned int category_masks[32];
void set_cat_mask(int cat, unsigned int mask);
2023-03-17 10:25:35 -05:00
int phys2d_in_air(cpBody *body);
2021-11-30 21:29:18 -06:00
#endif