Skip to content

redinator2000/kintematic

Repository files navigation

kintematic

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.

Types

  • 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 in i2d units per timestep. Shape_Line can be a one-way platform.

  • Shape_Variant - std::variant of 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.

Functions

  • Shape::as_polygon(), Shape_Point_from_i2d, Shape_Polygon_right_triangle, Shape_Polygon_from_points, shape_position_point, and convex_hull are useful for creating and converting shapes

  • Shape_Polygon_area is usually just used to check the orientation of a Shape_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 a Minkowski_Set after running minkowski_rectangle on a lot of shapes, keeping track of shape id's.

  • minkowski_set_append - sometimes it is better to create a Minkowski_Set one shape at a time

  • raycast_unmoving - returns an std::optional<Impact> for the point when a line defined by a start and end point intersects with a shape

    If the end point is exactly on the edge of a shape, raycast is not considered to hit.

  • clip_velocity - simulates moving a Shape_Rectangle forward. Returns what the Shape's velocity should be in order to not collide with anything in a Minkowski_Set

  • move_and_slide - Most significant function of kintematic

    Called once per timestep.

    Moves a Shape_Rectangle forward, sliding along anything it hits in a Minkowski_Set.

    The rectangle will get pushed by any shapes in the Minkowski_Set with 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,

About

Basic 2D collisions for fixed integers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages