Compare commits

..

No commits in common. 'dev' and 'master' have entirely different histories.
dev ... master

9
Cargo.lock generated

@ -1164,7 +1164,6 @@ dependencies = [
"bevy", "bevy",
"core", "core",
"hello", "hello",
"physics",
] ]
[[package]] [[package]]
@ -1382,7 +1381,6 @@ name = "core"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"bevy", "bevy",
"physics",
] ]
[[package]] [[package]]
@ -2684,13 +2682,6 @@ dependencies = [
"indexmap", "indexmap",
] ]
[[package]]
name = "physics"
version = "0.1.0"
dependencies = [
"bevy",
]
[[package]] [[package]]
name = "pin-project-lite" name = "pin-project-lite"
version = "0.2.14" version = "0.2.14"

@ -27,12 +27,10 @@ linker = "rust-lld.exe"
[dependencies] [dependencies]
hello = { workspace = true } hello = { workspace = true }
core = { workspace = true } core = { workspace = true }
physics = { workspace = true }
bevy = { workspace = true } bevy = { workspace = true }
# bevy = { version = "0.13.0", features = ["dynamic_linking"] } # bevy = { version = "0.13.0", features = ["dynamic_linking"] }
[workspace.dependencies] [workspace.dependencies]
hello = { path = "crates/hello" } hello = { path = "crates/hello" }
core = { path = "crates/core" } core = { path = "crates/core" }
physics = { path = "crates/physics" }
bevy = { version = "0.13.0" } bevy = { version = "0.13.0" }

BIN
asset src/brick.blend (Stored with Git LFS)

Binary file not shown.

BIN
asset src/wall.blend (Stored with Git LFS)

Binary file not shown.

BIN
assets/brick.glb (Stored with Git LFS)

Binary file not shown.

BIN
assets/wall.glb (Stored with Git LFS)

Binary file not shown.

@ -6,7 +6,6 @@ edition = "2021"
[dependencies] [dependencies]
bevy = { workspace = true } bevy = { workspace = true }
physics = { workspace = true }

@ -1,14 +1,15 @@
use bevy::{pbr::wireframe::{Wireframe, WireframePlugin}, prelude::*}; use bevy::prelude::*;
use physics::{components::{Velocity, AABB}, PhysicsPlugin}; use crate::movement::{MovementPlugin, Velocity};
pub struct CorePlugin; pub struct CorePlugin;
impl Plugin for CorePlugin impl Plugin for CorePlugin
{ {
fn build(&self, app: &mut App) fn build(&self, app: &mut App)
{ {
app.add_plugins(PhysicsPlugin {debug_draw_colliders: true}) app.add_plugins(MovementPlugin)
.add_systems(Startup, setup); .add_systems(Startup, setup);
} }
} }
@ -35,19 +36,13 @@ fn setup(mut commands: Commands, server: Res<AssetServer>, mut ambient_light: Re
..default() ..default()
}); });
// TESTING:
// BRICK // BRICK
let brick_handle: Handle<Scene> = server.load("brick.glb#Scene0"); let brick_handle: Handle<Scene> = server.load("brick.glb#Scene0");
commands.spawn((SceneBundle { commands.spawn(SceneBundle {
scene: brick_handle, scene: brick_handle,
transform: Transform::from_xyz(0.0, 7.0, 0.0), transform: Transform::from_xyz(0.0, 8.0, 0.0),
.. default() .. default()
// TODO: need to figure out how to get the box dimensions from the loaded scene });
},
AABB::from_point_and_size(Vec3::new(0.0, 7.0, 0.0), Vec3::new(2.0, 2.0, 2.0))
));
// BALL // BALL
let ball_handle: Handle<Scene> = server.load("ball.glb#Scene0"); let ball_handle: Handle<Scene> = server.load("ball.glb#Scene0");
@ -56,7 +51,7 @@ fn setup(mut commands: Commands, server: Res<AssetServer>, mut ambient_light: Re
transform: Transform::from_xyz(0.0, -7.75, 0.0), transform: Transform::from_xyz(0.0, -7.75, 0.0),
..default() ..default()
}, },
Velocity::new(8.0, 8.0, 0.0))); Velocity::new(0.5, 0.5, 0.0)));
// PADDLE // PADDLE
let paddle_handle: Handle<Scene> = server.load("paddle.glb#Scene0"); let paddle_handle: Handle<Scene> = server.load("paddle.glb#Scene0");
@ -65,26 +60,4 @@ fn setup(mut commands: Commands, server: Res<AssetServer>, mut ambient_light: Re
transform: Transform::from_xyz(0.0, -8.0, 0.0), transform: Transform::from_xyz(0.0, -8.0, 0.0),
..default() ..default()
}); });
// WALLS
let wall_handle: Handle<Scene> = 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()
});
} }

@ -1,3 +1,4 @@
pub mod core; pub mod core;
pub mod movement;

@ -2,16 +2,38 @@
use bevy::prelude::*; use bevy::prelude::*;
// pub struct MovementPlugin; pub struct MovementPlugin;
// impl Plugin for MovementPlugin impl Plugin for MovementPlugin
// { {
// fn build(&self, app: &mut App) fn build(&self, app: &mut App)
// { {
// app.add_systems(Update, update_movement); app.add_systems(Update, update_movement);
// } }
// } }
// COMPONENTS #[derive(Component)]
pub struct Velocity(Vec3);
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 // SYSTEMS
fn update_movement(mut moving_objects: Query<(&Velocity, &mut Transform)>, time: Res<Time>)
{
for (velocity, mut transform) in moving_objects.iter_mut()
{
transform.translation += velocity.0 * time.delta_seconds();
}
}

@ -1,11 +0,0 @@
[package]
name = "physics"
description = "The Physics Module For the Game"
version = "0.1.0"
edition = "2021"
[dependencies]
bevy = { workspace = true }

@ -1,137 +0,0 @@
use bevy::prelude::*;
#[derive(Component)]
pub struct Velocity
{
pub value: Vec3,
}
impl Default for Velocity
{
fn default() -> Self
{
Self { value: Vec3::new(0.0, 0.0, 0.0)}
}
}
impl Velocity
{
pub fn new(x: f32, y: f32, z: f32) -> Self{
Self { value: Vec3::new(x, y, z) }
}
}
#[derive(Component)]
pub struct AABB
{
min_extents: Vec3,
max_extents: Vec3,
half_size: Vec3,
}
impl AABB
{
// CONSTRUCTORS
pub fn from_point_and_size(center: Vec3, dimensions: Vec3) -> Self
{
let half_size = dimensions * 0.5;
Self {
min_extents: center - half_size,
max_extents: center + half_size,
half_size
}
}
pub fn from_point_and_mesh(center: Vec3, mesh: Handle<Mesh>) -> Self
{
// TODO: Build an AABB around the given mesh
// Find the smallest and largets vertices on each axis
// and use those to set the extents of the AABB
todo!()
}
// ACCESSORS
pub fn get_center_point(&self) -> Vec3
{
Vec3::new(self.min_extents.x + self.half_size.x,
self.min_extents.y + self.half_size.y,
self.min_extents.z + self.half_size.z)
}
pub fn get_half_size(&self) -> Vec3
{
self.half_size.clone()
}
// INTERFACE METHODS
pub fn set_position(&mut self, position: Vec3)
{
self.min_extents = Vec3::new(
position.x - self.half_size.x,
position.y - self.half_size.y,
position.z - self.half_size.z);
self.max_extents = Vec3::new(
position.x + self.half_size.x,
position.y + self.half_size.y,
position.z + self.half_size.z);
}
pub fn set_size(&mut self, size: Vec3)
{
let center = self.get_center_point();
self.half_size = size * 0.5;
self.min_extents = Vec3::new(
center.x - self.half_size.x,
center.y - self.half_size.y,
center.z - self.half_size.z);
self.max_extents = Vec3::new(
center.x + self.half_size.x,
center.y + self.half_size.y,
center.z + self.half_size.z);
}
pub fn translate(&mut self, translation: Vec3)
{
self.min_extents.x += translation.x;
self.min_extents.y += translation.y;
self.min_extents.z += translation.z;
self.max_extents.x += translation.x;
self.max_extents.y += translation.y;
self.max_extents.z += translation.z;
}
pub fn contains_point(&self, test_point: Vec3) -> bool
{
if test_point.x < self.min_extents.x { return false; }
if test_point.y < self.min_extents.y { return false; }
if test_point.z < self.min_extents.z { return false; }
if test_point.x > self.max_extents.x { return false; }
if test_point.y > self.max_extents.y { return false; }
if test_point.z > self.max_extents.z { return false; }
true
}
pub fn intersects_with(&self, other: &AABB) -> bool
{
if self.min_extents.x > other.max_extents.x ||
other.min_extents.x > self.max_extents.x { return false }
if self.min_extents.y > other.max_extents.y ||
other.min_extents.y > self.max_extents.y { return false }
if self.min_extents.z > other.max_extents.z ||
other.min_extents.z > self.max_extents.z { return false }
true
}
}
#[derive(Component)]
pub struct ColliderDebug;

@ -1,31 +0,0 @@
pub mod components;
pub mod systems;
use bevy::{pbr::wireframe::WireframePlugin, prelude::*};
pub struct PhysicsPlugin
{
pub debug_draw_colliders: bool,
}
impl Plugin for PhysicsPlugin
{
fn build(&self, app: &mut App)
{
app.add_plugins(WireframePlugin)
.add_systems(Update, systems::update_movement);
if self.debug_draw_colliders
{
app.add_systems(Update, systems::debug_draw_aabbs);
}
}
}
impl Default for PhysicsPlugin
{
fn default() -> Self {
Self { debug_draw_colliders: false }
}
}

@ -1,77 +0,0 @@
use bevy::{pbr::wireframe::{Wireframe, WireframeColor}, prelude::*};
use crate::components::{ColliderDebug, Velocity, AABB};
pub(crate) fn update_movement(mut moving_objects: Query<(&Velocity, &mut Transform)>, time: Res<Time>)
{
for (velocity, mut transform) in moving_objects.iter_mut()
{
transform.translation += velocity.value * time.delta_seconds();
}
}
pub(crate) fn update_colliders()
{
todo!()
}
pub(crate) fn debug_draw_aabbs(
mut commands: Commands,
aabbs: Query<(Entity, &AABB), Without<ColliderDebug>>,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>
){
// TODO: Spawn one of these for each collider in the scene,
// need to set the scale, rotation and translation to match the AABB
for (entity, _aabb) in aabbs.iter()
{
let cube_mesh_handle: Handle<Mesh> = meshes.add(Cuboid::default());
commands.entity(entity).insert((PbrBundle
{
mesh: cube_mesh_handle,
material: materials.add(StandardMaterial
{
base_color: Color::Rgba { red: 0.0, green: 1.0, blue: 0.0, alpha: 0.25 },
alpha_mode: AlphaMode::Blend,
..default()
}),
transform: Transform::from_xyz(0.0, 7.25, -1.0)
//.with_rotation(Quat::from_rotation_y(45.0))
.with_rotation(Quat::from_rotation_x(45.0)),
..default()
},
Wireframe,
WireframeColor { color: Color::GREEN },
));
}
// TEST CUBE
// Spawns a cube with a colored wireframe and partially transparent body
// Should be able to update the material on the fly to change the colors
// to red when the AABB is intersecting another AABB
// commands.spawn((PbrBundle {
// mesh: cube_mesh_handle,
// material: materials.add(StandardMaterial {
// base_color: Color::Rgba { red: 0.0, green: 1.0, blue: 0.0, alpha: 0.25 },
// alpha_mode: AlphaMode::Blend,
// ..default()
// }),
// transform: Transform::from_xyz(0.0, 7.25, -1.0)
// //.with_rotation(Quat::from_rotation_y(45.0))
// .with_rotation(Quat::from_rotation_x(45.0)),
// ..default()
// },
// Wireframe, WireframeColor { color: Color::GREEN },
// ));
}
pub(crate) fn debug_update_colliders(colliders: Query<&ColliderDebug>)
{
}
Loading…
Cancel
Save