Physics Support

- NEW CRATE: raidillon_physics.
- Added new models to be able to test the physics support.
- Added a new system "PhysicsSystem" to apply physics calculations to the ECS world.
- NEW COMPONENT: RigidBodyComponent
This commit is contained in:
reo 2025-10-19 17:40:51 +03:00
parent d280a0b9a5
commit 8b5a6167eb
13 changed files with 697 additions and 43 deletions

3
game/src/systems/mod.rs Normal file
View file

@ -0,0 +1,3 @@
mod physics;
pub use physics::PhysicsSystem;

View file

@ -0,0 +1,34 @@
use raidillon_core::scene::Scene;
use raidillon_ecs::components::RigidBodyComponent;
use raidillon_ecs::Transform;
use raidillon_engine::EngineResources;
use raidillon_engine::system::System;
use raidillon_physics::Physics;
use raidillon_platform::PlatformContext;
#[derive(Default)]
pub struct PhysicsSystem;
impl System for PhysicsSystem {
fn load_world(&mut self, res: &mut EngineResources, scene: &mut Scene) {
let p = Physics::default();
res.insert(p);
}
fn fixed_update(&mut self, res: &mut EngineResources, scene: &mut Scene) {
let pctx = res.get::<PlatformContext>().expect("PlatformContext missing").clone();
let physics = res.get_mut::<Physics>().expect("Physics missing");
physics.step(pctx.time_ctx.fixed_dt);
let mut query = scene.world.query::<(&mut Transform, &RigidBodyComponent)>();
for (_ent, (tr, rb_component)) in query.iter() {
if let Some(body) = physics.get_rigid_body(rb_component.0) {
let pos = body.position();
let translation = Physics::rapier_translation_to_glam(&pos.translation.vector);
let rotation = Physics::rapier_rotation_to_glam(&pos.rotation);
tr.translation = translation;
tr.rotation = rotation;
}
}
}
}