Skip to content
Devon edited this page Feb 12, 2021 · 1 revision

If you find any errors, please open an issue or submit a pull request!

Initialization

The collision system is currently stateless, and as such doesn't require initialization like other systems within Astera.

Colliders

Within the collision system there are the following currently supported collider types:

- AABB
- Circle
- Ray

You can create the respective structs with

/* Create an AABB (Axis Aligned Bounding Box)
 * center - the center of the aabb
 * halfsize - the size / 2
 * returns: aabb structure */
c_aabb c_aabb_create(vec2 center, vec2 halfsize);
 /* Create a Circle
 * center - the center of the circle
 * radius - the radius of the circle
 * returns: circle structure */
c_circle c_circle_create(vec2 center, float radius);
/* Create a ray
 * NOTE: this will normalize the direction if the length is greater
 *       than 1
 * center - the point/center to cast from direction
 * direction - the direction of the ray
 * distance - the max distance of the ray
 * returns: ray structure, 0 length = fail */
c_ray c_ray_create(vec2 center, vec2 direction, float distance);

Movement

In order to keep the collider structures up to date with accurate positions, you can call the c_circle_move or c_aabb_move functions to move the positions, or modify the structure's data directly.

Resolution

There are a series of c_type_vs_type methods within col.h used to check if two types overlap. As well there are various c_type_vs_type_man which returns a c_manifold which contains values needed to correct the collision/overlap. Keep in mind the ordering of the colliders as sometimes you'll need to negate based on which collider moved into the other. You can alternatively use c_test and pass the colliders in that way and if there is no overlap, the manifold returned distance will be 0.

Here's the reference for c_test from the col.h header:

/* Test 2 Collider types
 * a - 1st collider
 * a_type - the 1st collider type
 * b - 2nd collider
 * b_type - the 2nd collider type */
c_manifold c_test(void* a, c_types a_type, void* b, c_types b_type);

Rays

Ray's/planes/raycasts are considered regular types and as a result require no special handling to interact with other types. Do note that you'll have to manually test each type against each other unless you implement your own broadphase methods or until Astera has one implemented.

Clone this wiki locally