private void buildForRender(IGLBoundingBox renderBox, IGLMatrices matrices, Vector3 bottomLeft, Vector3 topLeft, Vector3 bottomRight, Vector3 topRight) { renderBox.BottomLeft = Vector3.Transform(bottomLeft, matrices.ViewportMatrix); renderBox.TopLeft = Vector3.Transform(topLeft, matrices.ViewportMatrix); renderBox.BottomRight = Vector3.Transform(bottomRight, matrices.ViewportMatrix); renderBox.TopRight = Vector3.Transform(topRight, matrices.ViewportMatrix); }
public void Render(int texture, IGLBoundingBox boundingBox, IGLColor color) { Vector3 bottomLeft = boundingBox.BottomLeft; Vector3 topLeft = boundingBox.TopLeft; Vector3 bottomRight = boundingBox.BottomRight; Vector3 topRight = boundingBox.TopRight; _glUtils.DrawQuad (texture, bottomLeft, bottomRight, topLeft, topRight, color.R, color.G, color.B, color.A); }
public void Render(int texture, IGLBoundingBox boundingBox, IGLColor color) { Vector3 bottomLeft = boundingBox.BottomLeft; Vector3 topLeft = boundingBox.TopLeft; Vector3 bottomRight = boundingBox.BottomRight; Vector3 topRight = boundingBox.TopRight; _glUtils.DrawQuad(texture, bottomLeft, bottomRight, topLeft, topRight, color.R, color.G, color.B, color.A); }
//Hit test box should be built without viewport transformation, and vertices need to be arranged //in case the sprite was flipped private void buildForHitTest(IGLBoundingBox hitTestBox, Vector3 bottomLeft, Vector3 topLeft, Vector3 bottomRight, Vector3 topRight) { if (bottomLeft.X > bottomRight.X) { if (bottomLeft.Y > topLeft.Y) //flipped on x and y { hitTestBox.BottomLeft = topRight; hitTestBox.BottomRight = topLeft; hitTestBox.TopLeft = bottomRight; hitTestBox.TopRight = bottomLeft; } else //flipped on x { hitTestBox.BottomLeft = bottomRight; hitTestBox.BottomRight = bottomLeft; hitTestBox.TopLeft = topRight; hitTestBox.TopRight = topLeft; } } else { if (bottomLeft.Y > topLeft.Y) //flipped on y { hitTestBox.BottomLeft = topLeft; hitTestBox.BottomRight = topRight; hitTestBox.TopLeft = bottomLeft; hitTestBox.TopRight = bottomRight; } else //not flipped { hitTestBox.BottomLeft = bottomLeft; hitTestBox.BottomRight = bottomRight; hitTestBox.TopLeft = topLeft; hitTestBox.TopRight = topRight; } } }
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); } }
public GLBoundingBoxes(IGLBoundingBox renderBox, IGLBoundingBox hitTestBox) { RenderBox = renderBox; HitTestBox = hitTestBox; }