123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- import { __decorate } from "../../tslib.es6.js";
- import { serialize } from "../../Misc/decorators.js";
- import { CameraInputTypes } from "../../Cameras/cameraInputsManager.js";
- import { BaseCameraPointersInput } from "../../Cameras/Inputs/BaseCameraPointersInput.js";
- import { Logger } from "../../Misc/logger.js";
- /**
- * Manage the pointers inputs to control an follow camera.
- * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs
- */
- export class FollowCameraPointersInput extends BaseCameraPointersInput {
- constructor() {
- super(...arguments);
- /**
- * Defines the pointer angular sensibility along the X axis or how fast is
- * the camera rotating.
- * A negative number will reverse the axis direction.
- */
- this.angularSensibilityX = 1;
- /**
- * Defines the pointer angular sensibility along the Y axis or how fast is
- * the camera rotating.
- * A negative number will reverse the axis direction.
- */
- this.angularSensibilityY = 1;
- /**
- * Defines the pointer pinch precision or how fast is the camera zooming.
- * A negative number will reverse the axis direction.
- */
- this.pinchPrecision = 10000.0;
- /**
- * pinchDeltaPercentage will be used instead of pinchPrecision if different
- * from 0.
- * It defines the percentage of current camera.radius to use as delta when
- * pinch zoom is used.
- */
- this.pinchDeltaPercentage = 0;
- /**
- * Pointer X axis controls zoom. (X axis modifies camera.radius value.)
- */
- this.axisXControlRadius = false;
- /**
- * Pointer X axis controls height. (X axis modifies camera.heightOffset value.)
- */
- this.axisXControlHeight = false;
- /**
- * Pointer X axis controls angle. (X axis modifies camera.rotationOffset value.)
- */
- this.axisXControlRotation = true;
- /**
- * Pointer Y axis controls zoom. (Y axis modifies camera.radius value.)
- */
- this.axisYControlRadius = false;
- /**
- * Pointer Y axis controls height. (Y axis modifies camera.heightOffset value.)
- */
- this.axisYControlHeight = true;
- /**
- * Pointer Y axis controls angle. (Y axis modifies camera.rotationOffset value.)
- */
- this.axisYControlRotation = false;
- /**
- * Pinch controls zoom. (Pinch modifies camera.radius value.)
- */
- this.axisPinchControlRadius = true;
- /**
- * Pinch controls height. (Pinch modifies camera.heightOffset value.)
- */
- this.axisPinchControlHeight = false;
- /**
- * Pinch controls angle. (Pinch modifies camera.rotationOffset value.)
- */
- this.axisPinchControlRotation = false;
- /**
- * Log error messages if basic misconfiguration has occurred.
- */
- this.warningEnable = true;
- /* Check for obvious misconfiguration. */
- this._warningCounter = 0;
- }
- /**
- * Gets the class name of the current input.
- * @returns the class name
- */
- getClassName() {
- return "FollowCameraPointersInput";
- }
- onTouch(pointA, offsetX, offsetY) {
- this._warning();
- if (this.axisXControlRotation) {
- this.camera.rotationOffset += offsetX / this.angularSensibilityX;
- }
- else if (this.axisYControlRotation) {
- this.camera.rotationOffset += offsetY / this.angularSensibilityX;
- }
- if (this.axisXControlHeight) {
- this.camera.heightOffset += offsetX / this.angularSensibilityY;
- }
- else if (this.axisYControlHeight) {
- this.camera.heightOffset += offsetY / this.angularSensibilityY;
- }
- if (this.axisXControlRadius) {
- this.camera.radius -= offsetX / this.angularSensibilityY;
- }
- else if (this.axisYControlRadius) {
- this.camera.radius -= offsetY / this.angularSensibilityY;
- }
- }
- onMultiTouch(pointA, pointB, previousPinchSquaredDistance, pinchSquaredDistance, previousMultiTouchPanPosition, multiTouchPanPosition) {
- if (previousPinchSquaredDistance === 0 && previousMultiTouchPanPosition === null) {
- // First time this method is called for new pinch.
- // Next time this is called there will be a
- // previousPinchSquaredDistance and pinchSquaredDistance to compare.
- return;
- }
- if (pinchSquaredDistance === 0 && multiTouchPanPosition === null) {
- // Last time this method is called at the end of a pinch.
- return;
- }
- let pinchDelta = (pinchSquaredDistance - previousPinchSquaredDistance) / ((this.pinchPrecision * (this.angularSensibilityX + this.angularSensibilityY)) / 2);
- if (this.pinchDeltaPercentage) {
- pinchDelta *= 0.01 * this.pinchDeltaPercentage;
- if (this.axisPinchControlRotation) {
- this.camera.rotationOffset += pinchDelta * this.camera.rotationOffset;
- }
- if (this.axisPinchControlHeight) {
- this.camera.heightOffset += pinchDelta * this.camera.heightOffset;
- }
- if (this.axisPinchControlRadius) {
- this.camera.radius -= pinchDelta * this.camera.radius;
- }
- }
- else {
- if (this.axisPinchControlRotation) {
- this.camera.rotationOffset += pinchDelta;
- }
- if (this.axisPinchControlHeight) {
- this.camera.heightOffset += pinchDelta;
- }
- if (this.axisPinchControlRadius) {
- this.camera.radius -= pinchDelta;
- }
- }
- }
- _warning() {
- if (!this.warningEnable || this._warningCounter++ % 100 !== 0) {
- return;
- }
- const warn = "It probably only makes sense to control ONE camera " + "property with each pointer axis. Set 'warningEnable = false' " + "if you are sure. Currently enabled: ";
- if (+this.axisXControlRotation + +this.axisXControlHeight + +this.axisXControlRadius <= 1) {
- Logger.Warn(warn +
- "axisXControlRotation: " +
- this.axisXControlRotation +
- ", axisXControlHeight: " +
- this.axisXControlHeight +
- ", axisXControlRadius: " +
- this.axisXControlRadius);
- }
- if (+this.axisYControlRotation + +this.axisYControlHeight + +this.axisYControlRadius <= 1) {
- Logger.Warn(warn +
- "axisYControlRotation: " +
- this.axisYControlRotation +
- ", axisYControlHeight: " +
- this.axisYControlHeight +
- ", axisYControlRadius: " +
- this.axisYControlRadius);
- }
- if (+this.axisPinchControlRotation + +this.axisPinchControlHeight + +this.axisPinchControlRadius <= 1) {
- Logger.Warn(warn +
- "axisPinchControlRotation: " +
- this.axisPinchControlRotation +
- ", axisPinchControlHeight: " +
- this.axisPinchControlHeight +
- ", axisPinchControlRadius: " +
- this.axisPinchControlRadius);
- }
- }
- }
- __decorate([
- serialize()
- ], FollowCameraPointersInput.prototype, "angularSensibilityX", void 0);
- __decorate([
- serialize()
- ], FollowCameraPointersInput.prototype, "angularSensibilityY", void 0);
- __decorate([
- serialize()
- ], FollowCameraPointersInput.prototype, "pinchPrecision", void 0);
- __decorate([
- serialize()
- ], FollowCameraPointersInput.prototype, "pinchDeltaPercentage", void 0);
- __decorate([
- serialize()
- ], FollowCameraPointersInput.prototype, "axisXControlRadius", void 0);
- __decorate([
- serialize()
- ], FollowCameraPointersInput.prototype, "axisXControlHeight", void 0);
- __decorate([
- serialize()
- ], FollowCameraPointersInput.prototype, "axisXControlRotation", void 0);
- __decorate([
- serialize()
- ], FollowCameraPointersInput.prototype, "axisYControlRadius", void 0);
- __decorate([
- serialize()
- ], FollowCameraPointersInput.prototype, "axisYControlHeight", void 0);
- __decorate([
- serialize()
- ], FollowCameraPointersInput.prototype, "axisYControlRotation", void 0);
- __decorate([
- serialize()
- ], FollowCameraPointersInput.prototype, "axisPinchControlRadius", void 0);
- __decorate([
- serialize()
- ], FollowCameraPointersInput.prototype, "axisPinchControlHeight", void 0);
- __decorate([
- serialize()
- ], FollowCameraPointersInput.prototype, "axisPinchControlRotation", void 0);
- CameraInputTypes["FollowCameraPointersInput"] = FollowCameraPointersInput;
- //# sourceMappingURL=followCameraPointersInput.js.map
|