rhusics

Crates.iorhusics
lib.rsrhusics
version0.2.0
sourcesrc
created_at2017-10-26 22:01:57.426955
updated_at2018-01-07 13:03:35.191819
descriptionPhysics library for use with `specs`
homepagehttps://github.com/Rhuagh/rhusics.git
repositoryhttps://github.com/Rhuagh/rhusics.git
max_upload_size
id37051
size170,088
Simon Rönnberg (Rhuagh)

documentation

https://docs.rs/rhusics

README

Physics library for use in Specs, using cgmath and collision-rs.

Example

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

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

use rhusics::ecs::collide::prelude2d::{register_collision, BasicCollisionSystem2, BodyPose2,
                                       BroadBruteForce2, CollisionMode, CollisionShape2,
                                       CollisionStrategy, ContactEvent2, GJK2, Rectangle};

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

    let mut reader_1 = world
        .write_resource::<EventChannel<ContactEvent2<f32>>>()
        .register_reader();

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

    world
        .create_entity()
        .with(CollisionShape2::<f32, BodyPose2<f32>, ()>::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::<f32, BodyPose2<f32>, ()>::new()
        .with_broad_phase(BroadBruteForce2::default())
        .with_narrow_phase(GJK2::new());
    system.run_now(&world.res);
    println!(
        "Contacts: {:?}",
        world
            .read_resource::<EventChannel<ContactEvent2<f32>>>()
            .read(&mut reader_1)
            .collect::<Vec<_>>()
    );
}

Features:

  • Has support for all primitives in collision-rs
  • Has support for the following broad phase algorithms in collision-rs:
    • 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 shape components. Can optionally use broad and/or narrow phase detection. Library supplies a transform implementation for convenience.
  • specs::System for spatial sorting on user supplied transform, and shape components.
  • Has support for doing spatial sort/collision detection using the collision-rs DBVT.
  • Support for doing broad phase using the collision-rs DBVT.
  • Continuous collision detection, using GJK
  • Simple rigid body implementation with single contact forward resolution

TODO:

  • Impulse solver
  • Integrator implementations (Euler, RK4, etc.)
  • Parallel solver implementation
Commit count: 185

cargo fmt