/PhysicsEngines/JigLib/JigLibJoint.cs
C# | 103 lines | 74 code | 11 blank | 18 comment | 6 complexity | 08917619f9df73eb6cb1448f2e05a2d0 MD5 | raw file
Possible License(s): Apache-2.0
- using Delta.PhysicsEngines.Enums;
- using Delta.Utilities.Datatypes;
- using Delta.Utilities.Helpers;
- using JigLibX.Physics;
- using XnaVector3 = Microsoft.Xna.Framework.Vector3;
-
- namespace Delta.PhysicsEngines.JigLib
- {
- /// <summary>
- /// JItter joint implementation
- /// </summary>
- internal class JitterJoint : PhysicsJoint
- {
- #region Constraint (Public)
- /// <summary>
- /// Gets jitter Constraint
- /// </summary>
- public Constraint Constraint
- {
- get;
- private set;
- }
- #endregion
-
- #region Private
-
- #region physicsManager (Private)
- private JigLibPhysics physicsManager;
- #endregion
-
- #endregion
-
- #region Constructors
- /// <summary>
- /// Initializes a new instance of the <see cref="JitterJoint"/> class.
- /// </summary>
- /// <param name="physicsManager">The physics manager.</param>
- /// <param name="jointType">Type of the joint.</param>
- /// <param name="bodyA">The body A.</param>
- /// <param name="bodyB">The body B.</param>
- /// <param name="args">The args.</param>
- public JitterJoint(
- JigLibPhysics physicsManager,
- JointType jointType,
- PhysicsBody bodyA,
- PhysicsBody bodyB, object[] args)
- : base(jointType, bodyA, bodyB, args)
- {
- this.physicsManager = physicsManager;
-
- CreateJoint();
- }
- #endregion
-
- #region Methods (Private)
-
- #region CreateJoint
- /// <summary>
- /// Creates jitter joint.
- /// </summary>
- private void CreateJoint()
- {
- Body rigidBodyA = (BodyA as JigLibBody).Body;
- Body rigidBodyB = BodyB != null
- ? (BodyB as JigLibBody).Body
- : null;
- switch (JointType)
- {
- case JointType.PointOnPoint:
- Vector anchor = ArrayHelper.SafeGet<PropertyType, Vector>(
- Properties, PropertyType.Anchor1);
- XnaVector3 localAnchor;
- JigLibDatatypesMapping.Convert(ref anchor, out localAnchor);
-
- // Do we create single body point on point ?
- if (rigidBodyB != null)
- {
- Constraint = new ConstraintPoint(
- rigidBodyA,
- rigidBodyA.Position,
- rigidBodyB,
- rigidBodyB.Position,
- 1.0f,
- 0.0f);
- }
- else
- {
- Constraint = new ConstraintPoint(rigidBodyA, localAnchor, null,
- localAnchor, 1.0f, 0.0f);
- }
- break;
- }
-
- if (Constraint != null)
- {
- Constraint.EnableConstraint();
- }
- }
- #endregion
-
- #endregion
- }
- }