PageRenderTime 671ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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