private void CreateCollision()
 {
     frbCollision        = ShapeManager.AddAxisAlignedRectangle();
     frbCollision.ScaleX = 4;
     frbCollision.ScaleY = 4;
     frbCollision.AttachTo(this, false);
 }
        public void PreparePhysicsDebugInformation_ShouldDrawCollisionGeometryWithDifferentColor_WhenEntityIsColliding()
        {
            // Arrange
            _configurationBuilder.WithRenderCollisionGeometry(true);
            var physicsSystem       = GetPhysicsSystem();
            var physicsSceneBuilder = new PhysicsSceneBuilder();
            var circleEntity        = physicsSceneBuilder.AddCircleCollider(10, 20, 30);
            var rectangleEntity     = physicsSceneBuilder.AddRectangleCollider(10, 20, 100, 200);
            var scene = physicsSceneBuilder.Build();

            physicsSystem.ProcessPhysics(scene);

            // Assume
            Assume.That(circleEntity.GetComponent <CircleColliderComponent>().IsColliding, Is.True);
            Assume.That(rectangleEntity.GetComponent <RectangleColliderComponent>().IsColliding, Is.True);

            // Act
            physicsSystem.PreparePhysicsDebugInformation();

            // Assert
            var circle = new Circle(new Vector2(10, 20), 30);

            _debugRenderer.Received(1).DrawCircle(circle, _colorWhenColliding);

            var rectangle = new AxisAlignedRectangle(new Vector2(100, 200));
            var transform = rectangleEntity.GetComponent <Transform2DComponent>().ToMatrix();

            _debugRenderer.Received(1).DrawRectangle(rectangle, _colorWhenColliding, transform);
        }
Exemple #3
0
        private List <PositionedNode> GetNodesThatCollideWithShapeCollection(ShapeCollection sc, Dictionary <int, Dictionary <int, PositionedNode> > allNodes)
        {
            var returnValue = new List <PositionedNode>();

            if (sc != null && sc.Polygons != null)
            {
                foreach (Polygon polygon in sc.Polygons)
                {
                    polygon.ForceUpdateDependencies();
                }

                foreach (var xpair in allNodes)
                {
                    foreach (var ypair in xpair.Value)
                    {
                        PositionedNode node      = ypair.Value;
                        var            rectangle = new AxisAlignedRectangle {
                            Position = node.Position, ScaleX = 1, ScaleY = 1
                        };

                        if (sc.CollideAgainst(rectangle))
                        {
                            returnValue.Add(node);
                        }
                    }
                }
            }
            return(returnValue);
        }
    public LODMeshObject(LODMeshObject parent, QuadTreeNode quadTreeNode, AxisAlignedRectangle bounds, int depth)
    {
        Invalid = true;
        Parent = parent;
        QuadNode = quadTreeNode;
        Bounds = bounds;
        Depth = depth;
        TotalDepth = QuadNode.Depth + Depth;
        Children = new LODMeshObject[4];
        CornerReference = new bool[5];

        Center = FindOrCreateCorner(Bounds.Position, true);

        Vector2 halfSize = Bounds.Size / 2;
        Corner = new Corner[8];
        Corner[0] = FindOrCreateCorner(Bounds.Position + new Vector2(-halfSize.x, -halfSize.y), Parent == null); // bottom left
        Corner[1] = FindOrCreateCorner(Bounds.Position + new Vector2(-halfSize.x, 0), true); // left

        Corner[2] = FindOrCreateCorner(Bounds.Position + new Vector2(-halfSize.x, halfSize.y), Parent == null); // top left
        Corner[3] = FindOrCreateCorner(Bounds.Position + new Vector2(0, halfSize.y), true); // top

        Corner[4] = FindOrCreateCorner(Bounds.Position + new Vector2(halfSize.x, halfSize.y), Parent == null); // top right
        Corner[5] = FindOrCreateCorner(Bounds.Position + new Vector2(halfSize.x, 0), true); // right

        Corner[6] = FindOrCreateCorner(Bounds.Position + new Vector2(halfSize.x, -halfSize.y), Parent == null); // bottom right
        Corner[7] = FindOrCreateCorner(Bounds.Position + new Vector2(0, -halfSize.y), true); // bottom
    }
        public TextWidthHandles()
        {
            mLeftLine        = ShapeManager.AddLine();
            mTopSolidLine    = ShapeManager.AddLine();
            mBottomSolidLine = ShapeManager.AddLine();
            mTopSoftLine     = ShapeManager.AddLine();
            mBottomSoftLine  = ShapeManager.AddLine();
            mRightLine       = ShapeManager.AddLine();

            mRightBox = ShapeManager.AddAxisAlignedRectangle();

            mLeftLine.Color        = Color.Green;
            mTopSolidLine.Color    = Color.Green;
            mBottomSolidLine.Color = Color.Green;
            mRightLine.Color       = Color.Green;

#if FRB_MDX
            mTopSoftLine.Color = Color.FromArgb(
                128, Color.Green);

            mBottomSoftLine.Color = mTopSoftLine.Color;
#else
            throw new NotImplementedException();
#endif

            mRightBox.Color = Color.Orange;
        }
        private void UpdateCornerRectangleCount()
        {
            int numberOfEdges = 0;

            foreach (Polygon polygon in CurrentShapeCollection.Polygons)
            {
                // Polygons of 1 point should still draw their point

                if (polygon.Points.Count == 1)
                {
                    numberOfEdges++;
                }
                else
                {
                    numberOfEdges +=
                        polygon.Points.Count - 1; // assume the last point repeats
                }
            }

            while (mCorners.Count < numberOfEdges)
            {
                AxisAlignedRectangle newRectangle = ShapeManager.AddAxisAlignedRectangle();
                newRectangle.Color = Color.Red;

                newRectangle.ScaleX = newRectangle.ScaleY = .3f;

                mCorners.Add(newRectangle);
            }

            while (mCorners.Count > numberOfEdges)
            {
                ShapeManager.Remove(mCorners[mCorners.Count - 1]);
            }
        }
Exemple #7
0
        private void btnLoadScene_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            IList <ICartesianCoordinate> coordinates = null;
            CostMatrix <double>          costs       = null;

            if (radioButton1.Checked)
            {
                coordinates = LoadCSV_Coordinates(Path.Combine(dropboxlocation, @"10001.csv"));
            }
            else if (radioButton2.Checked)
            {
                coordinates = new[] { new Point(3, 0), new Point(3, 5), new Point(5, 2), new Point(1, 1), new Point(4, 6) };
            }

            if (radioButton4.Checked)
            {
                costs = LoadCSV_Costs(Path.Combine(dropboxlocation, @"dump.csv"), coordinates.Count);
            }
            else if (radioButton3.Checked)
            {
                var costWithFunction = new CostWithFunction <ICartesianCoordinate>(coordinates, Diverse.DistanceSquared);
                costs = new CostMatrix <double>(costWithFunction, coordinates.Count);
            }

            boundingRectangle = coordinates.BoundingRectangle(); // for viewport

            algorithmSet = new AlgorithmSet <ICartesianCoordinate>(coordinates, costs);
            algorithmSet.ClusterAfterIterationEvent += algorithmSet_ClusterAfterIterationEvent;
            algorithmSetClusters      = null;
            lastTSPResultWithClusters = null;

            panel1.Refresh();
        }
        public bool CollideAgainstSolid(AxisAlignedRectangle movableObject)
        {
            bool toReturn = false;

            toReturn = mShapes.CollideAgainstBounce(movableObject, true, mSortAxis, 1, 0, 0);

            return(toReturn);
        }
        public ResourceReturnHighLevelGoal(Unit owner, TileNodeNetwork nodeNetwork, Building targetReturnBuilding)
        {
            Owner       = owner;
            NodeNetwork = nodeNetwork;

            ResourceReturnBuilding     = targetReturnBuilding;
            ResourceReturnBuildingTile = GetSingleTile(ResourceReturnBuilding.Position);
        }
Exemple #10
0
        private void CreatePolygonForAxisAlignedRectangle(AxisAlignedRectangle axisAlignedRectangle)
        {
            Polygon newPoly = CreatePolygonForIScalable(axisAlignedRectangle);

            const int pixelsOut = 2;

            GrowPolygonByPixels(pixelsOut, axisAlignedRectangle.Z, newPoly);
        }
        public static bool IsInLineOfSight(Vector3 position1, Vector3 position2, float collisionThreshold, ShapeCollection shapeCollection)
        {
            Segment segment = new Segment(new FlatRedBall.Math.Geometry.Point(ref position1),
                                          new FlatRedBall.Math.Geometry.Point(ref position2));

            for (int i = 0; i < shapeCollection.Polygons.Count; i++)
            {
                Polygon polygon = shapeCollection.Polygons[i];

                if (polygon.CollideAgainst(segment) ||
                    (collisionThreshold > 0 && segment.DistanceTo(polygon) < collisionThreshold))
                {
                    return(false);
                }
            }

            for (int i = 0; i < shapeCollection.AxisAlignedRectangles.Count; i++)
            {
                AxisAlignedRectangle rectangle = shapeCollection.AxisAlignedRectangles[i];

                FlatRedBall.Math.Geometry.Point throwaway;

                if (rectangle.Intersects(segment, out throwaway) ||
                    (collisionThreshold > 0 && segment.DistanceTo(rectangle) < collisionThreshold))
                {
                    return(false);
                }
            }

            for (int i = 0; i < shapeCollection.Circles.Count; i++)
            {
                Circle circle = shapeCollection.Circles[i];

                if (segment.DistanceTo(circle) < collisionThreshold)
                {
                    return(false);
                }
            }

#if DEBUG
            if (shapeCollection.Capsule2Ds.Count != 0)
            {
                throw new Exception("IsInLineOfSight does not support ShapeCollections with Capsule2Ds");
            }
#endif

            for (int i = 0; i < shapeCollection.Lines.Count; i++)
            {
                Line line = shapeCollection.Lines[i];

                if (segment.DistanceTo(line.AsSegment()) < collisionThreshold)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #12
0
        private void AddShapes(ShapeCollection shapeCol, float ScaleX, float ScaleY, Vector3 position, bool Visible, Color color)
        {
            AxisAlignedRectangle rect = new AxisAlignedRectangle(ScaleX, ScaleY);

            rect.Position = position;
            rect.Visible  = false;
            rect.Color    = color;
            shapeCol.AxisAlignedRectangles.Add(rect);
        }
        public void LowerRight_Test(double centerX, double centerY, double width, double height, double expectedX, double expectedY)
        {
            // Arrange
            var rectangle = new AxisAlignedRectangle(centerX, centerY, width, height);

            // Act
            // Assert
            Assert.That(rectangle.LowerRight, Is.EqualTo(new Vector2(expectedX, expectedY)).Using(Vector2Comparer));
        }
        public void Height_Test()
        {
            // Arrange
            var rectangle = new AxisAlignedRectangle(20, 10);

            // Act
            // Assert
            Assert.That(rectangle.Height, Is.EqualTo(10));
        }
        public void Min_Test(double centerX, double centerY, double width, double height, double minX, double minY)
        {
            // Arrange
            var rectangle = new AxisAlignedRectangle(centerX, centerY, width, height);

            // Act
            // Assert
            Assert.That(rectangle.Min, Is.EqualTo(new Vector2(minX, minY)).Using(Vector2Comparer));
        }
Exemple #16
0
        public NavArea(AxisAlignedRectangle polygon, int id)
        {
            Portals = new List <TNode>();

            ID      = id;
            Polygon = polygon;

            _CalculateEdges();
        }
        public void Width_Test()
        {
            // Arrange
            var rectangle = new AxisAlignedRectangle(20, 10);

            // Act
            // Assert
            Assert.That(rectangle.Width, Is.EqualTo(20));
        }
        public static void ConvertTiledObjectToFrbShape(mapObjectgroupObject @object, out Polygon polygon, out AxisAlignedRectangle rectangle, out Circle circle)
        {
            polygon   = null;
            rectangle = null;
            circle    = null;
            if (@object.polygon != null)
            {
                foreach (mapObjectgroupObjectPolygon tiledPolygon in @object.polygon)
                {
                    // TODO: Make this a rectangle object
                    polygon = ConvertTmxObjectToFrbPolygon(@object.Name,
                                                           @object.x, @object.y, @object.Rotation, tiledPolygon.points, true);
                    polygon.Visible = tiledPolygon.Visible == 1;
                }
            }

            if (@object.polyline != null)
            {
                foreach (mapObjectgroupObjectPolyline polyline in @object.polyline)
                {
                    polygon = ConvertTmxObjectToFrbPolygon(@object.Name,
                                                           @object.x, @object.y, @object.Rotation, polyline.points, false);
                    polygon.Visible = polyline.Visible == 1;
                }
            }

            if (@object.polygon == null && @object.polyline == null)
            {
                if (@object.Rotation == 0 && @object.ellipse == null)
                {
                    rectangle = new AxisAlignedRectangle()
                    {
                        Name   = @object.Name,
                        X      = (float)@object.x + (@object.width / 2),
                        Y      = (float)[email protected] - (@object.height / 2),
                        ScaleX = @object.width / 2,
                        ScaleY = @object.height / 2,
                    };
                    rectangle.Visible = @object.Visible == 1;
                }
                else if (@object.ellipse != null && @object.width == @object.height)
                {
                    circle = new Circle()
                    {
                        Name   = @object.Name,
                        X      = (float)@object.x + (@object.width / 2),
                        Y      = (float)[email protected] - (@object.height / 2),
                        Radius = @object.width / 2
                    };
                    circle.Visible = @object.Visible == 1;
                }
                else
                {
                    polygon = ConvertTmxObjectToFrbPolygon(@object.Name, @object.x, @object.y, @object.width, @object.height, @object.Rotation, @object.ellipse);
                }
            }
        }
        public void Constructor_FromWidthAndHeight_ShouldSetCenterAndDimensions()
        {
            // Arrange
            // Act
            var rectangle = new AxisAlignedRectangle(123, 456);

            // Assert
            Assert.That(rectangle.Center, Is.EqualTo(Vector2.Zero));
            Assert.That(rectangle.Dimensions, Is.EqualTo(new Vector2(123, 456)));
        }
        public void Constructor_FromCenterXAndCenterYAndWidthAndHeight_ShouldSetCenterAndDimensions()
        {
            // Arrange
            // Act
            var rectangle = new AxisAlignedRectangle(12, 34, 56, 78);

            // Assert
            Assert.That(rectangle.Center, Is.EqualTo(new Vector2(12, 34)));
            Assert.That(rectangle.Dimensions, Is.EqualTo(new Vector2(56, 78)));
        }
        private void UpdateRepositionDirectionsFor(AxisAlignedRectangle newAar)
        {
            // Let's see what is surrounding this rectangle and update it and the surrounding rects appropriately
            float keyValue = GetKeyValue(newAar.X, newAar.Y);

            float keyValueBefore = keyValue - GridSize * 3 / 2.0f;
            float keyValueAfter  = keyValue + GridSize * 3 / 2.0f;

            int before = Rectangles.GetFirstAfter(keyValueBefore, mSortAxis, 0, Rectangles.Count);
            int after  = Rectangles.GetFirstAfter(keyValueAfter, mSortAxis, 0, Rectangles.Count);

            AxisAlignedRectangle leftOf  = GetTileAt(newAar.X - GridSize, newAar.Y, before, after);
            AxisAlignedRectangle rightOf = GetTileAt(newAar.X + GridSize, newAar.Y, before, after);
            AxisAlignedRectangle above   = GetTileAt(newAar.X, newAar.Y + GridSize, before, after);
            AxisAlignedRectangle below   = GetTileAt(newAar.X, newAar.Y - GridSize, before, after);

            RepositionDirections directions = RepositionDirections.All;

            if (leftOf != null)
            {
                directions -= RepositionDirections.Left;
                if ((leftOf.RepositionDirections & RepositionDirections.Right) == RepositionDirections.Right)
                {
                    leftOf.RepositionDirections -= RepositionDirections.Right;
                }
            }
            if (rightOf != null)
            {
                directions -= RepositionDirections.Right;

                if ((rightOf.RepositionDirections & RepositionDirections.Left) == RepositionDirections.Left)
                {
                    rightOf.RepositionDirections -= RepositionDirections.Left;
                }
            }
            if (above != null)
            {
                directions -= RepositionDirections.Up;

                if ((above.RepositionDirections & RepositionDirections.Down) == RepositionDirections.Down)
                {
                    above.RepositionDirections -= RepositionDirections.Down;
                }
            }
            if (below != null)
            {
                directions -= RepositionDirections.Down;
                if ((below.RepositionDirections & RepositionDirections.Up) == RepositionDirections.Up)
                {
                    below.RepositionDirections -= RepositionDirections.Up;
                }
            }

            newAar.RepositionDirections = directions;
        }
Exemple #22
0
        private static void AddRectangleStrip(TileShapeCollection tileShapeCollection, float x, float y, float width, float height)
        {
            AxisAlignedRectangle rectangle = new AxisAlignedRectangle();

            rectangle.X      = x;
            rectangle.Y      = y;
            rectangle.Width  = width;
            rectangle.Height = height;

            tileShapeCollection.Rectangles.Add(rectangle);
        }
        public SplinePointSelectionMarker()
        {
            mRectangle       = ShapeManager.AddAxisAlignedRectangle();
            mLine            = ShapeManager.AddLine();
            mRectangle.Color = Color.LightBlue;

            mEndpoint1       = ShapeManager.AddCircle();
            mEndpoint1.Color = Color.Yellow;
            mEndpoint2       = ShapeManager.AddCircle();
            mEndpoint2.Color = Color.Yellow;
        }
Exemple #24
0
        public CameraBounds(Camera cameraShowing)
        {
            if (cameraShowing == null)
            {
                throw new NullReferenceException("Need a non-null Camera to show");
            }

            mCamera = cameraShowing;

            mRectangle = ShapeManager.AddAxisAlignedRectangle();
        }
        public SplinePointSelectionMarker()
        {
            mRectangle = ShapeManager.AddAxisAlignedRectangle();
            mLine = ShapeManager.AddLine();
            mRectangle.Color = Color.LightBlue;

            mEndpoint1 = ShapeManager.AddCircle();
            mEndpoint1.Color = Color.Yellow;
            mEndpoint2 = ShapeManager.AddCircle();
            mEndpoint2.Color = Color.Yellow;
        }
        public void ToString_Test(double x, double y, double w, double h, string expected)
        {
            // Arrange
            var rectangle = new AxisAlignedRectangle(x, y, w, h);

            // Act
            var actual = rectangle.ToString();

            // Assert
            Assert.That(actual, Is.EqualTo(expected));
        }
        public override void Initialize(bool addToManagers)
        {
            base.Initialize(addToManagers);

            mObjectHighlight = new ObjectHighlight();
            mObjectHighlight.Color = Color.Orange;
            mEditingHandles = new EditingHandles();

            mRectangle = ShapeManager.AddAxisAlignedRectangle();
            mSprite = SpriteManager.AddSprite("redball.bmp");
            mSprite.X = 5;
        }
Exemple #28
0
        public CameraBounds(Camera cameraShowing)
        {
            if (cameraShowing == null)
            {
                throw new NullReferenceException("Need a non-null Camera to show");
            }

            mCamera = cameraShowing;

            mRectangle = ShapeManager.AddAxisAlignedRectangle();

        }
Exemple #29
0
        public override void Initialize(bool addToManagers)
        {
            base.Initialize(addToManagers);

            mObjectHighlight       = new ObjectHighlight();
            mObjectHighlight.Color = Color.Orange;
            mEditingHandles        = new EditingHandles();

            mRectangle = ShapeManager.AddAxisAlignedRectangle();
            mSprite    = SpriteManager.AddSprite("redball.bmp");
            mSprite.X  = 5;
        }
        public ResourceCollectHighLevelGoal(Unit owner, TileNodeNetwork nodeNetwork, Vector3 clickPosition, AxisAlignedRectangle targetResourceMergedTile, ResourceType targetResourceType, PositionedObjectList <Building> allBuildings)
        {
            Owner       = owner;
            NodeNetwork = nodeNetwork;
            TargetResourceMergedTile = targetResourceMergedTile;
            TargetResourceType       = targetResourceType;
            AllBuildings             = allBuildings;

            // TODO: Handle when we can't get to desired tile (e.g., tree in the middle of forest).
            SingleTargetResourceTileCenter = GetSingleTileCenterFromClickPosition(clickPosition);
            SingleTargetResourceTile       = GetSingleTile(SingleTargetResourceTileCenter);
        }
 public QuadTreeNode(QuadTree quadTree, QuadTreeNode parent, Vector2 position, float length, float minSize, int depth)
 {
     Active = true;
     Parent = parent;
     QuadTree = quadTree;
     Position = position;
     SideLength = length;
     MinSize = minSize;
     Depth = depth;
     AAR = new AxisAlignedRectangle(Position, SideLength * 2);
     MeshObject = new LODMeshObject(null, this, AAR, 0);
     CreateGameobject();
 }
        public WalkToHighLevelGoal GetResourceReturnWalkGoal()
        {
            ResourceReturnBuildingTile = GetSingleTile(ResourceReturnBuilding.Position);
            Vector3 pointSlightlySkewedTowardOwner = DeterminePositionWithinTileSlightlyCloserToOwner(ResourceReturnBuildingTile.Position, ResourceReturnBuildingTile.Width);
            var     walkGoal = new WalkToHighLevelGoal()
            {
                Owner          = Owner,
                TargetPosition = pointSlightlySkewedTowardOwner,
                ForceAttemptToGetToExactTarget = true,
            };

            return(walkGoal);
        }
		void CustomInitialize()
		{
            mStatic = new AxisAlignedRectangle();
            mFalling = new AxisAlignedRectangle();
            ShapeManager.AddAxisAlignedRectangle(mStatic);
            ShapeManager.AddAxisAlignedRectangle(mFalling);

            mStatic.ScaleX = 32;
            mStatic.ScaleY = 32;

            mFalling.ScaleX = 16;
            mFalling.ScaleY = 16;
		}
Exemple #34
0
        void CustomInitialize()
        {
            mStatic  = new AxisAlignedRectangle();
            mFalling = new AxisAlignedRectangle();
            ShapeManager.AddAxisAlignedRectangle(mStatic);
            ShapeManager.AddAxisAlignedRectangle(mFalling);

            mStatic.ScaleX = 32;
            mStatic.ScaleY = 32;

            mFalling.ScaleX = 16;
            mFalling.ScaleY = 16;
        }
        public void Overlaps_ShouldReturnTrue_GivenAxisAlignedRectangleThatOverlapsOtherAxisAlignedRectangle(double centerX1, double centerY1, double width1,
                                                                                                             double height1, double centerX2, double centerY2, double width2, double height2, bool expected)
        {
            // Arrange
            var rectangle1 = new AxisAlignedRectangle(centerX1, centerY1, width1, height1);
            var rectangle2 = new AxisAlignedRectangle(centerX2, centerY2, width2, height2);

            // Act
            var actual = rectangle1.Overlaps(rectangle2);

            // Assert
            Assert.That(actual, Is.EqualTo(expected));
        }
        public void Contains_ShouldReturnTrue_GivenPointThatIsContainedInAxisAlignedRectangle(double centerX, double centerY, double width, double height,
                                                                                              double pointX, double pointY, bool expected)
        {
            // Arrange
            var rectangle = new AxisAlignedRectangle(centerX, centerY, width, height);
            var point     = new Vector2(pointX, pointY);

            // Act
            var actual = rectangle.Contains(point);

            // Assert
            Assert.That(actual, Is.EqualTo(expected));
        }
Exemple #37
0
        public static void Merge(Polygon polygon, AxisAlignedRectangle rectangle)
        {
            List<ContactPoint> contactPoints = GetContactPoints(polygon, rectangle);

            int firstPointToStartAt = GetPointToStartAt(polygon, rectangle);
        
            if (firstPointToStartAt == -1)
            {
                throw new NotImplementedException();
                // return a polygon that is the same shape as the rectangle
            }

            List<Vector3> thisVertices = GetAbsoluteVertices(polygon);
            List<Vector3> otherVertices = GetAbsoluteVertices(rectangle);

            SetPointsFromContactPointsAndVertices(polygon, null, contactPoints, firstPointToStartAt, thisVertices, otherVertices);
        }
        private void UpdateRepositionDirectionsFor(AxisAlignedRectangle newAar)
        {
            // Let's see what is surrounding this rectangle and update it and the surrounding rects appropriately
            float keyValue = GetKeyValue(newAar.X, newAar.Y);

            float keyValueBefore = keyValue - GridSize * 3 / 2.0f;
            float keyValueAfter = keyValue + GridSize * 3 / 2.0f;

            int before = Rectangles.GetFirstAfter(keyValueBefore, mSortAxis, 0, Rectangles.Count);
            int after = Rectangles.GetFirstAfter(keyValueAfter, mSortAxis, 0, Rectangles.Count);

            AxisAlignedRectangle leftOf = GetTileAt(newAar.X - GridSize, newAar.Y, before, after);
            AxisAlignedRectangle rightOf = GetTileAt(newAar.X + GridSize, newAar.Y, before, after);
            AxisAlignedRectangle above = GetTileAt(newAar.X, newAar.Y + GridSize, before, after);
            AxisAlignedRectangle below = GetTileAt(newAar.X, newAar.Y - GridSize, before, after);

            RepositionDirections directions = RepositionDirections.All;
            if (leftOf != null)
            {
                directions -= RepositionDirections.Left;
                if ((leftOf.RepositionDirections & RepositionDirections.Right) == RepositionDirections.Right)
                {
                    leftOf.RepositionDirections -= RepositionDirections.Right;
                }
            }
            if (rightOf != null)
            {
                directions -= RepositionDirections.Right;

                if ((rightOf.RepositionDirections & RepositionDirections.Left) == RepositionDirections.Left)
                {
                    rightOf.RepositionDirections -= RepositionDirections.Left;
                }
            }
            if (above != null)
            {
                directions -= RepositionDirections.Up;

                if ((above.RepositionDirections & RepositionDirections.Down) == RepositionDirections.Down)
                {
                    above.RepositionDirections -= RepositionDirections.Down;
                }
            }
            if (below != null)
            {
                directions -= RepositionDirections.Down;
                if ((below.RepositionDirections & RepositionDirections.Up) == RepositionDirections.Up)
                {
                    below.RepositionDirections -= RepositionDirections.Up;
                }
            }

            newAar.RepositionDirections = directions;

        }
        public bool CollideAgainstSolid(AxisAlignedRectangle movableObject)
        {
            bool toReturn = false;

            toReturn = mShapes.CollideAgainstBounce(movableObject, true, mSortAxis, 1, 0, 0);

            return toReturn;
        }
        public ObjectHighlight()
        {
            mHighlightRectangle = ShapeManager.AddAxisAlignedRectangle();

        }
Exemple #41
0
        private void CreatePolygonForAxisAlignedRectangle(AxisAlignedRectangle axisAlignedRectangle)
        {
            Polygon newPoly = CreatePolygonForIScalable(axisAlignedRectangle);

            const int pixelsOut = 2;

            GrowPolygonByPixels(pixelsOut, axisAlignedRectangle.Z, newPoly);
        }
Exemple #42
0
 private static int GetPointToStartAt(Polygon polygon, AxisAlignedRectangle rectangle)
 {
     int firstPointToStartAt = -1;
     for (int i = 0; i < polygon.mVertices.Length - 1; i++)
     {
         if (!rectangle.IsPointInside(ref polygon.mVertices[i].Position))
         {
             firstPointToStartAt = i;
             break;
         }
     }
     return firstPointToStartAt;
 }
        public TextWidthHandles()
        {
            mLeftLine = ShapeManager.AddLine();
            mTopSolidLine = ShapeManager.AddLine();
            mBottomSolidLine = ShapeManager.AddLine();
            mTopSoftLine = ShapeManager.AddLine();
            mBottomSoftLine = ShapeManager.AddLine();
            mRightLine = ShapeManager.AddLine();

            mRightBox = ShapeManager.AddAxisAlignedRectangle();

            mLeftLine.Color = Color.Green;
            mTopSolidLine.Color = Color.Green;
            mBottomSolidLine.Color = Color.Green;
            mRightLine.Color = Color.Green;

#if FRB_MDX
            mTopSoftLine.Color = Color.FromArgb(
                128, Color.Green);

            mBottomSoftLine.Color = mTopSoftLine.Color;
#else
            throw new NotImplementedException();
#endif

            mRightBox.Color = Color.Orange;


        }
Exemple #44
0
        //----------------------------------------------------------------------------------
        //--------FUNKTIONEN----------------------------------------------------------------
        void GhostInitialize()
        {
            TheodorGhostInstance.Collision.Height = 205;
            TheodorGhostInstance.Collision.Width = 110; // Theo Ghost Collision Size
            TheodorGhostInstance.X = 530;

            // Create Collision: GhostBoden
            GhostBoden = new AxisAlignedRectangle();
            GhostBoden.ScaleX = 1800;
            GhostBoden.ScaleY = 50;
            GhostBoden.Y = -50;

            this.GhostBodenCollision.AxisAlignedRectangles.Add(GhostBoden);  // Add it to the ShapeCollection so the ghost can collide against it
        }
        //------INITIALIZE----------------------------------------------------------------
        public virtual void CustomInitialize()
        {
            EnableKeys();
            FixLayers();

            Manager.LevelStartTime = TimeManager.CurrentTime;

            Manager.CollisionsVisible = false;  // Collision Visibility An/Aus
            DisableLayers = false;      // Erstmal Layer aktivieren
            DisableLayerBack = false;   // LayerBack aktivieren

            //TheodorInstance erstellen --"Child" -- "GrownUp"--
            StartCharacterState("GrownUp", -550);

            CollisionHeightLayerFront = PlatformerCharacterBase.getInstance().Collision.Height * 0.5f;
            CollisionHeightLayerMid = PlatformerCharacterBase.getInstance().Collision.Height * 0.45f;
            CollisionHeightLayerBack = PlatformerCharacterBase.getInstance().Collision.Height * 0.4f;
            PlatformerCharacterBase.getInstance().Collision.Height = CollisionHeightLayerFront;

            CollisionWidthLayerFront = PlatformerCharacterBase.getInstance().Collision.Width * 0.5f;
            CollisionWidthLayerMid = PlatformerCharacterBase.getInstance().Collision.Width * 0.45f;
            CollisionWidthLayerBack = PlatformerCharacterBase.getInstance().Collision.Width * 0.4f;
            PlatformerCharacterBase.getInstance().Collision.Width = CollisionWidthLayerFront;

            // Create Collision: Boden
            if (Boden == null)
            {
                Boden = new AxisAlignedRectangle();
                Boden.ScaleX = 2200;
                Boden.ScaleY = 50;
                Boden.Y = -50;
                this.SolidCollisions.AxisAlignedRectangles.Add(Boden);  // Add it to the ShapeCollection so the player can collide against it
                PlatformerCharacterBase.getInstance().Y = 75;       // Make the character appear on top of the rectangle
            }
            InitializeFlower();

            if (Manager.CollisionsVisible) CollisionVisibilityOn();
        }
Exemple #46
0
        public void SetCollision(AxisAlignedRectangle rectangle)
        {
            mCollisionCircle = null;
            mCollisionPolygon = null;
            mCollisionLine = null;

            mCollisionAxisAlignedRectangle = rectangle;
            //mCollisionAxisAlignedRectangle.ScaleX = ScaleX;
            //mCollisionAxisAlignedRectangle.ScaleY = ScaleY;

            mCollisionAxisAlignedRectangle.AttachTo(this, false);
            mCollisionAxisAlignedRectangle.ForceUpdateDependencies();
        }
Exemple #47
0
        public void SetCollision(Line line)
        {
            mCollisionCircle = null;
            mCollisionAxisAlignedRectangle = null;
            mCollisionPolygon = null;

            mCollisionLine = line;

            mCollisionLine.AttachTo(this, false);
            mCollisionLine.ForceUpdateDependencies();
        }
Exemple #48
0
 public CameraBounds(CameraSave cameraSave)
 {
     mCameraSave = cameraSave;
     mRectangle = ShapeManager.AddAxisAlignedRectangle();
 }
Exemple #49
0
        private void btnLoadScene_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            IList<ICartesianCoordinate> coordinates = null;
            CostMatrix<double> costs = null;

            if (radioButton1.Checked)
            {
                coordinates = LoadCSV_Coordinates(Path.Combine(dropboxlocation, @"10001.csv"));
            }
            else if (radioButton2.Checked)
            {
                coordinates = new[] { new Point(3, 0), new Point(3, 5), new Point(5, 2), new Point(1, 1), new Point(4, 6) };
            }

            if (radioButton4.Checked)
            {
                costs = LoadCSV_Costs(Path.Combine(dropboxlocation, @"dump.csv"), coordinates.Count);
            }
            else if (radioButton3.Checked)
            {
                var costWithFunction = new CostWithFunction<ICartesianCoordinate>(coordinates, Diverse.DistanceSquared);
                costs = new CostMatrix<double>(costWithFunction, coordinates.Count);
            }

            boundingRectangle = coordinates.BoundingRectangle(); // for viewport

            algorithmSet = new AlgorithmSet<ICartesianCoordinate>(coordinates, costs);
            algorithmSet.ClusterAfterIterationEvent += algorithmSet_ClusterAfterIterationEvent;
            algorithmSetClusters = null;
            lastTSPResultWithClusters = null;

            panel1.Refresh();
        }
Exemple #50
0
        public float DistanceTo(AxisAlignedRectangle rectangle)
        {
            float finalDistance = float.MaxValue;

            finalDistance = System.Math.Min(finalDistance, DistanceTo(rectangle.Left, rectangle.Top));
            finalDistance = System.Math.Min(finalDistance, DistanceTo(rectangle.Left, rectangle.Bottom));
            finalDistance = System.Math.Min(finalDistance, DistanceTo(rectangle.Right, rectangle.Top));
            finalDistance = System.Math.Min(finalDistance, DistanceTo(rectangle.Right, rectangle.Bottom));

            Segment rectSegment;

            rectSegment = new Segment(rectangle.Left, rectangle.Top, rectangle.Left, rectangle.Bottom);
            finalDistance = System.Math.Min(finalDistance, DistanceTo(rectSegment));
            rectSegment = new Segment(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Top);
            finalDistance = System.Math.Min(finalDistance, DistanceTo(rectSegment));
            rectSegment = new Segment(rectangle.Right, rectangle.Top, rectangle.Right, rectangle.Bottom);
            finalDistance = System.Math.Min(finalDistance, DistanceTo(rectSegment));
            rectSegment = new Segment(rectangle.Left, rectangle.Bottom, rectangle.Right, rectangle.Bottom);
            finalDistance = System.Math.Min(finalDistance, DistanceTo(rectSegment));

            return finalDistance;
        }
        public void AddCollisionAtWorld(float x, float y)
        {
            // Make sure there isn't already collision here
            if (GetTileAt(x, y) == null)
            {
                // x and y
                // represent
                // the center
                // of the tile
                // where the user
                // may want to add 
                // collision.  Let's
                // subtract half width/
                // height so we can use the
                // bottom/left
                float roundedX = MathFunctions.RoundFloat(x - GridSize / 2.0f, GridSize, mLeftSeedX);
                float roundedY = MathFunctions.RoundFloat(y - GridSize / 2.0f, GridSize, mBottomSeedY);

                AxisAlignedRectangle newAar = new AxisAlignedRectangle();
                newAar.Width = GridSize;
                newAar.Height = GridSize;
                newAar.Left = roundedX;
                newAar.Bottom = roundedY;

                if (this.mVisible)
                {
                    newAar.Visible = true;
                }

                float keyValue = GetKeyValue(roundedX, roundedY);

                int index = mShapes.AxisAlignedRectangles.GetFirstAfter(keyValue, mSortAxis,
                    0, mShapes.AxisAlignedRectangles.Count);

                mShapes.AxisAlignedRectangles.Insert(index, newAar);

                UpdateRepositionDirectionsFor(newAar);
            }
        }
Exemple #52
0
        public ReactiveHud()
        {
            mCameraBounds = new CameraBounds(EditorData.BoundsCamera);

            mCurrentAxisAlignedRectangleHighlight = ShapeManager.AddAxisAlignedRectangle();
            mCurrentAxisAlignedRectangleHighlight.Visible = false;

            mCurrentAxisAlignedCubeHighlight = ShapeManager.AddAxisAlignedRectangle();
            mCurrentAxisAlignedCubeHighlight.Visible = false;

            mCurrentCircleHighlight = ShapeManager.AddAxisAlignedRectangle();
            mCurrentCircleHighlight.Visible = false;

            mCurrentSphereHighlight = ShapeManager.AddAxisAlignedRectangle();
            mCurrentSphereHighlight.Visible = false;

            mCrossHair = new Crosshair();
            mCrossHair.Visible = false;


            float screensize = 5f;
            Vector3 forwardVector = MathFunctions.ForwardVector3;
            Matrix rotationMatrix = SpriteManager.Camera.RotationMatrix;
            MathFunctions.TransformVector(ref forwardVector, ref rotationMatrix);


            float planeDistance = Vector3.Dot(forwardVector, -SpriteManager.Camera.Position);

            float planeScreenHeight = 2f * planeDistance * (float)Math.Tan((double)SpriteManager.Camera.FieldOfView);
            float planeScreenWidth = planeScreenHeight / SpriteManager.Camera.FieldOfView;


            float width = screensize * planeScreenWidth / (float)SpriteManager.Camera.DestinationRectangle.Width;
            float height = screensize * planeScreenHeight / (float)SpriteManager.Camera.DestinationRectangle.Height;


            mNewPointPolygon = Polygon.CreateEquilateral(3, Math.Min(width, height), 0); //.3f, 0);
            mNewPointPolygon.Color = EditorProperties.NewPointPolygonColor;

            mPointText = TextManager.AddText("");

            NewPointPolygonScale = 10 / SpriteManager.Camera.PixelsPerUnitAt(mNewPointPolygon.Z);

        }
 public bool CollideAgainst(AxisAlignedRectangle rectangle)
 {
     return mShapes.CollideAgainst(rectangle, true, mSortAxis);
 }
Exemple #54
0
        private void TestForPushingOnPolygonCorner()
        {
            Cursor cursor = GuiManager.Cursor;

            if (cursor.WindowOver != null)
                return;

            #region Primary Push
            if (cursor.PrimaryPush)
            {
                mCornerRectangleGrabbed = null;
                mCornerIndexGrabbed = -1;
                mCornerIndexSelected = -1;
                bool pushHandled = false;

                if (EditorData.EditingLogic.CurrentShapeCollection.Polygons.Count != 0)
                {
                    int rectangleNumber = 0;
                    // See if the user is over any of the corners
                    foreach (Polygon polygon in EditorData.EditingLogic.CurrentShapeCollection.Polygons)
                    {
                        for (int i = 0; i < polygon.Points.Count - 1; i++)
                        {
                            if (cursor.IsOn<AxisAlignedRectangle>(mCorners[rectangleNumber]))
                            {
                                mCornerIndexGrabbed = i;
                                mCornerIndexSelected = i;
                                mCornerRectangleGrabbed = mCorners[rectangleNumber];

                                pushHandled = true;
                                UndoManager.AddToWatch(polygon);
                                break;
                            }

                            rectangleNumber++;
                        }

                        if (pushHandled)
                            break;
                    }
                }
            }
            #endregion

            #region Primary Down

            if ( this.mCornerRectangleGrabbed != null)
            {
                if (GuiData.ToolsWindow.IsMoveButtonPressed)
                {
                    Polygon parentPolygon = mCornerRectangleGrabbed.Parent as Polygon;

                    // Get the position of the cursor in object space
                    Vector3 newRelativePosition = new Vector3(cursor.WorldXAt(0), cursor.WorldYAt(0), 0);

                    newRelativePosition -= parentPolygon.Position;

                    Matrix invertedMatrix = parentPolygon.RotationMatrix;
#if FRB_MDX
                    invertedMatrix.Invert();
                    Vector4 temporary = Vector3.Transform(newRelativePosition, invertedMatrix);
#else
                    Matrix.Invert(ref invertedMatrix, out invertedMatrix);

                    Vector3 temporary = newRelativePosition;

                    MathFunctions.TransformVector(ref temporary, ref invertedMatrix);
#endif


                    mCornerRectangleGrabbed.RelativePosition = new Vector3(temporary.X, temporary.Y, 0);

                    parentPolygon.SetPoint(mCornerIndexGrabbed, mCornerRectangleGrabbed.RelativePosition.X,
                        mCornerRectangleGrabbed.RelativePosition.Y);

                    if (mCornerIndexGrabbed == 0)
                    {
                        parentPolygon.SetPoint(
                            parentPolygon.Points.Count - 1,
                            mCornerRectangleGrabbed.RelativePosition.X,
                            mCornerRectangleGrabbed.RelativePosition.Y);
                    }
                }
            }

            #endregion

            #region Primary Release

            if (cursor.PrimaryClick)
            {
                if (mCornerRectangleGrabbed == null)
                {
                    mCornerIndexSelected = -1;
                }
                else
                {
                    UndoManager.RecordUndos<Polygon>();
                    UndoManager.ClearObjectsWatching<Polygon>();

                }

                mCornerRectangleGrabbed = null;
                mCornerIndexGrabbed = -1;



            }

            #endregion
        }
Exemple #55
0
        public bool CollideAgainst(AxisAlignedRectangle axisAlignedRectangle)
        {
            if (mCollisionAxisAlignedRectangle != null)
            {
                return axisAlignedRectangle.CollideAgainst(mCollisionAxisAlignedRectangle);
            }
            else if (mCollisionCircle != null)
            {
                return axisAlignedRectangle.CollideAgainst(mCollisionCircle);
            }
            else if (mCollisionPolygon != null)
            {
                return mCollisionPolygon.CollideAgainst(axisAlignedRectangle);
            }
            else if (mCollisionLine != null)
            {
                return mCollisionLine.CollideAgainst(axisAlignedRectangle);
            }

            return false;
        }
Exemple #56
0
        private static Segment[] GetSegments(AxisAlignedRectangle rectangle)
        {
            Segment[] rectangleSegments = new Segment[4];

            rectangleSegments[0] = new Segment(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Top); // top
            rectangleSegments[1] = new Segment(rectangle.Right, rectangle.Top, rectangle.Right, rectangle.Bottom); // right
            rectangleSegments[2] = new Segment(rectangle.Right, rectangle.Bottom, rectangle.Left, rectangle.Bottom); // bottom
            rectangleSegments[3] = new Segment(rectangle.Left, rectangle.Bottom, rectangle.Left, rectangle.Top); // left
            return rectangleSegments;
        }
Exemple #57
0
        public void SetCollision(Circle circle)
        {
            mCollisionAxisAlignedRectangle = null;
            mCollisionPolygon = null;
            mCollisionLine = null;

            mCollisionCircle = circle;
            mCollisionCircle.Radius = ScaleX;

            mCollisionCircle.AttachTo(this, false);
            mCollisionCircle.ForceUpdateDependencies();
        }
Exemple #58
0
 private static List<Vector3> GetAbsoluteVertices(AxisAlignedRectangle rectangle)
 {
     List<Vector3> otherVertices = new List<Vector3>(4);
     otherVertices.Add(new Vector3(rectangle.Left, rectangle.Top, 0));
     otherVertices.Add(new Vector3(rectangle.Right, rectangle.Top, 0));
     otherVertices.Add(new Vector3(rectangle.Right, rectangle.Bottom, 0));
     otherVertices.Add(new Vector3(rectangle.Left, rectangle.Bottom, 0));
     return otherVertices;
 }
Exemple #59
0
 public void ClearCollision()
 {
     if (mCollisionAxisAlignedRectangle != null)
     {
         ShapeManager.Remove(mCollisionAxisAlignedRectangle);
         mCollisionAxisAlignedRectangle = null;
     }
     if (mCollisionCircle != null)
     {
         ShapeManager.Remove(mCollisionCircle);
         mCollisionCircle = null;
     }
     if (mCollisionPolygon != null)
     {
         ShapeManager.Remove(mCollisionPolygon);
         mCollisionPolygon = null;
     }
     if (mCollisionLine != null)
     {
         ShapeManager.Remove(mCollisionLine);
         mCollisionLine = null;
     }
 }
Exemple #60
0
        private static List<ContactPoint> GetContactPoints(Polygon polygon, AxisAlignedRectangle rectangle)
        {
            Segment[] firstSegments = GetSegments(polygon);
            Segment[] secondSegments = GetSegments(rectangle);

            List<ContactPoint> contactPoints = GetContactPoints(firstSegments, secondSegments);

            return contactPoints;
        }