public void BuildFloor(Voxel floorMap, Voxel.Coord floorCoordinate, Direction forwardDir, Direction rightDir) { List <EffectBlockFactory.BlockBuildOrder> buildCoords = new List <EffectBlockFactory.BlockBuildOrder>(); Voxel.Coord newFloorCoordinate = floorMap.GetCoordinate(this.Position); floorCoordinate.SetComponent(rightDir, newFloorCoordinate.GetComponent(rightDir)); floorCoordinate.SetComponent(forwardDir, newFloorCoordinate.GetComponent(forwardDir)); Direction upDir = floorMap.GetRelativeDirection(Direction.PositiveY); const int radius = 3; foreach (Voxel.Coord x in this.spreadFromCenter(floorCoordinate, rightDir)) { if (floorMap[x.Move(upDir)].Hard) { break; } int dx = x.GetComponent(rightDir) - floorCoordinate.GetComponent(rightDir); for (Voxel.Coord y = x.Move(forwardDir, -radius); y.GetComponent(forwardDir) < floorCoordinate.GetComponent(forwardDir) + radius; y = y.Move(forwardDir)) { if (floorMap[y.Move(upDir)].Hard) { break; } int dy = y.GetComponent(forwardDir) - floorCoordinate.GetComponent(forwardDir); if ((float)Math.Sqrt(dx * dx + dy * dy) < radius && floorMap[y].ID == 0) { buildCoords.Add(new EffectBlockFactory.BlockBuildOrder { Voxel = floorMap, Coordinate = y, State = Voxel.States.Blue, }); } } } Factory.Get <EffectBlockFactory>().Build(this.main, buildCoords, this.Position); }
public static void Consolidate(Main main, DynamicVoxel voxel, Voxel targetVoxel, Voxel.Coord targetCoord, float interval = 1.0f) { if (targetVoxel != null) { // Combine this map with the other one Direction x = targetVoxel.GetRelativeDirection(voxel.GetAbsoluteVector(Vector3.Right)); Direction y = targetVoxel.GetRelativeDirection(voxel.GetAbsoluteVector(Vector3.Up)); Direction z = targetVoxel.GetRelativeDirection(voxel.GetAbsoluteVector(Vector3.Backward)); if (x.IsParallel(y)) { x = y.Cross(z); } else if (y.IsParallel(z)) { y = x.Cross(z); } Voxel.Coord offset = new Voxel.Coord(); float closestCoordDistance = float.MaxValue; Vector3 closestCoordPosition = targetVoxel.GetAbsolutePosition(targetCoord); foreach (Voxel.Coord c in voxel.Chunks.SelectMany(c => c.Boxes).SelectMany(b => b.GetCoords())) { float distance = (voxel.GetAbsolutePosition(c) - closestCoordPosition).LengthSquared(); if (distance < closestCoordDistance) { closestCoordDistance = distance; offset = c; } } Vector3 toLevitatingMap = voxel.Transform.Value.Translation - targetVoxel.GetAbsolutePosition(targetCoord); offset = offset.Move(voxel.GetRelativeDirection(-toLevitatingMap)); Quaternion orientation = Quaternion.CreateFromRotationMatrix(voxel.Transform.Value); EffectBlockFactory blockFactory = Factory.Get <EffectBlockFactory>(); int index = 0; List <Voxel.Coord> coords = voxel.Chunks.SelectMany(c => c.Boxes).SelectMany(b => b.GetCoords()).ToList(); Voxel.Coord camera = voxel.GetCoordinate(main.Camera.Position); foreach (Voxel.Coord c in coords.OrderBy(c2 => new Vector3(c2.X - camera.X, c2.Y - camera.Y, c2.Z - camera.Z).LengthSquared())) { Voxel.Coord offsetFromCenter = c.Move(-offset.X, -offset.Y, -offset.Z); Voxel.Coord targetCoord2 = new Voxel.Coord(); targetCoord2.SetComponent(x, offsetFromCenter.GetComponent(Direction.PositiveX)); targetCoord2.SetComponent(y, offsetFromCenter.GetComponent(Direction.PositiveY)); targetCoord2.SetComponent(z, offsetFromCenter.GetComponent(Direction.PositiveZ)); targetCoord2 = targetCoord2.Move(targetCoord.X, targetCoord.Y, targetCoord.Z); if (targetVoxel[targetCoord2].ID == 0) { Entity blockEntity = blockFactory.CreateAndBind(main); c.Data.ApplyToEffectBlock(blockEntity.Get <ModelInstance>()); EffectBlock effectBlock = blockEntity.Get <EffectBlock>(); effectBlock.Offset.Value = targetVoxel.GetRelativePosition(targetCoord2); effectBlock.DoScale = false; effectBlock.StartPosition = voxel.GetAbsolutePosition(c); effectBlock.StartOrientation = orientation; effectBlock.TotalLifetime = (0.05f + (index * 0.0075f)) * interval; effectBlock.Setup(targetVoxel.Entity, targetCoord2, c.Data.ID); main.Add(blockEntity); index++; } } // Delete the map voxel.Entity.Delete.Execute(); } }
public static void Consolidate(Main main, DynamicVoxel voxel, Voxel targetVoxel, Voxel.Coord targetCoord, float interval = 1.0f) { if (targetVoxel != null) { // Combine this map with the other one Direction x = targetVoxel.GetRelativeDirection(voxel.GetAbsoluteVector(Vector3.Right)); Direction y = targetVoxel.GetRelativeDirection(voxel.GetAbsoluteVector(Vector3.Up)); Direction z = targetVoxel.GetRelativeDirection(voxel.GetAbsoluteVector(Vector3.Backward)); if (x.IsParallel(y)) x = y.Cross(z); else if (y.IsParallel(z)) y = x.Cross(z); Voxel.Coord offset = new Voxel.Coord(); float closestCoordDistance = float.MaxValue; Vector3 closestCoordPosition = targetVoxel.GetAbsolutePosition(targetCoord); lock (voxel.MutationLock) { foreach (Voxel.Coord c in voxel.Chunks.SelectMany(c => c.Boxes).SelectMany(b => b.GetCoords())) { float distance = (voxel.GetAbsolutePosition(c) - closestCoordPosition).LengthSquared(); if (distance < closestCoordDistance) { closestCoordDistance = distance; offset = c; } } } Vector3 toLevitatingMap = voxel.Transform.Value.Translation - targetVoxel.GetAbsolutePosition(targetCoord); offset = offset.Move(voxel.GetRelativeDirection(-toLevitatingMap)); Quaternion orientation = Quaternion.CreateFromRotationMatrix(voxel.Transform.Value); EffectBlockFactory blockFactory = Factory.Get<EffectBlockFactory>(); int index = 0; List<Voxel.Coord> coords; lock (voxel.MutationLock) coords = voxel.Chunks.SelectMany(c => c.Boxes).SelectMany(b => b.GetCoords()).ToList(); Voxel.Coord camera = voxel.GetCoordinate(main.Camera.Position); foreach (Voxel.Coord c in coords.OrderBy(c2 => new Vector3(c2.X - camera.X, c2.Y - camera.Y, c2.Z - camera.Z).LengthSquared())) { Voxel.Coord offsetFromCenter = c.Move(-offset.X, -offset.Y, -offset.Z); Voxel.Coord targetCoord2 = new Voxel.Coord(); targetCoord2.SetComponent(x, offsetFromCenter.GetComponent(Direction.PositiveX)); targetCoord2.SetComponent(y, offsetFromCenter.GetComponent(Direction.PositiveY)); targetCoord2.SetComponent(z, offsetFromCenter.GetComponent(Direction.PositiveZ)); targetCoord2 = targetCoord2.Move(targetCoord.X, targetCoord.Y, targetCoord.Z); if (targetVoxel[targetCoord2].ID == 0) { Entity blockEntity = blockFactory.CreateAndBind(main); c.Data.ApplyToEffectBlock(blockEntity.Get<ModelInstance>()); EffectBlock effectBlock = blockEntity.Get<EffectBlock>(); effectBlock.Offset.Value = targetVoxel.GetRelativePosition(targetCoord2); effectBlock.DoScale = false; effectBlock.StartPosition = voxel.GetAbsolutePosition(c); effectBlock.StartOrientation = orientation; effectBlock.TotalLifetime = (0.05f + (index * 0.0075f)) * interval; effectBlock.Setup(targetVoxel.Entity, targetCoord2, c.Data.ID); main.Add(blockEntity); index++; } } // Delete the map voxel.Entity.Delete.Execute(); } }