kintematic namespace kint is a c++ library that solves collisions for one kinematic rectangle in a world of static or constant velocity shapes
All logic is done with integers. move_and_slide is implemented by finding a int/int rational raycast point, then quantizing that point on to an integer grid to the best non-colliding point.
Features AABB optimization, non-AABB polygon shapes, one way platforms, and walking up small steps.
-
i2d- two dimensional integer vector. Positive y is "down" for documentation, but kintematic's logic is orienation agnostic -
Rational- int/int rational type -
Rational2D- two dimensional rational vector -
Shape_Point,Shape_Line,Shape_Rectangle,Shape_Polygon- collision shapes with velocity. Velocity is ini2dunits per timestep.Shape_Linecan be a one-way platform. -
Shape_Variant-std::variantof all 4 shapes -
enum Right_Triangle_Corner- used to turn a rectangle into a right triangle by defining which of the 4 points should become the right angle corner -
uint64_t- id value to keep track of shapes -
Impact- return type of raycasts for one shape -
Impact_ID- return type of raycasts for multiple shapes. Has an ID to store which shape it hit. -
Minkowski_Set- collection of shapes that have been minkowski-summed with a rectangle. Useful to prepare before doing a lot of raycasts.
-
Shape::as_polygon(),Shape_Point_from_i2d,Shape_Polygon_right_triangle,Shape_Polygon_from_points,shape_position_point, andconvex_hullare useful for creating and converting shapes -
Shape_Polygon_areais usually just used to check the orientation of aShape_Polygon. Should always be positive. -
collides_unmoving- returns if two shapes are overlapping (not considering velocity).A point exactly on the edge of a rectangle is not considered to be overlapping.
Two lines with the same end are not considered to be overlapping.
A point exactly on a point is considered to be overlapping.
-
minkowski_rectangle- returns minkowski sum of a rectangle and a shape. The two original shapes collide when the minkowski sum collides with the top-left corner of the rectangle. -
minkowski_motion- returns the shape-cast shape as a shape follows its velocity -
minkowski_set_create- returns aMinkowski_Setafter runningminkowski_rectangleon a lot of shapes, keeping track of shape id's. -
minkowski_set_append- sometimes it is better to create aMinkowski_Setone shape at a time -
raycast_unmoving- returns anstd::optional<Impact>for the point when a line defined by a start and end point intersects with a shapeIf the end point is exactly on the edge of a shape, raycast is not considered to hit.
-
clip_velocity- simulates moving aShape_Rectangleforward. Returns what the Shape's velocity should be in order to not collide with anything in aMinkowski_Set -
move_and_slide- Most significant function ofkintematicCalled once per timestep.
Moves a
Shape_Rectangleforward, sliding along anything it hits in aMinkowski_Set.The rectangle will get pushed by any shapes in the
Minkowski_Setwith velocity.Returns
Impact_IDs for any shapes the rectangle hit.Has an optional parameter for moving up small steps, defined by a vector in the upwards direction with a length of the tallest step size,