diff options
author | Kris Kowal | 2012-07-06 11:52:06 -0700 |
---|---|---|
committer | Kris Kowal | 2012-07-06 15:01:48 -0700 |
commit | 648ee61ae84216d0236e0dbc211addc13b2cfa3a (patch) | |
tree | 8f0f55557bd0c47a84e49c1977c950645d284607 /js/lib/geom | |
parent | aedd14b18695d031f695d27dfbd94df5614495bb (diff) | |
download | ninja-648ee61ae84216d0236e0dbc211addc13b2cfa3a.tar.gz |
Expand tabs
Diffstat (limited to 'js/lib/geom')
-rwxr-xr-x | js/lib/geom/circle.js | 216 | ||||
-rwxr-xr-x | js/lib/geom/geom-obj.js | 40 | ||||
-rwxr-xr-x | js/lib/geom/line.js | 68 | ||||
-rwxr-xr-x | js/lib/geom/rectangle.js | 1132 | ||||
-rw-r--r-- | js/lib/geom/shape-primitive.js | 336 |
5 files changed, 896 insertions, 896 deletions
diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js index 39cde514..a06355eb 100755 --- a/js/lib/geom/circle.js +++ b/js/lib/geom/circle.js | |||
@@ -31,14 +31,14 @@ POSSIBILITY OF SUCH DAMAGE. | |||
31 | var GeomObj = require("js/lib/geom/geom-obj").GeomObj; | 31 | var GeomObj = require("js/lib/geom/geom-obj").GeomObj; |
32 | var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive; | 32 | var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive; |
33 | var MaterialsModel = require("js/models/materials-model").MaterialsModel; | 33 | var MaterialsModel = require("js/models/materials-model").MaterialsModel; |
34 | var drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils; | 34 | var drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils; |
35 | var vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils; | 35 | var vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils; |
36 | 36 | ||
37 | /////////////////////////////////////////////////////////////////////// | 37 | /////////////////////////////////////////////////////////////////////// |
38 | // Class GLCircle | 38 | // Class GLCircle |
39 | // GL representation of a circle. | 39 | // GL representation of a circle. |
40 | // Derived from class GLGeomObj | 40 | // Derived from class GLGeomObj |
41 | // The position and dimensions of the stroke, fill, and inner Radius should be in pixels | 41 | // The position and dimensions of the stroke, fill, and inner Radius should be in pixels |
42 | /////////////////////////////////////////////////////////////////////// | 42 | /////////////////////////////////////////////////////////////////////// |
43 | exports.Circle = Object.create(GeomObj, { | 43 | exports.Circle = Object.create(GeomObj, { |
44 | 44 | ||
@@ -57,7 +57,7 @@ exports.Circle = Object.create(GeomObj, { | |||
57 | _strokeStyle: { value : "Solid", writable: true }, | 57 | _strokeStyle: { value : "Solid", writable: true }, |
58 | _aspectRatio: { value : 1.0, writable: true }, | 58 | _aspectRatio: { value : 1.0, writable: true }, |
59 | 59 | ||
60 | init: { | 60 | init: { |
61 | value: function(world, xOffset, yOffset, width, height, strokeSize, strokeColor, fillColor, innerRadius, strokeMaterial, fillMaterial, strokeStyle) { | 61 | value: function(world, xOffset, yOffset, width, height, strokeSize, strokeColor, fillColor, innerRadius, strokeMaterial, fillMaterial, strokeStyle) { |
62 | if(arguments.length > 0) { | 62 | if(arguments.length > 0) { |
63 | this._width = width; | 63 | this._width = width; |
@@ -85,14 +85,14 @@ exports.Circle = Object.create(GeomObj, { | |||
85 | } else { | 85 | } else { |
86 | this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); | 86 | this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); |
87 | } | 87 | } |
88 | if (strokeColor && this._strokeMaterial.hasProperty( "color" )) this._strokeMaterial.setProperty( "color", this._strokeColor ); | 88 | if (strokeColor && this._strokeMaterial.hasProperty( "color" )) this._strokeMaterial.setProperty( "color", this._strokeColor ); |
89 | 89 | ||
90 | if(fillMaterial) { | 90 | if(fillMaterial) { |
91 | this._fillMaterial = fillMaterial.dup(); | 91 | this._fillMaterial = fillMaterial.dup(); |
92 | } else { | 92 | } else { |
93 | this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); | 93 | this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); |
94 | } | 94 | } |
95 | if (fillColor && this._fillMaterial.hasProperty( "color" )) this._fillMaterial.setProperty( "color", this._fillColor ); | 95 | if (fillColor && this._fillMaterial.hasProperty( "color" )) this._fillMaterial.setProperty( "color", this._fillColor ); |
96 | } | 96 | } |
97 | }, | 97 | }, |
98 | 98 | ||
@@ -203,7 +203,7 @@ exports.Circle = Object.create(GeomObj, { | |||
203 | }, | 203 | }, |
204 | 204 | ||
205 | /////////////////////////////////////////////////////////////////////// | 205 | /////////////////////////////////////////////////////////////////////// |
206 | // update the "color of the material | 206 | // update the "color of the material |
207 | getFillColor: { | 207 | getFillColor: { |
208 | value: function() { | 208 | value: function() { |
209 | return this._fillColor; | 209 | return this._fillColor; |
@@ -251,15 +251,15 @@ exports.Circle = Object.create(GeomObj, { | |||
251 | 251 | ||
252 | // get the normalized device coordinates (NDC) for | 252 | // get the normalized device coordinates (NDC) for |
253 | // all position and dimensions. | 253 | // all position and dimensions. |
254 | var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); | 254 | var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); |
255 | var xNDC = 2*this._xOffset/vpw, yNDC = -2*this._yOffset/vph, | 255 | var xNDC = 2*this._xOffset/vpw, yNDC = -2*this._yOffset/vph, |
256 | xRadNDC = this._width/vpw, yRadNDC = this._height/vph, | 256 | xRadNDC = this._width/vpw, yRadNDC = this._height/vph, |
257 | xStrokeNDC = 2*this._strokeWidth/vpw, yStrokeNDC = 2*this._strokeWidth/vph, | 257 | xStrokeNDC = 2*this._strokeWidth/vpw, yStrokeNDC = 2*this._strokeWidth/vph, |
258 | xInnRadNDC = this._innerRadius*xRadNDC, yInnRadNDC = this._innerRadius*yRadNDC; | 258 | xInnRadNDC = this._innerRadius*xRadNDC, yInnRadNDC = this._innerRadius*yRadNDC; |
259 | 259 | ||
260 | var aspect = world.getAspect(); | 260 | var aspect = world.getAspect(); |
261 | var zn = world.getZNear(), zf = world.getZFar(); | 261 | var zn = world.getZNear(), zf = world.getZFar(); |
262 | var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0), | 262 | var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0), |
263 | b = -t, | 263 | b = -t, |
264 | r = aspect*t, | 264 | r = aspect*t, |
265 | l = -r; | 265 | l = -r; |
@@ -321,7 +321,7 @@ exports.Circle = Object.create(GeomObj, { | |||
321 | if(this._strokeWidth > 0) { | 321 | if(this._strokeWidth > 0) { |
322 | var numStrokes = 1; | 322 | var numStrokes = 1; |
323 | if(this._innerRadius !== 0) { | 323 | if(this._innerRadius !== 0) { |
324 | strokeMaterial0 = this.makeStrokeMaterial(); | 324 | strokeMaterial0 = this.makeStrokeMaterial(); |
325 | strokePrim0 = this.generateOvalRing(x, y, reverseRotMat, innerStrokeScaleMat, innerRadiusScaleMat, nTriangles, strokeMaterial0); | 325 | strokePrim0 = this.generateOvalRing(x, y, reverseRotMat, innerStrokeScaleMat, innerRadiusScaleMat, nTriangles, strokeMaterial0); |
326 | } | 326 | } |
327 | 327 | ||
@@ -330,14 +330,14 @@ exports.Circle = Object.create(GeomObj, { | |||
330 | } | 330 | } |
331 | 331 | ||
332 | if (strokePrim0) { | 332 | if (strokePrim0) { |
333 | strokeMaterial0.fitToPrimitive( strokePrim0 ); | 333 | strokeMaterial0.fitToPrimitive( strokePrim0 ); |
334 | 334 | ||
335 | this._primArray.push( strokePrim0 ); | 335 | this._primArray.push( strokePrim0 ); |
336 | this._materialNodeArray.push( strokeMaterial0.getMaterialNode() ); | 336 | this._materialNodeArray.push( strokeMaterial0.getMaterialNode() ); |
337 | } | 337 | } |
338 | 338 | ||
339 | if (strokePrim1) { | 339 | if (strokePrim1) { |
340 | strokeMaterial2.fitToPrimitive( strokePrim1 ); | 340 | strokeMaterial2.fitToPrimitive( strokePrim1 ); |
341 | 341 | ||
342 | this._primArray.push( strokePrim1 ); | 342 | this._primArray.push( strokePrim1 ); |
343 | this._materialNodeArray.push( strokeMaterial2.getMaterialNode() ); | 343 | this._materialNodeArray.push( strokeMaterial2.getMaterialNode() ); |
@@ -353,7 +353,7 @@ exports.Circle = Object.create(GeomObj, { | |||
353 | } | 353 | } |
354 | 354 | ||
355 | if (fillPrim) { | 355 | if (fillPrim) { |
356 | fillMaterial.fitToPrimitive( fillPrim ); | 356 | fillMaterial.fitToPrimitive( fillPrim ); |
357 | 357 | ||
358 | this._primArray.push( fillPrim ); | 358 | this._primArray.push( fillPrim ); |
359 | this._materialNodeArray.push( fillMaterial.getMaterialNode() ); | 359 | this._materialNodeArray.push( fillMaterial.getMaterialNode() ); |
@@ -371,7 +371,7 @@ exports.Circle = Object.create(GeomObj, { | |||
371 | var x = pts[0], y = pts[1], z = 0; | 371 | var x = pts[0], y = pts[1], z = 0; |
372 | var xs = scaleMat[0], ys = scaleMat[4]; | 372 | var xs = scaleMat[0], ys = scaleMat[4]; |
373 | 373 | ||
374 | var vrts = [], nrms = [], uvs = [], indices = []; | 374 | var vrts = [], nrms = [], uvs = [], indices = []; |
375 | var index = 0; | 375 | var index = 0; |
376 | for (var i=0; i<nTriangles; i++) { | 376 | for (var i=0; i<nTriangles; i++) { |
377 | //pt = rotationMat.multiply( pt ); | 377 | //pt = rotationMat.multiply( pt ); |
@@ -418,14 +418,14 @@ exports.Circle = Object.create(GeomObj, { | |||
418 | 418 | ||
419 | this.recalcTexMapCoords( vrts, uvs ); | 419 | this.recalcTexMapCoords( vrts, uvs ); |
420 | 420 | ||
421 | //refine the mesh for vertex deformations | 421 | //refine the mesh for vertex deformations |
422 | if (material) { | 422 | if (material) { |
423 | if (material.hasVertexDeformation()) { | 423 | if (material.hasVertexDeformation()) { |
424 | var paramRange = material.getVertexDeformationRange(); | 424 | var paramRange = material.getVertexDeformationRange(); |
425 | var tolerance = material.getVertexDeformationTolerance(); | 425 | var tolerance = material.getVertexDeformationTolerance(); |
426 | ShapePrimitive.refineMesh( vrts, nrms, uvs, indices, vrts.length/3, paramRange, tolerance ); | 426 | ShapePrimitive.refineMesh( vrts, nrms, uvs, indices, vrts.length/3, paramRange, tolerance ); |
427 | } | 427 | } |
428 | } | 428 | } |
429 | 429 | ||
430 | return ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, index); | 430 | return ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, index); |
431 | } | 431 | } |
@@ -442,7 +442,7 @@ exports.Circle = Object.create(GeomObj, { | |||
442 | pt0s = glmat4.multiplyVec3(innerScaleMat, pt, []); | 442 | pt0s = glmat4.multiplyVec3(innerScaleMat, pt, []); |
443 | pt1s = glmat4.multiplyVec3(outerScaleMat, pt, []); | 443 | pt1s = glmat4.multiplyVec3(outerScaleMat, pt, []); |
444 | 444 | ||
445 | var vrts = [], nrms = [], uvs = [], indices = []; | 445 | var vrts = [], nrms = [], uvs = [], indices = []; |
446 | 446 | ||
447 | // normals | 447 | // normals |
448 | var insideAngle = -15.0*Math.PI/180.0, | 448 | var insideAngle = -15.0*Math.PI/180.0, |
@@ -486,16 +486,16 @@ exports.Circle = Object.create(GeomObj, { | |||
486 | 486 | ||
487 | this.recalcTexMapCoords( vrts, uvs ); | 487 | this.recalcTexMapCoords( vrts, uvs ); |
488 | 488 | ||
489 | /* | 489 | /* |
490 | //refine the mesh for vertex deformations | 490 | //refine the mesh for vertex deformations |
491 | if (material) { | 491 | if (material) { |
492 | if (material.hasVertexDeformation()) { | 492 | if (material.hasVertexDeformation()) { |
493 | var paramRange = material.getVertexDeformationRange(); | 493 | var paramRange = material.getVertexDeformationRange(); |
494 | var tolerance = material.getVertexDeformationTolerance(); | 494 | var tolerance = material.getVertexDeformationTolerance(); |
495 | ShapePrimitive.refineMesh( vrts, nrms, uvs, indices, indices.length, paramRange, tolerance ); | 495 | ShapePrimitive.refineMesh( vrts, nrms, uvs, indices, indices.length, paramRange, tolerance ); |
496 | } | 496 | } |
497 | } | 497 | } |
498 | */ | 498 | */ |
499 | 499 | ||
500 | return ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLE_STRIP, indices.length); | 500 | return ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLE_STRIP, indices.length); |
501 | } | 501 | } |
@@ -572,7 +572,7 @@ exports.Circle = Object.create(GeomObj, { | |||
572 | ctx.fillStyle = c; | 572 | ctx.fillStyle = c; |
573 | } | 573 | } |
574 | // draw the fill | 574 | // draw the fill |
575 | // ctx.beginPath(); | 575 | // ctx.beginPath(); |
576 | var p = MathUtils.transformPoint( bezPts[0], mat ); | 576 | var p = MathUtils.transformPoint( bezPts[0], mat ); |
577 | ctx.moveTo( p[0], p[1] ); | 577 | ctx.moveTo( p[0], p[1] ); |
578 | var index = 1; | 578 | var index = 1; |
@@ -623,7 +623,7 @@ exports.Circle = Object.create(GeomObj, { | |||
623 | 623 | ||
624 | // set up the stroke style | 624 | // set up the stroke style |
625 | ctx.beginPath(); | 625 | ctx.beginPath(); |
626 | ctx.lineWidth = lineWidth; | 626 |