babylon.virtualJoysticksCamera.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536
  1. var BABYLON = BABYLON || {};
  2. (function () {
  3. BABYLON.VirtualJoysticksCamera = function (name, position, scene) {
  4. BABYLON.FreeCamera.call(this, name, position, scene);
  5. this.leftjoystick = new BABYLON.VirtualJoystick(true);
  6. this.leftjoystick.setAxisForUD("Z");
  7. this.leftjoystick.setAxisForLR("X");
  8. this.leftjoystick.setJoystickSensibility(0.15);
  9. this.rightjoystick = new BABYLON.VirtualJoystick(false);
  10. this.rightjoystick.setAxisForUD("X");
  11. this.rightjoystick.setAxisForLR("Y");
  12. this.rightjoystick.reverseUpDown = true;
  13. this.rightjoystick.setJoystickSensibility(0.05);
  14. this.rightjoystick.setJoystickColor("yellow");
  15. };
  16. // We're mainly based on the logic defined into the FreeCamera code
  17. BABYLON.VirtualJoysticksCamera.prototype = Object.create(BABYLON.FreeCamera.prototype);
  18. BABYLON.VirtualJoysticksCamera.prototype._checkInputs = function () {
  19. var cameraTransform = BABYLON.Matrix.RotationYawPitchRoll(this.rotation.y, this.rotation.x, 0);
  20. var deltaTransform = BABYLON.Vector3.TransformCoordinates(this.leftjoystick.deltaPosition, cameraTransform);
  21. this.cameraDirection = this.cameraDirection.add(deltaTransform);
  22. this.cameraRotation = this.cameraRotation.add(this.rightjoystick.deltaPosition);
  23. if (!this.leftjoystick.pressed) {
  24. this.leftjoystick.deltaPosition = this.leftjoystick.deltaPosition.scale(0.9);
  25. }
  26. if (!this.rightjoystick.pressed) {
  27. this.rightjoystick.deltaPosition = this.rightjoystick.deltaPosition.scale(0.9);
  28. }
  29. };
  30. BABYLON.VirtualJoysticksCamera.prototype.dispose = function () {
  31. this.leftjoystick.releaseCanvas();
  32. };
  33. })();