Compare commits

..

No commits in common. '0c630d000e674812b4fee24213ad0c767afc2d94' and '236bb69be1b45aa50de8b1fd1330c6a930f771cf' have entirely different histories.

@ -1,14 +1,14 @@
use bevy::{pbr::wireframe::{Wireframe, WireframePlugin}, prelude::*}; use bevy::prelude::*;
use physics::{components::{Velocity, AABB}, PhysicsPlugin}; use physics::{PhysicsPlugin, components::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(PhysicsPlugin)
.add_systems(Startup, setup); .add_systems(Startup, setup);
} }
} }
@ -35,19 +35,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, 7.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");

@ -43,14 +43,6 @@ impl AABB
} }
} }
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 // ACCESSORS
pub fn get_center_point(&self) -> Vec3 pub fn get_center_point(&self) -> Vec3
{ {
@ -132,6 +124,3 @@ impl AABB
true true
} }
} }
#[derive(Component)]
pub struct ColliderDebug;

@ -2,30 +2,13 @@
pub mod components; pub mod components;
pub mod systems; pub mod systems;
use bevy::{pbr::wireframe::WireframePlugin, prelude::*}; use bevy::prelude::*;
pub struct PhysicsPlugin
{
pub debug_draw_colliders: bool,
}
pub struct PhysicsPlugin;
impl Plugin for PhysicsPlugin impl Plugin for PhysicsPlugin
{ {
fn build(&self, app: &mut App) fn build(&self, app: &mut App)
{ {
app.add_plugins(WireframePlugin) app.add_systems(Update, systems::update_movement);
.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,7 +1,7 @@
use bevy::{pbr::wireframe::{Wireframe, WireframeColor}, prelude::*}; use bevy::prelude::*;
use crate::components::{ColliderDebug, Velocity, AABB}; use crate::components::Velocity;
pub(crate) fn update_movement(mut moving_objects: Query<(&Velocity, &mut Transform)>, time: Res<Time>) pub(crate) fn update_movement(mut moving_objects: Query<(&Velocity, &mut Transform)>, time: Res<Time>)
{ {
@ -11,67 +11,3 @@ pub(crate) fn update_movement(mut moving_objects: Query<(&Velocity, &mut Transfo
} }
} }
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