API Docs for: 0.6.1
Show:

File: src/equations/RotationalMotorEquation.js

  1. module.exports = RotationalMotorEquation;
  2.  
  3. var Vec3 = require('../math/Vec3');
  4. var Mat3 = require('../math/Mat3');
  5. var Equation = require('./Equation');
  6.  
  7. /**
  8. * Rotational motor constraint. Tries to keep the relative angular velocity of the bodies to a given value.
  9. * @class RotationalMotorEquation
  10. * @constructor
  11. * @author schteppe
  12. * @param {Body} bodyA
  13. * @param {Body} bodyB
  14. * @param {Number} maxForce
  15. * @extends Equation
  16. */
  17. function RotationalMotorEquation(bodyA, bodyB, maxForce){
  18. maxForce = typeof(maxForce)!=='undefined' ? maxForce : 1e6;
  19. Equation.call(this,bodyA,bodyB,-maxForce,maxForce);
  20.  
  21. /**
  22. * World oriented rotational axis
  23. * @property {Vec3} axisA
  24. */
  25. this.axisA = new Vec3();
  26.  
  27. /**
  28. * World oriented rotational axis
  29. * @property {Vec3} axisB
  30. */
  31. this.axisB = new Vec3(); // World oriented rotational axis
  32.  
  33. /**
  34. * Motor velocity
  35. * @property {Number} targetVelocity
  36. */
  37. this.targetVelocity = 0;
  38. }
  39.  
  40. RotationalMotorEquation.prototype = new Equation();
  41. RotationalMotorEquation.prototype.constructor = RotationalMotorEquation;
  42.  
  43. RotationalMotorEquation.prototype.computeB = function(h){
  44. var a = this.a,
  45. b = this.b,
  46. bi = this.bi,
  47. bj = this.bj,
  48.  
  49. axisA = this.axisA,
  50. axisB = this.axisB,
  51.  
  52. GA = this.jacobianElementA,
  53. GB = this.jacobianElementB;
  54.  
  55. // g = 0
  56. // gdot = axisA * wi - axisB * wj
  57. // gdot = G * W = G * [vi wi vj wj]
  58. // =>
  59. // G = [0 axisA 0 -axisB]
  60.  
  61. GA.rotational.copy(axisA);
  62. axisB.negate(GB.rotational);
  63.  
  64. var GW = this.computeGW() - this.targetVelocity,
  65. GiMf = this.computeGiMf();
  66.  
  67. var B = - GW * b - h * GiMf;
  68.  
  69. return B;
  70. };
  71.