aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/geom-obj.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/geom/geom-obj.js')
-rwxr-xr-xjs/lib/geom/geom-obj.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js
index 2f5559a7..4efa5d60 100755
--- a/js/lib/geom/geom-obj.js
+++ b/js/lib/geom/geom-obj.js
@@ -415,6 +415,65 @@ var GeomObj = function GLGeomObj()
415 } 415 }
416 }; 416 };
417 417
418
419 this.getGLCenter = function()
420 {
421 // get the normalized device coordinates (NDC) for
422 // all position and dimensions.
423 var world = this.getWorld();
424 var vpw = world.getViewportWidth(), vph = world.getViewportHeight();
425 var xNDC = 2*this._xOffset/vpw, yNDC = -2*this._yOffset/vph;
426
427 var aspect = world.getAspect();
428 var zn = world.getZNear(), zf = world.getZFar();
429 var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0),
430 b = -t,
431 r = aspect*t,
432 l = -r;
433
434 // calculate the object coordinates from their NDC coordinates
435 var z = -world.getViewDistance();
436
437 // unproject to get the position of the origin in GL
438 var x = -z*(r-l)/(2.0*zn)*xNDC,
439 y = -z*(t-b)/(2.0*zn)*yNDC;
440 z = 0.0;
441
442 // transform by the object's transformation matrix
443 var ctr = MathUtils.transformPoint( [x, y, z], this.getMatrix() );
444
445 return ctr;
446 };
447
448 this.preViewToGL = function( preViewPt )
449 {
450 // get the normalized device coordinates (NDC) for
451 // all position and dimensions.
452 var world = this.getWorld();
453 var vpw = world.getViewportWidth(), vph = world.getViewportHeight();
454 var xNDC = 2*preViewPt[0]/vpw, yNDC = -2*preViewPt[1]/vph;
455
456 var aspect = world.getAspect();
457 var zn = world.getZNear(), zf = world.getZFar();
458 var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0),
459 b = -t,
460 r = aspect*t,
461 l = -r;
462
463 // calculate the object coordinates from their NDC coordinates
464 var z = -world.getViewDistance();
465
466 // unproject to get the position of the origin in GL
467 var x = -z*(r-l)/(2.0*zn)*xNDC,
468 y = -z*(t-b)/(2.0*zn)*yNDC;
469 z = 0.0;
470
471 // transform by the object's transformation matrix
472 var glPt = MathUtils.transformPoint( [x, y, z], this.getMatrix() );
473
474 return glPt;
475 };
476
418 this.buildBuffers = function () { 477 this.buildBuffers = function () {
419 // this function must be overridden by the base class 478 // this function must be overridden by the base class
420 alert("GLGeomObj.buildBuffers must be overridden by base class"); 479 alert("GLGeomObj.buildBuffers must be overridden by base class");