コード例 #1
0
        public override void _Ready()
        {
            var size    = GetViewportRect().Size;
            var physics = new VerletWorld();

            physics.AddBehavior(new GravityBehavior());
            AddChild(physics);

            const int separation      = 30;
            var       pointCount      = new Vector2(12, 10);
            var       totalSize       = pointCount * separation;
            var       topLeftPosition = (size / 2) - (totalSize / 2);

            new VerletCloth(
                physics,
                topLeftPosition: topLeftPosition,
                pointCount: pointCount,
                separation: separation,
                pinMode: VerletCloth.PinModeEnum.TopCorners,
                tearSensitivityFactor: 2f,
                stiffness: 1f,
                drawPoints: true,
                pointRadius: 8f
                );
        }
コード例 #2
0
        public override void _Ready()
        {
            var size    = GetViewportRect().Size;
            var physics = new VerletWorld();

            physics.AddBehavior(new GravityBehavior());
            AddChild(physics);

            new VerletCreature(
                physics,
                centerPosition: size / 2,
                height: 200,
                gravityScale: 0.5f,
                drawSupportLinks: true
                );

            new VerletRagdoll(
                physics,
                new Vector2(size.x * 0.75f, size.y / 2),
                height: 200,
                gravityScale: 0.25f,
                tearSensitivityFactor: 4,
                pointRadius: 5f,
                drawIntermediatePoints: false,
                drawSupportLinks: true
                );
        }
コード例 #3
0
        public override void _Ready()
        {
            var size    = GetViewportRect().Size;
            var physics = new VerletWorld();

            AddChild(physics);

            // Attractor
            var attractor = physics.CreatePoint(size / 2, radius: 24, color: Colors.LightGoldenrod, mass: 1000);

            physics.AddBehavior(new AttractionBehavior(attractor, strength: 0.01f, radius: size.x));

            // Create clusters
            var cluster1 = new VerletCluster(
                physics,
                size / 4,
                pointCount: 8,
                diameter: 50
                );
            var cluster2 = new VerletCluster(
                physics,
                size * 0.75f,
                pointCount: 8,
                diameter: 50
                );

            // Hidden link to simulate collisions
            physics.CreateLink(cluster1.Points[0], cluster2.Points[0], minimalDistance: 50, visible: false);
        }
コード例 #4
0
        public override void _Ready()
        {
            var size    = GetViewportRect().Size;
            var physics = new VerletWorld();

            AddChild(physics);

            new VerletClusterGraph(physics, size / 2);
        }
コード例 #5
0
            public override void _Ready()
            {
                var size         = GetViewportRect().Size;
                var rootPosition = new Vector2(size.x / 2, size.y / 1.15f);

                var physics = new VerletWorld();

                AddChild(physics);

                new VerletTree(physics, rootPosition, Mathf.Pi / 6, 125, 4);
            }
コード例 #6
0
        public override void _Ready()
        {
            var size    = GetViewportRect().Size;
            var physics = new VerletWorld();

            physics.AddBehavior(new GravityBehavior());
            AddChild(physics);

            new VerletChainBuilder(physics)
            .AddPointAtPosition(x: size.x / 2, y: 0)
            .AddPointsWithOffset(pointCount: 8, x: 10, y: 10)
            .AddPointWithOffset(x: 10, y: 10, configurator: (point) => point.Radius = 30)
            .Build(stiffness: 0.5f);
        }
コード例 #7
0
        public override void _Ready()
        {
            var size = GetViewportRect().Size;

            var physics = new VerletWorld();

            physics.AddBehavior(new GravityBehavior());
            AddChild(physics);

            new VerletChainBuilder(physics)
            .AddPointAtPosition(new Vector2(size.x / 2, 0))
            .AddPointAtPosition((size / 2) + new Vector2(80, 0))
            .Build(restingDistance: size.y / 2, tearSensitivity: -1, stiffness: 0.5f);
        }
コード例 #8
0
        void createRope(VerletWorld world)
        {
            // create an array of points for our rope
            var linePoints = new Vector2[10];

            for (var i = 0; i < 10; i++)
            {
                linePoints[i] = new Vector2(30 * i + 50, 10);
            }

            var line = new LineSegments(linePoints, 0.3f)
                       .pinParticleAtIndex(0);

            world.addComposite(line);
        }
コード例 #9
0
        public override void _Ready()
        {
            var size    = GetViewportRect().Size;
            var physics = new VerletWorld();

            AddChild(physics);

            var attractor = physics.CreatePoint(size / 2, radius: 24, color: Colors.LightGoldenrod, mass: 1000);

            physics.AddBehavior(new AttractionBehavior(attractor, strength: 0.01f, radius: size.x));

            const int pointCount = 18;

            for (int i = 0; i < pointCount; ++i)
            {
                var pt = physics.CreatePoint(MathUtils.RandVector2(0, size.x, 0, size.y), radius: 16, mass: 10);
                physics.AddBehavior(new AttractionBehavior(pt, strength: -0.1f, radius: pt.Radius * 4));
            }
        }
コード例 #10
0
                public VerletTree(VerletWorld world, Vector2 rootPosition, float angle, float length, int generations)
                {
                    var pointSize  = 10f;
                    var branchSize = 10f;

                    var root     = world.CreatePoint(rootPosition, radius: pointSize, color: Colors.LightPink);
                    var rootTop  = world.CreatePoint(rootPosition + new Vector2(0, -length), radius: pointSize, color: Colors.LightPink);
                    var rootLink = world.CreateLink(root, rootTop, restingDistance: length, width: branchSize);

                    // Fix tree root
                    rootTop.PinToCurrentPosition();
                    root.PinToCurrentPosition();

                    var lastLevel = new List <VerletLink>();

                    lastLevel.Add(rootLink);

                    for (var i = 0; i < generations; ++i)
                    {
                        var newLevel = new List <VerletLink>();
                        pointSize  *= 0.66f;
                        branchSize *= 0.66f;

                        foreach (var link in lastLevel)
                        {
                            var newLength        = (link.B.Position - link.A.Position) * 0.66f;
                            var leftPointTarget  = link.B.Position + newLength.Rotated(angle);
                            var rightPointTarget = link.B.Position + newLength.Rotated(-angle);
                            var leftPoint        = world.CreatePoint(leftPointTarget, radius: pointSize, color: Colors.LightPink);
                            var rightPoint       = world.CreatePoint(rightPointTarget, radius: pointSize, color: Colors.LightPink);
                            var leftLink         = world.CreateLink(link.B, leftPoint, restingDistance: newLength.Length(), width: branchSize, tearSensitivityFactor: 2f);
                            var rightLink        = world.CreateLink(link.B, rightPoint, restingDistance: newLength.Length(), width: branchSize, tearSensitivityFactor: 2f);

                            newLevel.Add(leftLink);
                            newLevel.Add(rightLink);
                        }

                        lastLevel = newLevel;
                    }
                }
コード例 #11
0
        public override void _Ready()
        {
            var size    = GetViewportRect().Size;
            var physics = new VerletWorld();

            AddChild(physics);

            var       center     = size / 2;
            const int pointCount = 12;
            const int diameter   = 128;

            new VerletCluster(
                physics,
                centerPosition: center,
                pointCount: pointCount,
                diameter: diameter,
                tearSensitivityFactor: 3,
                stiffness: 0.01f,
                drawPoints: true,
                pointRadius: 8f
                );
        }
コード例 #12
0
            public VerletClusterGraph(VerletWorld world, Vector2 centerPosition)
            {
                void linkClusters(VerletCluster cl1, VerletCluster cl2, float restingDistance, float minimalDistance, float linkStiffness)
                {
                    for (int i = 0; i < cl1.Points.Count; ++i)
                    {
                        for (int j = 0; j < cl2.Points.Count; ++j)
                        {
                            var a = cl1.Points[i];
                            var b = cl2.Points[j];

                            var link = world.CreateLink(a, b);
                            link.RestingDistance = restingDistance;
                            link.MinimalDistance = minimalDistance;
                            link.TearSensitivity = -1;
                            link.Modulate        = Colors.LightCyan.WithAlpha(64);
                            link.Stiffness       = linkStiffness;
                        }
                    }
                }

                const float stiffness = 0.01f;
                var         clusters  = new List <VerletCluster>()
                {
                    new VerletCluster(
                        world,
                        centerPosition + MathUtils.RandVector2(-5, 5, -5, 5),
                        pointCount: 8,
                        diameter: 50,
                        tearSensitivityFactor: -1,
                        stiffness: stiffness
                        ),
                    new VerletCluster(
                        world,
                        centerPosition + MathUtils.RandVector2(-5, 5, -5, 5),
                        pointCount: 12,
                        diameter: 75,
                        tearSensitivityFactor: -1,
                        stiffness: stiffness
                        ),
                    new VerletCluster(
                        world,
                        centerPosition + MathUtils.RandVector2(-5, 5, -5, 5),
                        pointCount: 6,
                        diameter: 25,
                        tearSensitivityFactor: -1,
                        stiffness: stiffness
                        ),
                    new VerletCluster(
                        world,
                        centerPosition + MathUtils.RandVector2(-5, 5, -5, 5),
                        pointCount: 4,
                        diameter: 50,
                        tearSensitivityFactor: -1,
                        stiffness: stiffness
                        )
                };

                for (int i = 0; i < clusters.Count - 1; ++i)
                {
                    for (int j = i + 1; j < clusters.Count; ++j)
                    {
                        linkClusters(
                            clusters[i],
                            clusters[j],
                            restingDistance: 200,
                            minimalDistance: 10,
                            linkStiffness: 0.1f
                            );
                    }
                }
            }
コード例 #13
0
 public VerletSystem()
 {
     world = new VerletWorld(new Rectangle(0, 0, (int)width, (int)height));
 }
コード例 #14
0
            public VerletCreature(VerletWorld world, Vector2 centerPosition, float height, float gravityScale = 1, float pointRadius = 10f, bool drawPoints = true, bool drawSupportLinks = false)
            {
                const float tearSensitivityFactor = -1;
                const float stiffness             = 0.10f;
                Color       supportLinkColor      = Colors.LightCyan.WithAlpha(64);
                float       sep = height / 4;

                VerletPoint createPoint()
                {
                    return(world.CreatePoint(centerPosition + MathUtils.RandVector2(-5, 5, -5, 5), gravityScale: gravityScale, radius: pointRadius, visible: drawPoints));
                }

                VerletLink createLink(VerletPoint a, VerletPoint b, float distance)
                {
                    return(world.CreateLink(a, b, restingDistance: distance, tearSensitivityFactor: tearSensitivityFactor, stiffness: stiffness));
                }

                VerletLink createSupportLink(VerletPoint a, VerletPoint b, float distance)
                {
                    return(world.CreateLink(a, b, restingDistance: distance, tearSensitivityFactor: -1, stiffness: stiffness, color: supportLinkColor, visible: drawSupportLinks));
                }

                // Head
                var topLeft      = createPoint();
                var topMiddle    = createPoint();
                var topRight     = createPoint();
                var topLeftSide  = createPoint();
                var topRightSide = createPoint();
                var neckLeft     = createPoint();
                var neckRight    = createPoint();

                createLink(topMiddle, topRight, sep);
                createLink(topRight, topRightSide, sep);
                createLink(topRightSide, neckRight, sep);
                createLink(topMiddle, topLeft, sep);
                createLink(topLeft, topLeftSide, sep);
                createLink(topLeftSide, neckLeft, sep);
                createSupportLink(neckLeft, neckRight, sep * 2);

                // Body
                var bodyLeftSide   = createPoint();
                var bodyRightSide  = createPoint();
                var bottomLeft     = createPoint();
                var bottomMidLeft  = createPoint();
                var bottomMiddle   = createPoint();
                var bottomMidRight = createPoint();
                var bottomRight    = createPoint();

                createLink(bodyRightSide, bottomRight, sep);
                createLink(bottomRight, bottomMidRight, sep);
                createLink(bottomMidRight, bottomMiddle, sep);
                createLink(bodyLeftSide, bottomLeft, sep);
                createLink(bottomLeft, bottomMidLeft, sep);
                createLink(bottomMidLeft, bottomMiddle, sep);
                createSupportLink(bodyLeftSide, bodyRightSide, sep * 3);

                // Attach
                createLink(neckLeft, bodyLeftSide, sep);
                createLink(neckRight, bodyRightSide, sep);
                createSupportLink(topMiddle, bottomMiddle, height);
                createSupportLink(topLeftSide, bottomMidRight, height * 1.1f);
                createSupportLink(topRightSide, bottomMidLeft, height * 1.1f);
                createSupportLink(topLeft, bottomRight, height * 1.1f);
                createSupportLink(topRight, bottomLeft, height * 1.1f);
            }
コード例 #15
0
 public VerletSystem()
 {
     World = new VerletWorld(new Rectangle(0, 0, (int)Width, (int)Height));
 }