babylon.inputCollisionFilter.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. "use strict";
  2. var BABYLON = BABYLON || {};
  3. (function () {
  4. BABYLON.InputCollisionFilter = function (scene, target, ellipsoid) {
  5. BABYLON.inputFilter.call(this, scene, target);
  6. this._transformedDirection = new BABYLON.Vector3();
  7. this._tempNewPosition = new BABYLON.Vector3();
  8. this._tempNewPosition2 = new BABYLON.Vector3();
  9. this._ellipsoid = ellipsoid || new BABYLON.Vector3(.2,.855,.2);
  10. this._collider = new BABYLON.Collider();
  11. this._collidedPosition = new BABYLON.Vector3(0, 0, 0);
  12. this._cameraHeight = 1.7;
  13. this._positionBottom = new BABYLON.Vector3(0, 0, 0);
  14. };
  15. BABYLON.InputCollisionFilter.prototype = Object.create(BABYLON.inputFilter.prototype);
  16. BABYLON.InputCollisionFilter.prototype.moveRelative = function (relativeMovement) {
  17. var rotation = this.getOrientation();
  18. BABYLON.Vector3.TransformNormalToRef(relativeMovement, this.getOrientationMatrix(), this._transformedDirection);
  19. this.getPosition().addToRef(this._transformedDirection, this._tempNewPosition);
  20. //this._tempNewPosition.y -= this._ellipsoid.y;
  21. this._collider.radius = this._ellipsoid;
  22. var p = this.getPosition();
  23. this._positionBottom.x = p.x;
  24. this._positionBottom.y = p.y;
  25. this._positionBottom.z = p.z;
  26. this._positionBottom.y += this._ellipsoid.y - this._cameraHeight;
  27. this.scene._getNewPosition(this._positionBottom, this._transformedDirection, this._collider, 3, this._collidedPosition);
  28. this._collidedPosition.subtractToRef(this._positionBottom, this._tempNewPosition2);
  29. if (this._tempNewPosition2.length() > BABYLON.Engine.collisionsEpsilon * 2) {
  30. BABYLON.Vector3.TransformNormalToRef(this._tempNewPosition2, this.getInvertOrientationMatrix(), this._tempNewPosition);
  31. this.target.moveRelative(this._tempNewPosition);
  32. }
  33. };
  34. })();