|
1 | 1 | import { describe, expect, it } from 'vitest'; |
2 | 2 | import type { Mat4, Vec3 } from '../../../src'; |
3 | | -import { mat4, quat } from '../../../src'; |
| 3 | +import { mat4, quat, vec3 } from '../../../src'; |
4 | 4 |
|
5 | 5 | describe('mat4', () => { |
6 | 6 | describe('create', () => { |
@@ -673,6 +673,25 @@ describe('mat4', () => { |
673 | 673 | expect(result[10]).not.toBe(mat4.perspectiveNO(mat4.create(), Math.PI / 4, 16 / 9, 0.1, 100)[10]); |
674 | 674 | }); |
675 | 675 |
|
| 676 | + it('perspectiveReverseZ should map near to depth 1 and far to depth 0', () => { |
| 677 | + const projection = mat4.perspectiveReverseZ(mat4.create(), Math.PI / 3, 2, 0.1, 100); |
| 678 | + const point: Vec3 = [0, 0, 0]; |
| 679 | + |
| 680 | + expect(projection).toEqual(mat4.perspectiveZO(mat4.create(), Math.PI / 3, 2, 100, 0.1)); |
| 681 | + expect(vec3.transformMat4(point, [0, 0, -0.1], projection)[2]).toBeCloseTo(1); |
| 682 | + expect(vec3.transformMat4(point, [0, 0, -100], projection)[2]).toBeCloseTo(0); |
| 683 | + }); |
| 684 | + |
| 685 | + it('perspectiveReverseZ should support an infinite far plane', () => { |
| 686 | + const projection = mat4.perspectiveReverseZ(mat4.create(), Math.PI / 3, 2, 0.1, Infinity); |
| 687 | + const point: Vec3 = [0, 0, 0]; |
| 688 | + |
| 689 | + expect(projection.every(Number.isFinite)).toBe(true); |
| 690 | + expect(vec3.transformMat4(point, [0, 0, -0.1], projection)[2]).toBeCloseTo(1); |
| 691 | + expect(vec3.transformMat4(point, [0, 0, -0.2], projection)[2]).toBeCloseTo(0.5); |
| 692 | + expect(vec3.transformMat4(point, [0, 0, -1e9], projection)[2]).toBeCloseTo(0, 8); |
| 693 | + }); |
| 694 | + |
676 | 695 | it('orthoZO should create zero-to-one depth range orthographic', () => { |
677 | 696 | const result = mat4.create(); |
678 | 697 | mat4.orthoZO(result, -1, 1, -1, 1, 0.1, 100); |
|
0 commit comments