Skip to content

pfirsich/wuzy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

123 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wuzy

Collision Detection Library

Almost always when I make games I come up with some ad-hoc stuff for collision detection, which often works, but is always a huge pain and takes too much time in game jams.

I feel like either you bump a few spheres and AABBs into each other with your own code OR you have to go super big and use a full blown physics engine. This is supposed to fit into the gigantic gap inbetween.

This is supposed to be the least amount of code that lets you control a character in a level.

It will just do collision detection and resolution, no kinematics or dynamics. You can just create colliders and bump them into each other and get vectors that resolve the collision. It also does ray casting.

Most of the games I made were not made with any of the big engines, so I only used a proper physics engine a few times and I hated it quite a bit. It's very restrictive that most of the time you cannot set the position directly (which makes sense, but it is restrictive none the less) and I firmly believe that for most games the optimal physics have nothing to do with real-world kinematics and dynamics, so this library handles collision detection and resolution. No accelerations or forces, no constraints or anything of the sort. Maybe velocites if I ever introduce continuous collision detection.

Something like this: https://docs.godotengine.org/en/stable/classes/class_kinematicbody.html

This is not made for AAA games and millions of colliders. This is for games that hobby gamedevs might make in a gamejam or the average indie game you can get on Steam. It tries to be obvious and easy to integrate. It's supposed to provide the minimum amount of collision detection and resolution you need to make a game (that is not super focused on physics).

Integration

wuzy provides a C header file (include/wuzy/wuzy.h), but is written in C++20. All dynamic allocations are obvious and can be controlled via a custom allocator. Only a few operations dynamically allocate at all (such a creating a new AABB Tree or preparing memory for queries) and it's possible to do all of that at initialization time.

If you don't want to use CMake, you can build src/wuzy.cpp yourself with std=c++20. It should compile with -Wall -Wextra -pedantic -Werror -Wconversion and -fno-exceptions/-fno-rtti, if you need them.

There is a C++ wrapper in include/wuzy/wuzy.hpp and a few examples in examples/.

Architecture

wuzy uses GJK to test whether shapes overlap and EPA (Expanding Polytope Algorithm) to generate contact information (collision normal and depth). To speed up queries there is also a AABB Tree.

I plan to add a high-level API which should should reduce the API surface to the essential and allow usage without understanding any of the involved algorithms at all.

Usage Notes

If you need collisions with meshes, create an AABB tree with triangles.

TODO

  • Replace Muratori's GJK variant with a proper GJK that finds the closest point on the simplex generically and remembers witness points on each collider for every support point - with this I can implement wuzy_gjk_toi properly with conservative advancements AND I can get contact points. Also I fixed more than a handful of weird edge cases and I am still finding them. I'm done with this approach.
  • Special case a fast path for Capsule-Triangle intersection
  • wuzy_aabb_tree_update_node with flags (rebuild subtree, rotate, re-insert)
  • Fast effective bvh updates for animated scenes
  • AABB Tree Rebalancing, bulk-insert of nodes that balances tree (for levels): https://box2d.org/files/ErinCatto_DynamicBVH_Full.pdf
  • Tests!
  • Some support for continuous collision detection - I really just need support for sweeping shapes to the support functions (somehow). The swept shapes are convex again (for linear movement at least), so there has to be a way. If you really need this and this hasn't been implemented yet, just do some raycasts and then multisample.

Maybe Later

Resources

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors