babylon.physicsJoint.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. var __extends = (this && this.__extends) || function (d, b) {
  2. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  3. function __() { this.constructor = d; }
  4. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5. };
  6. var BABYLON;
  7. (function (BABYLON) {
  8. /**
  9. * This is a holder class for the physics joint created by the physics plugin.
  10. * It holds a set of functions to control the underlying joint.
  11. */
  12. var PhysicsJoint = (function () {
  13. function PhysicsJoint(type, jointData) {
  14. this.type = type;
  15. this.jointData = jointData;
  16. jointData.nativeParams = jointData.nativeParams || {};
  17. }
  18. Object.defineProperty(PhysicsJoint.prototype, "physicsJoint", {
  19. get: function () {
  20. return this._physicsJoint;
  21. },
  22. set: function (newJoint) {
  23. if (this._physicsJoint) {
  24. }
  25. this._physicsJoint = newJoint;
  26. },
  27. enumerable: true,
  28. configurable: true
  29. });
  30. Object.defineProperty(PhysicsJoint.prototype, "physicsPlugin", {
  31. set: function (physicsPlugin) {
  32. this._physicsPlugin = physicsPlugin;
  33. },
  34. enumerable: true,
  35. configurable: true
  36. });
  37. /**
  38. * Execute a function that is physics-plugin specific.
  39. * @param {Function} func the function that will be executed.
  40. * It accepts two parameters: the physics world and the physics joint.
  41. */
  42. PhysicsJoint.prototype.executeNativeFunction = function (func) {
  43. func(this._physicsPlugin.world, this._physicsJoint);
  44. };
  45. //TODO check if the native joints are the same
  46. //Joint Types
  47. PhysicsJoint.DistanceJoint = 0;
  48. PhysicsJoint.HingeJoint = 1;
  49. PhysicsJoint.BallAndSocketJoint = 2;
  50. PhysicsJoint.WheelJoint = 3;
  51. PhysicsJoint.SliderJoint = 4;
  52. //OIMO
  53. PhysicsJoint.PrismaticJoint = 5;
  54. //ENERGY FTW! (compare with this - http://ode-wiki.org/wiki/index.php?title=Manual:_Joint_Types_and_Functions)
  55. PhysicsJoint.UniversalJoint = 6;
  56. PhysicsJoint.Hinge2Joint = PhysicsJoint.WheelJoint;
  57. //Cannon
  58. //Similar to a Ball-Joint. Different in params
  59. PhysicsJoint.PointToPointJoint = 8;
  60. //Cannon only at the moment
  61. PhysicsJoint.SpringJoint = 9;
  62. PhysicsJoint.LockJoint = 10;
  63. return PhysicsJoint;
  64. })();
  65. BABYLON.PhysicsJoint = PhysicsJoint;
  66. /**
  67. * A class representing a physics distance joint.
  68. */
  69. var DistanceJoint = (function (_super) {
  70. __extends(DistanceJoint, _super);
  71. function DistanceJoint(jointData) {
  72. _super.call(this, PhysicsJoint.DistanceJoint, jointData);
  73. }
  74. /**
  75. * Update the predefined distance.
  76. */
  77. DistanceJoint.prototype.updateDistance = function (maxDistance, minDistance) {
  78. this._physicsPlugin.updateDistanceJoint(this, maxDistance, minDistance);
  79. };
  80. return DistanceJoint;
  81. })(PhysicsJoint);
  82. BABYLON.DistanceJoint = DistanceJoint;
  83. var MotorEnabledJoint = (function (_super) {
  84. __extends(MotorEnabledJoint, _super);
  85. function MotorEnabledJoint(type, jointData) {
  86. _super.call(this, type, jointData);
  87. }
  88. /**
  89. * Set the motor values.
  90. * Attention, this function is plugin specific. Engines won't react 100% the same.
  91. * @param {number} force the force to apply
  92. * @param {number} maxForce max force for this motor.
  93. */
  94. MotorEnabledJoint.prototype.setMotor = function (force, maxForce) {
  95. this._physicsPlugin.setMotor(this, force, maxForce);
  96. };
  97. /**
  98. * Set the motor's limits.
  99. * Attention, this function is plugin specific. Engines won't react 100% the same.
  100. */
  101. MotorEnabledJoint.prototype.setLimit = function (upperLimit, lowerLimit) {
  102. this._physicsPlugin.setLimit(this, upperLimit, lowerLimit);
  103. };
  104. return MotorEnabledJoint;
  105. })(PhysicsJoint);
  106. BABYLON.MotorEnabledJoint = MotorEnabledJoint;
  107. /**
  108. * This class represents a single hinge physics joint
  109. */
  110. var HingeJoint = (function (_super) {
  111. __extends(HingeJoint, _super);
  112. function HingeJoint(jointData) {
  113. _super.call(this, PhysicsJoint.HingeJoint, jointData);
  114. }
  115. /**
  116. * Set the motor values.
  117. * Attention, this function is plugin specific. Engines won't react 100% the same.
  118. * @param {number} force the force to apply
  119. * @param {number} maxForce max force for this motor.
  120. */
  121. HingeJoint.prototype.setMotor = function (force, maxForce) {
  122. this._physicsPlugin.setMotor(this, force, maxForce);
  123. };
  124. /**
  125. * Set the motor's limits.
  126. * Attention, this function is plugin specific. Engines won't react 100% the same.
  127. */
  128. HingeJoint.prototype.setLimit = function (upperLimit, lowerLimit) {
  129. this._physicsPlugin.setLimit(this, upperLimit, lowerLimit);
  130. };
  131. return HingeJoint;
  132. })(MotorEnabledJoint);
  133. BABYLON.HingeJoint = HingeJoint;
  134. /**
  135. * This class represents a dual hinge physics joint (same as wheel joint)
  136. */
  137. var Hinge2Joint = (function (_super) {
  138. __extends(Hinge2Joint, _super);
  139. function Hinge2Joint(jointData) {
  140. _super.call(this, PhysicsJoint.Hinge2Joint, jointData);
  141. }
  142. /**
  143. * Set the motor values.
  144. * Attention, this function is plugin specific. Engines won't react 100% the same.
  145. * @param {number} force the force to apply
  146. * @param {number} maxForce max force for this motor.
  147. * @param {motorIndex} the motor's index, 0 or 1.
  148. */
  149. Hinge2Joint.prototype.setMotor = function (force, maxForce, motorIndex) {
  150. if (motorIndex === void 0) { motorIndex = 0; }
  151. this._physicsPlugin.setMotor(this, force, maxForce, motorIndex);
  152. };
  153. /**
  154. * Set the motor limits.
  155. * Attention, this function is plugin specific. Engines won't react 100% the same.
  156. * @param {number} upperLimit the upper limit
  157. * @param {number} lowerLimit lower limit
  158. * @param {motorIndex} the motor's index, 0 or 1.
  159. */
  160. Hinge2Joint.prototype.setLimit = function (upperLimit, lowerLimit, motorIndex) {
  161. if (motorIndex === void 0) { motorIndex = 0; }
  162. this._physicsPlugin.setLimit(this, upperLimit, lowerLimit, motorIndex);
  163. };
  164. return Hinge2Joint;
  165. })(MotorEnabledJoint);
  166. BABYLON.Hinge2Joint = Hinge2Joint;
  167. })(BABYLON || (BABYLON = {}));