/* * Kepler * */ import mesh from './mesh.js'; import entity from './entity.js'; import material from './material.js'; import sampler2D from './sampler2D.js'; import {math, vector2, vector3, matrix4} from './math.js'; /** * primitive object **/ class linePrimitives{ constructor( engine ) { this.indices; } /** * set viewport * @param {(viewport)} viewport **/ setViewport( viewport ){ this.viewport = viewport; this.gl = viewport.gl; } createLineCubeVertices = function(size, opt_matrix) { var k = size / 2; var vertices = [ [-k, -k, -k], [+k, -k, -k], [-k, +k, -k], [+k, +k, -k], [-k, -k, +k], [+k, -k, +k], [-k, +k, +k], [+k, +k, +k] ]; var indices = [ [0, 1], [1, 3], [3, 2], [2, 0], [4, 5], [5, 7], [7, 6], [6, 4], [0, 4], [1, 5], [2, 6], [3, 7] ]; //var vertexInfo = o3djs.lineprimitives.createLineVertexInfo(); //var positionStream = vertexInfo.addStream(3, o3djs.base.o3d.Stream.POSITION); var vertexArray = []; var indexArray = []; for (var v = 0; v < vertices.length; ++v) { vertexArray.push( vertices[v][0], vertices[v][1], vertices[v][2] ); } for (var i = 0; i < indices.length; ++i) { indexArray.push(indices[i][0], indices[i][1]); } var newMesh = new mesh(this.engine); var normalData = []; var textureCoordData = []; newMesh.shape = 2; newMesh.createMeshFromArrays( indexArray, vertexArray, false, false ); newMesh.draw_type = this.gl.LINES; return newMesh; } /** * get frustum corner coordinates * @param {(matrix4)} projection * @param {(matrix4)} view * @param {(matrix4)} world **/ getFrustumCorners = function(projection, view, world) { var cornerVertices = [ [-1,1,1],[1,1,1],[1,-1,1],[-1,-1,1], [-1,1,-1],[1,1,-1],[1,-1,-1],[-1,-1,-1] ]; var viewClone = matrix4.copyMatrix(view); //viewClone = matrix4.setTranslation(viewClone, [0,0,0]); //if(world) { var viewProjection = matrix4.inverse( matrix4.composition(projection, viewClone) ); //} else { //var viewProjection = matrix4.inverse( projection ); //} var corners = []; for(var c =0; c < cornerVertices.length;c++) { var vert = cornerVertices[c]; vert.push(0.0); vert = matrix4.transformPoint(viewProjection, vert); corners.push(vert); } return corners; }; drawFrustum( projection, view, world ) { var corners = this.getFrustumCorners(projection, view, world); console.log("corners",corners); var vertexArray = []; var normalArray = []; var textureArray = []; var indexArray = []; for(var c = 0; c= 3'); } var vertexArray = []; var normalArray = []; var textureArray = []; var indexArray = []; // Generate the individual vertices in our vertex buffer. for (var i = 0; i <= subdivisions; i++) { var theta = length * 0.5 * Math.PI * i / subdivisions; var theta2 = Math.PI * i + 1 / subdivisions; var outerRadius = radius+1; //var outer_ring = new vector3(outerRadius * Math.cos(theta), 0, outerRadius * Math.sin(theta)); //var outer_ring = new vector3(radiusRadius * Math.cos(theta), 0, radiusRadius * Math.sin(theta)); if(i%2 == 0) { //outer ring vertexArray.push(outerRadius * Math.cos(theta), 0, outerRadius * Math.sin(theta)); //inner ring vertexArray.push(radius * Math.cos(theta), 0, radius * Math.sin(theta)); //outer ring //vertexArray.push(outerRadius * Math.cos(theta2), 0, outerRadius * Math.sin(theta2)); } else { //vertexArray.push(radius * Math.cos(theta), 0, radius * Math.sin(theta)); //vertexArray.push(outerRadius * Math.cos(theta), 0, outerRadius * Math.sin(theta)); //vertexArray.push(radius * Math.cos(theta2), 0, radius * Math.sin(theta2)); } } // Connect the vertices by simple lines. for (var i = 0; i < subdivisions; i++) { indexArray.push(i, i+1, i+2); } var newMesh = new mesh(this.engine); //newMesh.shape = 3; //newMesh.draw_type = this.gl.LINES; newMesh.createMeshFromArrays( indexArray, vertexArray, false, false ); return newMesh; } getLine(triangleIndex) { var indexIndex = triangleIndex * 3; return [this.indices[indexIndex + 0], this.indices[indexIndex + 1], this.indices[indexIndex + 2]]; } setLine = function(lineIndex, index1, index2) { var indexIndex = lineIndex * 2; this.indices[indexIndex + 0] = index1; this.indices[indexIndex + 1] = index2; } /** * Adds a line. * @param {number} index1 The index of the first vertex of the line. * @param {number} index2 The index of the second vertex of the line. */ addLine(index1, index2) { this.indices.push(index1, index2); }; numLines() { return this.indices.length / 2; } } export {linePrimitives as default};