From 236bb69be1b45aa50de8b1fd1330c6a930f771cf Mon Sep 17 00:00:00 2001 From: Joey Pollack Date: Sat, 18 May 2024 19:17:41 -0400 Subject: [PATCH] Adds start of physics plugin --- Cargo.lock | 9 +++ Cargo.toml | 2 + asset src/brick.blend | 4 +- asset src/wall.blend | 3 + assets/brick.glb | 2 +- assets/wall.glb | 3 + crates/core/Cargo.toml | 1 + crates/core/src/core.rs | 31 ++++++-- crates/core/src/lib.rs | 3 +- crates/core/src/movement.rs | 40 +++------- crates/physics/Cargo.toml | 11 +++ crates/physics/src/components.rs | 126 +++++++++++++++++++++++++++++++ crates/physics/src/lib.rs | 14 ++++ crates/physics/src/systems.rs | 13 ++++ 14 files changed, 221 insertions(+), 41 deletions(-) create mode 100644 asset src/wall.blend create mode 100644 assets/wall.glb create mode 100644 crates/physics/Cargo.toml create mode 100644 crates/physics/src/components.rs create mode 100644 crates/physics/src/lib.rs create mode 100644 crates/physics/src/systems.rs diff --git a/Cargo.lock b/Cargo.lock index 42f9b8f..19cd12f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1164,6 +1164,7 @@ dependencies = [ "bevy", "core", "hello", + "physics", ] [[package]] @@ -1381,6 +1382,7 @@ name = "core" version = "0.1.0" dependencies = [ "bevy", + "physics", ] [[package]] @@ -2682,6 +2684,13 @@ dependencies = [ "indexmap", ] +[[package]] +name = "physics" +version = "0.1.0" +dependencies = [ + "bevy", +] + [[package]] name = "pin-project-lite" version = "0.2.14" diff --git a/Cargo.toml b/Cargo.toml index c56affb..fdb4358 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,10 +27,12 @@ linker = "rust-lld.exe" [dependencies] hello = { workspace = true } core = { workspace = true } +physics = { workspace = true } bevy = { workspace = true } # bevy = { version = "0.13.0", features = ["dynamic_linking"] } [workspace.dependencies] hello = { path = "crates/hello" } core = { path = "crates/core" } +physics = { path = "crates/physics" } bevy = { version = "0.13.0" } \ No newline at end of file diff --git a/asset src/brick.blend b/asset src/brick.blend index 2c4d1c2..09ce11c 100644 --- a/asset src/brick.blend +++ b/asset src/brick.blend @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8db6e2d54830375ad391a9098e291e596bf18640b6aa540e0d134fad58453b68 -size 858732 +oid sha256:c44f51ceec8fd47c47c308542512a17e76b8c859d12c2ab34f213e8c0215e1ad +size 859684 diff --git a/asset src/wall.blend b/asset src/wall.blend new file mode 100644 index 0000000..147bdac --- /dev/null +++ b/asset src/wall.blend @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:075ffb772dd82fd0218f0f6f8d306b10c5f9be7c40e2d3afc88ff807af0e9d49 +size 883512 diff --git a/assets/brick.glb b/assets/brick.glb index 5dc106e..54d410d 100644 --- a/assets/brick.glb +++ b/assets/brick.glb @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f1d8de30e96634729bca2268949346b39cdff4c7314f83f198b1daddec02dad2 +oid sha256:57fb6b3bffcbbc96b4f77ca22e7240f9c5519a9438f0978d9f625bd976e51c8b size 4472 diff --git a/assets/wall.glb b/assets/wall.glb new file mode 100644 index 0000000..4957132 --- /dev/null +++ b/assets/wall.glb @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1a0394029c58d2faf07bf36de1f8f620b2c73a1b9a0fa8879dc11ef5d6ab820a +size 1996 diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index 509dca3..ceda816 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] bevy = { workspace = true } +physics = { workspace = true } diff --git a/crates/core/src/core.rs b/crates/core/src/core.rs index f937702..8a3bc2a 100644 --- a/crates/core/src/core.rs +++ b/crates/core/src/core.rs @@ -1,15 +1,14 @@ use bevy::prelude::*; -use crate::movement::{MovementPlugin, Velocity}; +use physics::{PhysicsPlugin, components::Velocity}; pub struct CorePlugin; - impl Plugin for CorePlugin { fn build(&self, app: &mut App) { - app.add_plugins(MovementPlugin) + app.add_plugins(PhysicsPlugin) .add_systems(Startup, setup); } } @@ -40,7 +39,7 @@ fn setup(mut commands: Commands, server: Res, mut ambient_light: Re let brick_handle: Handle = server.load("brick.glb#Scene0"); commands.spawn(SceneBundle { scene: brick_handle, - transform: Transform::from_xyz(0.0, 8.0, 0.0), + transform: Transform::from_xyz(0.0, 7.0, 0.0), .. default() }); @@ -51,7 +50,7 @@ fn setup(mut commands: Commands, server: Res, mut ambient_light: Re transform: Transform::from_xyz(0.0, -7.75, 0.0), ..default() }, - Velocity::new(0.5, 0.5, 0.0))); + Velocity::new(8.0, 8.0, 0.0))); // PADDLE let paddle_handle: Handle = server.load("paddle.glb#Scene0"); @@ -60,4 +59,26 @@ fn setup(mut commands: Commands, server: Res, mut ambient_light: Re transform: Transform::from_xyz(0.0, -8.0, 0.0), ..default() }); + + // WALLS + let wall_handle: Handle = server.load("wall.glb#Scene0"); + commands.spawn(SceneBundle { + scene: wall_handle.clone(), + transform: Transform::from_xyz(13.0, 0.0, 0.0), + ..default() + }); + + commands.spawn(SceneBundle { + scene: wall_handle.clone(), + transform: Transform::from_xyz(-13.0, 0.0, 0.0), + ..default() + }); + + commands.spawn(SceneBundle { + scene: wall_handle.clone(), + transform: Transform::from_rotation(Quat::from_rotation_z(3.14159 * 0.5)) + .with_translation(Vec3::new(0.0, 10.0, 0.0)), + ..default() + }); + } \ No newline at end of file diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 2ca2a62..14d0377 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -1,4 +1,3 @@ -pub mod core; -pub mod movement; \ No newline at end of file +pub mod core; \ No newline at end of file diff --git a/crates/core/src/movement.rs b/crates/core/src/movement.rs index 128e736..3d4d568 100644 --- a/crates/core/src/movement.rs +++ b/crates/core/src/movement.rs @@ -2,38 +2,16 @@ use bevy::prelude::*; -pub struct MovementPlugin; -impl Plugin for MovementPlugin -{ - fn build(&self, app: &mut App) - { - app.add_systems(Update, update_movement); - } -} +// pub struct MovementPlugin; +// impl Plugin for MovementPlugin +// { +// fn build(&self, app: &mut App) +// { +// app.add_systems(Update, update_movement); +// } +// } -#[derive(Component)] -pub struct Velocity(Vec3); +// COMPONENTS -impl Default for Velocity -{ - fn default() -> Self - { - Self { 0: Vec3::new(0.0, 0.0, 0.0)} - } -} - -impl Velocity -{ - pub fn new(x: f32, y: f32, z: f32) -> Self{ - Self { 0: Vec3::new(x, y, z) } - } -} // SYSTEMS -fn update_movement(mut moving_objects: Query<(&Velocity, &mut Transform)>, time: Res