babylon.gravityInputController.js 1.1 KB

123456789101112131415161718192021222324
  1. "use strict";
  2. var BABYLON = BABYLON || {};
  3. (function () {
  4. BABYLON.GravityInputController = function (scene, target) {
  5. BABYLON.inputController.call(this, scene, target);
  6. this._fallSpeed = 1; // 1 meters per second
  7. this._moveVectorGlobal = new BABYLON.Vector3(0, 0, 0);
  8. this._moveVectorLocal = new BABYLON.Vector3(0, 0, 0);
  9. this._invertMatrix = new BABYLON.Matrix();
  10. };
  11. BABYLON.GravityInputController.prototype = Object.create(BABYLON.inputController.prototype);
  12. BABYLON.GravityInputController.prototype.update = function () {
  13. var orientation = this.target.getOrientation();
  14. BABYLON.Matrix.RotationYawPitchRollToRef(orientation.yaw, orientation.pitch, orientation.roll, this._invertMatrix);
  15. this._invertMatrix.invert();
  16. this._moveVectorGlobal.x = 0;
  17. this._moveVectorGlobal.y = -this._fallSpeed * BABYLON.Tools.GetDeltaTime() / 1000.0;
  18. this._moveVectorGlobal.z = 0;
  19. BABYLON.Vector3.TransformNormalToRef(this._moveVectorGlobal,this._invertMatrix, this._moveVectorLocal);
  20. this.target.moveRelative(this._moveVectorLocal);
  21. };
  22. })();