Skip to content

Commit 3cc41e5

Browse files
committed
add much to docs
1 parent fb257e0 commit 3cc41e5

File tree

6 files changed

+157
-63
lines changed

6 files changed

+157
-63
lines changed

glmath.js

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

glutil-eval.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ function BezierCurve(cp, u1, u2){
159159
* in a B&eacute;zier curve.
160160
* @param {number} u Point on the curve to evaluate (generally within the range
161161
* given in the constructor).
162-
* @return An array of the result of
162+
* @return {Array<number>} An array of the result of
163163
* the evaluation. Its length will be equal to the
164164
* length of a control point, as specified in the constructor.
165165
*/
@@ -228,7 +228,7 @@ function BezierSurface(cp, u1, u2, v1, v2){
228228
* @param {number} u U-coordinate of the surface to evaluate (generally within the range
229229
* given in the constructor).
230230
* @param {number} v V-coordinate of the surface to evaluate.
231-
* @return An array of the result of
231+
* @return {Array<number>} An array of the result of
232232
* the evaluation. Its length will be equal to the
233233
* length of a control point, as specified in the constructor.
234234
*/

glutil.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,7 @@ function Scene3D(canvasOrContext){
12211221
this.context.blendFunc(context.SRC_ALPHA,context.ONE_MINUS_SRC_ALPHA);
12221222
this.context.enable(this.context.DEPTH_TEST);
12231223
this.context.depthFunc(this.context.LEQUAL);
1224-
this.context.clearDepth(999999);
1224+
this.context.clearDepth(1.0);
12251225
this._setClearColor();
12261226
this.context.clear(
12271227
this.context.COLOR_BUFFER_BIT |
@@ -1327,7 +1327,10 @@ Scene3D.prototype.createBuffer=function(){
13271327

13281328
/**
13291329
* Sets this scene's projection matrix to a perspective projection.
1330-
* @param {number} fov Vertical field of view, in degrees. Should be less
1330+
* <p>
1331+
* For considerations when choosing the "near" and "far" parameters,
1332+
* see {@link glmath.GLMath.mat4perspective}.
1333+
* @param {number} fov Vertical field of view, in degrees. Should be less
13311334
* than 180 degrees. (The smaller
13321335
* this number, the bigger close objects appear to be. As a result,
13331336
* zoom can be implemented by multiplying field of view by an
@@ -1336,7 +1339,7 @@ Scene3D.prototype.createBuffer=function(){
13361339
* the scene's aspect ratio (getAspect()).
13371340
* @param {number} near The distance from the camera to
13381341
* the near clipping plane. Objects closer than this distance won't be
1339-
* seen. This should be slightly greater than 0.
1342+
* seen.
13401343
* @param {number} far The distance from the camera to
13411344
* the far clipping plane. Objects beyond this distance will be too far
13421345
* to be seen.
@@ -1353,6 +1356,9 @@ Scene3D.prototype.setPerspective=function(fov, aspect, near, far){
13531356
/**
13541357
* Sets this scene's projection matrix to a perspective projection that defines
13551358
* the view frustum, or the limits in the camera's view.
1359+
* <p>
1360+
* For considerations when choosing the "near" and "far" parameters,
1361+
* see {@link glmath.GLMath.mat4perspective}.
13561362
* @param {number} left X-coordinate of the point where the left
13571363
* clipping plane meets the near clipping plane.
13581364
* @param {number} right X-coordinate of the point where the right
@@ -1363,7 +1369,7 @@ Scene3D.prototype.setPerspective=function(fov, aspect, near, far){
13631369
* clipping plane meets the near clipping plane.
13641370
* @param {number} near The distance from the camera to
13651371
* the near clipping plane. Objects closer than this distance won't be
1366-
* seen. This should be slightly greater than 0.
1372+
* seen.
13671373
* @param {number} far The distance from the camera to
13681374
* the far clipping plane. Objects beyond this distance will be too far
13691375
* to be seen.
@@ -1377,6 +1383,9 @@ Scene3D.prototype.setFrustum=function(left,right,bottom,top,near,far){
13771383
* Sets this scene's projection matrix to an orthographic projection.
13781384
* In this projection, the left clipping plane is parallel to the right clipping
13791385
* plane and the top to the bottom.
1386+
* <p>
1387+
* For considerations when choosing the "near" and "far" parameters,
1388+
* see {@link glmath.GLMath.mat4perspective}.
13801389
* @param {number} left Leftmost coordinate of the 3D view.
13811390
* @param {number} right Rightmost coordinate of the 3D view.
13821391
* (Note that right can be greater than left or vice versa.)

glutil_min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)