Skip to content

smokku/hecs_rapier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

physics engine for hecs

Port of bevy_rapier2d to hecs ECS.

WARNING

Example

use hecs_rapier as physics;
use hecs::World;

let mut world = World::new();

/* Create structures necessary for the simulation. */
let gravity = vector![0.0, -9.81];
let integration_parameters = physics::IntegrationParameters::default();
let mut physics_pipeline = physics::PhysicsPipeline::new();
let mut island_manager = physics::IslandManager::new();
let mut broad_phase = physics::BroadPhase::new();
let mut narrow_phase = physics::NarrowPhase::new();
let mut joint_set = physics::JointSet::new();
let mut joints_entity_map = physics::JointsEntityMap::default();
let mut ccd_solver = physics::CCDSolver::new();
// let physics_hooks = ();
let event_handler = ();
let mut modification_tracker = physics::ModificationTracker::default();

while running {
        physics::attach_bodies_and_colliders(&mut world);
        physics::create_joints(&mut self.world, &mut joint_set, &mut joints_entity_map);
        physics::finalize_collider_attach_to_bodies(&mut world, &mut modification_tracker);


        physics::prepare_step(&mut world, &mut modification_tracker);

        while need_to_step {

            physics::step_world(
                &mut world,
                &gravity,
                &integration_parameters,
                &mut physics_pipeline,
                &mut modification_tracker,
                &mut island_manager,
                &mut broad_phase,
                &mut narrow_phase,
                &mut joint_set,
                &mut joints_entity_map,
                &mut ccd_solver,
                &event_handler,
            );

        }


        physics::collect_removals(&mut world, &mut modification_tracker);

        next_frame().await;
        world.clear_trackers();
}