private void DrawGizmos2() { //Draw land bounds DrawRectangle.ForGizmo(_target.LayoutBounds, Color.gray); //Get intersection points if (Application.isPlaying) { if (IsMapMode()) { //Draw cursor-map intersection var mapInter = GetMapIntersection(); if (mapInter.HasValue) { Gizmos.color = Color.red; Gizmos.DrawSphere(mapInter.Value, 0.05f); DrawChunkAndBlock(Convert(mapInter.Value)); if (IsLayoutMode()) { DrawSelectedZone(Convert(mapInter.Value)); } } } else if (IsLayoutMode()) { var layoutHit = GetLayoutIntersection(); if (layoutHit.HasValue) { DrawSelectedZone(layoutHit.Value); DrawChunkAndBlock(layoutHit.Value); } } } }
private void DrawSelectedZone(Vector2 worldPosition) { //Calc zone under cursor if (_main.LandLayout != null && _main.LandLayout.Zones.Any() && _main.LandLayout.Bounds.Contains((Vector2i)worldPosition)) { var selectedZone = _main.LandLayout.Zones.OrderBy(z => Vector2.SqrMagnitude(z.Center - worldPosition)).First(); var zoneColor = _target[selectedZone.Type].LandColor; Gizmos.color = zoneColor; //Draw zone bounds //foreach (var chunk in selectedZone.ChunkBounds) //DrawRectangle.ForGizmo(Chunk.GetBounds(chunk), zoneColor); foreach (var chunk in _main.LandLayout.GetChunks(selectedZone)) { DrawRectangle.ForGizmo(Chunk.GetBounds(chunk), zoneColor); } foreach (var block in selectedZone.GetBlocks2()) { var blockBounds = new Bounds2i(block, 1, 1); DrawRectangle.ForGizmo(blockBounds, zoneColor); } } }
void OnDrawGizmos() { if (_handle1 && _handle2) { Gizmos.color = Color.white; Gizmos.DrawLine(_handle1.transform.position, _handle2.transform.position); //var p1 = new Vector2i(_handle1.transform.position.x, _handle1.transform.position.z); //var p2 = new Vector2i(_handle2.transform.position.x, _handle2.transform.position.z); var p1 = new Vector2(_handle1.transform.position.x, _handle1.transform.position.z); var p2 = new Vector2(_handle2.transform.position.x, _handle2.transform.position.z); var pi1 = (Vector2i)p1; var pi2 = (Vector2i)p2; //var points = Rasterization.DDA(p1, p2, true).ToArray(); Debug.Log("Rasterization.DDA conservative"); var pointsDDA = Rasterization.DDA(p1, p2, false).ToArray(); //var points = Rasterization.lineNoDiag(pi1.X, pi1.Z, pi2.X, pi2.Z).ToArray(); Debug.Log("Rasterization.lineNoDiag"); var pointsBresInt = Rasterization.BresenhamInt(pi1, pi2).ToArray(); var pointsBresFloat = Rasterization.BresenhamFloat(p1.X, p1.Y, p2.X, p2.Y).ToArray(); Assert.IsTrue(pointsDDA.Length == pointsDDA.Distinct().Count()); Assert.IsTrue(pointsBresInt.Length == pointsBresInt.Distinct().Count()); Assert.IsTrue(pointsBresFloat.Length == pointsBresFloat.Distinct().Count()); if (counter % 20 < 10) { foreach (var p in pointsDDA) { DrawRectangle.ForGizmo(new Bounds2i(p, 1, 1), Color.white); } } /* * else if (counter % 21 < 14) * foreach (var p in pointsBresInt) * DrawRectangle.ForGizmo(new Bounds2i(p, 1, 1), Color.red); */ else //if (counter % 21 >= 14) { foreach (var p in pointsBresFloat) { DrawRectangle.ForGizmo(new Bounds2i(p, 1, 1), Color.green); } } counter++; } }
private void DrawChunkAndBlock(Vector2 worldPosition) { const float yOffset = 0.01f; if (IsMapMode()) { var chunkPos = Chunk.GetPosition(worldPosition); Chunk chunk; if (_main.Map.Map.TryGetValue(chunkPos, out chunk)) { //Draw chunk bounds var chunkBounds = (Bounds)Chunk.GetBounds(chunkPos); var r1 = new Vector3(chunkBounds.min.x, chunk.HeightMap[0, 0] + yOffset, chunkBounds.min.z); var r2 = new Vector3(chunkBounds.max.x, chunk.HeightMap[chunk.GridSize - 1, 0] + yOffset, chunkBounds.min.z); var r3 = new Vector3(chunkBounds.min.x, chunk.HeightMap[0, chunk.GridSize - 1] + yOffset, chunkBounds.max.z); var r4 = new Vector3(chunkBounds.max.x, chunk.HeightMap[chunk.GridSize - 1, chunk.GridSize - 1] + yOffset, chunkBounds.max.z); DrawPolyline.ForGizmo(GetChunkPolyBound(chunk, yOffset), Color.red); //Draw block bounds var blockPos = (Vector2i)worldPosition; var localPos = Chunk.GetLocalPosition(worldPosition); r1 = new Vector3(blockPos.X, chunk.HeightMap[localPos.X, localPos.Z] + yOffset, blockPos.Z); r2 = new Vector3(blockPos.X + 1, chunk.HeightMap[localPos.X + 1, localPos.Z] + yOffset, blockPos.Z); r3 = new Vector3(blockPos.X, chunk.HeightMap[localPos.X, localPos.Z + 1] + yOffset, blockPos.Z + 1); r4 = new Vector3(blockPos.X + 1, chunk.HeightMap[localPos.X + 1, localPos.Z + 1] + yOffset, blockPos.Z + 1); DrawRectangle.ForDebug(r1, r2, r4, r3, Color.red); //Draw block normal var n1 = chunk.NormalMap[localPos.X, localPos.Z]; var blockCenter = (r1 + r2 + r3 + r4) / 4; DrawArrow.ForDebug(blockCenter, n1, Color.red); } } else //Layout mode { //Draw chunk bounds var chunkPos = Chunk.GetPosition(worldPosition); var chunkBounds = Chunk.GetBounds(chunkPos); DrawRectangle.ForGizmo(chunkBounds, Color.red); //Draw block bounds DrawRectangle.ForGizmo(new Bounds2i((Vector2i)worldPosition, 1, 1), Color.red); } }
void OnDrawGizmos() { if (ShowChunksValue) { foreach (var valuableChunk in ValuableChunkPos(Range)) { DrawRectangle.ForGizmo( Chunk.GetBounds(valuableChunk.Position), Color.Lerp(Color.black, Color.red, valuableChunk.Value), true); } } if (DebugDraw) { DrawArrow.ForGizmo(transform.position, transform.forward * 10, Color.magenta, 3); } }
void OnDrawGizmos() { if (_h1 && _h2 && _h3 && _h4) { var center = (_h1.position + _h2.position + _h3.position + _h4.position) / 4; var h1 = new HalfPlane((Vector2)_h1.position, (Vector2)_h2.position, (Vector2)center); var h2 = new HalfPlane((Vector2)_h2.position, (Vector2)_h3.position, (Vector2)center); var h3 = new HalfPlane((Vector2)_h3.position, (Vector2)_h4.position, (Vector2)center); var h4 = new HalfPlane((Vector2)_h4.position, (Vector2)_h1.position, (Vector2)center); var containsCallCounter = 0; var isContains = new Predicate <Vector2>(delegate(Vector2 p) { containsCallCounter++; return(HalfPlane.ContainsInConvex(p, new [] { h1, h2, h3, h4 })); }); var bounds = new Box2( Mathf.Min(_h1.position.x, _h2.position.x, _h3.position.x, _h4.position.x), Mathf.Max(_h1.position.z, _h2.position.z, _h3.position.z, _h4.position.z), Mathf.Max(_h1.position.x, _h2.position.x, _h3.position.x, _h4.position.x), Mathf.Min(_h1.position.z, _h2.position.z, _h3.position.z, _h4.position.z)); //Draw test polygon Gizmos.color = Color.white; Gizmos.DrawLine(_h1.position, _h2.position); Gizmos.DrawLine(_h2.position, _h3.position); Gizmos.DrawLine(_h3.position, _h4.position); Gizmos.DrawLine(_h4.position, _h1.position); //Draw "world" bounds DrawRectangle.ForGizmo(bounds, Color.gray); if (Workmode == Mode.Blocks) { //Draw block bounds var blockBounds = (Bounds2i)bounds; //Draw block centers inside bounds foreach (var blockBound in blockBounds) { var blockCenter = BlockInfo.GetWorldCenter(blockBound); DebugExtension.DrawPoint((Vector3)blockCenter, Color.white / 2, 0.1f); } var blocks = Rasterization.ConvexToBlocks(isContains, bounds); Assert.IsTrue(blocks.Length == blocks.Distinct().Count()); //Draw rasterized blocks foreach (var p in blocks) { DrawRectangle.ForGizmo(new Bounds2i(p, 1, 1), Color.green); } } else { var vertices = Rasterization.ConvexToVertices(isContains, bounds); Assert.IsTrue(vertices.Length == vertices.Distinct().Count()); //Draw rasterized vertices foreach (var p in vertices) { DebugExtension.DrawPoint(p, Color.green, 0.1f); } } Debug.LogFormat("Contains calls count {0}", containsCallCounter); } }