Ejemplo n.º 1
0
        public override void Initialize()
        {
            Vector2 trans = new Vector2();

            _polygons = new List <Vertices>();

            _polygons.Add(PolygonTools.CreateGear(5f, 10, 0f, 6f));
            _polygons.Add(PolygonTools.CreateGear(4f, 15, 100f, 3f));

            trans.X = 0f;
            trans.Y = 8f;
            _polygons[0].Translate(ref trans);
            _polygons[1].Translate(ref trans);

            _polygons.Add(PolygonTools.CreateGear(5f, 10, 50f, 5f));

            trans.X = 22f;
            trans.Y = 17f;
            _polygons[2].Translate(ref trans);

            AddRectangle(5, 10);
            AddCircle(5, 32);

            trans.X = -20f;
            trans.Y = 8f;
            _polygons[3].Translate(ref trans);
            trans.Y = 20f;
            _polygons[4].Translate(ref trans);

            _subject = _polygons[0];
            _clip    = _polygons[1];

            base.Initialize();
        }
Ejemplo n.º 2
0
        public Objects(World world, Vector2 startPosition, Vector2 endPosition, int count, float radius, ObjectType type, float toothHeight = 1f)
        {
            _bodyRadius = radius;
            BodyList    = new List <Body>(count);


            for (int i = 0; i < count; i++)
            {
                switch (type)
                {
                case ObjectType.Circle:
                    BodyList.Add(world.CreateCircle(radius, 1f));
                    break;

                case ObjectType.Rectangle:
                    BodyList.Add(world.CreateRectangle(radius, radius, 1f));
                    _bodyRadius = radius / 2f;
                    break;

                case ObjectType.Star:
                    BodyList.Add(world.CreateGear(radius, 10, 0f, toothHeight, 1f));
                    _bodyRadius = radius * 2.7f;
                    break;

                case ObjectType.Gear:
                    BodyList.Add(world.CreateGear(radius, 10, 100f, toothHeight, 1f));
                    _bodyRadius = radius * 2.7f;
                    break;
                }
            }

            for (int i = 0; i < BodyList.Count; i++)
            {
                Body body = BodyList[i];
                body.BodyType = BodyType.Dynamic;
                body.Position = Vector2.Lerp(startPosition, endPosition, i / (float)(count - 1));
                body.SetRestitution(0.7f);
                body.SetFriction(0.2f);
            }

            //GFX
            switch (type)
            {
            case ObjectType.Circle:
                _object = new Sprite(ContentWrapper.CircleTexture(radius, ContentWrapper.Gold, ContentWrapper.Grey, 24f));
                break;

            case ObjectType.Rectangle:
                _object = new Sprite(ContentWrapper.PolygonTexture(PolygonTools.CreateRectangle(radius / 2f, radius / 2f), ContentWrapper.Red, ContentWrapper.Grey, 24f));
                break;

            case ObjectType.Star:
                _object = new Sprite(ContentWrapper.PolygonTexture(PolygonTools.CreateGear(radius, 10, 0f, toothHeight), ContentWrapper.Brown, ContentWrapper.Black, 24f));
                break;

            case ObjectType.Gear:
                _object = new Sprite(ContentWrapper.PolygonTexture(PolygonTools.CreateGear(radius, 10, 100f, toothHeight), ContentWrapper.Orange, ContentWrapper.Grey, 24f));
                break;
            }
        }
Ejemplo n.º 3
0
        public Objects(World world, Vector2 startPosition, Vector2 endPosition, int count, float radius, ObjectType type)
        {
            _bodies             = new List <Body>(count);
            CollidesWith        = Category.All;
            CollisionCategories = Category.All;

            // Physics
            for (int i = 0; i < count; i++)
            {
                switch (type)
                {
                case ObjectType.Circle:
                    _bodies.Add(BodyFactory.CreateCircle(world, radius, 1f));
                    break;

                case ObjectType.Rectangle:
                    _bodies.Add(BodyFactory.CreateRectangle(world, radius, radius, 1f));
                    break;

                case ObjectType.Star:
                    _bodies.Add(BodyFactory.CreateGear(world, radius, 10, 0f, 1f, 1f));
                    break;

                case ObjectType.Gear:
                    _bodies.Add(BodyFactory.CreateGear(world, radius, 10, 100f, 1f, 1f));
                    break;
                }
            }

            for (int i = 0; i < _bodies.Count; i++)
            {
                Body body = _bodies[i];
                body.BodyType    = BodyType.Dynamic;
                body.Position    = Vector2.Lerp(startPosition, endPosition, i / (float)(count - 1));
                body.Restitution = 0.7f;
                body.Friction    = 0.2f;
            }

            //GFX
            switch (type)
            {
            case ObjectType.Circle:
                _object = new Sprite(ContentWrapper.CircleTexture(radius, ContentWrapper.Gold, ContentWrapper.Grey));
                break;

            case ObjectType.Rectangle:
                _object = new Sprite(ContentWrapper.PolygonTexture(PolygonTools.CreateRectangle(radius / 2f, radius / 2f), ContentWrapper.Red, ContentWrapper.Grey));
                break;

            case ObjectType.Star:
                _object = new Sprite(ContentWrapper.PolygonTexture(PolygonTools.CreateGear(radius, 10, 0f, 1f), ContentWrapper.Brown, ContentWrapper.Black));
                break;

            case ObjectType.Gear:
                _object = new Sprite(ContentWrapper.PolygonTexture(PolygonTools.CreateGear(radius, 10, 100f, 1f), ContentWrapper.Orange, ContentWrapper.Grey));
                break;
            }
        }
Ejemplo n.º 4
0
        public override void Initialize()
        {
            _messages = new List <TextMessage>();

            _left = PolygonTools.CreateGear(5, 10, 40, 5);

            /*_left.Add(new Vector2(0.5f, 0.5f));
             * _left.Add(new Vector2(2, -2));
             * _left.Add(new Vector2(2, 2));
             * _left.Add(new Vector2(-2, 2));*/

            base.Initialize();
        }
Ejemplo n.º 5
0
        public static Body CreateGear(World world, float radius, int numberOfTeeth, float tipPercentage, float toothHeight, float density, Vector2 position = new Vector2(), float rotation = 0, BodyType bodyType = BodyType.Static, object userData = null)
        {
            var gearPolygon = PolygonTools.CreateGear(radius, numberOfTeeth, tipPercentage, toothHeight);

            //Gears can in some cases be convex
            if (!gearPolygon.IsConvex())
            {
                //Decompose the gear:
                var list = Triangulate.ConvexPartition(gearPolygon, TriangulationAlgorithm.Earclip);
                return(CreateCompoundPolygon(world, list, density, position, rotation, bodyType, userData));
            }

            return(CreatePolygon(world, gearPolygon, density, position, rotation, bodyType, userData));
        }
Ejemplo n.º 6
0
        public static Body CreateGear(World world, float radius, int numberOfTeeth, float tipPercentage, float toothHeight, float density, object userData = null)
        {
            Vertices gearPolygon = PolygonTools.CreateGear(radius, numberOfTeeth, tipPercentage, toothHeight);

            //Gears can in some cases be convex
            if (!gearPolygon.IsConvex())
            {
                //Decompose the gear:
                List <Vertices> list = Triangulate.ConvexPartition(gearPolygon, TriangulationAlgorithm.Earclip);

                return(CreateCompoundPolygon(world, list, density, userData));
            }

            return(CreatePolygon(world, gearPolygon, density, userData));
        }
Ejemplo n.º 7
0
        public Body CreateGear(float radius, int numberOfTeeth, float tipPercentage, float toothHeight, float density, Vector2 position = new Vector2(), float rotation = 0, BodyType bodyType = BodyType.Static)
        {
            Vertices gearPolygon = PolygonTools.CreateGear(radius, numberOfTeeth, tipPercentage, toothHeight);

            //Gears can in some cases be convex
            if (!gearPolygon.IsConvex())
            {
                //Decompose the gear:
                List <Vertices> list = Triangulate.ConvexPartition(gearPolygon, TriangulationAlgorithm.Earclip);

                return(CreateCompoundPolygon(list, density, position, rotation, bodyType));
            }

            return(CreatePolygon(gearPolygon, density, position, rotation, bodyType));
        }
Ejemplo n.º 8
0
        public static Body CreateGear(World world, float radius, int numberOfTeeth, float tipPercentage,
                                      float toothHeight, float density, PressPlay.FFWD.Components.Collider userData)
        {
            Vertices gearPolygon = PolygonTools.CreateGear(radius, numberOfTeeth, tipPercentage, toothHeight);

            //Gears can in some cases be convex
            if (!gearPolygon.IsConvex())
            {
                //Decompose the gear:
                List <Vertices> list = EarclipDecomposer.ConvexPartition(gearPolygon);

                return(CreateCompoundPolygon(world, list, density, userData));
            }

            return(CreatePolygon(world, gearPolygon, density, userData));
        }
Ejemplo n.º 9
0
        public static List <Fixture> AttachGear(this Body body, float radius, int numberOfTeeth, float tipPercentage, float toothHeight, float density)
        {
            var gearPolygon = PolygonTools.CreateGear(FSConvert.DisplayToSim * radius, numberOfTeeth, tipPercentage, FSConvert.DisplayToSim * toothHeight);

            // Gears can in some cases be convex
            if (!gearPolygon.IsConvex())
            {
                //Decompose the gear:
                var list = Triangulate.ConvexPartition(gearPolygon, TriangulationAlgorithm.Earclip);
                return(body.AttachCompoundPolygon(list, density));
            }

            var fixtures = new List <Fixture>();

            fixtures.Add(body.AttachPolygon(gearPolygon, density));
            return(fixtures);
        }
Ejemplo n.º 10
0
        public static List <Fixture> CreateGear(World world, float radius, int numberOfTeeth, float tipPercentage,
                                                float toothHeight, float density)
        {
            Vertices gearPolygon = PolygonTools.CreateGear(radius, numberOfTeeth, tipPercentage, toothHeight);

            //Gears can in some cases be convex
            if (!gearPolygon.IsConvex())
            {
                //Decompose the gear:
                List <Vertices> list = EarclipDecomposer.ConvexPartition(gearPolygon);

                return(CreateCompoundPolygon(world, list, density));
            }

            List <Fixture> fixtures = new List <Fixture>();

            fixtures.Add(CreatePolygon(world, gearPolygon, density));
            return(fixtures);
        }
Ejemplo n.º 11
0
        public Objects(World world, ScreenManager screenManager, Vector2 startPosition, Vector2 endPosition, int count, float radius, ObjectType type, float toothHeight = 1f)
        {
            _batch      = screenManager.SpriteBatch;
            _bodyRadius = radius;
            BodyList    = new List <Body>(count);


            for (int i = 0; i < count; i++)
            {
                switch (type)
                {
                case ObjectType.Circle:
                    BodyList.Add(world.CreateCircle(radius, 1f));
                    break;

                case ObjectType.Rectangle:
                    BodyList.Add(world.CreateRectangle(radius, radius, 1f));
                    _bodyRadius = radius / 2f;
                    break;

                case ObjectType.Star:
                    BodyList.Add(world.CreateGear(radius, 10, 0f, toothHeight, 1f));
                    _bodyRadius = radius * 2.7f;
                    break;

                case ObjectType.Gear:
                    BodyList.Add(world.CreateGear(radius, 10, 100f, toothHeight, 1f));
                    _bodyRadius = radius * 2.7f;
                    break;
                }
            }

            for (int i = 0; i < BodyList.Count; i++)
            {
                Body body = BodyList[i];
                body.BodyType = BodyType.Dynamic;
                body.Position = Vector2.Lerp(startPosition, endPosition, i / (float)(count - 1));
                foreach (Fixture fixture in body.FixtureList)
                {
                    fixture.Restitution         = 0.7f;
                    fixture.Friction            = 0.2f;
                    fixture.CollisionCategories = Category.All;
                    fixture.CollidesWith        = Category.All;
                }
            }

            //GFX
            AssetCreator creator = screenManager.Assets;

            switch (type)
            {
            case ObjectType.Circle:
                _object = new Sprite(creator.CircleTexture(radius, MaterialType.Dots, Color.DarkRed, 0.8f, 24f));
                break;

            case ObjectType.Rectangle:
                _object = new Sprite(creator.TextureFromVertices(PolygonTools.CreateRectangle(radius / 2f, radius / 2f), MaterialType.Dots, Color.Blue, 0.8f, 24f));
                break;

            case ObjectType.Star:
                _object = new Sprite(creator.TextureFromVertices(PolygonTools.CreateGear(radius, 10, 0f, toothHeight), MaterialType.Dots, Color.Yellow, 0.8f, 24f));
                break;

            case ObjectType.Gear:
                _object = new Sprite(creator.TextureFromVertices(PolygonTools.CreateGear(radius, 10, 100f, toothHeight), MaterialType.Dots, Color.DarkGreen, 0.8f, 24f));
                break;
            }
        }
Ejemplo n.º 12
0
    void Start()
    {
        // Create Vector2 vertices
        Vector2[] vertices2D = null;

        switch (tipo)
        {
        case Tipo.CAPSULE:
            vertices2D = USVG.PolygonTools.CreateCapsule(Height, Radius, Edges);
            break;

        case Tipo.CIRCLE:
            vertices2D = PolygonTools.CreateCircle(Radius, Edges);
            break;

        case Tipo.ELIPSE:
            vertices2D = PolygonTools.CreateEllipse(Radius, yRadius, Edges);
            break;

        case Tipo.GEAR:
            vertices2D = PolygonTools.CreateGear(Radius, NumberOfTheeth, TipPercentage, ToothHeight);
            break;

        case Tipo.ROUNDED_RECTANGLE:
            vertices2D = PolygonTools.CreateRoundedRectangle(Height, Width, Radius, yRadius, Edges);
            break;

        default:
        case Tipo.RECTANGLE:
            vertices2D = PolygonTools.CreateRectangle(Height, Width);
            break;
        }


        // Use the triangulator to get indices for creating triangles
        Triangulator tr = new Triangulator(vertices2D);

        int[] indices = tr.Triangulate();

        // Create the Vector3 vertices
        Vector3[] vertices = new Vector3[vertices2D.Length];
        for (int i = 0; i < vertices.Length; i++)
        {
            vertices[i] = new Vector3(vertices2D[i].x, vertices2D[i].y, 0);
        }

        // Create the mesh
        Mesh msh = new Mesh();

        msh.vertices  = vertices;
        msh.triangles = indices;
        msh.RecalculateNormals();
        msh.RecalculateBounds();

        // Set up game object with mesh;
        gameObject.AddComponent(typeof(MeshRenderer));
        MeshFilter filter = gameObject.GetComponent <MeshFilter>();

        if (filter == null)
        {
            filter = gameObject.AddComponent(typeof(MeshFilter)) as MeshFilter;
        }

        filter.mesh = msh;
    }
Ejemplo n.º 13
0
        public Objects(World world, PhysicsGameScreen screen, Vector2 startPosition, Vector2 endPosition, int count,
                       float radius, ObjectType type)
        {
            _bodies             = new List <Body>(count);
            CollidesWith        = Category.All;
            CollisionCategories = Category.All;

            for (int i = 0; i < count; ++i)
            {
                switch (type)
                {
                case ObjectType.Circle:
                    _bodies.Add(BodyFactory.CreateCircle(world, radius, 1f));
                    break;

                case ObjectType.Rectangle:
                    _bodies.Add(BodyFactory.CreateRectangle(world, radius, radius, 1f));
                    break;

                case ObjectType.Star:
                    _bodies.Add(BodyFactory.CreateGear(world, radius, 10, 0f, 1f, 1f));
                    break;

                case ObjectType.Gear:
                    _bodies.Add(BodyFactory.CreateGear(world, radius, 10, 100f, 1f, 1f));
                    break;
                }
            }

            for (int i = 0; i < _bodies.Count; ++i)
            {
                Body body = _bodies[i];
                body.BodyType            = BodyType.Dynamic;
                body.Position            = Vector2.Lerp(startPosition, endPosition, i / (float)(count - 1));
                body.Restitution         = .7f;
                body.Friction            = .2f;
                body.CollisionCategories = CollisionCategories;
                body.CollidesWith        = CollidesWith;
            }

            _screen = screen;

            //GFX
            AssetCreator creator = _screen.ScreenManager.Assets;

            switch (type)
            {
            case ObjectType.Circle:
                _object = new Sprite(creator.CircleTexture(radius, MaterialType.Dots, Color.DarkRed, 0.8f));
                break;

            case ObjectType.Rectangle:
                _object =
                    new Sprite(creator.TextureFromVertices(PolygonTools.CreateRectangle(radius / 2f, radius / 2f),
                                                           MaterialType.Dots, Color.Blue, 0.8f));
                break;

            case ObjectType.Star:
                _object = new Sprite(creator.TextureFromVertices(PolygonTools.CreateGear(radius, 10, 0f, 1f),
                                                                 MaterialType.Dots, Color.Yellow, 0.8f));
                break;

            case ObjectType.Gear:
                _object = new Sprite(creator.TextureFromVertices(PolygonTools.CreateGear(radius, 10, 100f, 1f),
                                                                 MaterialType.Dots, Color.DarkGreen, 0.8f));
                break;
            }
        }
Ejemplo n.º 14
0
        private void TextureFromDictionary(Dictionary <string, object> shapeParam, out Texture2D texture, out Vertices shapeVertices)
        {
            shapeVertices = null;
            texture       = null;
            ObjectType objectType = (ObjectType)shapeParam[ShapeParametersKeys.ObjectType];

            switch (objectType)
            {
            case ObjectType.Arc:
                shapeVertices = PolygonTools.CreatePreTransformedArt(MathHelper.ToRadians((float)shapeParam[ShapeParametersKeys.ArcDegrees]), (int)shapeParam[ShapeParametersKeys.ArcSides], (float)shapeParam[ShapeParametersKeys.ArcRadius]);
                texture       = ContentService.GetContentService().AssetCreator.TextureFromVertices(shapeVertices, (string)shapeParam[ShapeParametersKeys.Material], (Color)shapeParam[ShapeParametersKeys.Color], (float)shapeParam[ShapeParametersKeys.MaterialScale]);

                //shapeVertices.GetCollisionBox().;
                //Vector2 arcOffset = Vector2.One;
                //shapeVertices.Translate(ref arcOffset);
                break;

            case ObjectType.Capsule:
                shapeVertices = PolygonTools.CreateCapsule((float)shapeParam[ShapeParametersKeys.CapsuleHeight], (float)shapeParam[ShapeParametersKeys.CapsuleBottomRadius], (int)shapeParam[ShapeParametersKeys.CapsuleBottomEdges], (float)shapeParam[ShapeParametersKeys.CapsuleTopRadius], (int)shapeParam[ShapeParametersKeys.CapsuleTopEdges]);
                texture       = ContentService.GetContentService().AssetCreator.TextureFromVertices(shapeVertices, (string)shapeParam[ShapeParametersKeys.Material], (Color)shapeParam[ShapeParametersKeys.Color], (float)shapeParam[ShapeParametersKeys.MaterialScale]);
                break;

            case ObjectType.Gear:
                shapeVertices = PolygonTools.CreateGear((float)shapeParam[ShapeParametersKeys.GearTipPercentage], (int)shapeParam[ShapeParametersKeys.GearNumberOfTeeth], (float)shapeParam[ShapeParametersKeys.GearTipPercentage], (float)shapeParam[ShapeParametersKeys.GearToothHeigt]);
                texture       = ContentService.GetContentService().AssetCreator.TextureFromVertices(shapeVertices, (string)shapeParam[ShapeParametersKeys.Material], (Color)shapeParam[ShapeParametersKeys.Color], (float)shapeParam[ShapeParametersKeys.MaterialScale]);
                break;

            case ObjectType.Rectangle:
                shapeVertices = PolygonTools.CreateRectangle((float)shapeParam[ShapeParametersKeys.RectangleWidth], (float)shapeParam[ShapeParametersKeys.RectangleHeight]);
                texture       = ContentService.GetContentService().AssetCreator.TextureFromVertices(shapeVertices, (string)shapeParam[ShapeParametersKeys.Material], (Color)shapeParam[ShapeParametersKeys.Color], (float)shapeParam[ShapeParametersKeys.MaterialScale]);
                break;

            case ObjectType.RoundedRectangle:
                shapeVertices = PolygonTools.CreateRoundedRectangle((float)shapeParam[ShapeParametersKeys.RoundedRectangleWidth], (float)shapeParam[ShapeParametersKeys.RoundedRectangleHeight], (float)shapeParam[ShapeParametersKeys.RoundedRectangleXRadius], (float)shapeParam[ShapeParametersKeys.RoundedRectangleYRadius], (int)shapeParam[ShapeParametersKeys.RoundedRectangleSegments]);
                texture       = ContentService.GetContentService().AssetCreator.TextureFromVertices(shapeVertices, (string)shapeParam[ShapeParametersKeys.Material], (Color)shapeParam[ShapeParametersKeys.Color], (float)shapeParam[ShapeParametersKeys.MaterialScale]);
                break;

            case ObjectType.Ellipse:
                shapeVertices = PolygonTools.CreateEllipse((float)shapeParam[ShapeParametersKeys.EllipseXRadius], (float)shapeParam[ShapeParametersKeys.EllipseYRadius], (int)shapeParam[ShapeParametersKeys.EllipseNumberOfEdges]);
                texture       = ContentService.GetContentService().AssetCreator.EllipseTexture((float)shapeParam[ShapeParametersKeys.EllipseXRadius], (float)shapeParam[ShapeParametersKeys.EllipseYRadius], (string)shapeParam[ShapeParametersKeys.Material], (Color)shapeParam[ShapeParametersKeys.Color], (float)shapeParam[ShapeParametersKeys.MaterialScale]);
                break;

            case ObjectType.Circle:
                shapeVertices = PolygonTools.CreateCircle((float)shapeParam[ShapeParametersKeys.CircleRadius], (int)shapeParam[ShapeParametersKeys.CircleSegments]);
                texture       = ContentService.GetContentService().AssetCreator.CircleTexture((float)shapeParam[ShapeParametersKeys.CircleRadius], (string)shapeParam[ShapeParametersKeys.Material], (Color)shapeParam[ShapeParametersKeys.Color], (float)shapeParam[ShapeParametersKeys.MaterialScale]);
                break;

            case ObjectType.CustomShape:
                if ((bool)shapeParam[ShapeParametersKeys.CustomObjectUseOriginalTexture])
                {
                    ContentService.GetContentService().AssetCreator.ShapeFromTexture((string)shapeParam[ShapeParametersKeys.CustomObjectShape], (float)shapeParam[ShapeParametersKeys.CustomObjectScale], (Color)shapeParam[ShapeParametersKeys.Color], out texture, out shapeVertices);
                }
                else
                {
                    ContentService.GetContentService().AssetCreator.ShapeFromTexture((string)shapeParam[ShapeParametersKeys.CustomObjectShape], (float)shapeParam[ShapeParametersKeys.CustomObjectScale], (string)shapeParam[ShapeParametersKeys.Material], (Color)shapeParam[ShapeParametersKeys.Color], (float)shapeParam[ShapeParametersKeys.MaterialScale], out texture, out shapeVertices);
                }
                break;

            default:
                throw new Exception("Unknown Shape");
            }
        }