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>
|
2022-12-20 08:16:26 -06:00
|
|
|
#include "s7.h"
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-11-19 17:13:57 -06:00
|
|
|
struct gameobject;
|
2021-11-30 21:29:18 -06:00
|
|
|
|
|
|
|
extern cpBody *ballBody;
|
|
|
|
extern float phys2d_gravity;
|
|
|
|
extern int physOn;
|
|
|
|
extern cpSpace *space;
|
|
|
|
|
2022-12-21 19:24:59 -06:00
|
|
|
struct phys_cbs {
|
|
|
|
s7_pointer begin;
|
|
|
|
s7_pointer separate;
|
|
|
|
};
|
|
|
|
|
2021-11-30 21:29:18 -06:00
|
|
|
struct phys2d_shape {
|
|
|
|
cpShape *shape;
|
2022-11-19 17:13:57 -06:00
|
|
|
struct gameobject *go;
|
2021-11-30 21:29:18 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
struct phys2d_circle {
|
|
|
|
float radius;
|
|
|
|
float offset[2];
|
|
|
|
struct phys2d_shape shape;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct phys2d_segment {
|
|
|
|
float a[2];
|
|
|
|
float b[2];
|
|
|
|
float thickness;
|
|
|
|
struct phys2d_shape shape;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct phys2d_box {
|
|
|
|
float w;
|
|
|
|
float h;
|
|
|
|
float offset[2];
|
2022-08-17 00:01:51 -05:00
|
|
|
float r;
|
2021-11-30 21:29:18 -06:00
|
|
|
struct phys2d_shape shape;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct phys2d_edge {
|
|
|
|
int n;
|
|
|
|
float *points;
|
|
|
|
float thickness;
|
|
|
|
cpShape **shapes;
|
|
|
|
struct phys2d_shape shape;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct phys2d_poly {
|
|
|
|
int n;
|
|
|
|
float *points;
|
|
|
|
float radius;
|
|
|
|
struct phys2d_shape shape;
|
|
|
|
};
|
|
|
|
|
2022-11-19 17:13:57 -06:00
|
|
|
struct phys2d_circle *Make2DCircle(struct gameobject *go);
|
|
|
|
void phys2d_circleinit(struct phys2d_circle *circle, struct gameobject *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
|
|
|
|
2022-11-19 17:13:57 -06:00
|
|
|
struct phys2d_segment *Make2DSegment(struct gameobject *go);
|
|
|
|
void phys2d_seginit(struct phys2d_segment *seg, struct gameobject *go);
|
2022-08-28 22:34:33 -05:00
|
|
|
void phys2d_segdel(struct phys2d_segment *seg);
|
2021-11-30 21:29:18 -06:00
|
|
|
void phys2d_applyseg(struct phys2d_segment *seg);
|
|
|
|
void phys2d_dbgdrawseg(struct phys2d_segment *seg);
|
2022-08-12 14:03:56 -05:00
|
|
|
void segment_gui(struct phys2d_segment *seg);
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-11-19 17:13:57 -06:00
|
|
|
struct phys2d_box *Make2DBox(struct gameobject *go);
|
|
|
|
void phys2d_boxinit(struct phys2d_box *box, struct gameobject *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
|
|
|
|
2022-11-19 17:13:57 -06:00
|
|
|
struct phys2d_poly *Make2DPoly(struct gameobject *go);
|
|
|
|
void phys2d_polyinit(struct phys2d_poly *poly, struct gameobject *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);
|
2022-08-12 14:03:56 -05:00
|
|
|
void poly_gui(struct phys2d_poly *poly);
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-11-19 17:13:57 -06:00
|
|
|
struct phys2d_edge *Make2DEdge(struct gameobject *go);
|
|
|
|
void phys2d_edgeinit(struct phys2d_edge *edge, struct gameobject *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_edgeshapeapply(struct phys2d_shape *mshape, cpShape * shape);
|
|
|
|
void phys2d_dbgdrawedge(struct phys2d_edge *edge);
|
|
|
|
void phys2d_edgeaddvert(struct phys2d_edge *edge);
|
2022-08-12 14:03:56 -05:00
|
|
|
void edge_gui(struct phys2d_edge *edge);
|
2021-11-30 21:29:18 -06:00
|
|
|
|
|
|
|
|
|
|
|
void phys2d_init();
|
|
|
|
void phys2d_update(float deltaT);
|
|
|
|
void phys2d_apply();
|
|
|
|
|
2022-12-21 19:24:59 -06:00
|
|
|
void phys2d_add_handler_type(int cmd, struct gameobject *go, s7_pointer cb);
|
2022-12-22 03:50:40 -06:00
|
|
|
void phys2d_set_gravity(float x, float y);
|
2022-12-20 08:16:26 -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
|