@flighthq/camera 0.5.1-next.973.788d3d7 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/.tsbuildinfo.contract +1 -0
- package/dist/.tsbuildinfo.runtime +1 -0
- package/dist/basis.d.ts +2 -1
- package/dist/basis.d.ts.map +1 -1
- package/dist/basis.js.map +1 -1
- package/dist/camera.d.ts +3 -1
- package/dist/camera.d.ts.map +1 -1
- package/dist/camera.js +9 -3
- package/dist/camera.js.map +1 -1
- package/dist/camera2d.d.ts +5 -3
- package/dist/camera2d.d.ts.map +1 -1
- package/dist/camera2d.js +14 -11
- package/dist/camera2d.js.map +1 -1
- package/dist/contract.camera-types.d.ts +2 -0
- package/dist/contract.camera-types.d.ts.map +1 -0
- package/dist/contract.camera-types.js +4 -0
- package/dist/contract.camera-types.js.map +1 -0
- package/dist/contract.d.ts +20 -19
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +20 -19
- package/dist/contract.js.map +1 -1
- package/dist/cubeCapture.d.ts +4 -0
- package/dist/cubeCapture.d.ts.map +1 -0
- package/dist/cubeCapture.js +38 -0
- package/dist/cubeCapture.js.map +1 -0
- package/dist/culling.d.ts +2 -1
- package/dist/culling.d.ts.map +1 -1
- package/dist/culling.js +1 -1
- package/dist/culling.js.map +1 -1
- package/dist/depth.d.ts +10 -1
- package/dist/depth.d.ts.map +1 -1
- package/dist/depth.js +13 -22
- package/dist/depth.js.map +1 -1
- package/dist/enableCameraGuards.d.ts +2 -1
- package/dist/enableCameraGuards.d.ts.map +1 -1
- package/dist/enableCameraGuards.js +13 -13
- package/dist/enableCameraGuards.js.map +1 -1
- package/dist/explainCamera3DView.d.ts +1 -1
- package/dist/explainCamera3DView.d.ts.map +1 -1
- package/dist/frustumCorners.d.ts +2 -1
- package/dist/frustumCorners.d.ts.map +1 -1
- package/dist/frustumCorners.js +1 -1
- package/dist/frustumCorners.js.map +1 -1
- package/dist/index.d.ts +20 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -1
- package/dist/index.js.map +1 -1
- package/dist/intersection.d.ts +2 -1
- package/dist/intersection.d.ts.map +1 -1
- package/dist/intersection.js +1 -1
- package/dist/intersection.js.map +1 -1
- package/dist/parallax.d.ts +3 -2
- package/dist/parallax.d.ts.map +1 -1
- package/dist/parallax.js +5 -5
- package/dist/parallax.js.map +1 -1
- package/dist/picking.d.ts +2 -1
- package/dist/picking.d.ts.map +1 -1
- package/dist/picking.js +1 -1
- package/dist/picking.js.map +1 -1
- package/dist/projection.d.ts +6 -2
- package/dist/projection.d.ts.map +1 -1
- package/dist/projection.js +22 -4
- package/dist/projection.js.map +1 -1
- package/dist/projection2d.d.ts +4 -3
- package/dist/projection2d.d.ts.map +1 -1
- package/dist/projection2d.js +5 -5
- package/dist/projection2d.js.map +1 -1
- package/dist/reflection.d.ts +5 -0
- package/dist/reflection.d.ts.map +1 -0
- package/dist/reflection.js +58 -0
- package/dist/reflection.js.map +1 -0
- package/dist/shadowCamera.d.ts +2 -1
- package/dist/shadowCamera.d.ts.map +1 -1
- package/dist/shadowCamera.js +2 -2
- package/dist/shadowCamera.js.map +1 -1
- package/dist/types.d.ts +80 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/viewMatrix.d.ts +3 -2
- package/dist/viewMatrix.d.ts.map +1 -1
- package/dist/viewMatrix.js +2 -2
- package/dist/viewMatrix.js.map +1 -1
- package/dist/visibleBounds.d.ts +3 -2
- package/dist/visibleBounds.d.ts.map +1 -1
- package/dist/visibleBounds.js +4 -4
- package/dist/visibleBounds.js.map +1 -1
- package/dist/zoom.d.ts +2 -2
- package/dist/zoom.d.ts.map +1 -1
- package/dist/zoom.js +4 -4
- package/dist/zoom.js.map +1 -1
- package/package.json +8 -6
- package/src/basis.test.ts +3 -3
- package/src/camera.test.ts +68 -3
- package/src/camera2d.test.ts +19 -5
- package/src/cubeCapture.test.ts +120 -0
- package/src/culling.test.ts +3 -3
- package/src/depth.test.ts +3 -3
- package/src/enableCameraGuards.test.ts +48 -24
- package/src/explainCamera3DView.test.ts +10 -7
- package/src/frustumCorners.test.ts +4 -4
- package/src/intersection.test.ts +3 -3
- package/src/parallax.test.ts +8 -8
- package/src/picking.test.ts +3 -3
- package/src/projection.test.ts +56 -4
- package/src/projection2d.test.ts +23 -15
- package/src/reflection.test.ts +138 -0
- package/src/shadowCamera.test.ts +4 -4
- package/src/viewMatrix.test.ts +10 -10
- package/src/visibleBounds.test.ts +14 -14
- package/src/zoom.test.ts +11 -11
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { createMatrix4, createPlane } from '@flighthq/geometry/contract';
|
|
2
|
+
import type { Vector3Like } from '@flighthq/geometry/contract';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
|
|
5
|
+
import { getCamera3DForward, getCamera3DPosition } from './basis.ts';
|
|
6
|
+
import { createCamera3D, setCamera3DViewMatrix4FromLookAt } from './camera.ts';
|
|
7
|
+
import { createPerspectiveProjection, setProjectionMatrix4 } from './projection.ts';
|
|
8
|
+
import { applyObliqueNearClipPlane, reflectCamera3DByPlane } from './reflection.ts';
|
|
9
|
+
|
|
10
|
+
function near(a: number, b: number, eps = 1e-5): void {
|
|
11
|
+
expect(a).toBeCloseTo(b, -Math.log10(eps));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function perspectiveCamera(): ReturnType<typeof createCamera3D> {
|
|
15
|
+
const cam = createCamera3D({
|
|
16
|
+
far: 100,
|
|
17
|
+
near: 0.1,
|
|
18
|
+
projection: createPerspectiveProjection({ aspect: 1, fovY: Math.PI / 3 }),
|
|
19
|
+
});
|
|
20
|
+
setCamera3DViewMatrix4FromLookAt(cam, { x: 0, y: 0, z: 5 }, { x: 0, y: 0, z: 0 }, { x: 0, y: 1, z: 0 });
|
|
21
|
+
return cam;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function elevatedCamera(): ReturnType<typeof createCamera3D> {
|
|
25
|
+
const cam = createCamera3D({
|
|
26
|
+
far: 100,
|
|
27
|
+
near: 0.1,
|
|
28
|
+
projection: createPerspectiveProjection({ aspect: 1, fovY: Math.PI / 3 }),
|
|
29
|
+
});
|
|
30
|
+
setCamera3DViewMatrix4FromLookAt(cam, { x: 2, y: 5, z: 3 }, { x: 0, y: 0, z: 0 }, { x: 0, y: 1, z: 0 });
|
|
31
|
+
return cam;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function emptyCamera(): ReturnType<typeof createCamera3D> {
|
|
35
|
+
return createCamera3D({
|
|
36
|
+
far: 100,
|
|
37
|
+
near: 0.1,
|
|
38
|
+
projection: createPerspectiveProjection({ aspect: 1, fovY: Math.PI / 3 }),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe('applyObliqueNearClipPlane', () => {
|
|
43
|
+
it('replaces the near plane row of a perspective projection', () => {
|
|
44
|
+
const proj = createMatrix4();
|
|
45
|
+
const cam = perspectiveCamera();
|
|
46
|
+
setProjectionMatrix4(proj, cam.projection, 1, cam.near, cam.far);
|
|
47
|
+
const origM0 = proj.m[0];
|
|
48
|
+
const origM5 = proj.m[5];
|
|
49
|
+
const origM10 = proj.m[10];
|
|
50
|
+
const origM14 = proj.m[14];
|
|
51
|
+
applyObliqueNearClipPlane(proj, createPlane(0, 0, -1, -1));
|
|
52
|
+
expect(proj.m[0]).toBe(origM0);
|
|
53
|
+
expect(proj.m[5]).toBe(origM5);
|
|
54
|
+
expect(proj.m[10]).not.toBe(origM10);
|
|
55
|
+
expect(proj.m[14]).not.toBe(origM14);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('clips at the given view-space plane', () => {
|
|
59
|
+
const proj = createMatrix4();
|
|
60
|
+
const cam = perspectiveCamera();
|
|
61
|
+
setProjectionMatrix4(proj, cam.projection, 1, cam.near, cam.far);
|
|
62
|
+
const clipPlane = createPlane(0, 0, -1, -2);
|
|
63
|
+
applyObliqueNearClipPlane(proj, clipPlane);
|
|
64
|
+
const pointOnPlane: Vector3Like = { x: 0, y: 0, z: -2 };
|
|
65
|
+
const m = proj.m;
|
|
66
|
+
const clipZ = m[2] * pointOnPlane.x + m[6] * pointOnPlane.y + m[10] * pointOnPlane.z + m[14];
|
|
67
|
+
const clipW = m[3] * pointOnPlane.x + m[7] * pointOnPlane.y + m[11] * pointOnPlane.z + m[15];
|
|
68
|
+
near(clipZ / clipW, -1, 1e-4);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe('reflectCamera3DByPlane', () => {
|
|
73
|
+
it('reflects a camera through a horizontal plane at the origin', () => {
|
|
74
|
+
const cam = elevatedCamera();
|
|
75
|
+
const out = emptyCamera();
|
|
76
|
+
reflectCamera3DByPlane(out, cam, createPlane(0, 1, 0, 0));
|
|
77
|
+
const pos: Vector3Like = { x: 0, y: 0, z: 0 };
|
|
78
|
+
getCamera3DPosition(pos, out);
|
|
79
|
+
near(pos.x, 2);
|
|
80
|
+
near(pos.y, -5);
|
|
81
|
+
near(pos.z, 3);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('reflects a camera through the XZ plane at y=0', () => {
|
|
85
|
+
const cam = createCamera3D({
|
|
86
|
+
far: 50,
|
|
87
|
+
near: 0.5,
|
|
88
|
+
projection: createPerspectiveProjection({ aspect: 16 / 9, fovY: Math.PI / 4 }),
|
|
89
|
+
});
|
|
90
|
+
setCamera3DViewMatrix4FromLookAt(cam, { x: 3, y: 2, z: 0 }, { x: 0, y: 0, z: 0 }, { x: 0, y: 1, z: 0 });
|
|
91
|
+
const out = emptyCamera();
|
|
92
|
+
reflectCamera3DByPlane(out, cam, createPlane(0, 1, 0, 0));
|
|
93
|
+
expect(out.near).toBe(0.5);
|
|
94
|
+
expect(out.far).toBe(50);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('reflects through an offset plane', () => {
|
|
98
|
+
const cam = elevatedCamera();
|
|
99
|
+
const out = emptyCamera();
|
|
100
|
+
reflectCamera3DByPlane(out, cam, createPlane(0, 1, 0, -2));
|
|
101
|
+
const pos: Vector3Like = { x: 0, y: 0, z: 0 };
|
|
102
|
+
getCamera3DPosition(pos, out);
|
|
103
|
+
near(pos.x, 2);
|
|
104
|
+
near(pos.y, -1);
|
|
105
|
+
near(pos.z, 3);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('is alias-safe when out equals camera', () => {
|
|
109
|
+
const cam = elevatedCamera();
|
|
110
|
+
reflectCamera3DByPlane(cam, cam, createPlane(0, 1, 0, 0));
|
|
111
|
+
const pos: Vector3Like = { x: 0, y: 0, z: 0 };
|
|
112
|
+
getCamera3DPosition(pos, cam);
|
|
113
|
+
near(pos.y, -5);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('preserves view-direction symmetry for identity reflection (plane parallel to view)', () => {
|
|
117
|
+
const cam = perspectiveCamera();
|
|
118
|
+
const out = emptyCamera();
|
|
119
|
+
const zPlane = createPlane(0, 0, 1, 0);
|
|
120
|
+
reflectCamera3DByPlane(out, cam, zPlane);
|
|
121
|
+
const fwd: Vector3Like = { x: 0, y: 0, z: 0 };
|
|
122
|
+
getCamera3DForward(fwd, out);
|
|
123
|
+
near(fwd.x, 0);
|
|
124
|
+
near(fwd.y, 0);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('double reflection is identity', () => {
|
|
128
|
+
const cam = elevatedCamera();
|
|
129
|
+
const tmp = emptyCamera();
|
|
130
|
+
const out = emptyCamera();
|
|
131
|
+
const plane = createPlane(0, 1, 0, 0);
|
|
132
|
+
reflectCamera3DByPlane(tmp, cam, plane);
|
|
133
|
+
reflectCamera3DByPlane(out, tmp, plane);
|
|
134
|
+
for (let i = 0; i < 16; i++) {
|
|
135
|
+
near(out.view.m[i], cam.view.m[i], 1e-4);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
});
|
package/src/shadowCamera.test.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import type { OrthographicProjection } from '@flighthq/camera/contract';
|
|
1
2
|
import { createAabb } from '@flighthq/geometry/contract';
|
|
2
|
-
import type { OrthographicProjection } from '@flighthq/types/contract';
|
|
3
3
|
|
|
4
|
-
import { createCamera3D } from './camera';
|
|
5
|
-
import { createPerspectiveProjection } from './projection';
|
|
6
|
-
import { configureDirectionalShadowCamera3D, configureDirectionalShadowCamera3DTightFit } from './shadowCamera';
|
|
4
|
+
import { createCamera3D } from './camera.ts';
|
|
5
|
+
import { createPerspectiveProjection } from './projection.ts';
|
|
6
|
+
import { configureDirectionalShadowCamera3D, configureDirectionalShadowCamera3DTightFit } from './shadowCamera.ts';
|
|
7
7
|
|
|
8
8
|
function bounds() {
|
|
9
9
|
return createAabb(-1, -1, -1, 1, 1, 1);
|
package/src/viewMatrix.test.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { createMatrix, createVector2, matrixTransformPointXY } from '@flighthq/geometry/contract';
|
|
2
2
|
import { describe, expect, it } from 'vitest';
|
|
3
3
|
|
|
4
|
-
import { createCamera2D } from './camera2d';
|
|
5
|
-
import { getCamera2DViewMatrix } from './viewMatrix';
|
|
4
|
+
import { createCamera2D } from './camera2d.ts';
|
|
5
|
+
import { getCamera2DViewMatrix } from './viewMatrix.ts';
|
|
6
6
|
|
|
7
7
|
describe('getCamera2DViewMatrix', () => {
|
|
8
8
|
it('maps the camera center world point to the viewport center', () => {
|
|
9
|
-
const camera = createCamera2D(
|
|
9
|
+
const camera = createCamera2D();
|
|
10
10
|
const view = createMatrix();
|
|
11
|
-
getCamera2DViewMatrix(camera, view);
|
|
11
|
+
getCamera2DViewMatrix(camera, 800, 600, view);
|
|
12
12
|
const out = createVector2();
|
|
13
13
|
matrixTransformPointXY(out, view, 0, 0);
|
|
14
14
|
expect(out.x).toBeCloseTo(400, 9);
|
|
@@ -16,9 +16,9 @@ describe('getCamera2DViewMatrix', () => {
|
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
it('projects a right-of-center world point at zoom 1', () => {
|
|
19
|
-
const camera = createCamera2D(
|
|
19
|
+
const camera = createCamera2D();
|
|
20
20
|
const view = createMatrix();
|
|
21
|
-
getCamera2DViewMatrix(camera, view);
|
|
21
|
+
getCamera2DViewMatrix(camera, 800, 600, view);
|
|
22
22
|
const out = createVector2();
|
|
23
23
|
matrixTransformPointXY(out, view, 100, 0);
|
|
24
24
|
expect(out.x).toBeCloseTo(500, 9);
|
|
@@ -26,9 +26,9 @@ describe('getCamera2DViewMatrix', () => {
|
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
it('magnifies about the center at zoom 2', () => {
|
|
29
|
-
const camera = createCamera2D(
|
|
29
|
+
const camera = createCamera2D({ zoom: 2 });
|
|
30
30
|
const view = createMatrix();
|
|
31
|
-
getCamera2DViewMatrix(camera, view);
|
|
31
|
+
getCamera2DViewMatrix(camera, 800, 600, view);
|
|
32
32
|
const out = createVector2();
|
|
33
33
|
matrixTransformPointXY(out, view, 100, 0);
|
|
34
34
|
expect(out.x).toBeCloseTo(600, 9);
|
|
@@ -37,9 +37,9 @@ describe('getCamera2DViewMatrix', () => {
|
|
|
37
37
|
|
|
38
38
|
it('rotates the view opposite the camera rotation', () => {
|
|
39
39
|
// Camera3D rotated +90deg (CCW): a world point to the right appears above the center.
|
|
40
|
-
const camera = createCamera2D(
|
|
40
|
+
const camera = createCamera2D({ rotation: Math.PI / 2 });
|
|
41
41
|
const view = createMatrix();
|
|
42
|
-
getCamera2DViewMatrix(camera, view);
|
|
42
|
+
getCamera2DViewMatrix(camera, 800, 600, view);
|
|
43
43
|
const out = createVector2();
|
|
44
44
|
matrixTransformPointXY(out, view, 100, 0);
|
|
45
45
|
expect(out.x).toBeCloseTo(400, 9);
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { createRectangle, createVector2, intersectsRectangle } from '@flighthq/geometry/contract';
|
|
2
2
|
import { describe, expect, it, test } from 'vitest';
|
|
3
3
|
|
|
4
|
-
import { createCamera2D } from './camera2d';
|
|
5
|
-
import { unprojectCamera2DPoint } from './projection2d';
|
|
6
|
-
import { getCamera2DVisibleBounds, setCamera2DVisibleBoundsGuard } from './visibleBounds';
|
|
4
|
+
import { createCamera2D } from './camera2d.ts';
|
|
5
|
+
import { unprojectCamera2DPoint } from './projection2d.ts';
|
|
6
|
+
import { getCamera2DVisibleBounds, setCamera2DVisibleBoundsGuard } from './visibleBounds.ts';
|
|
7
7
|
|
|
8
8
|
describe('getCamera2DVisibleBounds', () => {
|
|
9
9
|
it('covers the full viewport in world units at zoom 1', () => {
|
|
10
|
-
const camera = createCamera2D(
|
|
10
|
+
const camera = createCamera2D();
|
|
11
11
|
const out = createRectangle();
|
|
12
|
-
getCamera2DVisibleBounds(camera, out);
|
|
12
|
+
getCamera2DVisibleBounds(camera, 800, 600, out);
|
|
13
13
|
expect(out.x).toBeCloseTo(-400, 9);
|
|
14
14
|
expect(out.y).toBeCloseTo(-300, 9);
|
|
15
15
|
expect(out.width).toBeCloseTo(800, 9);
|
|
@@ -17,9 +17,9 @@ describe('getCamera2DVisibleBounds', () => {
|
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
it('shrinks to half size centered at zoom 2', () => {
|
|
20
|
-
const camera = createCamera2D(
|
|
20
|
+
const camera = createCamera2D({ zoom: 2 });
|
|
21
21
|
const out = createRectangle();
|
|
22
|
-
getCamera2DVisibleBounds(camera, out);
|
|
22
|
+
getCamera2DVisibleBounds(camera, 800, 600, out);
|
|
23
23
|
expect(out.x).toBeCloseTo(-200, 9);
|
|
24
24
|
expect(out.y).toBeCloseTo(-150, 9);
|
|
25
25
|
expect(out.width).toBeCloseTo(400, 9);
|
|
@@ -27,9 +27,9 @@ describe('getCamera2DVisibleBounds', () => {
|
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
it('returns the enclosing AABB of a rotated view, larger than the viewport', () => {
|
|
30
|
-
const camera = createCamera2D(
|
|
30
|
+
const camera = createCamera2D({ rotation: Math.PI / 4 });
|
|
31
31
|
const out = createRectangle();
|
|
32
|
-
getCamera2DVisibleBounds(camera, out);
|
|
32
|
+
getCamera2DVisibleBounds(camera, 800, 600, out);
|
|
33
33
|
// AABB of an 800x600 rect rotated 45deg: both extents = (800 + 600) * cos(45deg).
|
|
34
34
|
expect(out.width).toBeCloseTo(989.9494936611666, 6);
|
|
35
35
|
expect(out.height).toBeCloseTo(989.9494936611666, 6);
|
|
@@ -44,7 +44,7 @@ describe('getCamera2DVisibleBounds', () => {
|
|
|
44
44
|
[0, 600],
|
|
45
45
|
];
|
|
46
46
|
for (const [sx, sy] of corners) {
|
|
47
|
-
unprojectCamera2DPoint(camera, sx, sy, corner);
|
|
47
|
+
unprojectCamera2DPoint(camera, 800, 600, sx, sy, corner);
|
|
48
48
|
expect(corner.x).toBeGreaterThanOrEqual(out.x - 1e-6);
|
|
49
49
|
expect(corner.x).toBeLessThanOrEqual(out.x + out.width + 1e-6);
|
|
50
50
|
expect(corner.y).toBeGreaterThanOrEqual(out.y - 1e-6);
|
|
@@ -56,7 +56,7 @@ describe('getCamera2DVisibleBounds', () => {
|
|
|
56
56
|
describe('setCamera2DVisibleBoundsGuard', () => {
|
|
57
57
|
test('fails toward drawing: an unbounded rectangle that still intersects distant content', () => {
|
|
58
58
|
const out = createRectangle();
|
|
59
|
-
getCamera2DVisibleBounds(createCamera2D(
|
|
59
|
+
getCamera2DVisibleBounds(createCamera2D({ zoom: 0 }), 64, 64, out);
|
|
60
60
|
// Finite on purpose — the max edge must survive ordinary arithmetic, not rely on NaN comparisons.
|
|
61
61
|
expect(Number.isFinite(out.x + out.width)).toBe(true);
|
|
62
62
|
expect(Number.isFinite(out.y + out.height)).toBe(true);
|
|
@@ -69,8 +69,8 @@ describe('setCamera2DVisibleBoundsGuard', () => {
|
|
|
69
69
|
const seen: number[] = [];
|
|
70
70
|
setCamera2DVisibleBoundsGuard((camera) => seen.push(camera.zoom));
|
|
71
71
|
try {
|
|
72
|
-
getCamera2DVisibleBounds(createCamera2D(
|
|
73
|
-
getCamera2DVisibleBounds(createCamera2D(64, 64
|
|
72
|
+
getCamera2DVisibleBounds(createCamera2D({ zoom: 0 }), 64, 64, createRectangle());
|
|
73
|
+
getCamera2DVisibleBounds(createCamera2D(), 64, 64, createRectangle());
|
|
74
74
|
expect(seen).toEqual([0]);
|
|
75
75
|
} finally {
|
|
76
76
|
setCamera2DVisibleBoundsGuard(null);
|
|
@@ -79,7 +79,7 @@ describe('setCamera2DVisibleBoundsGuard', () => {
|
|
|
79
79
|
|
|
80
80
|
test('leaves an invertible camera computing the same bounds as before', () => {
|
|
81
81
|
const out = createRectangle();
|
|
82
|
-
getCamera2DVisibleBounds(createCamera2D(64, 32
|
|
82
|
+
getCamera2DVisibleBounds(createCamera2D(), 64, 32, out);
|
|
83
83
|
expect(out.width).toBeCloseTo(64, 6);
|
|
84
84
|
expect(out.height).toBeCloseTo(32, 6);
|
|
85
85
|
});
|
package/src/zoom.test.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { createVector2 } from '@flighthq/geometry/contract';
|
|
2
2
|
import { describe, expect, it } from 'vitest';
|
|
3
3
|
|
|
4
|
-
import { createCamera2D } from './camera2d';
|
|
5
|
-
import { unprojectCamera2DPoint } from './projection2d';
|
|
6
|
-
import { zoomCamera2DAtScreenPoint } from './zoom';
|
|
4
|
+
import { createCamera2D } from './camera2d.ts';
|
|
5
|
+
import { unprojectCamera2DPoint } from './projection2d.ts';
|
|
6
|
+
import { zoomCamera2DAtScreenPoint } from './zoom.ts';
|
|
7
7
|
|
|
8
8
|
describe('zoomCamera2DAtScreenPoint', () => {
|
|
9
9
|
it('keeps the world point under a screen corner fixed while zooming', () => {
|
|
10
|
-
const camera = createCamera2D(
|
|
10
|
+
const camera = createCamera2D();
|
|
11
11
|
const before = createVector2();
|
|
12
|
-
unprojectCamera2DPoint(camera, 0, 0, before);
|
|
12
|
+
unprojectCamera2DPoint(camera, 800, 600, 0, 0, before);
|
|
13
13
|
|
|
14
|
-
zoomCamera2DAtScreenPoint(camera, 0, 0, 2);
|
|
14
|
+
zoomCamera2DAtScreenPoint(camera, 800, 600, 0, 0, 2);
|
|
15
15
|
|
|
16
16
|
const after = createVector2();
|
|
17
|
-
unprojectCamera2DPoint(camera, 0, 0, after);
|
|
17
|
+
unprojectCamera2DPoint(camera, 800, 600, 0, 0, after);
|
|
18
18
|
expect(camera.zoom).toBe(2);
|
|
19
19
|
expect(after.x).toBeCloseTo(before.x, 9);
|
|
20
20
|
expect(after.y).toBeCloseTo(before.y, 9);
|
|
@@ -24,14 +24,14 @@ describe('zoomCamera2DAtScreenPoint', () => {
|
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
it('keeps an arbitrary screen point fixed under a rotated camera', () => {
|
|
27
|
-
const camera = createCamera2D(
|
|
27
|
+
const camera = createCamera2D({ x: 30, y: -20, zoom: 1.5, rotation: Math.PI / 5 });
|
|
28
28
|
const before = createVector2();
|
|
29
|
-
unprojectCamera2DPoint(camera, 250, 175, before);
|
|
29
|
+
unprojectCamera2DPoint(camera, 800, 600, 250, 175, before);
|
|
30
30
|
|
|
31
|
-
zoomCamera2DAtScreenPoint(camera, 250, 175, 3);
|
|
31
|
+
zoomCamera2DAtScreenPoint(camera, 800, 600, 250, 175, 3);
|
|
32
32
|
|
|
33
33
|
const after = createVector2();
|
|
34
|
-
unprojectCamera2DPoint(camera, 250, 175, after);
|
|
34
|
+
unprojectCamera2DPoint(camera, 800, 600, 250, 175, after);
|
|
35
35
|
expect(camera.zoom).toBe(3);
|
|
36
36
|
expect(after.x).toBeCloseTo(before.x, 6);
|
|
37
37
|
expect(after.y).toBeCloseTo(before.y, 6);
|