1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00
azalea/azalea-world/src/entity/dimensions.rs
mat 719379a8a7
Bevy 0.10 (#79)
* replace 0.9.1 with 0.10.0

* start migrating to bevy .10

* well it compiles

* doesn't immediately panic

* remove unused imports

* fmt

* delete azalea-ecs

* make RelativeEntityUpdate an EntityCommand

* fix a doc test

* explain what FixedUpdate does
2023-03-07 14:14:36 -06:00

38 lines
1.1 KiB
Rust
Executable file

use azalea_core::{Vec3, AABB};
use bevy_ecs::{query::Changed, system::Query};
use super::{Physics, Position};
#[derive(Debug, Default)]
pub struct EntityDimensions {
pub width: f32,
pub height: f32,
}
impl EntityDimensions {
pub fn make_bounding_box(&self, pos: &Vec3) -> AABB {
let radius = (self.width / 2.0) as f64;
let height = self.height as f64;
AABB {
min_x: pos.x - radius,
min_y: pos.y,
min_z: pos.z - radius,
max_x: pos.x + radius,
max_y: pos.y + height,
max_z: pos.z + radius,
}
}
}
/// Sets the position of the entity. This doesn't update the cache in
/// azalea-world, and should only be used within azalea-world!
///
/// # Safety
/// Cached position in the world must be updated.
pub fn update_bounding_box(mut query: Query<(&Position, &mut Physics), Changed<Position>>) {
for (position, mut physics) in query.iter_mut() {
let bounding_box = physics.dimensions.make_bounding_box(position);
physics.bounding_box = bounding_box;
}
}