Esempio n. 1
0
        /// <summary>
        /// Modifies the first Polygon so that it is the result of both merged polygons.  
        /// This method assumes that the polygons collide and that both are drawn
        /// clockwise.
        /// </summary>
        /// <param name="polygon">The first polygon.  This one will be modified.</param>
        /// <param name="otherPolygon">The second polygon which will not be modified.</param>
        #endregion
        public static void Merge(Polygon polygon, Polygon otherPolygon)
        {
            // Vic says:  This is useful for debugging merging.  Don't remove it!!!
            bool shouldDebug = false;
            Segment[] firstSegments;
            Segment[] secondSegments;
            List<ContactPoint> contactPoints = GetContactPoints(polygon, otherPolygon, out firstSegments, out secondSegments);

#if !SILVERLIGHT && !WINDOWS_PHONE && !XBOX360 && !IOS && !MONODROID

            if (shouldDebug)
            {
                ShapeCollection sc = new ShapeCollection();
                sc.Polygons.Add(polygon);
                sc.Polygons.Add(otherPolygon);

                for (int i = 0; i < contactPoints.Count; i++)
                {
                    Circle circle = new Circle();
                    circle.Radius = .5f;
                    circle.Position = contactPoints[i].Position;

                    if (contactPoints[i].ContactType == ContactType.SegmentIntersection)
                    {
                        circle.Color = Color.Orange;
                    }
                    else
                    {
                        circle.Color = Color.Green;
                    }

                    sc.Circles.Add(circle);

                }



                FlatRedBall.Content.Math.Geometry.ShapeCollectionSave scs =
                    new FlatRedBall.Content.Math.Geometry.ShapeCollectionSave();

                scs.AddPolygonList(sc.Polygons);
                scs.AddCircleList(sc.Circles);

                string fileName = 
                    FlatRedBall.IO.FileManager.MyDocuments + "mergeTest.shcx";

                scs.Save(fileName);

                sc.Clear();
            }
#endif

            int firstPointToStartAt = GetPointToStartAt(polygon, otherPolygon);

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

            List<Vector3> thisVertices = GetAbsoluteVertices(firstSegments);
            List<Vector3> otherVertices = GetAbsoluteVertices(secondSegments);

            SetPointsFromContactPointsAndVertices(polygon, otherPolygon, contactPoints, firstPointToStartAt, thisVertices, otherVertices);
        }
Esempio n. 2
0
        public static void LoadShapeCollection(string fileName, ReplaceOrInsert replaceOrInsert)
        {
            #region Load and set the ShapeCollection

            FlatRedBall.Content.Math.Geometry.ShapeCollectionSave ssl = FlatRedBall.Content.Math.Geometry.ShapeCollectionSave.FromFile(fileName);
            ssl.Shift(mOffset);
            mOffset = new Vector3();
            // Remove the current shapes

            if (mTypesToLoad != null)
            {
                if (!mTypesToLoad.LoadCubes)
                {
                    ssl.AxisAlignedCubeSaves.Clear();
                }

                if (!mTypesToLoad.LoadRectangles)
                {
                    ssl.AxisAlignedRectangleSaves.Clear();
                }

                if (!mTypesToLoad.LoadCircles)
                {
                    ssl.CircleSaves.Clear();
                }

                if (!mTypesToLoad.LoadPolygons)
                {
                    ssl.PolygonSaves.Clear();
                }

                if (!mTypesToLoad.LoadSpheres)
                {
                    ssl.SphereSaves.Clear();
                }


                mTypesToLoad = null;
            }

            if (replaceOrInsert == ReplaceOrInsert.Replace)
            {
                EditorData.ShapeCollection.RemoveFromManagers(true);

                ssl.SetShapeCollection(EditorData.ShapeCollection);
                EditorData.ShapeCollection.AddToManagers();
            }
            else
            {
                string nameToPreserve = EditorData.ShapeCollection.Name;

                // Easiest way to get everything in the ShapeManager is to remove the shapes from the managers
                // then re-add them once the newly-loaded shapes have been put in the ShapeCollection
                EditorData.ShapeCollection.RemoveFromManagers(false);

                ssl.SetShapeCollection(EditorData.ShapeCollection); // this will just add to the ShapeCollection

                EditorData.ShapeCollection.AddToManagers();
                EditorData.ShapeCollection.Name = nameToPreserve;
            }
            #endregion

            #region Set the title of the window

            if (replaceOrInsert == ReplaceOrInsert.Replace)
            {
#if FRB_MDX
                // Do this before loading the SavedInformation
                GameForm.TitleText = "PolygonEditor - Editing " + fileName;
#else
                FlatRedBallServices.Game.Window.Title = "PolygonEditor Editing - " + fileName;
#endif
            }

            #endregion

            if (replaceOrInsert == ReplaceOrInsert.Replace)
            {
                EditorData.LastLoadedPolygonList     = null;
                EditorData.LastLoadedShapeCollection = fileName;
            }

            #region Load the SavedInformation if available

            if (replaceOrInsert == ReplaceOrInsert.Replace)
            {
                fileName = FileManager.RemoveExtension(fileName) + ".pesix";
                if (System.IO.File.Exists(fileName))
                {
                    try
                    {
                        PolygonEditorSettings savedInformation = PolygonEditorSettings.FromFile(fileName);
                        if (savedInformation.LineGridSave != null)
                        {
                            savedInformation.LineGridSave.ToLineGrid(EditorData.LineGrid);
                        }

                        if (savedInformation.BoundsCameraSave != null)
                        {
                            savedInformation.BoundsCameraSave.SetCamera(EditorData.BoundsCamera);
                        }

                        if (savedInformation.UsePixelCoordinates)
                        {
                            SpriteManager.Camera.UsePixelCoordinates(false);
                        }
                    }
                    catch
                    {
                        GuiManager.ShowMessageBox(
                            "Could not load the settings file " + fileName + ".  \nThe data file was loaded with no problems",
                            "Error");
                    }
                }
            }
            #endregion
        }
Esempio n. 3
0
        /// <summary>
        /// Modifies the first Polygon so that it is the result of both merged polygons.
        /// This method assumes that the polygons collide and that both are drawn
        /// clockwise.
        /// </summary>
        /// <param name="polygon">The first polygon.  This one will be modified.</param>
        /// <param name="otherPolygon">The second polygon which will not be modified.</param>
        #endregion
        public static void Merge(Polygon polygon, Polygon otherPolygon)
        {
            // Vic says:  This is useful for debugging merging.  Don't remove it!!!
            bool shouldDebug = false;

            Segment[]           firstSegments;
            Segment[]           secondSegments;
            List <ContactPoint> contactPoints = GetContactPoints(polygon, otherPolygon, out firstSegments, out secondSegments);

#if !MONOGAME
            if (shouldDebug)
            {
                ShapeCollection sc = new ShapeCollection();
                sc.Polygons.Add(polygon);
                sc.Polygons.Add(otherPolygon);

                for (int i = 0; i < contactPoints.Count; i++)
                {
                    Circle circle = new Circle();
                    circle.Radius   = .5f;
                    circle.Position = contactPoints[i].Position;

                    if (contactPoints[i].ContactType == ContactType.SegmentIntersection)
                    {
                        circle.Color = Color.Orange;
                    }
                    else
                    {
                        circle.Color = Color.Green;
                    }

                    sc.Circles.Add(circle);
                }



                FlatRedBall.Content.Math.Geometry.ShapeCollectionSave scs =
                    new FlatRedBall.Content.Math.Geometry.ShapeCollectionSave();

                scs.AddPolygonList(sc.Polygons);
                scs.AddCircleList(sc.Circles);

                string fileName =
                    FlatRedBall.IO.FileManager.MyDocuments + "mergeTest.shcx";

                scs.Save(fileName);

                sc.Clear();
            }
#endif

            int firstPointToStartAt = GetPointToStartAt(polygon, otherPolygon);

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

            List <Vector3> thisVertices  = GetAbsoluteVertices(firstSegments);
            List <Vector3> otherVertices = GetAbsoluteVertices(secondSegments);

            SetPointsFromContactPointsAndVertices(polygon, otherPolygon, contactPoints, firstPointToStartAt, thisVertices, otherVertices);
        }