aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/backup-delete/GLWorld.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/backup-delete/GLWorld.js')
-rwxr-xr-xjs/helper-classes/backup-delete/GLWorld.js1029
1 files changed, 0 insertions, 1029 deletions
diff --git a/js/helper-classes/backup-delete/GLWorld.js b/js/helper-classes/backup-delete/GLWorld.js
deleted file mode 100755
index c8bc4c1c..00000000
--- a/js/helper-classes/backup-delete/GLWorld.js
+++ /dev/null
@@ -1,1029 +0,0 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7// globals
8var shaderProgramArray = new Array;
9var glContextArray = new Array;
10
11var vertexShaderSource = "";
12var fragmentShaderSource = "";
13
14var rdgeStarted = false;
15
16var worldCounter = 0;
17
18
19///////////////////////////////////////////////////////////////////////
20// Class GLWorld
21// Manages display in a canvas
22///////////////////////////////////////////////////////////////////////
23function GLWorld( canvas, use3D )
24{
25 ///////////////////////////////////////////////////////////////////////
26 // Instance variables
27 ///////////////////////////////////////////////////////////////////////
28
29 // flag to do the drawing with WebGL
30 this._useWebGL = false;
31 if(use3D)
32 this._useWebGL = use3D;
33
34 this._canvas = canvas;
35 if (this._useWebGL)
36 this._glContext = canvas.getContext("experimental-webgl");
37 else
38 this._2DContext = canvas.getContext( "2d" );
39
40 this._viewportWidth = canvas.width;
41 this._viewportHeight = canvas.height;
42
43 // view parameters
44 this._fov = 45.0;
45 this._zNear = 0.1;
46 this._zFar = 100.0;
47 this._viewDist = 5.0;
48
49 // default light parameters
50 this._ambientLightColor = [0.1, 0.1, 0.1, 1.0];
51 this._diffuseLightColor = [0.1, 0.1, 0.1, 1.0];
52 this._specularLightColor = [0.6, 0.6, 0.6, 1.0];
53 this._pointLightLoc = [0.0, 0.0, 0.05];
54
55 // default material properties. Material properties should be overridden
56 // by the materials used by the objects
57 this._materialShininess = 20.0;
58
59 this._geomRoot = undefined;
60
61 this._cameraMat = Matrix.I(4);
62 this._cameraMat[14] = 5.0;
63 this._cameraMatInv = Matrix.I(4);
64 this._cameraMatInv[14] = -5.0;
65
66 this._camera;
67
68 // keep a flag indicating whether a render has been completed.
69 // this allows us to turn off automatic updating if there are
70 // no animated materials
71 this._firstRender = true;
72
73 this._worldCount = worldCounter;
74 worldCounter++;
75
76 // keep a counter for generating node names
77 this._nodeCounter = 0;
78
79
80 ///////////////////////////////////////////////////////////////////////
81 // Property accessors
82 ///////////////////////////////////////////////////////////////////////
83 this.getGLContext = function() { return this._glContext; }
84 this.setGLContext = function(gl) { this._glContext = gl; }
85
86 this.get2DContext = function() { return this._2DContext; }
87 this.set2DContext = function(c) { this._2DContext = c; }
88
89 this.getCanvas = function() { return this._canvas; }
90 this.setCanvas = function(c) { this._canvas = c; }
91
92 this.getShaderProgram = function() { return this._shaderProgram; }
93
94 this.getViewportWidth = function() { return this._viewportWidth; }
95 this.getViewportHeight = function() { return this._viewportHeight; }
96
97 this.getAspect = function() { return this._viewportWidth/this._viewportHeight; }
98
99 this.getGeomRoot = function() { return this._geomRoot; }
100 this.getZNear = function() { return this._zNear; }
101 this.getZFar = function() { return this._zFar; }
102 this.getFOV = function() { return this._fov; }
103
104 this.getCamera = function() { return this._camera; }
105
106 this.getCameraMat = function() { return this._cameraMat.slice(0); }
107 this.setCameraMat = function(c) { this._cameraMat = c.slice(0); this._cameraMatInv = glmat4.inverse(c, []); }
108
109 this.getCameraMatInverse = function() { return this._cameraMatInv.slice(0); }
110
111 this.getViewDistance = function() { return this._viewDist; }
112
113 this.getRootNode = function() { return this._rootNode; }
114 this.setRootNode = function(r) { this._rootNode = r; }
115
116 this.isWebGL = function() { return this._useWebGL; }
117
118 this.getRenderer = function() { return this.renderer; }
119
120 ////////////////////////////////////////////////////////////////////////////////////
121 // RDGE
122 // local variables
123 this.myScene = null;
124 this.elapsed = 0;
125 this.light = null;
126 this.light2 = null;
127 this.fillShader = null;
128 this.strokeShader = null;
129 this.renderer = null;
130
131 // keep an array of texture maps that need to be loaded
132 this._texMapsToLoad = [];
133 this._allMapsLoaded = true;
134
135 // this is the node to which objects get hung
136 this._rootNode;
137
138 // set up the camera matrix
139 var camMat = Matrix.I(4);
140 camMat[14] = this.getViewDistance();
141 this.setCameraMat( camMat );
142
143 // post-load processing of the scene
144 this.init = function()
145 {
146 var ctx1 = g_Engine.ctxMan.handleToObject(this._canvas.rdgeCtxHandle),
147 ctx2 = g_Engine.getContext();
148 if (ctx1 != ctx2) console.log( "***** different contexts *****" );
149 this.renderer = ctx1.renderer;
150 this.renderer._world = this;
151
152 // create a camera, set its perspective, and then point it at the origin
153 var cam = new camera();
154 this._camera = cam;
155 cam.setPerspective(this.getFOV(), this.getAspect(), this.getZNear(), this.getZFar());
156 cam.setLookAt([0, 0, this.getViewDistance()], [0, 0, 0], vec3.up());
157
158 // make this camera the active camera
159 this.renderer.cameraManager().setActiveCamera(cam);
160
161 // change clear color
162 //this.renderer.setClearFlags(g_Engine.getContext().DEPTH_BUFFER_BIT);
163 this.renderer.setClearColor([0.0, 0.0, 0.0, 0.0]);
164 //this.renderer.NinjaWorld = this;
165
166 // create an empty scene graph
167 this.myScene = new SceneGraph();
168
169 // create some lights
170 // light 1
171 this.light = createLightNode("myLight");
172 this.light.setPosition([0,0,1.2]);
173 this.light.setDiffuseColor([0.75,0.9,1.0,1.0]);
174
175 // light 2
176 this.light2 = createLightNode("myLight2");
177 this.light2.setPosition([-0.5,0,1.2]);
178 this.light2.setDiffuseColor([1.0,0.9,0.75,1.0]);
179
180 // create a light transform
181 var lightTr = createTransformNode("lightTr");
182
183 // create and attach a material - materials hold the light data
184 lightTr.attachMaterial(createMaterialNode("lights"));
185
186 // enable light channels 1, 2 - channel 0 is used by the default shader
187 lightTr.materialNode.enableLightChannel(1, this.light);
188 lightTr.materialNode.enableLightChannel(2, this.light2);
189
190 // all added objects are parented to the light node
191 this._rootNode = lightTr;
192
193 // add the light node to the scene
194 this.myScene.addNode(lightTr);
195
196 // Add the scene to the engine - necessary if you want the engine to draw for you
197 //g_Engine.AddScene("myScene" + this._canvas.id, this.myScene);
198 var name = this._canvas.getAttribute( "data-RDGE-id" );
199 g_Engine.AddScene("myScene" + name, this.myScene);
200 }
201
202 // main code for handling user interaction and updating the scene
203 this.update = function(dt)
204 {
205 if (!dt) dt = 0.2;
206
207 dt = 0.01; // use our own internal throttle
208 this.elapsed += dt;
209
210 if (this._useWebGL)
211 {
212 // changed the global position uniform of light 0, another way to change behavior of a light
213 rdgeGlobalParameters.u_light0Pos.set( [5*Math.cos(this.elapsed), 5*Math.sin(this.elapsed), 20]);
214
215 // orbit the light nodes around the boxes
216 this.light.setPosition([1.2*Math.cos(this.elapsed*2.0), 1.2*Math.sin(this.elapsed*2.0), 1.2*Math.cos(this.elapsed*2.0)]);
217 this.light2.setPosition([-1.2*Math.cos(this.elapsed*2.0), 1.2*Math.sin(this.elapsed*2.0), -1.2*Math.cos(this.elapsed)]);
218 }
219
220 this.updateMaterials( this.getGeomRoot(), this.elapsed );
221