/// <summary> /// Creates the constraint. /// </summary> /// <param name="type">The type.</param> /// <param name="rigidBodyA">The rigid body a.</param> /// <param name="rigidBodyB">The rigid body b.</param> /// <param name="frameA">The frame a.</param> /// <param name="frameB">The frame b.</param> /// <param name="useReferenceFrameA">if set to <c>true</c> [use reference frame a].</param> /// <returns></returns> /// <exception cref="System.Exception"> /// Cannot perform this action when the physics engine is set to CollisionsOnly /// or /// Both RigidBodies must be valid /// </exception> public static Constraint CreateConstraint(ConstraintTypes type, RigidbodyComponent rigidBodyA, RigidbodyComponent rigidBodyB, Matrix frameA, Matrix frameB, bool useReferenceFrameA = false) { if (rigidBodyA == null || rigidBodyB == null) throw new Exception("Both RigidBodies must be valid"); //todo check if the 2 rbs are on the same engine instance! var rbA = rigidBodyA.InternalRigidBody; var rbB = rigidBodyB.InternalRigidBody; switch (type) { case ConstraintTypes.Point2Point: { var constraint = new Point2PointConstraint { InternalPoint2PointConstraint = new BulletSharp.Point2PointConstraint(rbA, rbB, frameA.TranslationVector, frameB.TranslationVector), RigidBodyA = rigidBodyA, RigidBodyB = rigidBodyB }; constraint.InternalConstraint = constraint.InternalPoint2PointConstraint; rigidBodyA.LinkedConstraints.Add(constraint); rigidBodyB.LinkedConstraints.Add(constraint); return constraint; } case ConstraintTypes.Hinge: { var constraint = new HingeConstraint { InternalHingeConstraint = new BulletSharp.HingeConstraint(rbA, rbB, frameA, frameB, useReferenceFrameA), RigidBodyA = rigidBodyA, RigidBodyB = rigidBodyB }; constraint.InternalConstraint = constraint.InternalHingeConstraint; rigidBodyA.LinkedConstraints.Add(constraint); rigidBodyB.LinkedConstraints.Add(constraint); return constraint; } case ConstraintTypes.Slider: { var constraint = new SliderConstraint { InternalSliderConstraint = new BulletSharp.SliderConstraint(rbA, rbB, frameA, frameB, useReferenceFrameA), RigidBodyA = rigidBodyA, RigidBodyB = rigidBodyB }; constraint.InternalConstraint = constraint.InternalSliderConstraint; rigidBodyA.LinkedConstraints.Add(constraint); rigidBodyB.LinkedConstraints.Add(constraint); return constraint; } case ConstraintTypes.ConeTwist: { var constraint = new ConeTwistConstraint { InternalConeTwistConstraint = new BulletSharp.ConeTwistConstraint(rbA, rbB, frameA, frameB), RigidBodyA = rigidBodyA, RigidBodyB = rigidBodyB }; constraint.InternalConstraint = constraint.InternalConeTwistConstraint; rigidBodyA.LinkedConstraints.Add(constraint); rigidBodyB.LinkedConstraints.Add(constraint); return constraint; } case ConstraintTypes.Generic6DoF: { var constraint = new Generic6DoFConstraint { InternalGeneric6DofConstraint = new BulletSharp.Generic6DofConstraint(rbA, rbB, frameA, frameB, useReferenceFrameA), RigidBodyA = rigidBodyA, RigidBodyB = rigidBodyB }; constraint.InternalConstraint = constraint.InternalGeneric6DofConstraint; rigidBodyA.LinkedConstraints.Add(constraint); rigidBodyB.LinkedConstraints.Add(constraint); return constraint; } case ConstraintTypes.Generic6DoFSpring: { var constraint = new Generic6DoFSpringConstraint { InternalGeneric6DofSpringConstraint = new BulletSharp.Generic6DofSpringConstraint(rbA, rbB, frameA, frameB, useReferenceFrameA), RigidBodyA = rigidBodyA, RigidBodyB = rigidBodyB }; constraint.InternalConstraint = constraint.InternalGeneric6DofConstraint = constraint.InternalGeneric6DofSpringConstraint; rigidBodyA.LinkedConstraints.Add(constraint); rigidBodyB.LinkedConstraints.Add(constraint); return constraint; } case ConstraintTypes.Gear: { var constraint = new GearConstraint { InternalGearConstraint = new BulletSharp.GearConstraint(rbA, rbB, frameA.TranslationVector, frameB.TranslationVector), RigidBodyA = rigidBodyA, RigidBodyB = rigidBodyB }; constraint.InternalConstraint = constraint.InternalGearConstraint; rigidBodyA.LinkedConstraints.Add(constraint); rigidBodyB.LinkedConstraints.Add(constraint); return constraint; } } return null; }
/// <summary> /// Creates the constraint. /// </summary> /// <param name="type">The type.</param> /// <param name="rigidBodyA">The rigid body a.</param> /// <param name="rigidBodyB">The rigid body b.</param> /// <param name="frameA">The frame a.</param> /// <param name="frameB">The frame b.</param> /// <param name="useReferenceFrameA">if set to <c>true</c> [use reference frame a].</param> /// <returns></returns> /// <exception cref="System.Exception"> /// Cannot perform this action when the physics engine is set to CollisionsOnly /// or /// Both RigidBodies must be valid /// </exception> public static Constraint CreateConstraint(ConstraintTypes type, RigidbodyComponent rigidBodyA, RigidbodyComponent rigidBodyB, Matrix frameA, Matrix frameB, bool useReferenceFrameA = false) { if (rigidBodyA == null || rigidBodyB == null) { throw new Exception("Both RigidBodies must be valid"); } //todo check if the 2 rbs are on the same engine instance! var rbA = rigidBodyA.InternalRigidBody; var rbB = rigidBodyB.InternalRigidBody; switch (type) { case ConstraintTypes.Point2Point: { var constraint = new Point2PointConstraint { InternalPoint2PointConstraint = new BulletSharp.Point2PointConstraint(rbA, rbB, frameA.TranslationVector, frameB.TranslationVector), RigidBodyA = rigidBodyA, RigidBodyB = rigidBodyB }; constraint.InternalConstraint = constraint.InternalPoint2PointConstraint; rigidBodyA.LinkedConstraints.Add(constraint); rigidBodyB.LinkedConstraints.Add(constraint); return(constraint); } case ConstraintTypes.Hinge: { var constraint = new HingeConstraint { InternalHingeConstraint = new BulletSharp.HingeConstraint(rbA, rbB, frameA, frameB, useReferenceFrameA), RigidBodyA = rigidBodyA, RigidBodyB = rigidBodyB }; constraint.InternalConstraint = constraint.InternalHingeConstraint; rigidBodyA.LinkedConstraints.Add(constraint); rigidBodyB.LinkedConstraints.Add(constraint); return(constraint); } case ConstraintTypes.Slider: { var constraint = new SliderConstraint { InternalSliderConstraint = new BulletSharp.SliderConstraint(rbA, rbB, frameA, frameB, useReferenceFrameA), RigidBodyA = rigidBodyA, RigidBodyB = rigidBodyB }; constraint.InternalConstraint = constraint.InternalSliderConstraint; rigidBodyA.LinkedConstraints.Add(constraint); rigidBodyB.LinkedConstraints.Add(constraint); return(constraint); } case ConstraintTypes.ConeTwist: { var constraint = new ConeTwistConstraint { InternalConeTwistConstraint = new BulletSharp.ConeTwistConstraint(rbA, rbB, frameA, frameB), RigidBodyA = rigidBodyA, RigidBodyB = rigidBodyB }; constraint.InternalConstraint = constraint.InternalConeTwistConstraint; rigidBodyA.LinkedConstraints.Add(constraint); rigidBodyB.LinkedConstraints.Add(constraint); return(constraint); } case ConstraintTypes.Generic6DoF: { var constraint = new Generic6DoFConstraint { InternalGeneric6DofConstraint = new BulletSharp.Generic6DofConstraint(rbA, rbB, frameA, frameB, useReferenceFrameA), RigidBodyA = rigidBodyA, RigidBodyB = rigidBodyB }; constraint.InternalConstraint = constraint.InternalGeneric6DofConstraint; rigidBodyA.LinkedConstraints.Add(constraint); rigidBodyB.LinkedConstraints.Add(constraint); return(constraint); } case ConstraintTypes.Generic6DoFSpring: { var constraint = new Generic6DoFSpringConstraint { InternalGeneric6DofSpringConstraint = new BulletSharp.Generic6DofSpringConstraint(rbA, rbB, frameA, frameB, useReferenceFrameA), RigidBodyA = rigidBodyA, RigidBodyB = rigidBodyB }; constraint.InternalConstraint = constraint.InternalGeneric6DofConstraint = constraint.InternalGeneric6DofSpringConstraint; rigidBodyA.LinkedConstraints.Add(constraint); rigidBodyB.LinkedConstraints.Add(constraint); return(constraint); } case ConstraintTypes.Gear: { var constraint = new GearConstraint { InternalGearConstraint = new BulletSharp.GearConstraint(rbA, rbB, frameA.TranslationVector, frameB.TranslationVector), RigidBodyA = rigidBodyA, RigidBodyB = rigidBodyB }; constraint.InternalConstraint = constraint.InternalGearConstraint; rigidBodyA.LinkedConstraints.Add(constraint); rigidBodyB.LinkedConstraints.Add(constraint); return(constraint); } } return(null); }
/// <summary> /// Creates the constraint. /// </summary> /// <param name="type">The type.</param> /// <param name="rigidBodyA">The rigid body a.</param> /// <param name="frameA">The frame a.</param> /// <param name="useReferenceFrameA">if set to <c>true</c> [use reference frame a].</param> /// <returns></returns> /// <exception cref="System.Exception"> /// Cannot perform this action when the physics engine is set to CollisionsOnly /// or /// Both RigidBodies must be valid /// or /// A Gear constraint always needs two rigidbodies to be created. /// </exception> public static Constraint CreateConstraint(ConstraintTypes type, RigidbodyComponent rigidBodyA, Matrix frameA, bool useReferenceFrameA = false) { if (rigidBodyA == null) throw new Exception("Both RigidBodies must be valid"); var rbA = rigidBodyA.InternalRigidBody; switch (type) { case ConstraintTypes.Point2Point: { var constraint = new Point2PointConstraint { InternalPoint2PointConstraint = new BulletSharp.Point2PointConstraint(rbA, frameA.TranslationVector), RigidBodyA = rigidBodyA, }; constraint.InternalConstraint = constraint.InternalPoint2PointConstraint; rigidBodyA.LinkedConstraints.Add(constraint); return constraint; } case ConstraintTypes.Hinge: { var constraint = new HingeConstraint { InternalHingeConstraint = new BulletSharp.HingeConstraint(rbA, frameA, useReferenceFrameA), RigidBodyA = rigidBodyA, }; constraint.InternalConstraint = constraint.InternalHingeConstraint; rigidBodyA.LinkedConstraints.Add(constraint); return constraint; } case ConstraintTypes.Slider: { var constraint = new SliderConstraint { InternalSliderConstraint = new BulletSharp.SliderConstraint(rbA, frameA, useReferenceFrameA), RigidBodyA = rigidBodyA, }; constraint.InternalConstraint = constraint.InternalSliderConstraint; rigidBodyA.LinkedConstraints.Add(constraint); return constraint; } case ConstraintTypes.ConeTwist: { var constraint = new ConeTwistConstraint { InternalConeTwistConstraint = new BulletSharp.ConeTwistConstraint(rbA, frameA), RigidBodyA = rigidBodyA }; constraint.InternalConstraint = constraint.InternalConeTwistConstraint; rigidBodyA.LinkedConstraints.Add(constraint); return constraint; } case ConstraintTypes.Generic6DoF: { var constraint = new Generic6DoFConstraint { InternalGeneric6DofConstraint = new BulletSharp.Generic6DofConstraint(rbA, frameA, useReferenceFrameA), RigidBodyA = rigidBodyA }; constraint.InternalConstraint = constraint.InternalGeneric6DofConstraint; rigidBodyA.LinkedConstraints.Add(constraint); return constraint; } case ConstraintTypes.Generic6DoFSpring: { var constraint = new Generic6DoFSpringConstraint { InternalGeneric6DofSpringConstraint = new BulletSharp.Generic6DofSpringConstraint(rbA, frameA, useReferenceFrameA), RigidBodyA = rigidBodyA }; constraint.InternalConstraint = constraint.InternalGeneric6DofConstraint = constraint.InternalGeneric6DofSpringConstraint; rigidBodyA.LinkedConstraints.Add(constraint); return constraint; } case ConstraintTypes.Gear: { throw new Exception("A Gear constraint always needs two rigidbodies to be created."); } } return null; }
/// <summary> /// Creates the constraint. /// </summary> /// <param name="type">The type.</param> /// <param name="rigidBodyA">The rigid body a.</param> /// <param name="frameA">The frame a.</param> /// <param name="useReferenceFrameA">if set to <c>true</c> [use reference frame a].</param> /// <returns></returns> /// <exception cref="System.Exception"> /// Cannot perform this action when the physics engine is set to CollisionsOnly /// or /// Both RigidBodies must be valid /// or /// A Gear constraint always needs two rigidbodies to be created. /// </exception> public static Constraint CreateConstraint(ConstraintTypes type, RigidbodyComponent rigidBodyA, Matrix frameA, bool useReferenceFrameA = false) { if (rigidBodyA == null) { throw new Exception("Both RigidBodies must be valid"); } var rbA = rigidBodyA.InternalRigidBody; switch (type) { case ConstraintTypes.Point2Point: { var constraint = new Point2PointConstraint { InternalPoint2PointConstraint = new BulletSharp.Point2PointConstraint(rbA, frameA.TranslationVector), RigidBodyA = rigidBodyA, }; constraint.InternalConstraint = constraint.InternalPoint2PointConstraint; rigidBodyA.LinkedConstraints.Add(constraint); return(constraint); } case ConstraintTypes.Hinge: { var constraint = new HingeConstraint { InternalHingeConstraint = new BulletSharp.HingeConstraint(rbA, frameA, useReferenceFrameA), RigidBodyA = rigidBodyA, }; constraint.InternalConstraint = constraint.InternalHingeConstraint; rigidBodyA.LinkedConstraints.Add(constraint); return(constraint); } case ConstraintTypes.Slider: { var constraint = new SliderConstraint { InternalSliderConstraint = new BulletSharp.SliderConstraint(rbA, frameA, useReferenceFrameA), RigidBodyA = rigidBodyA, }; constraint.InternalConstraint = constraint.InternalSliderConstraint; rigidBodyA.LinkedConstraints.Add(constraint); return(constraint); } case ConstraintTypes.ConeTwist: { var constraint = new ConeTwistConstraint { InternalConeTwistConstraint = new BulletSharp.ConeTwistConstraint(rbA, frameA), RigidBodyA = rigidBodyA }; constraint.InternalConstraint = constraint.InternalConeTwistConstraint; rigidBodyA.LinkedConstraints.Add(constraint); return(constraint); } case ConstraintTypes.Generic6DoF: { var constraint = new Generic6DoFConstraint { InternalGeneric6DofConstraint = new BulletSharp.Generic6DofConstraint(rbA, frameA, useReferenceFrameA), RigidBodyA = rigidBodyA }; constraint.InternalConstraint = constraint.InternalGeneric6DofConstraint; rigidBodyA.LinkedConstraints.Add(constraint); return(constraint); } case ConstraintTypes.Generic6DoFSpring: { var constraint = new Generic6DoFSpringConstraint { InternalGeneric6DofSpringConstraint = new BulletSharp.Generic6DofSpringConstraint(rbA, frameA, useReferenceFrameA), RigidBodyA = rigidBodyA }; constraint.InternalConstraint = constraint.InternalGeneric6DofConstraint = constraint.InternalGeneric6DofSpringConstraint; rigidBodyA.LinkedConstraints.Add(constraint); return(constraint); } case ConstraintTypes.Gear: { throw new Exception("A Gear constraint always needs two rigidbodies to be created."); } } return(null); }