type camera

This commit is contained in:
Seve Badajoz
2021-08-12 16:35:27 -07:00
parent 925b785b1f
commit e49ad7a433
+23 -28
View File
@@ -11,30 +11,28 @@ const panBound = 0.8;
const scratch0 = new Float32Array(16); const scratch0 = new Float32Array(16);
const scratch1 = new Float32Array(16); const scratch1 = new Float32Array(16);
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS. function clamp(val: number, rng: Array<number>) {
function clamp(val: any, rng: any) {
return Math.max(Math.min(val, rng[1]), rng[0]); return Math.max(Math.min(val, rng[1]), rng[0]);
} }
class Camera { class Camera {
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
canvas: any; canvas: any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS. prevEvent: {
prevEvent: any; clientX: number;
clientY: number;
type: string;
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS. viewMatrix: mat3;
viewMatrix: any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS. viewMatrixInv: mat3;
viewMatrixInv: any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS. constructor(canvas: HTMLCanvasElement) {
constructor(canvas: any) {
this.prevEvent = { this.prevEvent = {
clientX: 0, clientX: 0,
clientY: 0, clientY: 0,
type: 0, type: "",
}; };
this.canvas = canvas; this.canvas = canvas;
this.viewMatrix = mat3.create(); this.viewMatrix = mat3.create();
@@ -53,8 +51,7 @@ class Camera {
return this.viewMatrix[0]; return this.viewMatrix[0];
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS. pan(dx: number, dy: number) {
pan(dx: any, dy: any) {
const m = this.viewMatrix; const m = this.viewMatrix;
const dyRange = [ const dyRange = [
-panBound - (m[7] + 1) / m[4], -panBound - (m[7] + 1) / m[4],
@@ -74,8 +71,7 @@ class Camera {
mat3.invert(this.viewMatrixInv, m); mat3.invert(this.viewMatrixInv, m);
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS. zoomAt(d: number, x = 0, y = 0) {
zoomAt(d: any, x = 0, y = 0) {
/* /*
Camera zoom at [x,y] Camera zoom at [x,y]
*/ */
@@ -98,15 +94,18 @@ class Camera {
Event handling Event handling
*/ */
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS. flush(e: MouseEvent) {
flush(e: any) {
this.prevEvent.type = e.type; this.prevEvent.type = e.type;
this.prevEvent.clientX = e.clientX; this.prevEvent.clientX = e.clientX;
this.prevEvent.clientY = e.clientY; this.prevEvent.clientY = e.clientY;
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS. localPosition(
localPosition(target: any, canvasX: any, canvasY: any, projectionInvTF: any) { target: HTMLCanvasElement,
canvasX: number,
canvasY: number,
projectionInvTF: mat3
) {
/* /*
Convert mouse position to local Convert mouse position to local
*/ */
@@ -126,8 +125,7 @@ class Camera {
return pos; return pos;
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS. mousePan(e: MouseEvent, projectionTF: mat3) {
mousePan(e: any, projectionTF: any) {
const projectionInvTF = mat3.invert(scratch0, projectionTF); const projectionInvTF = mat3.invert(scratch0, projectionTF);
const pos = this.localPosition( const pos = this.localPosition(
this.canvas, this.canvas,
@@ -147,8 +145,7 @@ class Camera {
return true; return true;
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS. wheelZoom(e: WheelEvent, projectionTF: mat3) {
wheelZoom(e: any, projectionTF: any) {
const { height } = this.canvas; const { height } = this.canvas;
const { deltaY, deltaMode, clientX, clientY } = e; const { deltaY, deltaMode, clientX, clientY } = e;
const scale = scaleSpeed * (deltaMode === 1 ? 12 : 1) * (deltaY || 0); const scale = scaleSpeed * (deltaMode === 1 ? 12 : 1) * (deltaY || 0);
@@ -164,8 +161,7 @@ class Camera {
return true; return true;
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS. handleEvent(e: MouseEvent, projectionTF: any) {
handleEvent(e: any, projectionTF: any) {
/* /*
process the event, and return true if camera view changed process the event, and return true if camera view changed
*/ */
@@ -194,8 +190,7 @@ class Camera {
} }
} }
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS. function attachCamera(canvas: HTMLCanvasElement) {
function attachCamera(canvas: any) {
return new Camera(canvas); return new Camera(canvas);
} }