@@ -75,6 +75,28 @@ return [a[1]*b[2]-a[2]*b[1],
7575vec3dot :function ( a , b ) {
7676return a [ 0 ] * b [ 0 ] + a [ 1 ] * b [ 1 ] + a [ 2 ] * b [ 2 ] ;
7777} ,
78+ /**
79+ * Adds two 3-element vectors and returns a new
80+ * vector with the result. Adding two vectors
81+ * is the same as adding each of their components.
82+ * @param {Array<number> } a The first 3-element vector.
83+ * @param {Array<number> } b The second 3-element vector.
84+ * @return {Array<number> } The resulting 3-element vector.
85+ */
86+ vec3add :function ( a , b ) {
87+ return [ a [ 0 ] + b [ 0 ] , a [ 1 ] + b [ 1 ] , a [ 2 ] + b [ 2 ] ] ;
88+ } ,
89+ /**
90+ * Subtracts two 3-element vectors and returns a new
91+ * vector with the result. Subtracting two vectors
92+ * is the same as subtracting each of their components.
93+ * @param {Array<number> } a The first 3-element vector.
94+ * @param {Array<number> } b The second 3-element vector.
95+ * @return {Array<number> } The resulting 3-element vector.
96+ */
97+ vec3sub :function ( a , b ) {
98+ return [ a [ 0 ] - b [ 0 ] , a [ 1 ] - b [ 1 ] , a [ 2 ] - b [ 2 ] ] ;
99+ } ,
78100/**
79101 * Adds two 3-element vectors and stores
80102 * the result in the first vector. Adding two vectors
@@ -1214,23 +1236,31 @@ mat4ortho:function(l,r,b,t,n,f){
12141236} ,
12151237
12161238/**
1217- * Returns a 4x4 matrix representing a perspective projection
1218- * given an X-axis field of view.<p>
1219- * This method assumes a right-hand coordinate system;
1220- * see { @link glmath.GLMath.mat4perspective}. For considerations
1221- * when choosing the "n" and "f" parameters,
1222- * see { @link glmath.GLMath.mat4perspective} .
1239+ * Returns a 4x4 matrix representing a perspective projection,
1240+ * given an X-axis field of view.</ p>
1241+ * This method assumes a right-handed coordinate system, such as
1242+ * OpenGL's. To adjust the result of this method to a left-handed system,
1243+ * such as Direct3D's, reverse the sign of the 9th, 10th, 11th, and 12th
1244+ * elements of the result (zero-based indices 8, 9, 10, and 11) .
12231245* @param {number } fovX X-axis field of view, in degrees. Should be less
12241246* than 180 degrees. (The smaller
12251247* this number, the bigger close objects appear to be.)
12261248* @param {number } aspectRatio The ratio of width to height of the viewport, usually
12271249* the scene's aspect ratio.
12281250* @param {number } near The distance from the camera to
12291251* the near clipping plane. Objects closer than this distance won't be
1230- * seen.
1252+ * seen.<p>This value should not be 0 or less, and should be set to the highest distance
1253+ * from the camera that the application can afford to clip out for being too
1254+ * close, for example, 0.5, 1, or higher.
12311255* @param {number } far The distance from the camera to
12321256* the far clipping plane. Objects beyond this distance will be too far
1233- * to be seen.
1257+ * to be seen. This value should be greater than "near" and be set so that the ratio of "far" to "near"
1258+ * is as small as the application can accept.<p>
1259+ * (Depth buffers often allow only 65536 possible values per pixel,
1260+ * which are more spread out toward the far clipping plane than toward the
1261+ * near plane due to the perspective projection. The greater the ratio of "far" to
1262+ * "near", the more the values spread out, and the more likely two objects close
1263+ * to the far plane will have identical depth values.)
12341264 * @return {Array<number> } The resulting 4x4 matrix.
12351265 */
12361266mat4perspectiveHorizontal :function ( fovX , aspectRatio , near , far ) {
@@ -1315,15 +1345,12 @@ mat4orthoAspect:function(l,r,b,t,n,f,aspect){
13151345 }
13161346} ,
13171347/**
1318- * Returns a 4x4 matrix representing a view frustum,
1319- * or the limits in the camera's view.<p>
1348+ * Returns a 4x4 matrix representing a perspective projection
1349+ * in the form of a view frustum, or the limits in the camera's view.<p>
13201350 * This method assumes a right-handed coordinate system, such as
13211351 * OpenGL's. To adjust the result of this method to a left-handed system,
13221352 * such as Direct3D's, reverse the sign of the 9th, 10th, 11th, and 12th
13231353 * elements of the result (zero-based indices 8, 9, 10, and 11).
1324- * <p>
1325- * For considerations when choosing the "n" and "f" parameters,
1326- * see {@link glmath.GLMath.mat4perspective}.
13271354 * @param {number } l X-coordinate of the point where the left
13281355 * clipping plane meets the near clipping plane.
13291356 * @param {number } r X-coordinate of the point where the right
@@ -1332,24 +1359,32 @@ mat4orthoAspect:function(l,r,b,t,n,f,aspect){
13321359 * clipping plane meets the near clipping plane.
13331360 * @param {number } t Y-coordinate of the point where the top
13341361 * clipping plane meets the near clipping plane.
1335- * @param {number } n The distance from the camera to
1362+ * @param {number } near The distance from the camera to
13361363* the near clipping plane. Objects closer than this distance won't be
1337- * seen.
1338- * @param {number } f The distance from the camera to
1364+ * seen.<p>This value should not be 0 or less, and should be set to the highest distance
1365+ * from the camera that the application can afford to clip out for being too
1366+ * close, for example, 0.5, 1, or higher.
1367+ * @param {number } far The distance from the camera to
13391368* the far clipping plane. Objects beyond this distance will be too far
1340- * to be seen.
1369+ * to be seen. This value should be greater than "near" and be set so that the ratio of "far" to "near"
1370+ * is as small as the application can accept.<p>
1371+ * (Depth buffers often allow only 65536 possible values per pixel,
1372+ * which are more spread out toward the far clipping plane than toward the
1373+ * near plane due to the perspective projection. The greater the ratio of "far" to
1374+ * "near", the more the values spread out, and the more likely two objects close
1375+ * to the far plane will have identical depth values.)
13411376 * @return {Array<number> } The resulting 4x4 matrix.
13421377 */
1343- mat4frustum :function ( l , r , b , t , n , f ) {
1344- var dn = 2 * n ;
1378+ mat4frustum :function ( l , r , b , t , near , far ) {
1379+ var dn = 2 * near ;
13451380 var onedx = 1 / ( r - l ) ;
13461381 var onedy = 1 / ( t - b ) ;
1347- var onedz = 1 / ( f - n ) ;
1382+ var onedz = 1 / ( far - near ) ;
13481383return [
13491384 dn * onedx , 0 , 0 , 0 ,
13501385 0 , dn * onedy , 0 , 0 ,
1351- ( l + r ) * onedx , ( t + b ) * onedy , - ( f + n ) * onedz , - 1 ,
1352- 0 , 0 , - ( dn * f ) * onedz , 0 ] ;
1386+ ( l + r ) * onedx , ( t + b ) * onedy , - ( far + near ) * onedz , - 1 ,
1387+ 0 , 0 , - ( dn * far ) * onedz , 0 ] ;
13531388} ,
13541389/**
13551390 * Modifies a 4x4 matrix by multiplying it by a
0 commit comments