Skip to content

Commit

Permalink
Merge pull request #922 from actnwit/feat/orbit-camera-controller
Browse files Browse the repository at this point in the history
feat: add isMouseDown, lastMouseDownTimeStamp, lastMouseUpTimeStamp g…
  • Loading branch information
Yuki Shimada authored Nov 28, 2021
2 parents 0012d45 + 73023fe commit f67b32f
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions src/foundation/cameras/OrbitCameraController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ICameraController from './ICameraController';
import MutableMatrix44 from '../math/MutableMatrix44';
import AABB from '../math/AABB';
import AbstractCameraController from './AbstractCameraController';
import { Is } from '../misc/Is';

declare let window: any;

Expand All @@ -23,7 +24,9 @@ export default class OrbitCameraController
public moveSpeed = 1;
public followTargetAABB = false;

private __isKeyUp = true;
private __isMouseDown = false;
private __lastMouseDownTimeStamp: number = 0;
private __lastMouseUpTimeStamp: number = 0;
private __originalY = -1;
private __originalX = -1;
private __buttonNumber = 0;
Expand Down Expand Up @@ -123,24 +126,21 @@ export default class OrbitCameraController

__mouseDown(e: MouseEvent) {
this.__tryToPreventDefault(e);
if (!this.__isKeyUp) return;
if (this.isMouseDown) return;
if (this.__isPressingCtrl) return;

this.__originalX = e.clientX;
this.__originalY = e.clientY;
this.__rot_bgn_x = this.__rot_x;
this.__rot_bgn_y = this.__rot_y;

this.__isKeyUp = false;

// if (typeof e.buttons !== "undefined") {
// this.updateCamera();
// }
this.__isMouseDown = true;
this.__lastMouseDownTimeStamp = e.timeStamp;
}

__mouseMove(e: MouseEvent) {
this.__tryToPreventDefault(e);
if (this.__isKeyUp) return;
if (Is.false(this.isMouseDown)) return;
if (this.__isPressingCtrl) return;

if (this.__buttonNumber === 0) {
Expand Down Expand Up @@ -192,7 +192,8 @@ export default class OrbitCameraController
this.__originalX = -1;
this.__originalY = -1;

this.__isKeyUp = true;
this.__isMouseDown = false;
this.__lastMouseUpTimeStamp = e.timeStamp;
}

__touchDown(e: TouchEvent) {
Expand All @@ -208,12 +209,13 @@ export default class OrbitCameraController
this.__originalY = (e.touches[0].clientY + e.touches[1].clientY) * 0.5;
}

this.__isKeyUp = false;
this.__isMouseDown = true;
this.__lastMouseDownTimeStamp = e.timeStamp;
}

__touchMove(e: TouchEvent) {
this.__tryToPreventDefault(e);
if (this.__isKeyUp) return;
if (Is.false(this.isMouseDown)) return;

let currentTouchX = e.touches[0].clientX;
let currentTouchY = e.touches[0].clientY;
Expand Down Expand Up @@ -248,7 +250,6 @@ export default class OrbitCameraController
if (touchNumber === 0) {
this.__originalX = -1;
this.__originalY = -1;
this.__isKeyUp = true;
} else if (touchNumber === 1) {
this.__originalX = e.touches[0].clientX;
this.__originalY = e.touches[0].clientY;
Expand All @@ -258,6 +259,8 @@ export default class OrbitCameraController
this.__originalX = (e.touches[0].clientX + e.touches[1].clientX) * 0.5;
this.__originalY = (e.touches[0].clientY + e.touches[1].clientY) * 0.5;
}
this.__isMouseDown = false;
this.__lastMouseUpTimeStamp = e.timeStamp;
}

set rotX(value: number) {
Expand Down Expand Up @@ -788,4 +791,16 @@ export default class OrbitCameraController
get scaleOfZNearAndZFar() {
return this.__scaleOfZNearAndZFar;
}

get isMouseDown(): boolean {
return this.__isMouseDown;
}

get lastMouseDownTimeStamp(): number {
return this.__lastMouseDownTimeStamp;
}

get lastMouseUpTimeStamp(): number {
return this.__lastMouseUpTimeStamp;
}
}

0 comments on commit f67b32f

Please sign in to comment.