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