Exemplo n.º 1
0
        /// <summary>
        /// Removes the constraint from the engine processing pipeline.
        /// </summary>
        /// <param name="constraint">The constraint.</param>
        /// <exception cref="System.Exception">Cannot perform this action when the physics engine is set to CollisionsOnly</exception>
        public void RemoveConstraint(Constraint constraint)
        {
            if (discreteDynamicsWorld == null) throw new Exception("Cannot perform this action when the physics engine is set to CollisionsOnly");

            discreteDynamicsWorld.RemoveConstraint(constraint.InternalConstraint);
            constraint.Simulation = null;
        }
Exemplo n.º 2
0
        void CreatePoint2PointConstraint()
        {
            cubeRigidBody.LinearFactor = Vector3.Zero;
            cubeRigidBody.AngularFactor = Vector3.Zero;
            sphereRigidBody.LinearFactor = new Vector3(1, 1, 1);
            sphereRigidBody.AngularFactor = new Vector3(1, 1, 1);

            currentConstraint = Simulation.CreateConstraint(ConstraintTypes.Point2Point, cubeRigidBody, sphereRigidBody, 
                Matrix.Identity, Matrix.Translation(new Vector3(4, 0, 0)));
            simulation.AddConstraint(currentConstraint);
            constraintNameBlock.Text = "Point to Point";

            //there are no limits so the sphere will orbit once we apply this
            sphereRigidBody.ApplyImpulse(new Vector3(0, 0, 18));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds the constraint to the engine processing pipeline.
        /// </summary>
        /// <param name="constraint">The constraint.</param>
        /// <param name="disableCollisionsBetweenLinkedBodies">if set to <c>true</c> [disable collisions between linked bodies].</param>
        /// <exception cref="System.Exception">Cannot perform this action when the physics engine is set to CollisionsOnly</exception>
        public void AddConstraint(Constraint constraint, bool disableCollisionsBetweenLinkedBodies)
        {
            if (discreteDynamicsWorld == null) throw new Exception("Cannot perform this action when the physics engine is set to CollisionsOnly");

            discreteDynamicsWorld.AddConstraint(constraint.InternalConstraint, disableCollisionsBetweenLinkedBodies);
            constraint.Simulation = this;
        }
Exemplo n.º 4
0
        void CreateGeneric6DoFConstraint()
        {
            cubeRigidBody.LinearFactor = Vector3.Zero;
            cubeRigidBody.AngularFactor = Vector3.Zero;
            sphereRigidBody.LinearFactor = new Vector3(1, 1, 1);
            sphereRigidBody.AngularFactor = new Vector3(1, 1, 1);

            currentConstraint = Simulation.CreateConstraint(ConstraintTypes.Generic6DoF, cubeRigidBody, sphereRigidBody, 
                Matrix.Identity, Matrix.Translation(new Vector3(4, 0, 0)));
            simulation.AddConstraint(currentConstraint);
            constraintNameBlock.Text = "Generic 6D of Freedom";

            sphereRigidBody.ApplyImpulse(new Vector3(0, 0, 18));
        }
Exemplo n.º 5
0
        void CreateConeTwistConstraint()
        {
            cubeRigidBody.LinearFactor = Vector3.Zero;
            cubeRigidBody.AngularFactor = Vector3.Zero;
            sphereRigidBody.LinearFactor = new Vector3(1, 1, 1);
            sphereRigidBody.AngularFactor = new Vector3(1, 1, 1);

            currentConstraint = Simulation.CreateConstraint(ConstraintTypes.ConeTwist, cubeRigidBody, sphereRigidBody, 
                Matrix.Identity, Matrix.Translation(new Vector3(4, 0, 0)));
            simulation.AddConstraint(currentConstraint);
            constraintNameBlock.Text = "Cone Twist";

            var coneTwist = (ConeTwistConstraint)currentConstraint;
            coneTwist.SetLimit(0.5f, 0.5f, 0.5f);

            //applying this impulse will show the cone limits
            sphereRigidBody.ApplyImpulse(new Vector3(0, 0, 18));
        }
Exemplo n.º 6
0
        void CreateSliderConstraint()
        {
            cubeRigidBody.LinearFactor = Vector3.Zero;
            cubeRigidBody.AngularFactor = Vector3.Zero;
            sphereRigidBody.LinearFactor = new Vector3(1, 1, 1);
            sphereRigidBody.AngularFactor = new Vector3(1, 1, 1);

            currentConstraint = Simulation.CreateConstraint(ConstraintTypes.Slider, cubeRigidBody, sphereRigidBody, Matrix.Identity, Matrix.Identity, true);
            simulation.AddConstraint(currentConstraint);
            constraintNameBlock.Text = "Slider";

            var slider = (SliderConstraint)currentConstraint;
            slider.LowerLinearLimit = -4;
            slider.UpperLinearLimit = 0;
            //avoid strange movements
            slider.LowerAngularLimit = (float)-Math.PI / 3.0f;
            slider.UpperAngularLimit = (float)Math.PI / 3.0f;

            //applying this impulse will let the sphere reach the lower linear limit and afterwards will be dragged back towards the cube
            sphereRigidBody.ApplyImpulse(new Vector3(-25, 0, 0));
        }
Exemplo n.º 7
0
        void CreateGearConstraint()
        {
            cubeRigidBody.LinearFactor = Vector3.Zero;
            cubeRigidBody.AngularFactor = new Vector3(1, 1, 1);
            sphereRigidBody.LinearFactor = Vector3.Zero;
            sphereRigidBody.AngularFactor = new Vector3(1, 1, 1);

            currentConstraint = Simulation.CreateConstraint(ConstraintTypes.Gear, sphereRigidBody, cubeRigidBody, 
                Matrix.Translation(new Vector3(1, 0, 0)), Matrix.Translation(new Vector3(1, 0, 0)));
            simulation.AddConstraint(currentConstraint);
            constraintNameBlock.Text = "Gear";

            var gear = (GearConstraint) currentConstraint;
            gear.Ratio = 0.5f;

            //this force will start a motion in the sphere which gets propagated into the cube
            sphereRigidBody.AngularVelocity = new Vector3(25, 0 ,0);
        }
Exemplo n.º 8
0
        void CreateHingeConstraint()
        {
            cubeRigidBody.LinearFactor = Vector3.Zero;
            cubeRigidBody.AngularFactor = Vector3.Zero;
            sphereRigidBody.LinearFactor = new Vector3(1, 1, 1);
            sphereRigidBody.AngularFactor = new Vector3(1, 1, 1);

            currentConstraint = Simulation.CreateConstraint(ConstraintTypes.Hinge, cubeRigidBody, sphereRigidBody, 
                Matrix.Identity, Matrix.Translation(new Vector3(4, 0, 0)));
            simulation.AddConstraint(currentConstraint);
            constraintNameBlock.Text = "Hinge";

            //applying this impulse will show the hinge limits stopping it
            sphereRigidBody.ApplyImpulse(new Vector3(0, 0, 18));
        }