opengl - WebGL 3d Cylinder and 3d Cone ontop of each other -
i in middle of making webgl program , need create cylinder using triangle strips , cone ontop of using triangle fans create tree simple game type program.
any tips or methods use this, understand how make rectangular prisms @ moment. im beginner in webgl appreciated :)
// block class creates rectangular prism............used steps/obstacles player avoid // constructor function block when created // arguments: vec3 location, floating-point angle (degrees) , vec3 scales function block(location, angle, scales) { var rs = mult(rotate(angle, [0,0,1]), scalem(scales)); this.trs = mult(translate(location), rs); } // block's render function // arguments: // offset - offset of vertices current vertex attribute array // worldview - current worldview transformation block.prototype.render = function(offset, worldview) { gl.uniformmatrix4fv(mvloc, false, flatten(mult(worldview, this.trs))); gl.drawarrays(gl.triangles, offset, block.nv); }; // number of vertices represent cube (nv) block.nv = 36; //makes vertices block/rectangle block.initmodel = function() { // 8 raw vertices of cube var rawverts = [ vec3(-0.5, -0.5, 0.5), vec3(-0.5, 0.5, 0.5), vec3( 0.5, 0.5, 0.5), vec3( 0.5, -0.5, 0.5), vec3(-0.5, -0.5, -0.5), vec3(-0.5, 0.5, -0.5), vec3( 0.5, 0.5, -0.5), vec3( 0.5, -0.5, -0.5) ]; // local array in develop 36 vertices var vertices = []; // nested function generating vertices each face function quad(a, b, c, d) { // if abcd anticlockwise winding on face // abc , acd anticlockwise windings on triangles var indices = [a, b, c, a, c, d]; (var = 0; < indices.length; ++i) { vertices.push(rawverts[indices[i]]); } } //generates cube's faces function docube() { // use anticlockwise windings quad(1, 0, 3, 2); quad(2, 3, 7, 6); quad(3, 0, 4, 7); quad(6, 5, 1, 2); quad(4, 5, 6, 7); quad(5, 4, 0, 1); } docube(); return vertices; }//end of block.initial model function //vertices intialised block.vertices = block.initmodel(); //end of block/rectangle class-------------------------------------------
Comments
Post a Comment