public PointF? FindClosestPoint (PointF point, out float distance) { int x = (int)point.X; int y = (int)point.Y; int width = Mask.Width; int height = Mask.Height; distance = 0f; if (x < 0) { distance -= x; x = 0; } if (x >= width) { distance += (width - x); x = width - 1; } if (y < 0) { distance -= y; y = 0; } if (y >= height) { distance += (height - y); y = height - 1; } float insideDistance; PointF? result = findClosestPoint(x, y, width, height, out insideDistance); distance += insideDistance; return result; }
partial void afterInitComponents(Resolver resolver) { RenderLayer = AGSLayers.UI; IgnoreScalingArea = true; IgnoreViewport = true; Anchor = new PointF (); Enabled = true; }
public bool IsMasked(PointF point, ISquare projectionBox, float scaleX, float scaleY) { float leftX = scaleX >= 0f ? projectionBox.BottomLeft.X : projectionBox.BottomRight.X; float rightX = scaleX >= 0f ? projectionBox.BottomRight.X : projectionBox.BottomLeft.X; float bottomY = scaleY >= 0f ? projectionBox.BottomLeft.Y : projectionBox.TopLeft.Y; float topY = scaleY >= 0f ? projectionBox.TopLeft.Y : projectionBox.BottomLeft.Y; float x = MathUtils.Lerp(leftX, 0, rightX, Width - 1, point.X); float y = MathUtils.Lerp(bottomY, 0, topY, Height - 1, point.Y); return IsMasked(new PointF (x, y)); }
public bool IsMasked(PointF point) { int x = (int)Math.Round(point.X, 0); int y = (int)Math.Round(point.Y, 0); if (x < 0 || x >= Width) return false; if (y < 0 || y >= Height) return false; return _mask [x][y]; }
public AGSSquare (PointF bottomLeft, PointF bottomRight, PointF topLeft, PointF topRight) : this() { BottomLeft = bottomLeft; BottomRight = bottomRight; TopLeft = topLeft; TopRight = topRight; MinX = MathUtils.Min(bottomLeft.X, bottomRight.X, topLeft.X, topRight.X); MaxX = MathUtils.Max(bottomLeft.X, bottomRight.X, topLeft.X, topRight.X); MinY = MathUtils.Min(bottomLeft.Y, bottomRight.Y, topLeft.Y, topRight.Y); MaxY = MathUtils.Max(bottomLeft.Y, bottomRight.Y, topLeft.Y, topRight.Y); }
//http://www.emanueleferonato.com/2012/03/09/algorithm-to-determine-if-a-point-is-inside-a-square-with-mathematics-no-hit-test-involved/ public bool Contains (PointF p) { PointF a = BottomLeft; PointF b = BottomRight; PointF c = TopRight; PointF d = TopLeft; if (triangleArea(a,b,p)>0 || triangleArea(b,c,p)>0 || triangleArea(c,d,p)>0 || triangleArea(d,a,p)>0) { return false; } return true; }
public void RenderBorderBack(ISquare square) { IGLColor color = IsSelected ? _selectedColor : _color; IGLColor foldColor = IsSelected ? _selectedFoldColor : _foldColor; _glUtils.DrawQuad(0, square.BottomLeft.ToVector3(), square.BottomRight.ToVector3(), square.TopLeft.ToVector3(), square.TopRight.ToVector3(), color, color, color, color); float foldHeight = (square.MaxY - square.MinY) * (1f / 5f); PointF foldBottom = new PointF((square.TopLeft.X + square.TopRight.X) / 2f, square.TopLeft.Y - foldHeight); _glUtils.DrawTriangleFan(0, new GLVertex[] { new GLVertex(square.TopLeft.ToVector2(), _emptyVector, foldColor), new GLVertex(foldBottom.ToVector2(), _emptyVector, foldColor), new GLVertex(square.TopRight.ToVector2(), _emptyVector, foldColor)}); }
private Matrix4 getModelMatrix(IHasModelMatrix sprite, PointF areaScaling, PointF resolutionTransform) { if (sprite == null) return Matrix4.Identity; float width = sprite.Width * resolutionTransform.X; float height = sprite.Height * resolutionTransform.Y; PointF anchorOffsets = getAnchorOffsets (sprite.Anchor, width, height); Matrix4 anchor = Matrix4.CreateTranslation (new Vector3(-anchorOffsets.X, -anchorOffsets.Y, 0f)); Matrix4 scale = Matrix4.CreateScale (new Vector3 (sprite.ScaleX * areaScaling.X, sprite.ScaleY * areaScaling.Y, 1f)); Matrix4 rotation = Matrix4.CreateRotationZ(sprite.Angle); float x = sprite.X * resolutionTransform.X; float y = sprite.Y * resolutionTransform.Y; Matrix4 transform = Matrix4.CreateTranslation (new Vector3(x, y, 0f)); return anchor * scale * rotation * transform; }
public IBrush LoadPathsGradientBrush(AGS.API.Color centerColor, AGS.API.PointF centerPoint, IBlend blend, AGS.API.PointF focusScales, AGS.API.Color[] surroundColors, IColorBlend interpolationColors, ITransformMatrix transform, AGS.API.WrapMode wrapMode) { PathGradientBrush g = new PathGradientBrush(new System.Drawing.Point[] { }); g.Blend = blend.Convert(); g.CenterColor = centerColor.Convert(); g.CenterPoint = centerPoint.Convert(); g.FocusScales = focusScales.Convert(); g.SurroundColors = surroundColors.Convert(); g.InterpolationColors = interpolationColors.Convert(); g.Transform = transform.Convert(); g.WrapMode = wrapMode.Convert(); return(new DesktopBrush(g)); }
//http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/ //http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-17-quaternions/ public IGLMatrices Build(IHasModelMatrix obj, IHasModelMatrix sprite, IObject parent, Matrix4 viewport, PointF areaScaling, PointF resolutionTransform) { Matrix4 spriteMatrix = getModelMatrix (sprite, NoScaling, NoScaling); Matrix4 objMatrix = getModelMatrix (obj, areaScaling, resolutionTransform); ModelMatrix = spriteMatrix * objMatrix; while (parent != null) { Matrix4 parentMatrix = getModelMatrix(parent, NoScaling, resolutionTransform); ModelMatrix = ModelMatrix * parentMatrix; parent = parent.TreeNode.Parent; } ViewportMatrix = viewport; return this; }
public bool IsMasked_WithProjection_Test(int width, int height, float x, float y, float projectionLeft, float projectionBottom, float scaleX, float scaleY, params int[] pointsInMask) { bool[][] array = GetArray(width, height, true, pointsInMask); AGSMask mask = new AGSMask(array, null); Mock <ISquare> square = new Mock <ISquare> (); AGS.API.PointF bottomLeft = new AGS.API.PointF(projectionLeft, projectionBottom); AGS.API.PointF bottomRight = new AGS.API.PointF(projectionLeft + width * Math.Abs(scaleX), projectionBottom); AGS.API.PointF topLeft = new AGS.API.PointF(projectionLeft, projectionBottom + height * Math.Abs(scaleY)); AGS.API.PointF topRight = new AGS.API.PointF(projectionLeft + width * Math.Abs(scaleX), projectionBottom + height * Math.Abs(scaleY)); square.Setup(s => s.BottomLeft).Returns(bottomLeft); square.Setup(s => s.BottomRight).Returns(bottomRight); square.Setup(s => s.TopLeft).Returns(topLeft); square.Setup(s => s.TopRight).Returns(topRight); return(mask.IsMasked(new AGS.API.PointF(x, y), square.Object, scaleX, scaleY)); }
public Matrix4 GetMatrix(IViewport viewport, PointF parallaxSpeed) { if (viewport.X == _lastX && viewport.Y == _lastY && viewport.ScaleX == _lastScaleX && viewport.Y == _lastScaleY && parallaxSpeed.X == _lastParallaxSpeedX && parallaxSpeed.Y == _lastParallaxSpeedY && viewport.Angle == _lastRotation) { return _lastMatrix; } _lastX = viewport.X; _lastY = viewport.Y; _lastScaleX = viewport.ScaleX; _lastScaleY = viewport.ScaleY; _lastParallaxSpeedX = parallaxSpeed.X; _lastParallaxSpeedY = parallaxSpeed.Y; _lastRotation = viewport.Angle; buildMatrix(); return _lastMatrix; }
public void Camera_ViewportMovesTest() { Mock <ICamera> camera = new Mock <ICamera> (); AGS.API.PointF sourcePoint = new AGS.API.PointF(15f, 25f); AGS.API.PointF targetPoint = new AGS.API.PointF(55f, 65f); camera.Setup(f => f.Tick(_mocks.Viewport().Object, It.IsAny <AGS.API.RectangleF>(), It.IsAny <AGS.API.Size>(), It.IsAny <bool>())).Callback(() => { _mocks.Viewport().Object.X = targetPoint.X; _mocks.Viewport().Object.Y = targetPoint.Y; }); _mocks.Viewport().Setup(v => v.X).Returns(sourcePoint.X); _mocks.Viewport().Setup(v => v.Y).Returns(sourcePoint.Y); _mocks.Viewport().Setup(v => v.Camera).Returns(camera.Object); var loop = getGameLoop(); loop.Update(); _mocks.Viewport().VerifySet(v => v.X = It.IsAny <float>(), Times.Once()); _mocks.Viewport().VerifySet(v => v.Y = It.IsAny <float>(), Times.Once()); _mocks.Viewport().VerifySet(v => v.X = targetPoint.X, Times.Once()); _mocks.Viewport().VerifySet(v => v.Y = targetPoint.Y, Times.Once()); }
public AGSWalkBehavior(IObject obj, IPathFinder pathFinder, IFaceDirectionBehavior faceDirection, IHasOutfit outfit, IObjectFactory objFactory, IGame game, IGLUtils glUtils) { _state = game.State; _cutscene = _state.Cutscene; _events = game.Events; _obj = obj; _pathFinder = pathFinder; _faceDirection = faceDirection; _outfit = outfit; _objFactory = objFactory; _glUtils = glUtils; _debugPath = new List<IObject> (); _walkCompleted = new TaskCompletionSource<object> (); _walkCompleted.SetResult(null); AdjustWalkSpeedToScaleArea = true; MovementLinkedToAnimation = true; WalkStep = new PointF(8f, 8f); _events.OnRepeatedlyExecute.Subscribe(onRepeatedlyExecute); }
private async Task addLampPosts(IGameFactory factory) { PointF parallaxSpeed = new PointF (1.4f, 1f); AGSRenderLayer parallaxLayer = new AGSRenderLayer (-50, parallaxSpeed); var image = await factory.Graphics.LoadImageAsync(_baseFolder + "lampPost.png"); var singleFrame = new AGSSingleFrameAnimation (image, factory.Graphics); const int numLampPosts = 3; for (int index = 0; index < numLampPosts; index++) { IObject lampPost = factory.Object.GetObject("Lamp Post " + index); lampPost.X = 200f * index + 30f; lampPost.Y = -130f; lampPost.RenderLayer = parallaxLayer; lampPost.StartAnimation(singleFrame); _room.Objects.Add(lampPost); } }
private void drawRoundCorner(PointF center, float radius, float angle, ISquare border, FourCorners<IGLColor> colors) { Vector2 tex = new Vector2 (); GLVertex centerVertex = new GLVertex (center.ToVector2(), tex, getColor(colors, border, center)); _roundCorner[0] = centerVertex; float step = (90f / (_roundCorner.Length - 2)); for (int i = 1; i < _roundCorner.Length; i++) { float anglerad = (float)Math.PI * angle / 180.0f; float x = (float)Math.Sin(anglerad) * radius; float y = (float)Math.Cos(anglerad) * radius; angle += step; PointF point = new PointF (x + center.X, y + center.Y); _roundCorner[i] = new GLVertex (point.ToVector2(), tex, getColor(colors, border, point)); } _glUtils.DrawTriangleFan(0, _roundCorner); }
private GLColor getColor(FourCorners<IGLColor> colors, ISquare border, PointF point) { return getColor(colors, MathUtils.Lerp(border.BottomLeft.X, 0f, border.BottomRight.X, 1f, point.X), MathUtils.Lerp(border.BottomRight.Y, 0f, border.TopRight.Y, 1f, point.Y)); }
public bool IsInArea (PointF point) { return Mask.IsMasked(point); }
public AGSRenderLayer(int z, PointF? parallaxSpeed = null, Size? independentResolution = null) { Z = z; ParallaxSpeed = parallaxSpeed ?? new PointF(1f, 1f); IndependentResolution = independentResolution; }
public void Prepare(IObject obj, IDrawableInfo drawable, IInObjectTree tree, IViewport viewport, PointF areaScaling) { }
public bool IsInArea(PointF point, ISquare projectionBox, float scaleX, float scaleY) { return Mask.IsMasked(point, projectionBox, scaleX, scaleY); }
public bool IsInArea(PointF point, ISquare projectionBox, float scaleX, float scaleY) { return _areaComponent.IsInArea(point, projectionBox, scaleX, scaleY); }
public IBrush LoadPathsGradientBrush(AGS.API.Color centerColor, AGS.API.PointF centerPoint, IBlend blend, AGS.API.PointF focusScales, AGS.API.Color[] surroundColors, IColorBlend interpolationColors, ITransformMatrix transform, WrapMode wrapMode) { throw new NotImplementedException(); }
public PointF? FindClosestPoint(PointF point, out float distance) { return _areaComponent.FindClosestPoint(point, out distance); }
public bool IsInArea(PointF point) { return _areaComponent.IsInArea(point); }
public bool IsMasked_WithProjection_Test(int width, int height, float x, float y, float projectionLeft, float projectionBottom, float scaleX, float scaleY, params int[] pointsInMask) { bool[][] array = GetArray(width, height, true, pointsInMask); AGSMask mask = new AGSMask(array, null); Mock<ISquare> square = new Mock<ISquare> (); AGS.API.PointF bottomLeft = new AGS.API.PointF (projectionLeft, projectionBottom); AGS.API.PointF bottomRight = new AGS.API.PointF (projectionLeft + width * Math.Abs(scaleX), projectionBottom); AGS.API.PointF topLeft = new AGS.API.PointF (projectionLeft, projectionBottom + height * Math.Abs(scaleY)); AGS.API.PointF topRight = new AGS.API.PointF (projectionLeft + width * Math.Abs(scaleX), projectionBottom + height * Math.Abs(scaleY)); square.Setup(s => s.BottomLeft).Returns(bottomLeft); square.Setup(s => s.BottomRight).Returns(bottomRight); square.Setup(s => s.TopLeft).Returns(topLeft); square.Setup(s => s.TopRight).Returns(topRight); return mask.IsMasked(new AGS.API.PointF (x, y), square.Object, scaleX, scaleY); }
public AGSLocation (PointF point, float? z = null) { _xy = point; _z = z; if (_z != null && _z.Value == point.Y) _z = null; }
public EmptyImage(PointF size) : this (size.X, size.Y) { }
public void Render (IObject obj, IViewport viewport, PointF areaScaling) { float x1 = obj.IgnoreViewport ? X1 : X1 - viewport.X; float x2 = obj.IgnoreViewport ? X2 : X2 - viewport.X; _glUtils.DrawLine (x1, Y1, x2, Y2, 1f, 1f, 0f, 0f, 1f); }
public AGSHasImage() { OnImageChanged = new AGSEvent<AGSEventArgs>(); Anchor = new PointF(0.5f, 0f); Tint = Colors.White; }
public void Render(IObject obj, IViewport viewport, PointF areaScaling) { 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); PointF resolutionFactor = new PointF(resolution.Width / gameResolution.Width, resolution.Height / gameResolution.Height); IGLMatrices matricesRender = _renderMatrixBuilder.Build(obj, obj.Animation.Sprite, obj.TreeNode.Parent, viewportMatrix, areaScaling, resolutionFactor); IGLMatrices matricesHitTest = resolutionMatches ? matricesRender : _hitTestMatrixBuilder.Build(obj, obj.Animation.Sprite, obj.TreeNode.Parent, viewportMatrix, areaScaling, GLMatrixBuilder.NoScaling); _boundingBoxBuilder.Build(BoundingBoxes, sprite.Image.Width, sprite.Image.Height, matricesHitTest, resolutionMatches, true); IGLBoundingBox hitTestBox = BoundingBoxes.HitTestBox; if (!resolutionMatches) { _boundingBoxBuilder.Build(BoundingBoxes, sprite.Image.Width, sprite.Image.Height, matricesRender, 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; float x = 0f; float y = 0f; while (parent != null) { x += parent.X; y += parent.Y; parent = parent.TreeNode.Parent; } _glUtils.DrawCross(x - viewport.X, y - viewport.Y, 10, 10, 1f, 1f, 1f, 1f); } }
private bool isWalkable(float x, float y) { PointF point = new PointF (x, y); foreach (var area in _character.Room.GetMatchingAreas(point, _character.ID)) { var walkableArea = area.GetComponent<IWalkableArea>(); if (walkableArea == null || !walkableArea.IsWalkable) continue; return true; } return false; }
private PointF getAnchorOffsets(PointF anchor, float width, float height) { float x = MathUtils.Lerp (0f, 0f, 1f, width, anchor.X); float y = MathUtils.Lerp (0f, 0f, 1f, height, anchor.Y); return new PointF (x, y); }
public void Camera_ViewportMovesTest() { Mock<ICamera> camera = new Mock<ICamera> (); AGS.API.PointF sourcePoint = new AGS.API.PointF (15f, 25f); AGS.API.PointF targetPoint = new AGS.API.PointF (55f, 65f); camera.Setup(f => f.Tick(_mocks.Viewport().Object, It.IsAny<AGS.API.Size>(), It.IsAny<AGS.API.Size>(), It.IsAny<bool>())).Callback(() => {_mocks.Viewport().Object.X = targetPoint.X; _mocks.Viewport().Object.Y = targetPoint.Y; }); _mocks.Viewport().Setup(v => v.X).Returns(sourcePoint.X); _mocks.Viewport().Setup(v => v.Y).Returns(sourcePoint.Y); _mocks.Viewport().Setup(v => v.Camera).Returns(camera.Object); var loop = getGameLoop(); loop.Update(); _mocks.Viewport().VerifySet(v => v.X = It.IsAny<float>(), Times.Once()); _mocks.Viewport().VerifySet(v => v.Y = It.IsAny<float>(), Times.Once()); _mocks.Viewport().VerifySet(v => v.X = targetPoint.X, Times.Once()); _mocks.Viewport().VerifySet(v => v.Y = targetPoint.Y, Times.Once()); }