33@fileoverview gl-matrix - High performance matrix and vector operations
44@author Brandon Jones
55@author Colin MacKenzie IV
6- @version 3.3.0
6+ @version 3.4.2
77
88Copyright (c) 2015-2021, Brandon Jones, Colin MacKenzie IV.
99
@@ -3244,6 +3244,8 @@ THE SOFTWARE.
32443244 }
32453245 /**
32463246 * Generates a perspective projection matrix with the given bounds.
3247+ * The near/far clip planes correspond to a normalized device coordinate Z range of [-1, 1],
3248+ * which matches WebGL/OpenGL's clip volume.
32473249 * Passing null/undefined/no value for far will generate infinite projection matrix.
32483250 *
32493251 * @param {mat4 } out mat4 frustum matrix will be written into
@@ -3254,7 +3256,7 @@ THE SOFTWARE.
32543256 * @returns {mat4 } out
32553257 */
32563258
3257- function perspective ( out , fovy , aspect , near , far ) {
3259+ function perspectiveNO ( out , fovy , aspect , near , far ) {
32583260 var f = 1.0 / Math . tan ( fovy / 2 ) ,
32593261 nf ;
32603262 out [ 0 ] = f / aspect ;
@@ -3283,6 +3285,55 @@ THE SOFTWARE.
32833285
32843286 return out ;
32853287 }
3288+ /**
3289+ * Alias for {@link mat4.perspectiveNO}
3290+ * @function
3291+ */
3292+
3293+ var perspective = perspectiveNO ;
3294+ /**
3295+ * Generates a perspective projection matrix suitable for WebGPU with the given bounds.
3296+ * The near/far clip planes correspond to a normalized device coordinate Z range of [0, 1],
3297+ * which matches WebGPU/Vulkan/DirectX/Metal's clip volume.
3298+ * Passing null/undefined/no value for far will generate infinite projection matrix.
3299+ *
3300+ * @param {mat4 } out mat4 frustum matrix will be written into
3301+ * @param {number } fovy Vertical field of view in radians
3302+ * @param {number } aspect Aspect ratio. typically viewport width/height
3303+ * @param {number } near Near bound of the frustum
3304+ * @param {number } far Far bound of the frustum, can be null or Infinity
3305+ * @returns {mat4 } out
3306+ */
3307+
3308+ function perspectiveZO ( out , fovy , aspect , near , far ) {
3309+ var f = 1.0 / Math . tan ( fovy / 2 ) ,
3310+ nf ;
3311+ out [ 0 ] = f / aspect ;
3312+ out [ 1 ] = 0 ;
3313+ out [ 2 ] = 0 ;
3314+ out [ 3 ] = 0 ;
3315+ out [ 4 ] = 0 ;
3316+ out [ 5 ] = f ;
3317+ out [ 6 ] = 0 ;
3318+ out [ 7 ] = 0 ;
3319+ out [ 8 ] = 0 ;
3320+ out [ 9 ] = 0 ;
3321+ out [ 11 ] = - 1 ;
3322+ out [ 12 ] = 0 ;
3323+ out [ 13 ] = 0 ;
3324+ out [ 15 ] = 0 ;
3325+
3326+ if ( far != null && far !== Infinity ) {
3327+ nf = 1 / ( near - far ) ;
3328+ out [ 10 ] = far * nf ;
3329+ out [ 14 ] = far * near * nf ;
3330+ } else {
3331+ out [ 10 ] = - 1 ;
3332+ out [ 14 ] = - near ;
3333+ }
3334+
3335+ return out ;
3336+ }
32863337 /**
32873338 * Generates a perspective projection matrix with the given field of view.
32883339 * This is primarily useful for generating projection matrices to be used
@@ -3321,7 +3372,9 @@ THE SOFTWARE.
33213372 return out ;
33223373 }
33233374 /**
3324- * Generates a orthogonal projection matrix with the given bounds
3375+ * Generates a orthogonal projection matrix with the given bounds.
3376+ * The near/far clip planes correspond to a normalized device coordinate Z range of [-1, 1],
3377+ * which matches WebGL/OpenGL's clip volume.
33253378 *
33263379 * @param {mat4 } out mat4 frustum matrix will be written into
33273380 * @param {number } left Left bound of the frustum
@@ -3333,7 +3386,7 @@ THE SOFTWARE.
33333386 * @returns {mat4 } out
33343387 */
33353388
3336- function ortho ( out , left , right , bottom , top , near , far ) {
3389+ function orthoNO ( out , left , right , bottom , top , near , far ) {
33373390 var lr = 1 / ( left - right ) ;
33383391 var bt = 1 / ( bottom - top ) ;
33393392 var nf = 1 / ( near - far ) ;
@@ -3355,6 +3408,49 @@ THE SOFTWARE.
33553408 out [ 15 ] = 1 ;
33563409 return out ;
33573410 }
3411+ /**
3412+ * Alias for {@link mat4.orthoNO}
3413+ * @function
3414+ */
3415+
3416+ var ortho = orthoNO ;
3417+ /**
3418+ * Generates a orthogonal projection matrix with the given bounds.
3419+ * The near/far clip planes correspond to a normalized device coordinate Z range of [0, 1],
3420+ * which matches WebGPU/Vulkan/DirectX/Metal's clip volume.
3421+ *
3422+ * @param {mat4 } out mat4 frustum matrix will be written into
3423+ * @param {number } left Left bound of the frustum
3424+ * @param {number } right Right bound of the frustum
3425+ * @param {number } bottom Bottom bound of the frustum
3426+ * @param {number } top Top bound of the frustum
3427+ * @param {number } near Near bound of the frustum
3428+ * @param {number } far Far bound of the frustum
3429+ * @returns {mat4 } out
3430+ */
3431+
3432+ function orthoZO ( out , left , right , bottom , top , near , far ) {
3433+ var lr = 1 / ( left - right ) ;
3434+ var bt = 1 / ( bottom - top ) ;
3435+ var nf = 1 / ( near - far ) ;
3436+ out [ 0 ] = - 2 * lr ;
3437+ out [ 1 ] = 0 ;
3438+ out [ 2 ] = 0 ;
3439+ out [ 3 ] = 0 ;
3440+ out [ 4 ] = 0 ;
3441+ out [ 5 ] = - 2 * bt ;
3442+ out [ 6 ] = 0 ;
3443+ out [ 7 ] = 0 ;
3444+ out [ 8 ] = 0 ;
3445+ out [ 9 ] = 0 ;
3446+ out [ 10 ] = nf ;
3447+ out [ 11 ] = 0 ;
3448+ out [ 12 ] = ( left + right ) * lr ;
3449+ out [ 13 ] = ( top + bottom ) * bt ;
3450+ out [ 14 ] = near * nf ;
3451+ out [ 15 ] = 1 ;
3452+ return out ;
3453+ }
33583454 /**
33593455 * Generates a look-at matrix with the given eye position, focal point, and up axis.
33603456 * If you want a matrix that actually makes an object look at another object, you should use targetTo instead.
@@ -3732,9 +3828,13 @@ THE SOFTWARE.
37323828 fromRotationTranslationScaleOrigin : fromRotationTranslationScaleOrigin ,
37333829 fromQuat : fromQuat$1 ,
37343830 frustum : frustum ,
3831+ perspectiveNO : perspectiveNO ,
37353832 perspective : perspective ,
3833+ perspectiveZO : perspectiveZO ,
37363834 perspectiveFromFieldOfView : perspectiveFromFieldOfView ,
3835+ orthoNO : orthoNO ,
37373836 ortho : ortho ,
3837+ orthoZO : orthoZO ,
37383838 lookAt : lookAt ,
37393839 targetTo : targetTo ,
37403840 str : str$3 ,
0 commit comments