/
tweet.html
382 lines (272 loc) · 13.9 KB
/
tweet.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<!--
________________________________________.___________ _______ ________
/ _____/\_ _____/\_ ___ \__ ___/| \_____ \ \ \/ __ \
\_____ \ | __)_ / \ \/ | | | |/ | \ / | \____ /
/ \ | \\ \____| | | / | \/ | \ / /
/_______ //_______ / \______ /|____| |___\_______ /\____|__ //____/
\/ \/ \/ \/ \/ .co.uk
WebGL Template v.1
tweet.html
This page loads tweets from Steven Gray's Tweet-o-meter and maps them to the world
Benjamin Blundell
oni @ section9.co.uk
http://www.section9.co.uk
http://www.casa.ucl.ac.uk
Based on the excellent work by Giles over at http://learningwebgl.com/
This software is released under Creative Commons Attribution Non-Commercial Share Alike
http://creativecommons.org/licenses/by-nc-sa/3.0/
-->
<html>
<head>
<title>Basic WebGL Template</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<link type="text/css" href="css/black-tie/jquery-ui-1.8.5.custom.css" rel="stylesheet" />
<link rel="stylesheet" href="css/960.css" />
<link rel="stylesheet" href="css/S9WebGL.css" />
<!-- JS For Additional OpenGL Functions -->
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.5.custom.min.js"></script>
<script type="text/javascript" src="js/sylvester.js"></script>
<script type="text/javascript" src="js/glUtils.js"></script>
<script type="text/javascript" src="js/webgl-debug.js"></script>
<script type="text/javascript" src="js/s9WebGL.js"></script>
<!-- Main Java Script GL Functions
- $S is the main Section9 WebGL Class instance that has master control
- $RL is the resource loader instance that controls all resources like
models, textures and shaders
- $R is shorthand for $RL.resourceByTag and allows nice access to each
resource via their user assigned name
There are 4 functons to override:
- setupResources - loading anything external here
- preLoop - Do all your initialization here
- draw - make your drawing calls here
- update - Update the state of your program here
-->
<script type="text/javascript">
// Globals you want to mess with
var sphere;
var locationCubes = {};
var locationCoords = {};
var locationHeights = {};
var worldShader;
var basicShader;
var rotateX = 0;
var rotateY = 0;
var zoom = 1;
// ****************************************************
// Setup controls - JQuery related - Not S9WebGL per-se
// ****************************************************
$(function(){
$('#sliderX').slider({
range: false,
orientation: "vertical",
values: [50],
slide: function(event, ui) {
rotateX = 360 / 100 * ui.value - 180;
}
});
$('#sliderY').slider({
range: false,
values: [50],
slide: function(event, ui) {
rotateY = 360 / 100 * ui.value - 180;
}
});
$('#sliderZoom').slider({
range: false,
orientation: "vertical",
values: [0],
slide: function(event, ui) {
zoom = 5 / 100 * ui.value + 1;
}
});
});
// ****************************************************
// Setup a JSON Call every 5 seconds to grab data
// ****************************************************
window.setInterval(grabFeeds, 3000);
function grabFeeds() {
$.getJSON('http://www.casa.ucl.ac.uk/tom/ajax-live/liveLocation.json', function(data) {
$.each(data, function(key, value) {
locationHeights[key] = value / 100.0;
});
});
}
// http://www.casa.ucl.ac.uk/tom/ajax-live/liveLocation.json
// ****************************************************
// S9 GL Load resources
// ****************************************************
$S.setupResources = function () {
$RL.addFragmentShader("shaders/world-fs.txt", "worldfrag");
$RL.addVertexShader("shaders/world-vs.txt", "worldvert");
$RL.addFragmentShader("shaders/cubeglow-fs.txt", "cubeglowfrag");
$RL.addVertexShader("shaders/cubeglow-vs.txt", "cubeglowvert");
// Add the starting url - the function grabs the remaining 6
// $RL.addTextureCube("textures/world_night_cube/cube","worldnight_cube");
$RL.addTextureCube("textures/world_day_cube/cube","worldday_cube");
}
// ****************************************************
// S9 GL Init Variables and Environment
// ****************************************************
$S.preLoop = function () {
sphere = createSphere(50,50);
locationCubes["london"] = createCuboid(0.05,0.05,0.1);
locationCubes["paris"] = createCuboid(0.05,0.05,0.1);
locationCubes["ny"] = createCuboid(0.05,0.05,0.1);
locationCubes["berlin"] = createCuboid(0.05,0.05,0.1);
locationCoords["london"] = [-54,0];
locationCoords["paris"] = [-48,2];
locationCoords["ny"] = [-40,-74];
locationCoords["berlin"] = [-52,13];
locationHeights["london"] =1;
locationHeights["paris"] = 1;
locationHeights["ny"] = 1;
locationHeights["berlin"] = 1;
// create Shader
worldShader = createShaders("worldvert","worldfrag", "worldmap");
// link variables and shader variables
$S.setActiveShader("worldmap");
worldShader.vertexPositionAttribute = gl.getAttribLocation(worldShader, "aVertexPosition");
gl.enableVertexAttribArray(worldShader.vertexPositionAttribute);
worldShader.vertexNormalAttribute = gl.getAttribLocation(worldShader, "aVertexNormal");
gl.enableVertexAttribArray(worldShader.vertexNormalAttribute);
worldShader.textureCoordAttribute = gl.getAttribLocation(worldShader, "aTextureCoord");
gl.enableVertexAttribArray(worldShader.textureCoordAttribute);
worldShader.pMatrixUniform = gl.getUniformLocation(worldShader, "uPMatrix");
worldShader.mvMatrixUniform = gl.getUniformLocation(worldShader, "uMVMatrix");
worldShader.nMatrixUniform = gl.getUniformLocation(worldShader, "uNMatrix");
worldShader.samplerUniform = gl.getUniformLocation(worldShader, "uSampler");
worldShader.materialAmbientColorUniform = gl.getUniformLocation(worldShader, "uMaterialAmbientColor");
worldShader.materialDiffuseColorUniform = gl.getUniformLocation(worldShader, "uMaterialDiffuseColor");
worldShader.materialSpecularColorUniform = gl.getUniformLocation(worldShader, "uMaterialSpecularColor");
worldShader.materialShininessUniform = gl.getUniformLocation(worldShader, "uMaterialShininess");
worldShader.materialEmissiveColorUniform = gl.getUniformLocation(worldShader, "uMaterialEmissiveColor");
worldShader.ambientLightingColorUniform = gl.getUniformLocation(worldShader, "uAmbientLightingColor");
worldShader.pointLightingLocationUniform = gl.getUniformLocation(worldShader, "uPointLightingLocation");
worldShader.pointLightingSpecularColorUniform = gl.getUniformLocation(worldShader, "uPointLightingSpecularColor");
worldShader.pointLightingDiffuseColorUniform = gl.getUniformLocation(worldShader, "uPointLightingDiffuseColor");
// Fixed variables for now
gl.uniform3f(worldShader.ambientLightingColorUniform, 0.2, 0.2, 0.2);
gl.uniform3f(worldShader.pointLightingLocationUniform, 0, 5, 10);
gl.uniform3f(worldShader.pointLightingDiffuseColorUniform, 0.5, 0.5, 0.5);
gl.uniform3f(worldShader.pointLightingSpecularColorUniform, 0.5, 0.5, 0.5);
gl.uniform3f(worldShader.materialAmbientColorUniform, 1.0, 1.0, 1.0);
gl.uniform3f(worldShader.materialDiffuseColorUniform, 1.0, 1.0, 1.0);
gl.uniform3f(worldShader.materialSpecularColorUniform, 1.5, 1.5, 1.5);
gl.uniform1f(worldShader.materialShininessUniform, 10);
gl.uniform3f(worldShader.materialEmissiveColorUniform, 0.5, 0.5, 0.5);
// BASIC Shader
// create Shader
basicShader = createShaders("cubeglowvert","cubeglowfrag", "cubeglow");
$S.setActiveShader("cubeglow");
basicShader.vertexPositionAttribute = gl.getAttribLocation(basicShader, "aVertexPosition");
gl.enableVertexAttribArray(basicShader.vertexPositionAttribute);
basicShader.vertexColorAttribute = gl.getAttribLocation(basicShader, "aVertexColor");
gl.enableVertexAttribArray(basicShader.vertexColorAttribute);
basicShader.pMatrixUniform = gl.getUniformLocation(basicShader, "uPMatrix");
basicShader.mvMatrixUniform = gl.getUniformLocation(basicShader, "uMVMatrix");
basicShader.nMatrixUniform = gl.getUniformLocation(basicShader, "uNMatrix");
basicShader.materialAmbientColorUniform = gl.getUniformLocation(basicShader, "uMaterialAmbientColor");
basicShader.materialDiffuseColorUniform = gl.getUniformLocation(basicShader, "uMaterialDiffuseColor");
basicShader.materialSpecularColorUniform = gl.getUniformLocation(basicShader, "uMaterialSpecularColor");
basicShader.materialShininessUniform = gl.getUniformLocation(basicShader, "uMaterialShininess");
basicShader.materialEmissiveColorUniform = gl.getUniformLocation(basicShader, "uMaterialEmissiveColor");
basicShader.ambientLightingColorUniform = gl.getUniformLocation(basicShader, "uAmbientLightingColor");
basicShader.pointLightingLocationUniform = gl.getUniformLocation(basicShader, "uPointLightingLocation");
basicShader.pointLightingSpecularColorUniform = gl.getUniformLocation(basicShader, "uPointLightingSpecularColor");
basicShader.pointLightingDiffuseColorUniform = gl.getUniformLocation(basicShader, "uPointLightingDiffuseColor");
gl.uniform3f(basicShader.ambientLightingColorUniform, 0.2, 0.2, 0.2);
gl.uniform3f(basicShader.pointLightingLocationUniform, 0, 5, 10);
gl.uniform3f(basicShader.pointLightingDiffuseColorUniform, 0.5, 0.5, 0.5);
gl.uniform3f(basicShader.pointLightingSpecularColorUniform, 0.5, 0.5, 0.5);
gl.uniform3f(basicShader.materialAmbientColorUniform, 1.0, 1.0, 1.0);
gl.uniform3f(basicShader.materialDiffuseColorUniform, 1.0, 1.0, 1.0);
gl.uniform3f(basicShader.materialSpecularColorUniform, 1.5, 1.5, 1.5);
gl.uniform1f(basicShader.materialShininessUniform, 10);
gl.uniform3f(basicShader.materialEmissiveColorUniform, 0.5, 0.5, 0.5);
}
// ****************************************************
// S9 GL Update GL
// ****************************************************
$S.update = function () {
if ($S.mouseDown){
rotateX += ($S.mouseY - $S.mouseYprev) * 180;
rotateY += ($S.mouseX - $S.mouseXprev) * 180;
}
}
// ****************************************************
// S9 GL Drawing
// ****************************************************
$S.draw = function () {
$S.setActiveShader("worldmap");
gl.clearColor(0.95, 0.95, 0.95, 1.0);
gl.clearDepth(1.0);
gl.viewport(0, 0, gl.viewportWidth, gl.viewportHeight);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
perspective(50, gl.viewportWidth / gl.viewportHeight, 0.1, 100.0);
loadIdentity();
// Draw the world first.
mvTranslate([0.0, 0.0, -10.0]);
mvScale([zoom,zoom,zoom]);
mvRotate(rotateX,[1.0,0.0,0.0]);
mvRotate(rotateY,[0.0,1.0,0.0]);
gl.bindTexture(gl.TEXTURE_CUBE_MAP, $R["worldday_cube"]);
sphere.draw();
// Now draw the bars
$S.setActiveShader("cubeglow");
$.each(locationCoords, function(key, value) {
mvPushMatrix();
lat = value[0];
lon = value[1];
mvRotate(lon,[0,1,0]);
mvRotate(lat,[1,0,0]);
mvTranslate([0.0, 0.0, 1.0 + ( locationHeights[key] / 20) ]);
mvScale([1,1,locationHeights[key]]);
locationCubes[key].draw();
mvPopMatrix();
});
}
</script>
</head>
<body onload="S9WebGL.initialize()">
<!-- The Progress Dialog for loading resources -->
<div id="dialog-modal" title="Loading Resources">
<div id="progressbar"></div>
</div>
<div class="container_16" id="mainLayout">
<div class="grid_3"> </div>
<div class="grid_10">
<canvas id="webgl-canvas" style="border: none;" width="580" height="580"></canvas>
</div>
<div class="grid_1">
<!-- Add some interaction sliders for moving things around -->
<div id="sliderX" class="ui-slider ui-slider-vertical ui-widget ui-widget-content ui-corner-all"
style=" height:480px;">
<div class="ui-slider-range ui-widget-header" ></div>
<a href="#" class="ui-slider-handle ui-state-default ui-corner-all" ></a>
</div>
<div id="sliderZoom" class="ui-slider ui-slider-vertical ui-widget ui-widget-content ui-corner-all"
style=" height:70px; margin-top:20px;">
<div class="ui-slider-range ui-widget-header" ></div>
<a href="#" class="ui-slider-handle ui-state-default ui-corner-all" ></a>
</div>
</div>
<div class="clear"></div>
<div class="grid_3"> </div>
<div class="grid_10">
<div id="sliderY" class="ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all"
style="width:480px; margin-top: 20px;">
<div class="ui-slider-range ui-widget-header" ></div>
<a href="#" class="ui-slider-handle ui-state-default ui-corner-all" ></a>
</div>
</div>
<div class="clear"></div>
<div class="grid_3"> </div>
<div class="grid_10">
<p><a href="http://www.khronos.org/webgl/wiki/Getting_a_WebGL_Implementation">The official
WebGL Page</a> will tell you how to get WebGL Enabled for your browser. In Safari, the easiest
thing to do is <a href="http://nightly.webkit.org/">download webkit nightly build</a> and run <pre>defaults write com.apple.Safari WebKitWebGLEnabled -bool YES</pre>
in a terminal.</p>
</div>
</body>
</html>