Skip to content

Instantly share code, notes, and snippets.

@williame
Created March 19, 2013 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save williame/5199589 to your computer and use it in GitHub Desktop.
Save williame/5199589 to your computer and use it in GitHub Desktop.
function emitCube(blf,trb,array,ofs) {
ofs = ofs || 0;
var left = blf[0], right = trb[0],
bottom = blf[1], top = trb[1],
front = blf[2], back = trb[2],
tlb = [left,top,back],
trf = [right,top,front],
tlf = [left,top,front],
brb = [right,bottom,back],
blb = [left,bottom,back],
brf = [right,bottom,front],
emit = function(vec3) {
array[ofs++] = vec3[0];
array[ofs++] = vec3[1];
array[ofs++] = vec3[2];
},
quad = function(normal,a,b,c,d) {
emit(a); emit(normal);
emit(b); emit(normal);
emit(c); emit(normal);
emit(a); emit(normal);
emit(c); emit(normal);
emit(d); emit(normal);
};
quad([1,0,0],blb,tlb,tlf,blf); // left
quad([-1,0,0],brf,trf,trb,brb); // right
quad([0,0,-1],blf,tlf,trf,brf); // front
quad([0,0,1],brb,trb,tlb,blb); // back
quad([0,-1,0],tlb,trb,trf,tlf); // up
quad([0,1,0],brb,blb,blf,brf); // down
}
function createCube(blf,trb) {
var array = new Float32Array(createCube.numVertices);
emitCube(blf,trb,array,0);
return array;
}
createCube.numVertices = 6*6; // six faces, each two triangles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment