Skip to content

Commit ed8a302

Browse files
committed
edit docs; avoid creating too-small or too-narrow triangles in tris.html; fix attribute-disable bug
1 parent ee158c5 commit ed8a302

File tree

8 files changed

+139
-86
lines changed

8 files changed

+139
-86
lines changed

camera.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,7 @@ Camera.prototype.moveForward=function(dist){
296296
Camera.prototype.getPosition=function(){
297297
return this.position.slice(0,3);
298298
}
299-
/**
300-
* Not documented yet.
301-
* @param {*} e
302-
*/
299+
/** @private */
303300
Camera.prototype.mousewheel=function(e){
304301
var ticks=e.delta/120.0;
305302
// mousewheel up (negative) means move forward,
@@ -453,6 +450,7 @@ InputTracker.ENTER=13;
453450
InputTracker.TAB=9;
454451
InputTracker.SHIFT=16;
455452
InputTracker.CTRL=17;
453+
InputTracker.ALT=18;
456454
InputTracker.ESC=27;
457455
InputTracker.SPACE=32;
458456
InputTracker.PAGEUP=33;

glmath.js

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,28 @@ return [a[1]*b[2]-a[2]*b[1],
7575
vec3dot:function(a,b){
7676
return 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
*/
12361266
mat4perspectiveHorizontal: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);
13481383
return [
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

glutil-eval.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ function BezierCurve(cp, u1, u2){
162162
* @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.
165+
* @example
166+
* // Generate 11 points forming the B&eacute;zier curve.
167+
* // Assumes the curve was created with u1=0 and u2=1 (the default).
168+
* var points=[];
169+
* for(var i=0;i<=10;i++){
170+
* points.push(curve.evaluate(i/10.0));
171+
* }
165172
*/
166173
BezierCurve.prototype.evaluate=function(u){
167174
var output=[];

glutil-mesh.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Mesh._isCompatibleMode=function(oldMode,newMode){
6363
return true;
6464
return false;
6565
}
66-
66+
/** @private */
6767
Mesh._recalcNormalsStart=function(vertices,uniqueVertices,faces,stride,offset,flat){
6868
for(var i=0;i<vertices.length;i+=stride){
6969
vertices[i+offset]=0.0
@@ -78,6 +78,7 @@ Mesh._recalcNormalsStart=function(vertices,uniqueVertices,faces,stride,offset,fl
7878
}
7979
}
8080
}
81+
/** @private */
8182
Mesh._recalcNormalsFinish=function(vertices,uniqueVertices,faces,stride,offset,flat){
8283
var len;
8384
if(!flat){

glutil.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ BufferedSubMesh.prototype.draw=function(program){
11601160
context.FLOAT, stride*4, offset*4);
11611161
} else {
11621162
program.setUniforms({"useColorAttr":0.0});
1163-
attr=program.get("uv");
1163+
attr=program.get("colorAttr");
11641164
if(attr!==null)context.disableVertexAttribArray(attr);
11651165
}
11661166
offset=Mesh.texCoordOffset(format);

0 commit comments

Comments
 (0)