@@ -1055,6 +1055,21 @@ mat4translate:function(mat,v3,v3y,v3z){
10551055 * OpenGL's. To adjust the result of this method to a left-handed system,
10561056 * such as Direct3D's, reverse the sign of the 9th, 10th, 11th, and 12th
10571057 * elements of the result (zero-based indices 8, 9, 10, and 11).
1058+ * <p><b>Choosing the "near" and "far" parameters:</b>
1059+ * Depth buffers often have 16 bits per pixel; each pixel isn't usually
1060+ * a floating-point number. If the difference between "far" and "near"
1061+ * is too high, the depth buffer can't distinguish well between two objects
1062+ * that are very close, especially if both objects are quite far in the distance.
1063+ * For best results:<ul>
1064+ * <li>For <code>mat4perspective</code> and <code>mat4frustum</code>,
1065+ * the "near" parameter should not be 0 or less, and should be set to the highest distance
1066+ * from the camera that the application can afford to clip out for being too
1067+ * close, for example, 0.1 or 1. This doesn't apply to <code>mat4ortho</code>.</li>
1068+ * <li>The difference between "far" and "near" should not be greater than 65536
1069+ * (the number of possible values per pixel in a 16-bit depth buffer) and should be
1070+ * as small as the application can accept. In any case, "far" cannot be less than
1071+ * "near".</li>
1072+ * </ul>
10581073* @param {number } fovY Vertical field of view, in degrees. Should be less
10591074* than 180 degrees. (The smaller
10601075* this number, the bigger close objects appear to be. As a result,
@@ -1064,18 +1079,18 @@ mat4translate:function(mat,v3,v3y,v3z){
10641079* the scene's aspect ratio.
10651080* @param {number } near The distance from the camera to
10661081* the near clipping plane. Objects closer than this distance won't be
1067- * seen. This should be slightly greater than 0.
1068- * @param {number } farZ The distance from the camera to
1082+ * seen.
1083+ * @param {number } far The distance from the camera to
10691084* the far clipping plane. Objects beyond this distance will be too far
10701085* to be seen.
10711086 * @return {Array<number> } The resulting 4x4 matrix.
10721087 */
1073- mat4perspective :function ( fovY , aspectRatio , nearZ , farZ ) {
1088+ mat4perspective :function ( fovY , aspectRatio , near , far ) {
10741089 var f = 1 / Math . tan ( fovY * GLMath . PiDividedBy360 ) ;
1075- var nmf = nearZ - farZ ;
1090+ var nmf = near - far ;
10761091 nmf = 1 / nmf ;
10771092 return [ f / aspectRatio , 0 , 0 , 0 , 0 , f , 0 , 0 , 0 , 0 ,
1078- nmf * ( nearZ + farZ ) , - 1 , 0 , 0 , nmf * nearZ * farZ * 2 , 0 ]
1093+ nmf * ( near + far ) , - 1 , 0 , 0 , nmf * near * far * 2 , 0 ]
10791094} ,
10801095/**
10811096 * Returns a 4x4 matrix representing a camera view.<p>
@@ -1131,6 +1146,9 @@ mat4lookat:function(viewerPos,lookingAt,up){
11311146 * OpenGL's. To adjust the result of this method to a left-handed system,
11321147 * such as Direct3D's, reverse the sign of the 9th, 10th, 11th, and 12th
11331148 * elements of the result (zero-based indices 8, 9, 10, and 11).
1149+ * <p>
1150+ * For considerations when choosing the "n" and "f" parameters,
1151+ * see {@link glmath.GLMath.mat4perspective}.
11341152 * @param {number } l Leftmost coordinate of the 3D view.
11351153 * @param {number } r Rightmost coordinate of the 3D view.
11361154 * (Note that r can be greater than l or vice versa.)
@@ -1174,6 +1192,9 @@ mat4ortho2d:function(l,r,b,t){
11741192 * OpenGL's. To adjust the result of this method to a left-handed system,
11751193 * such as Direct3D's, reverse the sign of the 9th, 10th, 11th, and 12th
11761194 * elements of the result (zero-based indices 8, 9, 10, and 11).
1195+ * <p>
1196+ * For considerations when choosing the "n" and "f" parameters,
1197+ * see {@link glmath.GLMath.mat4perspective}.
11771198 * @param {number } l X-coordinate of the point where the left
11781199 * clipping plane meets the near clipping plane.
11791200 * @param {number } r X-coordinate of the point where the right
@@ -1184,7 +1205,7 @@ mat4ortho2d:function(l,r,b,t){
11841205 * clipping plane meets the near clipping plane.
11851206* @param {number } n The distance from the camera to
11861207* the near clipping plane. Objects closer than this distance won't be
1187- * seen. This should be slightly greater than 0.
1208+ * seen.
11881209* @param {number } f The distance from the camera to
11891210* the far clipping plane. Objects beyond this distance will be too far
11901211* to be seen.
0 commit comments