mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
Entity has bounding box
This commit is contained in:
parent
de5a41a960
commit
ea288d4ba8
9 changed files with 101 additions and 26 deletions
3
azalea-core/README.md
Normal file
3
azalea-core/README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Azalea Core
|
||||
|
||||
Miscellaneous things in Azalea.
|
|
@ -1,9 +1,9 @@
|
|||
use crate::BlockHitResult;
|
||||
use azalea_core::{Axis, BlockPos, Direction, PositionXYZ, Vec3};
|
||||
use crate::{Axis, BlockHitResult, BlockPos, Direction, PositionXYZ, Vec3};
|
||||
|
||||
pub const EPSILON: f64 = 1.0E-7;
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
/// A rectangular prism with a starting and ending point.
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Default)]
|
||||
pub struct AABB {
|
||||
pub min_x: f64,
|
||||
pub min_y: f64,
|
|
@ -1,4 +1,4 @@
|
|||
use azalea_core::{BlockPos, Direction, Vec3};
|
||||
use crate::{BlockPos, Direction, Vec3};
|
||||
|
||||
pub struct BlockHitResult {
|
||||
pub location: Vec3,
|
|
@ -32,6 +32,12 @@ pub use cursor3d::*;
|
|||
mod bitset;
|
||||
pub use bitset::*;
|
||||
|
||||
mod aabb;
|
||||
pub use aabb::*;
|
||||
|
||||
mod block_hit_result;
|
||||
pub use block_hit_result::*;
|
||||
|
||||
// java moment
|
||||
// TODO: add tests and optimize/simplify this
|
||||
pub fn floor_mod(x: i32, y: u32) -> u32 {
|
||||
|
|
23
azalea-entity/src/dimensions.rs
Normal file
23
azalea-entity/src/dimensions.rs
Normal file
|
@ -0,0 +1,23 @@
|
|||
use azalea_core::{Vec3, AABB};
|
||||
|
||||
#[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,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
mod data;
|
||||
mod dimensions;
|
||||
|
||||
use azalea_core::{PositionDelta, Vec3};
|
||||
use azalea_core::{PositionDelta, Vec3, AABB};
|
||||
pub use data::*;
|
||||
pub use dimensions::*;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
|
@ -17,10 +19,19 @@ pub struct Entity {
|
|||
|
||||
pub x_rot: f32,
|
||||
pub y_rot: f32,
|
||||
|
||||
/// The width and height of the entity.
|
||||
pub dimensions: EntityDimensions,
|
||||
/// The bounding box of the entity. This is more than just width and height, unlike dimensions.
|
||||
pub bounding_box: AABB,
|
||||
}
|
||||
|
||||
impl Entity {
|
||||
pub fn new(id: u32, uuid: Uuid, pos: Vec3) -> Self {
|
||||
let dimensions = EntityDimensions {
|
||||
width: 0.8,
|
||||
height: 1.8,
|
||||
};
|
||||
Self {
|
||||
id,
|
||||
uuid,
|
||||
|
@ -29,6 +40,9 @@ impl Entity {
|
|||
delta: PositionDelta::default(),
|
||||
x_rot: 0.0,
|
||||
y_rot: 0.0,
|
||||
// TODO: have this be based on the entity type
|
||||
bounding_box: dimensions.make_bounding_box(&pos),
|
||||
dimensions: dimensions,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{aabb::EPSILON, ArrayVoxelShape, VoxelShape, AABB};
|
||||
use crate::{ArrayVoxelShape, VoxelShape, AABB};
|
||||
use azalea_block::{Block, BlockState};
|
||||
use azalea_core::{ChunkPos, ChunkSectionPos, Cursor3d, CursorIterationType};
|
||||
use azalea_core::{ChunkPos, ChunkSectionPos, Cursor3d, CursorIterationType, EPSILON};
|
||||
use azalea_entity::Entity;
|
||||
use azalea_world::{Chunk, Dimension};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
mod aabb;
|
||||
mod block_hit_result;
|
||||
mod dimension_collisions;
|
||||
mod discrete_voxel_shape;
|
||||
mod shape;
|
||||
|
||||
pub use aabb::*;
|
||||
use azalea_core::{Axis, PositionDelta, PositionXYZ, Vec3};
|
||||
use azalea_core::{Axis, PositionDelta, PositionXYZ, Vec3, AABB};
|
||||
use azalea_entity::Entity;
|
||||
use azalea_world::Dimension;
|
||||
pub use block_hit_result::*;
|
||||
use dimension_collisions::CollisionGetter;
|
||||
pub use discrete_voxel_shape::*;
|
||||
pub use shape::*;
|
||||
|
@ -23,6 +19,7 @@ pub enum MoverType {
|
|||
|
||||
trait HasPhysics {
|
||||
fn move_entity(&mut self, mover_type: &MoverType, movement: &PositionDelta);
|
||||
fn collide(&self, movement: &Vec3, dimension: &Dimension) -> Vec3;
|
||||
fn collide_bounding_box(
|
||||
entity: Option<&Self>,
|
||||
movement: &Vec3,
|
||||
|
@ -60,19 +57,52 @@ impl HasPhysics for Entity {
|
|||
// TODO
|
||||
}
|
||||
|
||||
// fn collide(movement: &Vec3, dimension: &Dimension) -> Vec3 {
|
||||
// if movement.length_sqr() == 0.0 {
|
||||
// *movement
|
||||
// } else {
|
||||
// // Self::collide_bounding_box(
|
||||
// // Some(self),
|
||||
// // movement,
|
||||
// // entityBoundingBox,
|
||||
// // this.level,
|
||||
// // entityCollisions,
|
||||
// // )
|
||||
// private Vec3 collide(Vec3 var1) {
|
||||
// AABB var2 = this.getBoundingBox();
|
||||
// List var3 = this.level.getEntityCollisions(this, var2.expandTowards(var1));
|
||||
// Vec3 var4 = var1.lengthSqr() == 0.0D ? var1 : collideBoundingBox(this, var1, var2, this.level, var3);
|
||||
// boolean var5 = var1.x != var4.x;
|
||||
// boolean var6 = var1.y != var4.y;
|
||||
// boolean var7 = var1.z != var4.z;
|
||||
// boolean var8 = this.onGround || var6 && var1.y < 0.0D;
|
||||
// if (this.maxUpStep > 0.0F && var8 && (var5 || var7)) {
|
||||
// Vec3 var9 = collideBoundingBox(this, new Vec3(var1.x, (double)this.maxUpStep, var1.z), var2, this.level, var3);
|
||||
// Vec3 var10 = collideBoundingBox(this, new Vec3(0.0D, (double)this.maxUpStep, 0.0D), var2.expandTowards(var1.x, 0.0D, var1.z), this.level, var3);
|
||||
// if (var10.y < (double)this.maxUpStep) {
|
||||
// Vec3 var11 = collideBoundingBox(this, new Vec3(var1.x, 0.0D, var1.z), var2.move(var10), this.level, var3).add(var10);
|
||||
// if (var11.horizontalDistanceSqr() > var9.horizontalDistanceSqr()) {
|
||||
// var9 = var11;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (var9.horizontalDistanceSqr() > var4.horizontalDistanceSqr()) {
|
||||
// return var9.add(collideBoundingBox(this, new Vec3(0.0D, -var9.y + var1.y, 0.0D), var2.move(var9), this.level, var3));
|
||||
// }
|
||||
// }
|
||||
|
||||
// return var4;
|
||||
// }
|
||||
fn collide(&self, movement: &Vec3, dimension: &Dimension) -> Vec3 {
|
||||
let entity_bounding_box = self.bounding_box;
|
||||
// TODO: get_entity_collisions
|
||||
// let entity_collisions = dimension.get_entity_collisions(self, entity_bounding_box.expand_towards(movement));
|
||||
let entity_collisions = Vec::new();
|
||||
let collided_movement = if movement.length_sqr() == 0.0 {
|
||||
*movement
|
||||
} else {
|
||||
Self::collide_bounding_box(
|
||||
Some(self),
|
||||
movement,
|
||||
&entity_bounding_box,
|
||||
dimension,
|
||||
entity_collisions,
|
||||
)
|
||||
};
|
||||
|
||||
// TODO: stepping (for stairs and stuff)
|
||||
|
||||
collided_movement
|
||||
}
|
||||
|
||||
fn collide_bounding_box(
|
||||
entity: Option<&Self>,
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use azalea_core::{binary_search, Axis, AxisCycle};
|
||||
|
||||
use crate::{BitSetDiscreteVoxelShape, DiscreteVoxelShape, AABB, EPSILON};
|
||||
use crate::{BitSetDiscreteVoxelShape, DiscreteVoxelShape, AABB};
|
||||
use azalea_core::{binary_search, Axis, AxisCycle, EPSILON};
|
||||
use std::{cmp, ops::Add};
|
||||
|
||||
pub struct Shapes {}
|
||||
|
|
Loading…
Add table
Reference in a new issue