Examples and tutorials » Octree new in 2020.06

Loose octree for accelerating collision detection.

Image

Simple, single-threaded implementation of a loose octree which is commonplace in computer graphics. In this example, octree is used for collision detection.

Controls

  • mouse drag rotates the camera
  • Shift mouse drag pans the camera
  • mouse wheel zooms in/out
  • R resets the camera to its original transformation
  • O switches between a brute force and octree collision detection
  • B shows/hides tree node bounding boxes
  • P toggles frame profiling to the console using DebugTools::FrameProfiler
  • Space pauses/resumes particle simulation

Additionally, various options can be set via command line:

  • -s, --spheres N — number of spheres to simulate (default: 2000)
  • -r, --sphere-radius R — sphere radius (default: 0.0333)
  • -v, --sphere-velocity V — sphere velocity (default: 0.05)

With the default setting, the octree collision detection is about twice as fast than the brute force method. In order to better see the octree visualization, run the example for example with the following parameters:

./magnum-octree -s 20 -r 0.1 -v 1.0

Credits

This example was originally contributed by Nghia Truong.

Source

Full source code is linked below and also available in the magnum-examples GitHub repository. This example depends on the ArcBall Camera example for camera navigation.

The ports branch contains additional patches for Emscripten support that aren't present in master in order to keep the example code as simple as possible.