예제 #1
0
        public void Render(IObject obj, IViewport viewport)
        {
            ISprite sprite = obj.Animation?.Sprite;

            if (sprite == null || sprite.Image == null)
            {
                return;
            }
            var boundingBoxes = obj.GetBoundingBoxes(viewport);

            if (boundingBoxes == null || !boundingBoxes.RenderBox.IsValid)
            {
                return;
            }

            ITexture texture = _textures.GetOrAdd(sprite.Image.ID, _createTextureFunc);

            _colorAdjusters[0] = sprite;
            _colorAdjusters[1] = obj;
            IGLColor color = _colorBuilder.Build(_colorAdjusters);

            IBorderStyle   border    = obj.Border;
            AGSBoundingBox borderBox = _emptySquare;

            if (!obj.Visible)
            {
                return;
            }
            if (border != null)
            {
                if (boundingBoxes.RenderBox.BottomLeft.X > boundingBoxes.RenderBox.BottomRight.X)
                {
                    borderBox = boundingBoxes.RenderBox.FlipHorizontal();
                }
                else
                {
                    borderBox = boundingBoxes.RenderBox;
                }

                border.RenderBorderBack(borderBox);
            }
            _renderer.Render(texture.ID, boundingBoxes, color);

            border?.RenderBorderFront(borderBox);
            if (obj.DebugDrawPivot)
            {
                IObject parent = obj.TreeNode.Parent;
                float   x      = obj.X;
                float   y      = obj.Y;
                while (parent != null)
                {
                    x     += (parent.X - parent.Width * parent.Pivot.X);
                    y     += (parent.Y - parent.Height * parent.Pivot.Y);
                    parent = parent.TreeNode.Parent;
                }
                _glUtils.DrawCross(x - viewport.X, y - viewport.Y, 10, 10, 1f, 1f, 1f, 1f);
            }
        }
예제 #2
0
        public void Render(IObject obj, IViewport viewport)
        {
            if (obj.Animation == null)
            {
                return;
            }
            ISprite sprite = obj.Animation.Sprite;

            if (sprite == null || sprite.Image == null)
            {
                return;
            }

            var  layerViewport     = _layerViewports.GetViewport(obj.RenderLayer.Z);
            var  gameResolution    = AGSGame.Game.Settings.VirtualResolution;
            var  resolution        = obj.RenderLayer.IndependentResolution ?? gameResolution;
            bool resolutionMatches = resolution.Equals(gameResolution);

            var viewportMatrix = obj.IgnoreViewport ? Matrix4.Identity : layerViewport.GetMatrix(viewport, obj.RenderLayer.ParallaxSpeed);

            var modelMatrices = obj.GetModelMatrices();

            _matrices.ModelMatrix    = modelMatrices.InVirtualResolutionMatrix;
            _matrices.ViewportMatrix = viewportMatrix;

            _boundingBoxBuilder.Build(BoundingBoxes, sprite.Image.Width,
                                      sprite.Image.Height, _matrices, resolutionMatches, true);
            IGLBoundingBox hitTestBox = BoundingBoxes.HitTestBox;

            if (!resolutionMatches)
            {
                _matrices.ModelMatrix = modelMatrices.InObjResolutionMatrix;
                _boundingBoxBuilder.Build(BoundingBoxes, sprite.Image.Width,
                                          sprite.Image.Height, _matrices, true, false);
            }
            IGLBoundingBox renderBox = BoundingBoxes.RenderBox;

            ITexture texture = _textures.GetOrAdd(sprite.Image.ID, () => createNewTexture(sprite.Image.ID));

            IGLColor color = _colorBuilder.Build(sprite, obj);

            IBorderStyle border       = obj.Border;
            ISquare      renderSquare = null;

            if (border != null)
            {
                renderSquare = renderBox.ToSquare();
                border.RenderBorderBack(renderSquare);
            }
            _renderer.Render(texture.ID, renderBox, color);

            Vector3 bottomLeft  = hitTestBox.BottomLeft;
            Vector3 topLeft     = hitTestBox.TopLeft;
            Vector3 bottomRight = hitTestBox.BottomRight;
            Vector3 topRight    = hitTestBox.TopRight;

            AGSSquare square = new AGSSquare(new PointF(bottomLeft.X, bottomLeft.Y),
                                             new PointF(bottomRight.X, bottomRight.Y), new PointF(topLeft.X, topLeft.Y),
                                             new PointF(topRight.X, topRight.Y));

            obj.BoundingBox = square;

            if (border != null)
            {
                border.RenderBorderFront(renderSquare);
            }
            if (obj.DebugDrawAnchor)
            {
                IObject parent = obj.TreeNode.Parent;
                float   x      = obj.X;
                float   y      = obj.Y;
                while (parent != null)
                {
                    x     += (parent.X - parent.Width * parent.Anchor.X);
                    y     += (parent.Y - parent.Height * parent.Anchor.Y);
                    parent = parent.TreeNode.Parent;
                }
                _glUtils.DrawCross(x - viewport.X, y - viewport.Y, 10, 10, 1f, 1f, 1f, 1f);
            }
        }