Skip to content

Instantly share code, notes, and snippets.

@philogb
Created October 7, 2011 21:51
Show Gist options
  • Save philogb/1271429 to your computer and use it in GitHub Desktop.
Save philogb/1271429 to your computer and use it in GitHub Desktop.
$(document).ready(function(){
var N = 1000, r = 5;
PhiloGL.unpack();
//Create cubes
var cubes = [];
for(var i=0; i<N; i++) {
var cube = new O3D.Cube({});
cube.colors = false;
cube.texCoords = false;
cube.normals = false;
cubes.push(cube);
}
//Create application
PhiloGL('theCanvas', {
camera: {
position: {
x: 0, y: 0, z: 15
}
},
onError: function() {
alert("There was an error creating the app.");
},
onLoad: function(app) {
//Unpack app properties
var gl = app.gl,
scene = app.scene,
canvas = app.canvas,
camera = app.camera,
math = Math,
cos = math.cos,
sin = math.sin,
pi2 = math.PI * 2,
pi2n = pi2 / N,
raf = Fx.requestAnimationFrame;
//Basic gl setup
gl.clearColor(1, 1, 1, 1);
gl.clearDepth(1.0);
gl.enable(gl.DEPTH_TEST);
gl.depthFunc(gl.LEQUAL);
gl.viewport(0, 0, +canvas.width, +canvas.height);
//Add object to the scene
scene.add.apply(scene, cubes);
//Draw the sceen
$("#bodies").html(N);
var t0 = Date.now();
var t = 0;
var fps = $('#fps');
//Animate
draw();
function draw(){
var t1 = Date.now();
fps.html(1000/(t1 - t0));
t0 = t1;
gl.viewport(0, 0, +canvas.width, +canvas.height);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
for(var i=0; i<N; i++){
var cube = cubes[i];
cube.position = {
x: r * cos(pi2n*i + t*0.001),
y: r * sin(pi2n*i + t*0.001),
z:-5.0
};
cube.update();
}
//render
scene.render();
t++;
raf(draw);
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment