[Opengeoscience-developers] OpenGeoscience branch, enhance_map_api, updated. c6e36c118843dd9f45c34564e664118585fc90d8

Aashish Chaudhary aashish.chaudhary at kitware.com
Fri Mar 1 00:40:08 EST 2013


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "OpenGeoscience".

The branch, enhance_map_api has been updated
       via  c6e36c118843dd9f45c34564e664118585fc90d8 (commit)
      from  18ff87b9f943a659be590098e2ac674161ccfcb4 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://public.kitware.com/gitweb?p=OpenGeoscience/opengeoscience.git;a=commitdiff;h=c6e36c118843dd9f45c34564e664118585fc90d8
commit c6e36c118843dd9f45c34564e664118585fc90d8
Author:     Aashish Chaudhary <aashish.chaudhary at kitware.com>
AuthorDate: Fri Mar 1 00:39:33 2013 -0500
Commit:     Aashish Chaudhary <aashish.chaudhary at kitware.com>
CommitDate: Fri Mar 1 00:39:33 2013 -0500

    Updated renderer class to current syntax and style

diff --git a/web/lib/geo/map.js b/web/lib/geo/map.js
index 759ed6d..9d8f797 100644
--- a/web/lib/geo/map.js
+++ b/web/lib/geo/map.js
@@ -22,7 +22,7 @@
  *
  */
 geoModule.latlng = function(lat, lng) {
-  // Check against no use of new()
+
   if (!(this instanceof geoModule.latlng)) {
     return new geoModule.latlng(lat, lng);
   }
diff --git a/web/lib/vgl/renderer.js b/web/lib/vgl/renderer.js
index a5ea7e2..4d4a05c 100644
--- a/web/lib/vgl/renderer.js
+++ b/web/lib/vgl/renderer.js
@@ -36,10 +36,20 @@ vglModule.renderState = function() {
 //
 //////////////////////////////////////////////////////////////////////////////
 
-///---------------------------------------------------------------------------
+/**
+ * renderer class provides key functionality to render a scene
+ *
+ */
 vglModule.renderer = function() {
+
+  if (!(this instanceof vglModule.renderer)) {
+    return new vglModule.renderer();
+  }
+
   vglModule.object.call(this);
 
+  /// Private member variables
+
   this.m_width = 1280;
   this.m_height = 1024;
   this.m_clippingRange = [0.1, 1000.0];
@@ -47,146 +57,173 @@ vglModule.renderer = function() {
   this.m_camera = new vglModule.camera();
 
   this.m_camera.addChild(this.m_sceneRoot);
-};
-
-inherit(vglModule.renderer, vglModule.object);
-
-/// Get scene root. Do not change scene root or its data unless
-/// required in some special circumstances.
-///---------------------------------------------------------------------------
-vglModule.renderer.prototype.sceneRoot = function() {
-  return this.m_sceneRoot;
-};
-
-/// Get main camera of the renderer
-///---------------------------------------------------------------------------
-vglModule.renderer.prototype.camera = function() {
-  return this.m_camera;
-};
-
-/// Get width of renderer
-///---------------------------------------------------------------------------
-vglModule.renderer.prototype.width = function() {
-  return this.m_width;
-};
-/// Get height of renderer
-///---------------------------------------------------------------------------
-vglModule.renderer.prototype.height = function() {
-  return this.m_height;
-};
-
-/// Render the scene
-///---------------------------------------------------------------------------
-vglModule.renderer.prototype.render = function() {
-  gl.clearColor(0.5, 0.5, 0.5, 1.0);
-  gl.enable(gl.DEPTH_TEST);
-  gl.depthFunc(gl.LEQUAL);
-  gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
-
-  // TODO Call it only once
-  this.resize();
-
-  perspectiveMatrix = this.m_camera.projectionMatrix(
-  (this.m_width / this.m_height), 0.1, 1000.0);
-
-  var renSt = new vglModule.renderState();
-  renSt.m_projectionMatrix = perspectiveMatrix;
-  var children = this.m_sceneRoot.children();
-  for (var i = 0; i < children.length; ++i) {
-    var actor = children[i];
-    mat4.multiply(this.m_camera.viewMatrix(), actor.matrix(), renSt.m_modelViewMatrix);
-    renSt.m_material = actor.material();
-    renSt.m_mapper = actor.mapper();
-
-    // TODO Fix this shortcut
-    renSt.m_material.render(renSt);
-    renSt.m_mapper.render(renSt);
-    renSt.m_material.remove(renSt);
-  }
-};
-
-/// Recalculate camera's clipping range
-///---------------------------------------------------------------------------
-vglModule.renderer.prototype.resetCameraClippingRange = function() {
-  // TODO
-};
 
-/// Resize viewport based on the new width and height of the window
-///---------------------------------------------------------------------------
-vglModule.renderer.prototype.resize = function() {
-  gl.viewport(0, 0, this.m_width, this.m_height);
-};
-
-/// Add new actor to the collection. This is required if the actor
-/// needs to be rendered by the vglModule.renderer.
-///---------------------------------------------------------------------------
-vglModule.renderer.prototype.addActor = function(actor) {
-  if (actor instanceof vglModule.actor) {
-    this.m_sceneRoot.addChild(actor);
-    return true;
-  }
-
-  return false;
-};
-/// Remove the actor from the collection.This method will
-/// not trigger reset camera.
-///---------------------------------------------------------------------------
-vglModule.renderer.prototype.removeActor = function(actor) {
-  if (actor in this.m_sceneRoot.children()) {
-    this.m_sceneRoot.removeChild(actor);
-    return true;
-  }
-
-  return false;
-};
-
-//----------------------------------------------------------------------------
-vglModule.renderer.worldToDisplay = function(
-  worldPt, viewMatrix, projectionMatrix, width, height) {
-  var viewProjectionMatrix = mat4.create();
-  mat4.multiply(projectionMatrix, viewMatrix, viewProjectionMatrix);
-
-  // Transform world to clipping coordinates
-  var clipPt = vec4.create();
-  mat4.multiplyVec4(viewProjectionMatrix, worldPt, clipPt);
-
-  if (clipPt[3] !== 0.0) {
-    clipPt[0] = clipPt[0] / clipPt[3];
-    clipPt[1] = clipPt[1] / clipPt[3];
-    clipPt[2] = clipPt[2] / clipPt[3];
-    clipPt[3] = 1.0;
+  /// Public member variables
+
+  /**
+   * Get scene root
+   *
+   */
+  this.sceneRoot = function() {
+    return this.m_sceneRoot;
+  };
+
+  /**
+   * Get main camera of the renderer
+   *
+   */
+  this.camera = function() {
+    return this.m_camera;
+  };
+
+  /**
+   * Get width of renderer
+   *
+   */
+  this.width = function() {
+    return this.m_width;
+  };
+
+  /**
+   * Get height of renderer
+   *
+   */
+  this.height = function() {
+    return this.m_height;
+  };
+
+  /**
+   * Render the scene
+   *
+   */
+  this.render = function() {
+    gl.clearColor(0.5, 0.5, 0.5, 1.0);
+    gl.enable(gl.DEPTH_TEST);
+    gl.depthFunc(gl.LEQUAL);
+    gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
+
+    // TODO Call it only once
+    this.resize();
+
+    perspectiveMatrix = this.m_camera.projectionMatrix(
+      (this.m_width / this.m_height), 0.1, 10000.0);
+
+    var renSt = new vglModule.renderState();
+    renSt.m_projectionMatrix = perspectiveMatrix;
+    var children = this.m_sceneRoot.children();
+    for (var i = 0; i < children.length; ++i) {
+      var actor = children[i];
+      mat4.multiply(this.m_camera.viewMatrix(), actor.matrix(), renSt.m_modelViewMatrix);
+      renSt.m_material = actor.material();
+      renSt.m_mapper = actor.mapper();
+
+      // TODO Fix this shortcut
+      renSt.m_material.render(renSt);
+      renSt.m_mapper.render(renSt);
+      renSt.m_material.remove(renSt);
+    }
+  };
+
+  /**
+   * Recalculate camera's clipping range
+   *
+   */
+  this.resetCameraClippingRange = function() {
+    // TODO
+  };
+
+  /**
+   * Resize viewport based on the new width and height of the window
+   *
+   */
+  this.resize = function() {
+    gl.viewport(0, 0, this.m_width, this.m_height);
+  };
+
+  /**
+   * Add new actor to the collection.
+   *
+   */
+  this.addActor = function(actor) {
+    if (actor instanceof vglModule.actor) {
+      this.m_sceneRoot.addChild(actor);
+      return true;
     }
 
-  var winX = Math.round( ( ( ( clipPt[0]) + 1 ) / 2.0) * width );
-  // We calculate -point3D.getY() because the screen Y axis is
-  // oriented top->down
-  var winY = Math.round((( 1 - clipPt[1] ) / 2.0) *  height );
-  var winZ = clipPt[2];
-  var winW = clipPt[3];
-
-  return vec4.createFrom(winX, winY, winZ, winW);
-};
-
-//----------------------------------------------------------------------------
-vglModule.renderer.displayToWorld = function(
-  displayPt, viewMatrix, projectionMatrix, width, height) {
-    var x =  ( 2.0 * displayPt[0] / width )  - 1;
-    var y = -( 2.0 * displayPt[1] / height ) + 1;
-    var z =  displayPt[2];
-
-    var viewProjectionInverse = mat4.create();
-    mat4.multiply(projectionMatrix, viewMatrix, viewProjectionInverse);
-    mat4.inverse(viewProjectionInverse, viewProjectionInverse);
-
-    var worldPt = vec4.createFrom(x, y, z, 1);
-    mat4.multiplyVec4(viewProjectionInverse, worldPt, worldPt);
-
-    if (worldPt[3] !== 0.0) {
-      worldPt[0] = worldPt[0] / worldPt[3];
-      worldPt[1] = worldPt[1] / worldPt[3];
-      worldPt[2] = worldPt[2] / worldPt[3];
-      worldPt[3] = 1.0;
+    return false;
+  };
+
+  /**
+   * Remove the actor from the collection
+   *
+   */
+  this.removeActor = function(actor) {
+    if (actor in this.m_sceneRoot.children()) {
+      this.m_sceneRoot.removeChild(actor);
+      return true;
     }
 
-    return worldPt;
+    return false;
+  };
+
+  /**
+   * Transform a point in the world space to display space
+   *
+   */
+  vglModule.renderer.worldToDisplay = function(
+    worldPt, viewMatrix, projectionMatrix, width, height) {
+    var viewProjectionMatrix = mat4.create();
+    mat4.multiply(projectionMatrix, viewMatrix, viewProjectionMatrix);
+
+    // Transform world to clipping coordinates
+    var clipPt = vec4.create();
+    mat4.multiplyVec4(viewProjectionMatrix, worldPt, clipPt);
+
+    if (clipPt[3] !== 0.0) {
+      clipPt[0] = clipPt[0] / clipPt[3];
+      clipPt[1] = clipPt[1] / clipPt[3];
+      clipPt[2] = clipPt[2] / clipPt[3];
+      clipPt[3] = 1.0;
+      }
+
+    var winX = Math.round( ( ( ( clipPt[0]) + 1 ) / 2.0) * width );
+    /// We calculate -point3D.getY() because the screen Y axis is
+    /// oriented top->down
+    var winY = Math.round((( 1 - clipPt[1] ) / 2.0) *  height );
+    var winZ = clipPt[2];
+    var winW = clipPt[3];
+
+    return vec4.createFrom(winX, winY, winZ, winW);
+  };
+
+  /**
+   * Transform a point in display space to world space
+   *
+   */
+  vglModule.renderer.displayToWorld = function(
+    displayPt, viewMatrix, projectionMatrix, width, height) {
+      var x =  ( 2.0 * displayPt[0] / width )  - 1;
+      var y = -( 2.0 * displayPt[1] / height ) + 1;
+      var z =  displayPt[2];
+
+      var viewProjectionInverse = mat4.create();
+      mat4.multiply(projectionMatrix, viewMatrix, viewProjectionInverse);
+      mat4.inverse(viewProjectionInverse, viewProjectionInverse);
+
+      var worldPt = vec4.createFrom(x, y, z, 1);
+      mat4.multiplyVec4(viewProjectionInverse, worldPt, worldPt);
+
+      if (worldPt[3] !== 0.0) {
+        worldPt[0] = worldPt[0] / worldPt[3];
+        worldPt[1] = worldPt[1] / worldPt[3];
+        worldPt[2] = worldPt[2] / worldPt[3];
+        worldPt[3] = 1.0;
+      }
+
+      return worldPt;
+  };
+
+  return this;
 };
+
+inherit(vglModule.renderer, vglModule.object);
\ No newline at end of file

-----------------------------------------------------------------------

Summary of changes:
 web/lib/geo/map.js      |    2 +-
 web/lib/vgl/renderer.js |  313 ++++++++++++++++++++++++++---------------------
 2 files changed, 176 insertions(+), 139 deletions(-)


hooks/post-receive
-- 
OpenGeoscience



More information about the Opengeoscience-developers mailing list