prosperon/source/engine/2dphysics.h

150 lines
4.1 KiB
C
Raw Normal View History

2021-11-30 21:29:18 -06:00
#ifndef TWODPHYSICS_H
#define TWODPHYSICS_H
2023-01-11 16:57:34 -06:00
#include "script.h"
2023-05-12 13:22:05 -05:00
#include <chipmunk/chipmunk.h>
2023-05-24 20:45:50 -05:00
#include "render.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;
2023-05-16 01:31:13 -05:00
extern struct rgba color_white;
extern struct rgba color_black;
extern struct rgba disabled_color;
extern struct rgba dynamic_color;
extern struct rgba kinematic_color;
extern struct rgba static_color;
2023-05-24 20:45:50 -05:00
extern struct rgba sleep_color;
2023-05-16 01:31:13 -05:00
2021-11-30 21:29:18 -06:00
struct phys2d_shape {
2023-05-12 13:22:05 -05:00
cpShape *shape;
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 {
2023-05-12 13:22:05 -05:00
float radius;
cpVect offset;
struct phys2d_shape shape;
2021-11-30 21:29:18 -06:00
};
2023-01-25 21:32:58 -06:00
/* A single segment */
2021-11-30 21:29:18 -06:00
struct phys2d_segment {
2023-05-12 13:22:05 -05:00
float a[2];
float b[2];
float thickness;
struct phys2d_shape shape;
2021-11-30 21:29:18 -06:00
};
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 {
2023-05-12 13:22:05 -05:00
cpVect *points;
float radius;
struct phys2d_shape shape;
2023-01-25 21:32:58 -06:00
};
/* A box shape; a type of a polygon collider */
2021-11-30 21:29:18 -06:00
struct phys2d_box {
2023-05-12 13:22:05 -05:00
float w;
float h;
float offset[2];
float rotation;
float r;
struct phys2d_shape shape;
2021-11-30 21:29:18 -06:00
};
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-05-12 13:22:05 -05:00
cpVect *points;
float thickness;
cpShape **shapes;
int closed; /* True if the first and last points should be connected */
struct phys2d_shape shape;
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 {
2023-05-12 13:22:05 -05:00
struct callee begin;
struct callee separate;
2023-01-11 16:57:34 -06:00
};
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-05-16 01:31:13 -05:00
struct rgba 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
2023-05-27 10:13:20 -05:00
void flush_collide_cbs();
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