示例#1
0
        public KinematicsSystem Initialize(Size area)
        {
            system = new KinematicsSystem();
            const int boxSize = 20;

            for (int i = 0; i < rows; i++)
            {
                double y = area.Height - boxSize * (i + 0.5);

                for (int j = 0; j < rows - i; j++)
                {
                    int x = (area.Width - boxSize * 2 * rows) / 2 + boxSize * 2 * j + boxSize * i;

                    var particle = new PhysicalParticle
                    {
                        Position       = new Vector2(x, y),
                        Polygon        = new Rectangle(-boxSize, -boxSize / 2, boxSize * 2, boxSize).ToPolygon(),
                        InertialMoment = boxSize * boxSize
                    };

                    system.AddParticles(particle);
                }
            }

            system.AddForceField(new ConstantGravityField());

            system.AddConstraints(new TwoBodyConstraint(new CollisionConstraint(), new AllPairs()));
            system.AddConstraints(new RectangleBoundaryConstraint(new Rectangle(Point.Zero, area)));

            return(system);
        }
示例#2
0
        public KinematicsSystem Initialize(Size area)
        {
            circleRadius   = area.Height * 0.375f;
            circlePosition = new Vector2(area.Width * .5f, area.Height * .5f);

            var particlePosition = circlePosition
                                   + Vector2.FromPolarDegrees(circleRadius, -60)
                                   + new Vector2(boxSize * .5f, boxSize * .5f)
            ;                    //+ new Vector2(0, boxSize * .5f);

            system = new KinematicsSystem();

            system.AddParticles(new PhysicalParticle
            {
                Position = particlePosition,
                //Angle = -(float)Math.PI / 4,
                InertialMoment = boxSize * boxSize / 12f,
            });

            system.AddConstraints(new CirclePerimeterOffcenterConstraint(
                                      system.Particles[0], circlePosition, circleRadius, new Vector2(-boxSize * .5f, -boxSize * .5f)));

            system.AddForceField(new ConstantGravityField());

            return(system);
        }
        public KinematicsSystem Initialize(Size area)
        {
            screenArea = area;


            ParticleGenerator generator = new ParticleGenerator();

            system = new KinematicsSystem();

            system.AddParticles(generator.Generate(particleCount, new Vector2(screenArea.Width / 2, 100), Vector2.Zero));

            system.AddForceField(new ConstantGravityField());

            system.AddConstraints(new RectangleBoundaryConstraint(new Rectangle(Point.Zero, area)));

            return(system);
        }
示例#4
0
        public KinematicsSystem Initialize(Size area)
        {
            boxes.Clear();

            system = new KinematicsSystem();

            for (int i = 0; i < BoxCount; i++)
            {
                boxes.Add(new PhysicalParticle
                {
                    Polygon  = new Rectangle(-boxSize / 2, -boxSize / 2, boxSize, boxSize).ToPolygon(),
                    Position = new Vector2(
                        area.Width * 0.5 + (BoxCount / 2 - i) * boxSize,
                        area.Height * 0.3
                        ),
                    Velocity = new Vector2(0, (BoxCount / 2 - i) * 100)
                });

                if (i > 0)
                {
                    var constraint = new JointConstraint(boxes[i - 1], new Vector2(-boxSize * 0.5, 0),
                                                         boxes[i], new Vector2(boxSize * 0.5, 0));

                    system.AddConstraints(constraint);
                }
            }

            sphere = new PhysicalParticle
            {
                Position = new Vector2(area.Width * 0.5, area.Height * 0.25)
            };

            var constraintBox = boxes[boxes.Count / 2];

            system.AddConstraints(
                new CirclePerimeterOffcenterConstraint(constraintBox,
                                                       sphere.Position, 40, constraintBox.Polygon[0]));

            system.AddParticles(boxes.ToArray());

            system.AddForceField(new ConstantGravityField());

            return(system);
        }
        public KinematicsSystem Initialize(Size area)
        {
            circleRadius   = area.Height * 0.375f;
            circlePosition = new Vector2(area.Width * .5f, area.Height * .5f);

            var particlePosition = circlePosition + Vector2.FromPolarDegrees(circleRadius, -90)
                                   + new Vector2(0, boxSize * .5f);

            system = new KinematicsSystem();

            GeometryBuilder.CreateChain(system, BoxCount, boxSize, particlePosition);

            system.AddConstraints(new CirclePerimeterOffcenterConstraint(
                                      system.Particles.First(), circlePosition, circleRadius, new Vector2(-boxSize * .5f, -boxSize * .5f)));

            system.AddForceField(new ConstantGravityField());

            return(system);
        }
        public KinematicsSystem Initialize(Size area)
        {
            system = new KinematicsSystem();

            var planet = new PhysicalParticle
            {
                Position       = (Vector2)area / 2,
                Polygon        = new RegularPolygonBuilder().BuildPolygon(6, 60),
                Mass           = 10,
                InertialMoment = 5 * 60 * 60,
            };

            system.AddParticles(planet);
            GenerateParticles(planet);

            system.AddConstraints(new TwoBodyConstraint(new CollisionConstraint(), new AllPairs()));
            system.AddForceField(new PlanetGravity(planet, 4000000));

            return(system);
        }
示例#7
0
        public KinematicsSystem Initialize(Size area)
        {
            circleRadius   = area.Height * 0.375f;
            circlePosition = new Vector2(area.Width * 0.5f, area.Height * 0.5f);

            var particlePosition = circlePosition + Vector2.FromPolarDegrees(circleRadius, -60);

            system = new KinematicsSystem();

            system.AddParticles(new PhysicalParticle
            {
                Position        = particlePosition,
                Angle           = 1.5f,
                AngularVelocity = 20f,
            });

            system.AddConstraints(new CirclePerimeterConstraint(system.Particles[0], circlePosition, circleRadius));

            system.AddForceField(new ConstantGravityField());

            return(system);
        }