aboutsummaryrefslogtreecommitdiff
path: root/js/lib/drawing/world.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/drawing/world.js')
-rwxr-xr-xjs/lib/drawing/world.js1266
1 files changed, 637 insertions, 629 deletions
diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js
index fb70d18c..71d0d098 100755
--- a/js/lib/drawing/world.js
+++ b/js/lib/drawing/world.js
@@ -46,66 +46,66 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
46 // Instance variables 46 // Instance variables
47 /////////////////////////////////////////////////////////////////////// 47 ///////////////////////////////////////////////////////////////////////
48 48
49 // flag to do the drawing with WebGL 49 // flag to do the drawing with WebGL
50 this._useWebGL = false; 50 this._useWebGL = false;
51 if(use3D) { 51 if(use3D) {
52 this._useWebGL = use3D; 52 this._useWebGL = use3D;
53 } 53 }
54 54
55 this._canvas = canvas; 55 this._canvas = canvas;
56 if (this._useWebGL) 56 if (this._useWebGL)
57 { 57 {
58 if(preserveDrawingBuffer) 58 if(preserveDrawingBuffer)
59 { 59 {
60 this._glContext = canvas.getContext("experimental-webgl", {preserveDrawingBuffer: true}); 60 this._glContext = canvas.getContext("experimental-webgl", {preserveDrawingBuffer: true});
61 } 61 }
62 else 62 else
63 { 63 {
64 this._glContext = canvas.getContext("experimental-webgl"); 64 this._glContext = canvas.getContext("experimental-webgl");
65 } 65 }
66 } 66 }
67 else 67 else
68 { 68 {
69 this._2DContext = canvas.getContext( "2d" ); 69 this._2DContext = canvas.getContext( "2d" );
70 } 70 }
71 71
72 this._viewportWidth = canvas.width; 72 this._viewportWidth = canvas.width;
73 this._viewportHeight = canvas.height; 73 this._viewportHeight = canvas.height;
74 74
75 // view parameters 75 // view parameters
76 this._fov = 45.0; 76 this._fov = 45.0;
77 this._zNear = 0.1; 77 this._zNear = 0.1;
78 this._zFar = 100.0; 78 this._zFar = 100.0;
79 this._viewDist = 5.0; 79 this._viewDist = 5.0;
80 80
81 // default light parameters 81 // default light parameters
82 this._ambientLightColor = [0.1, 0.1, 0.1, 1.0]; 82 this._ambientLightColor = [0.1, 0.1, 0.1, 1.0];
83 this._diffuseLightColor = [0.1, 0.1, 0.1, 1.0]; 83 this._diffuseLightColor = [0.1, 0.1, 0.1, 1.0];
84 this._specularLightColor = [0.6, 0.6, 0.6, 1.0]; 84 this._specularLightColor = [0.6, 0.6, 0.6, 1.0];
85 this._pointLightLoc = [0.0, 0.0, 0.05]; 85 this._pointLightLoc = [0.0, 0.0, 0.05];
86 86
87 // default material properties. Material properties should be overridden 87 // default material properties. Material properties should be overridden
88 // by the materials used by the objects 88 // by the materials used by the objects
89 this._materialShininess = 20.0; 89 this._materialShininess = 20.0;
90 90
91 this._geomRoot = undefined; 91 this._geomRoot = undefined;
92 92
93 this._cameraMat = Matrix.I(4); 93 this._cameraMat = Matrix.I(4);
94 this._cameraMat[14] = 5.0; 94 this._cameraMat[14] = 5.0;
95 this._cameraMatInv = Matrix.I(4); 95 this._cameraMatInv = Matrix.I(4);
96 this._cameraMatInv[14] = -5.0; 96 this._cameraMatInv[14] = -5.0;
97 97
98 this._camera = null; 98 this._camera = null;
99 // keep a flag indicating whether a render has been completed. 99 // keep a flag indicating whether a render has been completed.
100 // this allows us to turn off automatic updating if there are 100 // this allows us to turn off automatic updating if there are
101 // no animated materials 101 // no animated materials
102 this._firstRender = true; 102 this._firstRender = true;
103 103
104 this._worldCount = worldCounter; 104 this._worldCount = worldCounter;
105 worldCounter++; 105 worldCounter++;
106 106
107 // keep a counter for generating node names 107 // keep a counter for generating node names
108 this._nodeCounter = 0; 108 this._nodeCounter = 0;
109 109
110 // for sending notifications to listeners 110 // for sending notifications to listeners
111 this._notifier = new Notifier(); 111 this._notifier = new Notifier();
@@ -113,46 +113,46 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
113 /////////////////////////////////////////////////////////////////////// 113 ///////////////////////////////////////////////////////////////////////
114 // Property accessors 114 // Property accessors
115 /////////////////////////////////////////////////////////////////////// 115 ///////////////////////////////////////////////////////////////////////
116 this.getGLContext = function() { return this._glContext; }; 116 this.getGLContext = function() { return this._glContext; };
117 this.setGLContext = function(gl) { this._glContext = gl; }; 117 this.setGLContext = function(gl) { this._glContext = gl; };
118 118
119 this.get2DContext = function() { return this._2DContext; }; 119 this.get2DContext = function() { return this._2DContext; };
120 this.set2DContext = function(c) { this._2DContext = c; }; 120 this.set2DContext = function(c) { this._2DContext = c; };
121 121
122 this.getCanvas = function() { return this._canvas; }; 122 this.getCanvas = function() { return this._canvas; };
123 this.setCanvas = function(c) { this._canvas = c; }; 123 this.setCanvas = function(c) { this._canvas = c; };
124 124
125 this.getShaderProgram = function() { return this._shaderProgram; }; 125 this.getShaderProgram = function() { return this._shaderProgram; };
126 126
127 this.getViewportWidth = function() { return this._viewportWidth; }; 127 this.getViewportWidth = function() { return this._viewportWidth; };
128 this.getViewportHeight = function() { return this._viewportHeight; }; 128 this.getViewportHeight = function() { return this._viewportHeight; };
129 129
130 this.getAspect = function() { return this._viewportWidth/this._viewportHeight; }; 130 this.getAspect = function() { return this._viewportWidth/this._viewportHeight; };
131 131
132 this.getGeomRoot = function() { return this._geomRoot; }; 132 this.getGeomRoot = function() { return this._geomRoot; };
133 this.getZNear = function() { return this._zNear; }; 133 this.getZNear = function() { return this._zNear; };
134 this.getZFar = function() { return this._zFar; }; 134 this.getZFar = function() { return this._zFar; };
135 this.getFOV = function() { return this._fov; }; 135 this.getFOV = function() { return this._fov; };
136 136
137 this.getCamera = function() { return this._camera; }; 137 this.getCamera = function() { return this._camera; };
138 138
139 this.getCameraMat = function() { return this._cameraMat.slice(0); }; 139 this.getCameraMat = function() { return this._cameraMat.slice(0); };
140 this.setCameraMat = function(c) { this._cameraMat = c.slice(0); this._cameraMatInv = glmat4.inverse(c, []); }; 140 this.setCameraMat = function(c) { this._cameraMat = c.slice(0); this._cameraMatInv = glmat4.inverse(c, []); };
141 141
142 this.getCameraMatInverse = function() { return this._cameraMatInv.slice(0); }; 142 this.getCameraMatInverse = function() { return this._cameraMatInv.slice(0); };
143 143
144 this.getViewDistance = function() { return this._viewDist; }; 144 this.getViewDistance = function() { return this._viewDist; };
145 145
146 this.getRootNode = function() { return this._rootNode; }; 146 this.getRootNode = function() { return this._rootNode; };
147 this.setRootNode = function(r) { this._rootNode = r; }; 147 this.setRootNode = function(r) { this._rootNode = r; };
148 148
149 this.isWebGL = function() { return this._useWebGL; }; 149 this.isWebGL = function() { return this._useWebGL; };
150 150
151 this.getRenderer = function() { return this.renderer; }; 151 this.getRenderer = function() { return this.renderer; };
152 152
153 // Flag to play/pause animation at authortime 153 // Flag to play/pause animation at authortime
154 this._previewAnimation = true; 154 this._previewAnimation = true;
155 155
156 //////////////////////////////////////////////////////////////////////////////////// 156 ////////////////////////////////////////////////////////////////////////////////////
157 // RDGE 157 // RDGE
158 // local variables 158 // local variables
@@ -164,265 +164,265 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
164 this.strokeShader = null; 164 this.strokeShader = null;
165 this.renderer = null; 165 this.renderer = null;
166 166
167 // keep an array of texture maps that need to be loaded 167 // keep an array of texture maps that need to be loaded
168 this._texMapsToLoad = []; 168 this._texMapsToLoad = [];
169 this._allMapsLoaded = true; 169 this._allMapsLoaded = true;
170
171 // this is the node to which objects get hung
172 this._rootNode = null;
170 173
171 // this is the node to which objects get hung 174 // set up the camera matrix
172 this._rootNode = null; 175 var camMat = Matrix.I(4);
176 camMat[14] = this.getViewDistance();
177 this.setCameraMat( camMat );
173 178
174 // set up the camera matrix
175 var camMat = Matrix.I(4);
176 camMat[14] = this.getViewDistance();
177 this.setCameraMat( camMat );
178
179 // post-load processing of the scene 179 // post-load processing of the scene
180 this.init = function() 180 this.init = function()
181 { 181 {
182 var ctx1 = RDGE.globals.engine.ctxMan.handleToObject(this._canvas.rdgeCtxHandle), 182 var ctx1 = RDGE.globals.engine.ctxMan.handleToObject(this._canvas.rdgeCtxHandle),
183 ctx2 = RDGE.globals.engine.getContext(); 183 ctx2 = RDGE.globals.engine.getContext();
184 if (ctx1 != ctx2) console.log( "***** different contexts *****" ); 184 if (ctx1 != ctx2) console.log( "***** different contexts *****" );
185 this.renderer = ctx1.renderer; 185 this.renderer = ctx1.renderer;
186 this.renderer._world = this; 186 this.renderer._world = this;
187 187
188 // create a camera, set its perspective, and then point it at the origin 188 // create a camera, set its perspective, and then point it at the origin
189 var cam = new RDGE.camera(); 189 var cam = new RDGE.camera();
190 this._camera = cam; 190 this._camera = cam;
191 cam.setPerspective(this.getFOV(), this.getAspect(), this.getZNear(), this.getZFar()); 191 cam.setPerspective(this.getFOV(), this.getAspect(), this.getZNear(), this.getZFar());
192 cam.setLookAt([0, 0, this.getViewDistance()], [0, 0, 0], RDGE.vec3.up()); 192 cam.setLookAt([0, 0, this.getViewDistance()], [0, 0, 0], RDGE.vec3.up());
193 193
194 // make this camera the active camera 194 // make this camera the active camera