Use up to 2 AABBs for fence collision checks instead of 5

overlapping cuboids do fine
This commit is contained in:
Dylan K. Taylor 2017-10-13 09:40:29 +01:00
parent 7b5df10b6a
commit 21c79b0645

View File

@ -52,72 +52,51 @@ abstract class Fence extends Transparent{
protected function recalculateCollisionBoxes() : array{ protected function recalculateCollisionBoxes() : array{
$inset = 0.5 - $this->getThickness() / 2; $inset = 0.5 - $this->getThickness() / 2;
$bbs = [ /** @var AxisAlignedBB[] $bbs */
new AxisAlignedBB( //centre post AABB $bbs = [];
$this->x + $inset,
$this->y,
$this->z + $inset,
$this->x + 1 - $inset,
$this->y + 1.5,
$this->z + 1 - $inset
)
];
if($this->canConnect($this->getSide(Vector3::SIDE_WEST))){ $connectWest = $this->canConnect($this->getSide(Vector3::SIDE_WEST));
//western side connected part from start X to post (negative X) $connectEast = $this->canConnect($this->getSide(Vector3::SIDE_EAST));
//
// -# if($connectWest or $connectEast){
// //X axis (west/east)
$bbs[] = new AxisAlignedBB( $bbs[] = new AxisAlignedBB(
$this->x, $this->x + ($connectWest ? 0 : $inset),
$this->y, $this->y,
$this->z + $inset, $this->z + $inset,
$this->x + $inset, //don't overlap with centre post $this->x + 1 - ($connectEast ? 0 : $inset),
$this->y + 1.5, $this->y + 1.5,
$this->z + 1 - $inset $this->z + 1 - $inset
); );
} }
if($this->canConnect($this->getSide(Vector3::SIDE_EAST))){
//eastern side connected part from post to end X (positive X) $connectNorth = $this->canConnect($this->getSide(Vector3::SIDE_NORTH));
// $connectSouth = $this->canConnect($this->getSide(Vector3::SIDE_SOUTH));
// #-
// if($connectNorth or $connectSouth){
$bbs[] = new AxisAlignedBB( //Z axis (north/south)
$this->x + 1 - $inset,
$this->y,
$this->z + $inset,
$this->x + 1,
$this->y + 1.5,
$this->z + 1 - $inset
);
}
if($this->canConnect($this->getSide(Vector3::SIDE_NORTH))){
//northern side connected part from start Z to post (negative Z)
// |
// #
//
$bbs[] = new AxisAlignedBB( $bbs[] = new AxisAlignedBB(
$this->x + $inset, $this->x + $inset,
$this->y, $this->y,
$this->z, $this->z + ($connectNorth ? 0 : $inset),
$this->x + 1 - $inset, $this->x + 1 - $inset,
$this->y + 1.5, $this->y + 1.5,
$this->z + $inset $this->z + 1 - ($connectSouth ? 0 : $inset)
); );
} }
if($this->canConnect($this->getSide(Vector3::SIDE_SOUTH))){
//southern side connected part from post to end Z (positive Z) if(empty($bbs)){
// //centre post AABB (only needed if not connected on any axis - other BBs overlapping will do this if any connections are made)
// # return [
// | new AxisAlignedBB(
$bbs[] = new AxisAlignedBB( $this->x + $inset,
$this->x + $inset, $this->y,
$this->y, $this->z + $inset,
$this->z + 1 - $inset, $this->x + 1 - $inset,
$this->x + 1 - $inset, $this->y + 1.5,
$this->y + 1.5, $this->z + 1 - $inset
$this->z + 1 )
); ];
} }
return $bbs; return $bbs;