| | | 1 | | //======================================================================= |
| | | 2 | | // BoundsBlocker.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2024–present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | using FixedMathSharp; |
| | | 9 | | using FixedMathSharp.Geometry; |
| | | 10 | | using GridForge.Grids; |
| | | 11 | | |
| | | 12 | | namespace GridForge.Blockers; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// A manually placed blocker that obstructs a defined world-space bounding box. |
| | | 16 | | /// </summary> |
| | | 17 | | public class BoundsBlocker : Blocker |
| | | 18 | | { |
| | | 19 | | private readonly FixedBoundBox _blockBounds; |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// Initializes a new bounds blocker bound to the supplied world. |
| | | 23 | | /// </summary> |
| | | 24 | | /// <param name="world">The world whose grids this blocker should affect.</param> |
| | | 25 | | /// <param name="blockBounds">The bounding box to block.</param> |
| | | 26 | | /// <param name="isActive">Flag whether or not blocker is active.</param> |
| | | 27 | | /// <param name="cacheCoveredVoxels">Flag whether or not to cache covered voxels.</param> |
| | | 28 | | public BoundsBlocker( |
| | | 29 | | GridWorld world, |
| | | 30 | | FixedBoundBox blockBounds, |
| | | 31 | | bool isActive = true, |
| | 151 | 32 | | bool cacheCoveredVoxels = false) : base(world, isActive, cacheCoveredVoxels) |
| | | 33 | | { |
| | 151 | 34 | | _blockBounds = blockBounds; |
| | 151 | 35 | | } |
| | | 36 | | |
| | | 37 | | /// <summary> |
| | | 38 | | /// Initializes a new bounds blocker from world-space min/max bounds. |
| | | 39 | | /// </summary> |
| | | 40 | | /// <param name="world">The world whose grids this blocker should affect.</param> |
| | | 41 | | /// <param name="boundsMin">The world-space minimum bound.</param> |
| | | 42 | | /// <param name="boundsMax">The world-space maximum bound.</param> |
| | | 43 | | /// <param name="isActive">Flag whether or not blocker is active.</param> |
| | | 44 | | /// <param name="cacheCoveredVoxels">Flag whether or not to cache covered voxels.</param> |
| | | 45 | | public BoundsBlocker( |
| | | 46 | | GridWorld world, |
| | | 47 | | Vector3d boundsMin, |
| | | 48 | | Vector3d boundsMax, |
| | | 49 | | bool isActive = true, |
| | | 50 | | bool cacheCoveredVoxels = false) |
| | 1 | 51 | | : this( |
| | 1 | 52 | | world, |
| | 1 | 53 | | FixedBoundBox.FromMinMax(boundsMin, boundsMax), |
| | 1 | 54 | | isActive, |
| | 1 | 55 | | cacheCoveredVoxels) |
| | 1 | 56 | | { } |
| | | 57 | | |
| | | 58 | | /// <inheritdoc cref="Blocker.GetBoundsMin"/> |
| | 158 | 59 | | protected override Vector3d GetBoundsMin() => _blockBounds.Min; |
| | | 60 | | |
| | | 61 | | /// <inheritdoc cref="Blocker.GetBoundsMax"/> |
| | 158 | 62 | | protected override Vector3d GetBoundsMax() => _blockBounds.Max; |
| | | 63 | | } |