Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: samples/android_sample/assets/dart/main.dart

Issue 11883013: Refactored OpenGL embedder that works on Android, Mac or Linux. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import "dart:math" as Math; 5 import "dart:math" as Math;
6 import "android_extension.dart"; 6 import "extension.dart";
7 7
8 //precision mediump float;
vsm 2013/01/14 21:31:40 Delete the above.
gram 2013/01/16 01:49:16 Done.
8 const FRAGMENT_PROGRAM = """ 9 const FRAGMENT_PROGRAM = """
9 precision mediump float;
10 10
11 const vec3 lightDir = vec3(0.577350269, 0.577350269, -0.577350269); 11 const vec3 lightDir = vec3(0.577350269, 0.577350269, -0.577350269);
12 varying vec3 vPosition; 12 varying vec3 vPosition;
13 uniform vec3 cameraPos; 13 uniform vec3 cameraPos;
14 uniform vec3 sphere1Center; 14 uniform vec3 sphere1Center;
15 uniform vec3 sphere2Center; 15 uniform vec3 sphere2Center;
16 uniform vec3 sphere3Center; 16 uniform vec3 sphere3Center;
17 17
18 bool intersectSphere(vec3 center, vec3 lStart, vec3 lDir, 18 bool intersectSphere(vec3 center, vec3 lStart, vec3 lDir,
19 out float dist) { 19 out float dist) {
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 } 255 }
256 256
257 pushVec(v, arr) { 257 pushVec(v, arr) {
258 arr.addAll([v.x, v.y, v.z]); 258 arr.addAll([v.x, v.y, v.z]);
259 } 259 }
260 260
261 var t = 0; 261 var t = 0;
262 int width, height; 262 int width, height;
263 263
264 drawScene() { 264 drawScene() {
265 log("In drawScene");
265 var x1 = Math.sin(t * 1.1) * 1.5; 266 var x1 = Math.sin(t * 1.1) * 1.5;
266 var y1 = Math.cos(t * 1.3) * 1.5; 267 var y1 = Math.cos(t * 1.3) * 1.5;
267 var z1 = Math.sin(t + Math.PI/3) * 1.5; 268 var z1 = Math.sin(t + Math.PI/3) * 1.5;
268 var x2 = Math.cos(t * 1.2) * 1.5; 269 var x2 = Math.cos(t * 1.2) * 1.5;
269 var y2 = Math.sin(t * 1.4) * 1.5; 270 var y2 = Math.sin(t * 1.4) * 1.5;
270 var z2 = Math.sin(t*1.25 - Math.PI/3) * 1.5; 271 var z2 = Math.sin(t*1.25 - Math.PI/3) * 1.5;
271 var x3 = Math.cos(t * 1.15) * 1.5; 272 var x3 = Math.cos(t * 1.15) * 1.5;
272 var y3 = Math.sin(t * 1.37) * 1.5; 273 var y3 = Math.sin(t * 1.37) * 1.5;
273 var z3 = Math.sin(t*1.27) * 1.5; 274 var z3 = Math.sin(t*1.27) * 1.5;
274 275
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 gl.uniform3f(sphere1Center, x1, y1, z1); 311 gl.uniform3f(sphere1Center, x1, y1, z1);
311 gl.uniform3f(sphere2Center, x2, y2, z2); 312 gl.uniform3f(sphere2Center, x2, y2, z2);
312 gl.uniform3f(sphere3Center, x3, y3, z3); 313 gl.uniform3f(sphere3Center, x3, y3, z3);
313 314
314 gl.drawArrays(WebGLRenderingContext.TRIANGLE_STRIP, 0, 4); 315 gl.drawArrays(WebGLRenderingContext.TRIANGLE_STRIP, 0, 4);
315 316
316 t += 0.03; 317 t += 0.03;
317 if (t > Math.PI * 200) { 318 if (t > Math.PI * 200) {
318 t -= Math.PI * 200; 319 t -= Math.PI * 200;
319 } 320 }
321 log("Done drawScene");
320 } 322 }
321 323
322 setup(int w, int h) { 324 setup(int w, int h) {
323 initShaders(); 325 initShaders();
324 gl.clearColor(0.0, 0.0, 0.0, 1.0); 326 gl.clearColor(0.0, 0.0, 0.0, 1.0);
325 gl.clearDepth(1.0); 327 gl.clearDepth(1.0);
326 initBuffers(); 328 initBuffers();
327 resize(w, h); 329 resize(w, h);
328 playBackground("music/la_ere_gymnopedie.mp3"); 330 //playBackground("music/la_ere_gymnopedie.mp3");
vsm 2013/01/14 21:31:40 Either delete or add TODO to restore. Nit: space
gram 2013/01/16 01:49:16 Done.
329 } 331 }
330 332
331 resize(int w, int h) { 333 resize(int w, int h) {
334 log("in resize");
332 width = w; 335 width = w;
333 height = h; 336 height = h;
334 ratio = width / height; 337 ratio = width / height;
335 gl.viewport(0, 0, width, height); 338 gl.viewport(0, 0, width, height);
336 t -= 0.03; 339 t -= 0.03;
337 drawScene(); 340 drawScene();
341 log("done resize");
338 } 342 }
339 343
340 update() { 344 update() {
341 drawScene(); 345 drawScene();
342 eglSwapBuffers(); 346 glSwapBuffers();
343 } 347 }
344 348
345 onMotionDown(num when, num x, num y) { 349 onMotionDown(num when, num x, num y) {
346 t = (x / width) * Math.PI * 200; 350 t = (x / width) * Math.PI * 200;
347 } 351 }
348 352
349 onMotionUp(num when, num x, num y) {} 353 onMotionUp(num when, num x, num y) {}
350 onMotionMove(num when, num x, num y) {} 354 onMotionMove(num when, num x, num y) {}
351 onMotionCancel(num when, num x, num y) {} 355 onMotionCancel(num when, num x, num y) {}
352 onMotionOutside(num when, num x, num y) {} 356 onMotionOutside(num when, num x, num y) {}
353 onMotionPointerDown(num when, num x, num y) {} 357 onMotionPointerDown(num when, num x, num y) {}
354 onMotionPointerUp(num when, num x, num y) {} 358 onMotionPointerUp(num when, num x, num y) {}
355 onKeyDown(num when, int flags, int keycode, int metastate, int repeat) {} 359 onKeyDown(num when, int flags, int keycode, int metastate, int repeat) {}
356 onKeyUp(num when, int flags, int keycode, int metastate, int repeat) {} 360 onKeyUp(num when, int flags, int keycode, int metastate, int repeat) {}
357 onKeyMultiple(num when, int flags, int keycode, int metastate, int repeat) { 361 onKeyMultiple(num when, int flags, int keycode, int metastate, int repeat) {
358 } 362 }
359 363
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698