Example #1
0
        /// <inheritdoc/>
        public Constraint Build(RigidbodyComponent bodyA, RigidbodyComponent bodyB)
        {
            var axisA = Vector3.UnitX;

            AxisInA.Rotate(ref axisA);

            var axisB = Vector3.UnitX;

            AxisInA.Rotate(ref axisB);

            var hinge = bodyB == null
                ? Simulation.CreateHingeConstraint(bodyA, PivotInA, axisA, UseReferenceFrameA)
                : Simulation.CreateHingeConstraint(bodyA, PivotInA, axisA, bodyB, PivotInB, axisB, UseReferenceFrameA);

            if (Limit.SetLimit)
            {
                hinge.SetLimit(Limit.LowerLimit, Limit.UpperLimit);
            }

            if (Motor.EnableMotor)
            {
                hinge.EnableAngularMotor(Motor.EnableMotor, Motor.TargetVelocity, Motor.MaxMotorImpulse);
            }

            return(hinge);
        }
Example #2
0
        /// <inheritdoc/>
        public Constraint Build(RigidbodyComponent bodyA, RigidbodyComponent bodyB)
        {
            if (bodyB == null)
            {
                throw new System.InvalidOperationException("A Gear constraint requires two rigidbodies.");
            }

            var axis = Vector3.UnitX;

            AxisInA.Rotate(ref axis);
            var frameA = Matrix.Translation(axis);

            axis = Vector3.UnitX;
            AxisInB.Rotate(ref axis);
            var frameB = Matrix.Translation(axis);

            var gear = Simulation.CreateConstraint(ConstraintTypes.Gear, bodyA, bodyB, frameA, frameB) as GearConstraint;

            gear.Ratio = Ratio;

            return(gear);
        }