@@ -474,6 +474,95 @@ function check(Type) {
474
474
shouldBeCloseArray ( vec3 . transformMat4 ( [ 0 , 0 , zFar ] , m ) , [ 0 , 0 , Infinity ] , 0.000001 ) ;
475
475
} ) ;
476
476
477
+ it ( 'should compute perspective reverseZ with zFar' , ( ) => {
478
+ const fov = 2 ;
479
+ const aspect = 4 ;
480
+ const zNear = 10 ;
481
+ const zFar = 20 ;
482
+ const f = Math . tan ( Math . PI * 0.5 - 0.5 * fov ) ;
483
+ const rangeInv = 1 / ( zFar - zNear ) ;
484
+ const expected = [
485
+ f / aspect ,
486
+ 0 ,
487
+ 0 ,
488
+ 0 ,
489
+
490
+ 0 ,
491
+ f ,
492
+ 0 ,
493
+ 0 ,
494
+
495
+ 0 ,
496
+ 0 ,
497
+ zNear * rangeInv ,
498
+ - 1 ,
499
+
500
+ 0 ,
501
+ 0 ,
502
+ zFar * zNear * rangeInv ,
503
+ 0 ,
504
+ ] ;
505
+ testMat4WithAndWithoutDest ( ( dst ) => {
506
+ return mat4 . perspectiveReverseZ ( fov , aspect , zNear , zFar , dst ) ;
507
+ } , expected ) ;
508
+ } ) ;
509
+
510
+ it ( 'should compute correct perspective reverseZ' , ( ) => {
511
+ const fov = Math . PI / 4 ;
512
+ const aspect = 2 ;
513
+ const zNear = 10 ;
514
+ const zFar = 20 ;
515
+ const m = mat4 . perspectiveReverseZ ( fov , aspect , zNear , zFar ) ;
516
+ shouldBeCloseArray ( vec3 . transformMat4 ( [ 0 , 0 , - zNear ] , m ) , [ 0 , 0 , 1 ] , 0.000001 ) ;
517
+ shouldBeCloseArray ( vec3 . transformMat4 ( [ 0 , 0 , - 15 ] , m ) , [ 0 , 0 , 0.3333333432674408 ] , 0.000001 ) ;
518
+ shouldBeCloseArray ( vec3 . transformMat4 ( [ 0 , 0 , - zFar ] , m ) , [ 0 , 0 , 0 ] , 0.000001 ) ;
519
+ } ) ;
520
+
521
+ it ( 'should compute perspective reverseZ with zFar at infinity' , ( ) => {
522
+ const fov = 2 ;
523
+ const aspect = 4 ;
524
+ const zNear = 10 ;
525
+ const zFar = Infinity ;
526
+ const f = Math . tan ( Math . PI * 0.5 - 0.5 * fov ) ;
527
+ const expected = [
528
+ f / aspect ,
529
+ 0 ,
530
+ 0 ,
531
+ 0 ,
532
+
533
+ 0 ,
534
+ f ,
535
+ 0 ,
536
+ 0 ,
537
+
538
+ 0 ,
539
+ 0 ,
540
+ 0 ,
541
+ - 1 ,
542
+
543
+ 0 ,
544
+ 0 ,
545
+ zNear ,
546
+ 0 ,
547
+ ] ;
548
+ testMat4WithAndWithoutDest ( ( dst ) => {
549
+ return mat4 . perspectiveReverseZ ( fov , aspect , zNear , zFar , dst ) ;
550
+ } , expected ) ;
551
+ } ) ;
552
+
553
+ it ( 'should compute correct perspective reverseZ with zFar at Infinity' , ( ) => {
554
+ const fov = Math . PI / 4 ;
555
+ const aspect = 2 ;
556
+ const zNear = 10 ;
557
+ const zFar = Infinity ;
558
+ const m = mat4 . perspectiveReverseZ ( fov , aspect , zNear , zFar ) ;
559
+ shouldBeCloseArray ( vec3 . transformMat4 ( [ 0 , 0 , - zNear ] , m ) , [ 0 , 0 , 1 ] , 0.000001 ) ;
560
+ shouldBeCloseArray ( vec3 . transformMat4 ( [ 0 , 0 , - 1000 ] , m ) , [ 0 , 0 , 0.009999999776482582 ] , 0.000001 ) ;
561
+ shouldBeCloseArray ( vec3 . transformMat4 ( [ 0 , 0 , - 1000000 ] , m ) , [ 0 , 0 , 0.000009999999747378752 ] , 0.000001 ) ;
562
+ shouldBeCloseArray ( vec3 . transformMat4 ( [ 0 , 0 , - 1000000000 ] , m ) , [ 0 , 0 , 9.99999993922529e-9 ] , 0.000001 ) ;
563
+ shouldBeCloseArray ( vec3 . transformMat4 ( [ 0 , 0 , - zFar ] , m ) , [ 0 , 0 , 0 ] , 0.000001 ) ;
564
+ } ) ;
565
+
477
566
it ( 'should compute ortho' , ( ) => {
478
567
const left = 2 ;
479
568
const right = 4 ;
0 commit comments