public void PointTouchConstraintUnsatisfiedValue()
        {
            particle2.Position = new Vector2(20, 0);

            var pointTouchConstraint = new JointConstraint(particle1, point1, particle2, point2);

            pointTouchConstraint.Value(new[] { particle1, particle2 }).Should().BeApproximately(32, tolerance);
        }
Example #2
0
        private void ThreeBodyJointConstraint(Func <KinematicsSystem, IConstraintSolver> solver)
        {
            var a1 = new PhysicalParticle();
            var a2 = new PhysicalParticle();
            var a3 = new PhysicalParticle();
            var c1 = new JointConstraint(a1, Vector2.UnitX, a2, -Vector2.UnitX);
            var c2 = new JointConstraint(a2, Vector2.UnitX, a3, -Vector2.UnitX);

            a2.Position   = 2 * Vector2.UnitX;
            a3.Position   = 4 * Vector2.UnitX;
            a2.Velocity.X = 15;

            c1.Value(new List <PhysicalParticle> {
                a1, a2
            }).Should().Be(0);
            c2.Value(new List <PhysicalParticle> {
                a2, a3
            }).Should().Be(0);

            system.AddParticles(a1, a2, a3);
            system.AddConstraints(c1, c2);

            var constraintSolver = solver(system);
            var integrator       = new KinematicsIntegrator(system, constraintSolver)
            {
                MaximumTimeStep  = 0.005f,
                MaxStepsPerFrame = 1000
            };

            integrator.Integrate(1);

            a1.Position.X.Should().BeApproximately(5, tolerance);
            a2.Position.X.Should().BeApproximately(7, tolerance);
            a3.Position.X.Should().BeApproximately(9, tolerance);
            a1.Velocity.X.Should().BeApproximately(5, tolerance);
            a2.Velocity.X.Should().BeApproximately(5, tolerance);
            a3.Velocity.X.Should().BeApproximately(5, tolerance);
        }
        public void PointTouchConstraintSatisfiedValue()
        {
            var pointTouchConstraint = new JointConstraint(particle1, point1, particle2, point2);

            pointTouchConstraint.Value(new[] { particle1, particle2 }).Should().BeApproximately(0, tolerance);
        }