Crate rhusics [] [src]

Rhusics physics library

A physics library, primarily built to be used with specs. Uses cgmath for all computation.

Features:

  • Two different broad phase collision detection implementations:
    • Brute force
    • Sweep and Prune
  • Narrow phase collision detection using GJK, and optionally EPA for full contact information
  • specs::System for collision detection working on user supplied transform, and CollisionShape components. Can optionally use broad and/or narrow phase detection. Library supplies a transform implementation BodyPose for convenience.
  • Uses single precision as default, can be changed to double precision with the double feature.
  • Has support for doing spatial sort/collision detection using the collision-rs DBVT.
  • Support for doing broad phase using the collision-rs DBVT.
  • Has support for all primitives in collision-rs

Examples

extern crate rhusics;
extern crate cgmath;
extern crate specs;

use cgmath::{Transform, Rotation2, Rad, Point2};
use specs::{World, RunNow};

use rhusics::collide2d::*;

pub fn main() {
    let mut world = World::new();
    world_register::<BodyPose2>(&mut world);

    world
        .create_entity()
        .with(CollisionShape2::<BodyPose2>::new_simple(
            CollisionStrategy::FullResolution,
            CollisionMode::Discrete,
            Rectangle::new(10., 10.).into(),
        ))
        .with(BodyPose2::one());

    world
        .create_entity()
        .with(CollisionShape2::<BodyPose2>::new_simple(
            CollisionStrategy::FullResolution,
            CollisionMode::Discrete,
            Rectangle::new(10., 10.).into(),
        ))
        .with(BodyPose2::new(
            Point2::new(3., 2.),
            Rotation2::from_angle(Rad(0.)),
        ));

    let mut system = BasicCollisionSystem2::<BodyPose2>::new()
        .with_broad_phase(BroadBruteForce2::default())
        .with_narrow_phase(GJK2::new());
    system.run_now(&world.res);
    println!("Contacts: {:?}", *world.read_resource::<Contacts2>());
}

Modules

collide

Generic data structures and algorithms for collision detection

collide2d

Type wrappers and convenience functions for 2D collision detection

collide3d

Type wrappers and convenience functions for 3D collision detection

Structs

BodyPose

Transform that implements Pose, and can be used as the transform component throughout the library.

NextFrame

Wrapper for data computed for the next frame