public bool RayIntersectsBlockSelectionBox(BlockPos pos, BlockFilter filter) { if (filter?.Invoke(pos, blockSelectionTester.GetBlock(pos)) == false) { return(false); } Cuboidf[] selectionBoxes = blockSelectionTester.GetBlockIntersectionBoxes(pos); if (selectionBoxes == null) { return(false); } bool intersects = false; bool wasDecor = false; for (int i = 0; i < selectionBoxes.Length; i++) { tmpCuboidd.Set(selectionBoxes[i]).Translate(pos.X, pos.Y, pos.Z); if (RayIntersectsWithCuboid(tmpCuboidd, ref hitOnBlockFaceTmp, ref hitPositionTmp)) { bool isDecor = selectionBoxes[i] is DecorSelectionBox; if (intersects && (!wasDecor || isDecor) && hitPosition.SquareDistanceTo(ray.origin) <= hitPositionTmp.SquareDistanceTo(ray.origin)) { continue; } hitOnSelectionBox = i; intersects = true; wasDecor = isDecor; hitOnBlockFace = hitOnBlockFaceTmp; hitPosition.Set(hitPositionTmp); } } if (intersects && selectionBoxes[hitOnSelectionBox] is DecorSelectionBox dsb) { Vec3i posAdjust = dsb.PosAdjust; if (posAdjust != null) { pos.Add(posAdjust); } } return(intersects); }
/// <summary> /// Expands this in the given direction by amount d /// </summary> public void Expand(BlockFacing face, float d) { switch (face.Index) { case BlockFacing.indexNORTH: Z1 -= d; break; case BlockFacing.indexEAST: X2 += d; break; case BlockFacing.indexSOUTH: Z2 += d; break; case BlockFacing.indexWEST: X1 -= d; break; case BlockFacing.indexUP: Y2 += d; break; case BlockFacing.indexDOWN: Y1 -= d; break; } }
public static BlockFacing FromNormal(Vec3f vec) { float smallestAngle = GameMath.PI; BlockFacing facing = null; for (int i = 0; i < ALLFACES.Length; i++) { BlockFacing f = ALLFACES[i]; float angle = (float)Math.Acos(f.Normalf.Dot(vec)); if (angle < smallestAngle) { smallestAngle = angle; facing = f; } } return(facing); }
public Vec3i AddCopy(BlockFacing facing) { return(new Vec3i(X + facing.Normali.X, Y + facing.Normali.Y, Z + facing.Normali.Z)); }
internal void Offset(BlockFacing face) { this.X += face.Normali.X; this.Y += face.Normali.Y; this.Z += face.Normali.Z; }
/// <summary> /// Creates a copy of this blocks position and offsets it in the direction of given block face /// </summary> /// <param name="facing"></param> /// <param name="length"></param> /// <returns></returns> public BlockPos AddCopy(BlockFacing facing, int length) { return(new BlockPos(X + facing.Normali.X * length, Y + facing.Normali.Y * length, Z + facing.Normali.Z * length)); }
/// <summary> /// Creates a copy of this blocks position and offsets it in the direction of given block face /// </summary> /// <param name="facing"></param> /// <returns></returns> public BlockPos AddCopy(BlockFacing facing) { return(new BlockPos(X + facing.Normali.X, Y + facing.Normali.Y, Z + facing.Normali.Z)); }
public Vec3d AddCopy(BlockFacing facing) { return(new Vec3d(X + facing.Normalf.X, Y + facing.Normalf.Y, Z + facing.Normalf.Z)); }
/// <summary> /// Returns true if given byte flags contain given face /// </summary> /// <param name="flag"></param> /// <param name="facing"></param> /// <returns></returns> public static bool FlagContains(byte flag, BlockFacing facing) { return((flag & facing.flag) > 0); }