PageRenderTime 364ms CodeModel.GetById 141ms app.highlight 4ms RepoModel.GetById 217ms app.codeStats 0ms

/PhysicsEngines/JigLib/JigLibJoint.cs

#
C# | 103 lines | 74 code | 11 blank | 18 comment | 6 complexity | 08917619f9df73eb6cb1448f2e05a2d0 MD5 | raw file
  1using Delta.PhysicsEngines.Enums;
  2using Delta.Utilities.Datatypes;
  3using Delta.Utilities.Helpers;
  4using JigLibX.Physics;
  5using XnaVector3 = Microsoft.Xna.Framework.Vector3;
  6
  7namespace Delta.PhysicsEngines.JigLib
  8{
  9	/// <summary>
 10	/// JItter joint implementation
 11	/// </summary>
 12	internal class JitterJoint : PhysicsJoint
 13	{
 14		#region Constraint (Public)
 15		/// <summary>
 16		/// Gets jitter Constraint
 17		/// </summary>
 18		public Constraint Constraint
 19		{
 20			get;
 21			private set;
 22		}
 23		#endregion
 24
 25		#region Private
 26
 27		#region physicsManager (Private)
 28		private JigLibPhysics physicsManager;
 29		#endregion
 30
 31		#endregion
 32
 33		#region Constructors
 34		/// <summary>
 35		/// Initializes a new instance of the <see cref="JitterJoint"/> class.
 36		/// </summary>
 37		/// <param name="physicsManager">The physics manager.</param>
 38		/// <param name="jointType">Type of the joint.</param>
 39		/// <param name="bodyA">The body A.</param>
 40		/// <param name="bodyB">The body B.</param>
 41		/// <param name="args">The args.</param>
 42		public JitterJoint(
 43			JigLibPhysics physicsManager,
 44			JointType jointType,
 45			PhysicsBody bodyA,
 46			PhysicsBody bodyB, object[] args)
 47			: base(jointType, bodyA, bodyB, args)
 48		{
 49			this.physicsManager = physicsManager;
 50
 51			CreateJoint();
 52		}
 53		#endregion
 54
 55		#region Methods (Private)
 56
 57		#region CreateJoint
 58		/// <summary>
 59		/// Creates jitter joint.
 60		/// </summary>
 61		private void CreateJoint()
 62		{
 63			Body rigidBodyA = (BodyA as JigLibBody).Body;
 64			Body rigidBodyB = BodyB != null
 65			                  	? (BodyB as JigLibBody).Body
 66			                  	: null;
 67			switch (JointType)
 68			{
 69				case JointType.PointOnPoint:
 70					Vector anchor = ArrayHelper.SafeGet<PropertyType, Vector>(
 71						Properties, PropertyType.Anchor1);
 72					XnaVector3 localAnchor;
 73					JigLibDatatypesMapping.Convert(ref anchor, out localAnchor);
 74
 75					// Do we create single body point on point ? 
 76					if (rigidBodyB != null)
 77					{
 78						Constraint = new ConstraintPoint(
 79							rigidBodyA,
 80							rigidBodyA.Position,
 81							rigidBodyB,
 82							rigidBodyB.Position,
 83							1.0f,
 84							0.0f);
 85					}
 86					else
 87					{
 88						Constraint = new ConstraintPoint(rigidBodyA, localAnchor, null,
 89							localAnchor, 1.0f, 0.0f);
 90					}
 91					break;
 92			}
 93
 94			if (Constraint != null)
 95			{
 96				Constraint.EnableConstraint();
 97			}
 98		}
 99		#endregion
100
101		#endregion
102	}
103}