public static void WrapBlockCoords(int bx, int by, int bz, IndexPosition chunkIndex, out IndexPosition newBlockIndex, out IndexPosition newChunkIndex) { IndexPosition ipos = chunkIndex; if (bx < 0) { bx = HSIZE + bx; ipos.X--; } else if (bx >= HSIZE) { bx = bx - HSIZE; ipos.X++; } if (by < 0) { by = VSIZE + by; ipos.Y--; } else if (by >= VSIZE) { by = by - VSIZE; ipos.Y++; } if (bz < 0) { bz = HSIZE + bz; ipos.Z--; } else if (bz >= HSIZE) { bz = bz - HSIZE; ipos.Z++; } newBlockIndex = new IndexPosition(bx, by, bz); newChunkIndex = ipos; }
public void ShouldResolePosition() { IndexPosition position = new IndexPosition(); long index = position.At(9); Assert.That(index, Is.EqualTo(72)); }
public void ShrinkToFit() { CalculateMinMax(); IndexPosition newDim = Max - Min + new IndexPosition(1, 1, 1); Block[, ,] newData = new Block[newDim.Z, newDim.Y, newDim.X]; for (int x = 0; x <= Max.X; x++) { for (int y = 0; y <= Max.Y; y++) { for (int z = 0; z <= Max.Z; z++) { if (z < Min.Z || y < Min.Y || x < Min.X) { continue; } newData[z - Min.Z, y - Min.Y, x - Min.X] = Blocks[z, y, x]; } } } Blocks = newData; Width = newDim.X; Height = newDim.Y; Depth = newDim.Z; CalculateMinMax(); BuildMesh(); }
public IndexPosition WrapBlockCoords(ref int bx, ref int by, ref int bz) { IndexPosition ipos = IndexPosition; if (bx < 0) { bx = Width + bx; ipos.X--; } else if (bx >= Width) { bx = bx - Width; ipos.X++; } if (by < 0) { by = Height + by; ipos.Y--; } else if (by >= Height) { by = by - Height; ipos.Y++; } if (bz < 0) { bz = Depth + bz; ipos.Z--; } else if (bz >= Depth) { bz = bz - Depth; ipos.Z++; } return(ipos); }
public IndexPosition Update(float cubeSize, Camera camera) { if (!HasHold) { return(IndexPosition.Zero); } Vector3 newPos = camera.MouseRay.Direction * 2; Vector3 delta = (newPos - startPos) * 8 * cubeSize; IndexPosition iDelta = new IndexPosition( (int)(delta.X / cubeSize), (int)(delta.Y / cubeSize), (int)(delta.Z / cubeSize)); if (iDelta != IndexPosition.Zero) { if (Holding == Axis.X) { iDelta.Y = iDelta.Z = 0; } if (Holding == Axis.Y) { iDelta.X = iDelta.Z = 0; } if (Holding == Axis.Z) { iDelta.Y = iDelta.X = 0; } startPos = newPos; return(iDelta); } return(iDelta); }
public void TranslateTerrain(IndexPosition delta) { for (int x = 0; x < Terrain.Width * Chunk.HSIZE; x++) { for (int y = 0; y < Terrain.Height * Chunk.VSIZE; y++) { for (int z = 0; z < Terrain.Depth * Chunk.HSIZE; z++) { IndexPosition blockPos = new IndexPosition(x, y, z); IndexPosition newBlockPos = blockPos + delta; IndexPosition originChunkPos, originBlockPos; IndexPosition destChunkPos, destBlockPos; AceOfSpades.Terrain.GetLocalBlockCoords(blockPos, out originChunkPos, out originBlockPos); AceOfSpades.Terrain.GetLocalBlockCoords(newBlockPos, out destChunkPos, out destBlockPos); Chunk originChunk, destChunk; Terrain.Chunks.TryGetValue(originChunkPos, out originChunk); Terrain.Chunks.TryGetValue(destChunkPos, out destChunk); if (originChunk != null && destChunk != null && originChunk.IsBlockCoordInRange(originBlockPos)) { screen.WorldEditor.TerrainEditor.SetBlock(destChunk, originChunk[originBlockPos], destBlockPos); } } } } }
public void Update(float deltaTime) { UI.Update(deltaTime); if (Model != null) { Ray MouseRay = Camera.Active.MouseRay; IndexPosition blockNormalOffsetIndex = IndexPosition.Zero; IndexPosition MouseIndexPos = IndexPosition.Zero; CubeSide ModelSide = CubeSide.Bottom; Vector3 normal = Vector3.Zero; bool intersections = false; Color voxelColor = new Color(236, 157, 196); if (intersections = Model.RayIntersects(MouseRay, out MouseIndexPos, out ModelSide)) { normal = Maths.CubeSideToSurfaceNormal(ModelSide); blockNormalOffsetIndex = new IndexPosition( MouseIndexPos.X + (int)normal.X, MouseIndexPos.Y + (int)normal.Y, MouseIndexPos.Z + (int)normal.Z); } if (Model.IsBlockCoordInRange(MouseIndexPos) && intersections) { if (Input.GetMouseButtonDown(MouseButton.Left)) { Model.ChangeBlock(blockNormalOffsetIndex, new Block(1, voxelColor.R, voxelColor.G, voxelColor.B)); } } } }
void PopulateChunks() { int i = 0; for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { for (int z = 0; z < Depth; z++) { IndexPosition ipos = new IndexPosition(x, y, z); Chunk chunk = new Chunk(this, ipos, ChunkToWorldCoords(ipos)); Chunks.TryAdd(ipos, chunk); workers[i].Enqueue(chunk, TerrainWorkerAction.Populate); i++; if (i == workers.Length) { i = 0; } } } } }
void ApplyActionToBrush(IndexPosition chunkIndex, IndexPosition blockIndex, Action <Chunk, IndexPosition, int, int, int, float> action) { IndexPosition globalBlock = GetGlobalBlockCoords(chunkIndex, blockIndex); for (int x = -halfBrush; x <= halfBrush; x++) { for (int y = -halfBrush; y <= halfBrush; y++) { for (int z = -halfBrush; z <= halfBrush; z++) { float dist = (new Vector3(x, y, z)).Length; if (dist > halfBrush) { continue; } IndexPosition globalPos = globalBlock + new IndexPosition(x, y, z); IndexPosition cIndex, bIndex; GetLocalBlockCoords(globalPos, out cIndex, out bIndex); Chunk chunk; if (Terrain.Chunks.TryGetValue(cIndex, out chunk)) { action(chunk, bIndex, x, y, z, dist); } } } } }
protected override void Update(float deltaTime) { CharacterController.CanStep = !CharacterController.IsCrouching && !IsWalking; if (!GlobalNetwork.IsServer) { UpdateWorldModel(); Vector3 center = Transform.Position + Size / 2f; IndexPosition chunkIndex = new IndexPosition( (int)(center.X / Chunk.UNIT_HSIZE), (int)(center.Y / Chunk.UNIT_VSIZE), (int)(center.Z / Chunk.UNIT_HSIZE) ); if (World.Terrain.TryGetChunk(chunkIndex, out Chunk chunk)) { int blockX = (int)(center.X / Block.CUBE_SIZE) - (chunkIndex.X * Chunk.HSIZE); int blockY = (int)(center.Y / Block.CUBE_SIZE) - (chunkIndex.Y * Chunk.VSIZE); int blockZ = (int)(center.Z / Block.CUBE_SIZE) - (chunkIndex.Z * Chunk.HSIZE); Lighting = chunk.Lighting.LightingAt(blockX, blockY, blockZ); } } base.Update(deltaTime); }
IndexPosition ShiftIPos(IndexPosition ipos, CubeSide normal) { switch (normal) { case CubeSide.Back: ipos.Z++; break; case CubeSide.Bottom: ipos.Y--; break; case CubeSide.Front: ipos.Z--; break; case CubeSide.Left: ipos.X--; break; case CubeSide.Right: ipos.X++; break; case CubeSide.Top: ipos.Y++; break; } return(ipos); }
void CopySelection() { EditorSelectionBox selectionBox = TerrainEditor.SelectionBox; copy = new Block[ selectionBox.Max.Z - selectionBox.Min.Z + 1, selectionBox.Max.Y - selectionBox.Min.Y + 1, selectionBox.Max.X - selectionBox.Min.X + 1]; for (int x = selectionBox.Min.X, _x = 0; x <= selectionBox.Max.X; x++, _x++) { for (int y = selectionBox.Min.Y, _y = 0; y <= selectionBox.Max.Y; y++, _y++) { for (int z = selectionBox.Min.Z, _z = 0; z <= selectionBox.Max.Z; z++, _z++) { IndexPosition globalPos = new IndexPosition(x, y, z); IndexPosition cIndex, bIndex; GetLocalBlockCoords(globalPos, out cIndex, out bIndex); Chunk chunk; if (Terrain.Chunks.TryGetValue(cIndex, out chunk)) { copy[_z, _y, _x] = chunk.GetBlockSafe(bIndex.X, bIndex.Y, bIndex.Z); } } } } }
bool IsBlockPlacementSafe(IndexPosition blockPos, IndexPosition chunkPos) { Vector3 pos = Chunk.ChunkBlockToWorldCoords(chunkPos, blockPos); Vector3 halfSize = Block.CUBE_3D_SIZE / 2f; AxisAlignedBoundingBox aabb = new AxisAlignedBoundingBox(pos - halfSize, pos + halfSize); return(!aabb.Intersects(ownerPlayerPhysicsBody.GetCollider())); }
public void PositionToEditorObject(VoxelEditorObject eo) { Vector3 eo3DCubeSize = new Vector3(eo.CubeSize); xAxisPos = new IndexPosition(eo.Max.X + 1, eo.Min.Y, eo.Min.Z) * eo3DCubeSize + new Vector3(-cubeSize, 0, -cubeSize * 2); yAxisPos = new IndexPosition(eo.Min.X, eo.Max.Y + 1, eo.Min.Z) * eo3DCubeSize + new Vector3(-cubeSize * 2, -cubeSize, -cubeSize * 2); zAxisPos = new IndexPosition(eo.Min.X, eo.Min.Y, eo.Max.Z + 1) * eo3DCubeSize + new Vector3(-cubeSize * 2, 0, -cubeSize); }
public void ShouldIncreasePosition() { IndexPosition position = new IndexPosition(); position.Increase(); Assert.That(position.Value, Is.EqualTo(8)); }
public static IndexPosition GetGlobalBlockCoords(IndexPosition chunkPos, IndexPosition blockPos) { return(blockPos + new IndexPosition( chunkPos.X * Chunk.HSIZE, chunkPos.Y * Chunk.VSIZE, chunkPos.Z * Chunk.HSIZE)); }
public void SetBlock(Chunk chunk, Block block, IndexPosition blockPos) { if (chunk == null || !chunk.IsBlockCoordInRange(blockPos)) { return; } operationBatch.Add(new TerrainOperation(chunk, block, blockPos)); }
public void ShouldResolveCount() { IndexPosition position = new IndexPosition(); position.Increase(); position.Increase(); Assert.That(position.Size, Is.EqualTo(2)); }
public bool Contains(IndexPosition pos) { return(pos.X >= Min.X && pos.Y >= Min.Y && pos.Z >= Min.Z && pos.X <= Max.X && pos.Y <= Max.Y && pos.Z <= Max.Z); }
public void BuildMesh() { Color4 gridColor; Block b = Block.AIR; for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { for (int z = 0; z < Depth; z++) { if (x != 0 && y != 0 && z != 0) { continue; } IndexPosition blockIndex = new IndexPosition(x, y, z); Vector3 blockPos = new Vector3(x, y, z); Vector3 off = blockPos * meshBuilder.CubeSize; if (x == 0 && z == 0) { gridColor = Color4.Red; } else if (y == 0 && z == 0) { gridColor = Color4.Blue; } else if (x == 0 && y == 0) { gridColor = Color4.Green; } else { gridColor = Color4.Lavender; } if (x == 0) { meshBuilder.AddLeft(b, blockIndex, off, gridColor); } if (z == 0) { meshBuilder.AddBack(b, blockIndex, off, gridColor); } if (y == 0) { meshBuilder.AddBottom(b, blockIndex, off, gridColor); } } } } CreateOrUpdateMesh(BufferUsageHint.DynamicDraw); Mesh.BeginMode = BeginMode.Lines; }
public override Block SetBlock(IndexPosition chunkIndex, IndexPosition blockPos, Block block, bool placement) { channel.FireEvent("Server_SetBlock", client.ServerConnection, (short)chunkIndex.X, (short)chunkIndex.Y, (short)chunkIndex.Z, (ushort)blockPos.X, (ushort)blockPos.Y, (ushort)blockPos.Z, block.R, block.G, block.B, block.Data.Value, placement); return(block); }
public TerrainOperation(Chunk chunk, Block block, IndexPosition blockPos) { if (!chunk.IsBlockCoordInRange(blockPos)) { throw new ArgumentOutOfRangeException("blockPos", "Cannot create operation, block position is out of range!"); } this.chunk = chunk; this.block = block; this.blockPos = blockPos; }
public static TerrainOperation CreateUndoFor(Chunk chunk, IndexPosition blockPos) { if (!chunk.IsBlockCoordInRange(blockPos)) { throw new ArgumentOutOfRangeException("blockPos", "Cannot create undo operation, block position is out of range!"); } Block existing = chunk.GetBlockSafe(blockPos.X, blockPos.Y, blockPos.Z); return(new TerrainOperation(chunk, existing, blockPos)); }
public bool IsChunkShaped(IndexPosition pos, out Chunk chunk) { if (Chunks.TryGetValue(pos, out chunk)) { return(chunk.State > ChunkState.Unshaped); } else { return(false); } }
public Block GetBlockInChunk(IndexPosition chunkIndex, int bx, int by, int bz, out Chunk chunk) { if (Chunks.TryGetValue(chunkIndex, out chunk) && chunk.State > ChunkState.Unshaped) { return(chunk.GetBlockSafe(bx, by, bz)); } else { return(Block.STONE); } }
public void PositionToMinMax(IndexPosition min, IndexPosition max, float cubeSize, Vector3 offset) { Vector3 eo3DCubeSize = new Vector3(cubeSize); xAxisPos = new IndexPosition(max.X + 1, min.Y, min.Z) * eo3DCubeSize + new Vector3(-cubeSize, 0, -cubeSize * 2) + offset; yAxisPos = new IndexPosition(min.X, max.Y + 1, min.Z) * eo3DCubeSize + new Vector3(-cubeSize * 2, -cubeSize, -cubeSize * 2) + offset; zAxisPos = new IndexPosition(min.X, min.Y, max.Z + 1) * eo3DCubeSize + new Vector3(-cubeSize * 2, 0, -cubeSize) + offset; }
void PickColor() { TerrainRaycastResult result = World.TerrainPhysics.Raycast( new Ray(Camera.Position, Camera.ViewMatrix.Forward()), true, PLACE_RANGE); if (result.Intersects) { IndexPosition blockIndex = result.BlockIndex.Value; BlockColor = result.Chunk[blockIndex].GetColor(); } }
void CalculateMinMax() { Min = new IndexPosition( Math.Min(Primary.X, Secondary.X), Math.Min(Primary.Y, Secondary.Y), Math.Min(Primary.Z, Secondary.Z)); Max = new IndexPosition( Math.Max(Primary.X, Secondary.X), Math.Max(Primary.Y, Secondary.Y), Math.Max(Primary.Z, Secondary.Z)); }
public static CueFile TOCtoCUE(List <TOCEntry> tocEntries, string dataPath) { var cueFile = new CueFileEntry() { FileName = dataPath, Tracks = new List <CueTrack>(), FileType = "BINARY" }; var audioLeadin = new IndexPosition { Seconds = 2 }; foreach (var track in tocEntries) { var position = new IndexPosition { Minutes = track.Minutes, Seconds = track.Seconds, Frames = track.Frames, }; var indexes = new List <CueIndex>(); if (track.TrackType == TrackTypeEnum.Audio) { indexes.Add(new CueIndex() { Number = 0, Position = position - audioLeadin, }); } indexes.Add(new CueIndex() { Number = 1, Position = position, }); var cueTrack = new CueTrack() { DataType = GetDataType(track.TrackType), Indexes = indexes, Number = track.TrackNo }; cueFile.Tracks.Add(cueTrack); } return(new CueFile(new[] { cueFile })); }
public void AddChange(Chunk chunk, Block block, IndexPosition ipos) { if (TrackChanges) { BlockChange change = new BlockChange(chunk, block, ipos); AllChanges.Add(change); if (OnModified != null) { OnModified(this, change); } } }