power_play/src/collider.h

77 lines
2.5 KiB
C

#ifndef COLLIDER_H
#define COLLIDER_H
#if COLLIDER_DEBUG
extern u32 collider_debug_steps;
#endif
struct collider_support_point {
struct v2 p;
u32 i; /* Index of original point in shape */
};
struct collider_menkowski_point {
struct v2 p; /* Menkowski difference point */
struct collider_support_point s0; /* Support point of first shape in dir */
struct collider_support_point s1; /* Support point of second shape in -dir */
};
struct collider_menkowski_simplex {
u32 len;
struct collider_menkowski_point a, b, c;
};
struct collider_menkowski_feature {
u32 len;
struct collider_menkowski_point a, b;
};
struct collider_collision_point {
struct v2 point;
f32 separation;
u32 id; /* Based on polygon edge-to-edge */
};
struct collider_prototype { struct v2 points[64]; u32 len; };
struct collider_collision_points_result {
struct v2 normal;
struct collider_collision_point points[2];
u32 num_points;
/* For debugging */
b32 solved;
struct collider_menkowski_simplex simplex;
struct collider_prototype prototype;
/* Clipping faces */
struct v2 a0, b0, a1, b1;
struct v2 a0_clipped, b0_clipped, a1_clipped, b1_clipped;
};
struct collider_closest_points_result {
struct v2 p0, p1;
b32 colliding;
/* For debugging */
b32 solved;
struct collider_menkowski_simplex simplex;
struct collider_prototype prototype;
};
struct collider_support_point collider_get_support_point(struct collider_shape *shape, struct xform xf, struct v2 dir);
struct aabb collider_aabb_from_collider(struct collider_shape *shape, struct xform xf);
b32 collider_test_aabb(struct aabb box0, struct aabb box1);
struct collider_collision_points_result collider_collision_points(struct collider_shape *shape0, struct collider_shape *shape1, struct xform xf0, struct xform xf1);
struct collider_closest_points_result collider_closest_points(struct collider_shape *shape0, struct collider_shape *shape1, struct xform xf0, struct xform xf1);
f32 collider_time_of_impact(struct collider_shape *c0, struct collider_shape *c1, struct xform xf0_t0, struct xform xf1_t0, struct xform xf0_t1, struct xform xf1_t1, f32 tolerance, u32 max_iterations);
struct v2_array menkowski(struct arena *arena, struct collider_shape *shape0, struct collider_shape *shape1, struct xform xf0, struct xform xf1, u32 detail);
struct v2_array cloud(struct arena *arena, struct collider_shape *shape0, struct collider_shape *shape1, struct xform xf0, struct xform xf1);
#endif