public void Draw(RenderComposer composer) { _rendered = 0; _drawMemory.Clear(); var rect = new Rectangle( Engine.Renderer.Camera.ScreenToWorld(Vector2.Zero), Engine.Renderer.Camera.ScreenToWorld(Engine.Renderer.DrawBuffer.Size) * 2 // Engine.Configuration.RenderSize * (Engine.Renderer.Scale - (Engine.Renderer.IntScale - 1)) / Engine.Renderer.Camera.Zoom ); quadTree.GetObjects(rect, ref _drawMemory); composer.RenderOutline(new Vector3(rect.Position, 0f), rect.Size, Color.CornflowerBlue, 2); _rendered = _drawMemory.Count; Engine.Log.Info("\t" + "Mouse position \t" + Engine.Host.MousePosition, "TAAAG"); // ReSharper disable once ForCanBeConvertedToForeach for (var i = 0; i < _drawMemory.Count; i++) { var tile = _drawMemory[i]; var c = Color.White.ToUint(); var a = composer.GetBatch(); var data = a.GetData(_tileTexture.Texture); data[0].Vertex = tile.Vertex0; data[0].Color = c; data[0].UV = Vector2.Zero; data[1].Vertex = tile.Vertex1; data[1].Color = c; data[1].UV = new Vector2(1, 0); data[2].Vertex = tile.Vertex2; data[2].Color = c; data[2].UV = new Vector2(1, 1); data[3].Vertex = tile.Vertex3; data[3].Color = c; data[3].UV = new Vector2(0, 1); } composer.SetDepthTest(false); composer.SetUseViewMatrix(false); composer.RenderLine(new Vector2(20, 20), new Vector2(20, 30), Color.Green, 2); composer.RenderLine(new Vector2(20, 20), new Vector2(30, 20), Color.Red, 2); composer.RenderLine(new Vector3(20, 20, 0), new Vector3(20, 20, 30), Color.Blue, 10); RenderGui(composer); }
private void RenderMouseOverTiles(RenderComposer composer) { var mouseRect = new Rectangle(Engine.Renderer.Camera.ScreenToWorld(Vector2.Zero), new Vector2(1, 1)) { Center = Engine.Renderer.Camera.ScreenToWorld(Engine.InputManager.MousePosition) }; composer.RenderOutline(new Vector3(mouseRect.Position, 10), mouseRect.Size, Color.Magenta, 2); //composer.PushModelMatrix(Matrix4x4.CreateTranslation(new Vector3(-mouseRect.Position, 0))); composer.RenderTo(_frameBuffer); _drawMemory.Clear(); quadTree.GetObjects(mouseRect, ref _drawMemory); for (var i = 0; i < _drawMemory.Count; i++) { var tile = _drawMemory[i]; var a = composer.GetBatch(); var data = a.GetData(null); data[0].Vertex = tile.Vertex0.ToVec3(); data[0].Color = new Color(50 + i, i, 0).ToUint(); data[1].Vertex = tile.Vertex1.ToVec3(); data[1].Color = new Color(i * 20, i, 0).ToUint(); data[2].Vertex = tile.Vertex2.ToVec3(); data[2].Color = new Color(i * 20, i * 20, 0).ToUint(); data[3].Vertex = tile.Vertex3.ToVec3(); data[3].Color = new Color(i, i * 20, 0).ToUint(); } composer.PushCommand(new ExecCodeCommand() { Func = () => { byte[] pixels = _frameBuffer.Sample(new Rectangle(Engine.InputManager.MousePosition, Vector2.One)); _lastMouseX = pixels[3]; _lastMouseY = pixels[2]; } }); //composer.PopModelMatrix(); composer.RenderTo(null); }
private void RenderMap(RenderComposer composer) { _drawMemory.Clear(); var rect = new Rectangle( Engine.Renderer.Camera.ScreenToWorld(Vector2.Zero), Engine.Configuration.RenderSize * (Engine.Renderer.Scale - (Engine.Renderer.IntScale - 1)) / Engine.Renderer.Camera.Zoom ); quadTree.GetObjects(rect, ref _drawMemory); _rendered = _drawMemory.Count; composer.RenderOutline(new Vector3(rect.Position, 0f), rect.Size, Color.CornflowerBlue, 2); // ReSharper disable once ForCanBeConvertedToForeach for (var i = 0; i < _drawMemory.Count; i++) { var tile = _drawMemory[i]; var c = Color.White.ToUint(); var texture = tile.Height == 1 ? _tileMntTexture : i % 27 == 0 ? _tileGrs2Texture : _tileGrs1Texture; var a = composer.GetBatch(); var data = a.GetData(texture.Texture); data[0].Vertex = tile.Vertex0.ToVec3(); data[0].Color = c; data[0].UV = Vector2.Zero; data[1].Vertex = tile.Vertex1.ToVec3(); data[1].Color = c; data[1].UV = new Vector2(1, 0); data[2].Vertex = tile.Vertex2.ToVec3(); data[2].Color = c; data[2].UV = new Vector2(1, 1); data[3].Vertex = tile.Vertex3.ToVec3(); data[3].Color = c; data[3].UV = new Vector2(0, 1); } }
private void RenderMap(RenderComposer composer) { _drawMemory.Clear(); var rect = new Rectangle( Engine.Renderer.Camera.ScreenToWorld(Vector2.Zero), Engine.Configuration.RenderSize * (Engine.Renderer.Scale - (Engine.Renderer.IntScale - 1)) / Engine.Renderer.Camera.Zoom ); quadTree.GetObjects(rect, ref _drawMemory); // ReSharper disable once ForCanBeConvertedToForeach for (var i = 0; i < _drawMemory.Count; i++) { var tile = _drawMemory[i]; var span = composer.GetBatch().GetData(null); SetTileRenderData(tile, span); if (tile._hasStation) { composer.RenderSprite(tile.Position, towerSize, towerTextureAsset.Texture); // render tower } } }