From 119541a2b1176f24e4ea3fac8ca73018e40eab2e Mon Sep 17 00:00:00 2001 From: Bixilon Date: Thu, 10 Jun 2021 12:35:51 +0200 Subject: [PATCH] entities: hit box: eye padding --- .../minosoft/gui/rendering/chunk/models/AABB.kt | 13 +++++++++++++ .../gui/rendering/entities/EntityHitBoxMesh.kt | 6 +++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/models/AABB.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/models/AABB.kt index e5375e6ea..972969926 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/models/AABB.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/models/AABB.kt @@ -179,6 +179,19 @@ class AABB( return (position.x in min.x..max.x && position.y in min.y..max.y && position.z in min.z..max.z) } + fun shrink(size: Float): AABB { + return AABB(min + size, max - size) + } + + fun hShrink(size: Float): AABB { + val vec = Vec3d(size, 0.0, size) + return AABB(min + vec, max - vec) + } + + fun shrink(size: Double): AABB { + return AABB(min + size, max - size) + } + val center: Vec3d get() = Vec3d((min.x + max.x) / 2.0, (min.y + max.y) / 2.0, (min.z + max.z) / 2.0) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/entities/EntityHitBoxMesh.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/entities/EntityHitBoxMesh.kt index 17cb694f3..b889d0653 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/entities/EntityHitBoxMesh.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/entities/EntityHitBoxMesh.kt @@ -27,14 +27,14 @@ class EntityHitBoxMesh( val aabb = entity.aabb init { - val hitboxColor = when { + val hitBoxColor = when { entity.isInvisible -> Minosoft.config.config.game.entities.hitBox.invisibleEntitiesColor else -> Minosoft.config.config.game.entities.hitBox.hitBoxColor } - drawAABB(entity.aabb, Vec3d.EMPTY, LINE_WIDTH, hitboxColor) + drawAABB(entity.aabb, Vec3d.EMPTY, LINE_WIDTH, hitBoxColor) val halfWidth = entity.dimensions.x / 2 - val eyeAABB = AABB(Vec3(-halfWidth, entity.eyeHeight - LINE_WIDTH, -halfWidth), Vec3(halfWidth, entity.eyeHeight - LINE_WIDTH, halfWidth)) + val eyeAABB = AABB(Vec3(-halfWidth, entity.eyeHeight - LINE_WIDTH, -halfWidth), Vec3(halfWidth, entity.eyeHeight - LINE_WIDTH, halfWidth)).hShrink(LINE_WIDTH) drawAABB(eyeAABB, entity.position, LINE_WIDTH, Minosoft.config.config.game.entities.hitBox.eyeHeightColor) }