You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.8 KiB
62 lines
1.8 KiB
2 years ago
|
using System;
|
||
|
using System.Collections.Immutable;
|
||
|
using Silk.NET.Maths;
|
||
|
|
||
|
namespace gaemstone.Bloxel;
|
||
|
|
||
|
public enum BlockFacing
|
||
|
{
|
||
|
East, // +X
|
||
|
West, // -X
|
||
|
Up, // +Y
|
||
|
Down, // -Y
|
||
|
South, // +Z
|
||
|
North, // -Z
|
||
|
}
|
||
|
|
||
|
public static class BlockFacings
|
||
|
{
|
||
|
public static readonly ImmutableHashSet<BlockFacing> Horizontals
|
||
|
= ImmutableHashSet.Create(BlockFacing.East , BlockFacing.West ,
|
||
|
BlockFacing.South, BlockFacing.North);
|
||
|
|
||
|
public static readonly ImmutableHashSet<BlockFacing> Verticals
|
||
|
= ImmutableHashSet.Create(BlockFacing.Up, BlockFacing.Down);
|
||
|
|
||
|
public static readonly ImmutableHashSet<BlockFacing> All
|
||
|
= Horizontals.Union(Verticals);
|
||
|
}
|
||
|
|
||
|
public static class BlockFacingExtensions
|
||
|
{
|
||
|
public static void Deconstruct(this BlockFacing self, out int x, out int y, out int z)
|
||
|
=> (x, y, z) = self switch {
|
||
|
BlockFacing.East => (+1, 0, 0),
|
||
|
BlockFacing.West => (-1, 0, 0),
|
||
|
BlockFacing.Up => ( 0, +1, 0),
|
||
|
BlockFacing.Down => ( 0, -1, 0),
|
||
|
BlockFacing.South => ( 0, 0, +1),
|
||
|
BlockFacing.North => ( 0, 0, -1),
|
||
|
_ => throw new ArgumentException(
|
||
|
$"'{self}' is not a valid BlockFacing", nameof(self))
|
||
|
};
|
||
|
|
||
|
public static bool IsValid(this BlockFacing self)
|
||
|
=> (self >= BlockFacing.East) && (self <= BlockFacing.North);
|
||
|
|
||
|
public static BlockFacing GetOpposite(this BlockFacing self)
|
||
|
=> (BlockFacing)((int)self ^ 0b1);
|
||
|
|
||
|
public static Vector3D<float> ToVector3(this BlockFacing self)
|
||
|
=> self switch {
|
||
|
BlockFacing.East => Vector3D<float>.UnitX,
|
||
|
BlockFacing.West => -Vector3D<float>.UnitX,
|
||
|
BlockFacing.Up => Vector3D<float>.UnitY,
|
||
|
BlockFacing.Down => -Vector3D<float>.UnitY,
|
||
|
BlockFacing.South => Vector3D<float>.UnitZ,
|
||
|
BlockFacing.North => -Vector3D<float>.UnitZ,
|
||
|
_ => throw new ArgumentException(
|
||
|
$"'{self}' is not a valid BlockFacing", nameof(self))
|
||
|
};
|
||
|
}
|