1use crate::app::{App, Plugin};
2use gizmo_physics_rigid::world::PhysicsWorld;
3
4use crate::math::Vec3;
5
6#[non_exhaustive]
9pub struct PhysicsPlugin {
10 pub gravity: Vec3,
11}
12
13impl Default for PhysicsPlugin {
14 fn default() -> Self {
15 Self {
16 gravity: Vec3::new(0.0, -9.81, 0.0),
17 }
18 }
19}
20
21impl PhysicsPlugin {
22 pub fn new() -> Self {
24 Self::default()
25 }
26
27 pub fn with_gravity(mut self, gravity: Vec3) -> Self {
29 self.gravity = gravity;
30 self
31 }
32}
33
34impl<State: 'static> Plugin<State> for PhysicsPlugin {
35 fn build(&self, app: &mut App<State>) {
36 tracing::info!(
37 "[Plugin] PhysicsPlugin yükleniyor (Yerçekimi: {:?})...",
38 self.gravity
39 );
40 app.world
41 .insert_resource(PhysicsWorld::new().with_gravity(self.gravity));
42 app.schedule.add_di_system(
47 gizmo_core::system::SystemConfig::new(Box::new(
48 crate::systems::physics::PhysicsStepSystem,
49 ))
50 .label("physics_step"),
51 );
52 }
53}
54
55pub struct TransformPlugin;
57
58impl<State: 'static> Plugin<State> for TransformPlugin {
59 fn build(&self, app: &mut App<State>) {
60 app.schedule.add_di_system(
62 gizmo_core::system::SystemConfig::new(Box::new(
63 crate::systems::transform::TransformSyncSystem,
64 ))
65 .label("transform_sync"),
66 );
67 app.schedule.add_di_system(
68 gizmo_core::system::SystemConfig::new(Box::new(
69 crate::systems::transform::TransformPropagateSystem,
70 ))
71 .label("transform_propagate")
72 .after("transform_sync"),
73 );
74 }
75}