public void visualize(Cluster3DExt cluster) { if ((long) ((((double) (System.currentTimeMillis() - startTime)) / 500.0)) % 2 == 0) { // GL gl = Tools3D.getGL(pApplet); // Tools3D.beginGL(pApplet); // gl.glBegin(gl.GL_LINES); // MTLine[] lines = getVisualizationLines(cluster.getChildren()); // for(MTLine line : lines) // { // // gl.glVertex3f(line.getVerticesLocal()[0].x,line.getVerticesLocal()[0].y,line.getVerticesLocal()[0].z); // // gl.glVertex3f(line.getVerticesLocal()[1].x,line.getVerticesLocal()[1].y,line.getVerticesLocal()[1].z); // } // gl.glEnd(); // Tools3D.endGL(pApplet); pApplet.beginShape(PApplet.LINES); MTLine[] lines = getVisualizationLines(cluster.getChildren()); for (MTLine line : lines) { pApplet.vertex( line.getVerticesLocal()[0].x, line.getVerticesLocal()[0].y, line.getVerticesLocal()[0].z); pApplet.vertex( line.getVerticesLocal()[1].x, line.getVerticesLocal()[1].y, line.getVerticesLocal()[1].z); } // gl.glEnd(); // Tools3D.endGL(pApplet); pApplet.endShape(); } }
/** * Calls vertex() with all vertices in the vertex list. NOTE: begin/endShape() are not called. * * @param p */ public void drawVertices(PApplet p) { int id = 0; for (int i = 0; i < n; i++) { p.vertex(v[id].x, v[id].y, v[id++].z); } }
public void displayByArea(DisplayArea area) { changeMode(); position.add(direction); if (position.z > 300 || position.z < -300) { // ograniczenie poruszania się obszaru wyświetlania direction.mult(-1); } area.moveCenterTo(position); pApplet.stroke(255, 0, 0); pApplet.pushMatrix(); for (int j = 0; j < model.getSegmentCount(); j++) { Segment segment = model.getSegment(j); Face[] faces = segment.getFaces(); pApplet.beginShape(PConstants.QUADS); for (Face face : faces) { if (area.isColliding(face.getCenter())) { PVector[] v = face.getVertices(); PVector[] n = face.getNormals(); for (int k = 0; k < v.length; k++) { pApplet.normal(n[k].x, n[k].y, n[k].z); pApplet.vertex(v[k].x, v[k].y, v[k].z); } } } pApplet.endShape(); } pApplet.popMatrix(); }
/** * Calls beginShape() without parameters, then vertex() with all vertices in the vertex list * before finally calling endShape(). * * @param p */ public void draw(PApplet p) { int id = 0; p.beginShape(); for (int i = 0; i < n; i++) { p.vertex(v[id].x, v[id].y, v[id++].z); } p.endShape(); }
// Draw the shadow with texture mapping void display() { parent.noStroke(); parent.tint(0, 17); parent.beginShape(); parent.texture(img); for (int p = 0; p < shadow.length; p++) { parent.vertex(shadow[p].x, shadow[p].y, corners[p].x, corners[p].y); } parent.endShape(); parent.noTint(); }
/** * Calls begin/endShape(QUAD_STRIP) and draws all vertices in the vertex list. * * @param p */ public void drawQuadStrip(PApplet p) { int id = 0; p.beginShape(QUAD_STRIP); int nn = n / 2; for (int i = 0; i < nn; i++) { p.vertex(v[id].x, v[id].y, v[id++].z); p.vertex(v[id].x, v[id].y, v[id++].z); } p.endShape(); }
public void visualize(Cluster3DExt cluster) { // GL gl = Tools3D.getGL(pApplet); // Tools3D.beginGL(pApplet); // gl.glBegin(gl.GL_LINES); // MTLine[] lines = getVisualizationLines(cluster.getChildren()); // MTComponent linesGroup = new MTComponent(pApplet); // for(MTLine line : lines) // { // linesGroup.addChild(line); // } // cluster.setVisualComponentGroup(linesGroup); // // for(MTLine line : lines) // { // // gl.glVertex3f(line.getVerticesLocal()[0].x,line.getVerticesLocal()[0].y,line.getVerticesLocal()[0].z); // // gl.glVertex3f(line.getVerticesLocal()[1].x,line.getVerticesLocal()[1].y,line.getVerticesLocal()[1].z); // } // gl.glEnd(); // Tools3D.endGL(pApplet); pApplet.beginShape(PApplet.LINES); MTLine[] lines = getVisualizationLines(cluster.getChildren()); MTComponent linesGroup = new MTComponent(pApplet); for (MTLine line : lines) { linesGroup.addChild(line); } cluster.setVisualComponentGroup(linesGroup); for (MTLine line : lines) { pApplet.vertex( line.getVerticesLocal()[0].x, line.getVerticesLocal()[0].y, line.getVerticesLocal()[0].z); pApplet.vertex( line.getVerticesLocal()[1].x, line.getVerticesLocal()[1].y, line.getVerticesLocal()[1].z); } pApplet.endShape(); }
public void render(float _f) { parent.pushMatrix(); parent.scale(_f, -_f, _f); for (int i = 0; i < faces.length; i++) { parent.beginShape(TRIANGLES); for (int j = 0; j < 3; j++) { int vt = faces[i][j]; PVector dis; if (apply == -1) { dis = new PVector(0.0f, 0.0f, 0.0f); } else { dis = auList[apply].getMotion(vt); } parent.vertex(vertices[vt].x + dis.x, vertices[vt].y + dis.y, vertices[vt].z + dis.z); } parent.endShape(); } parent.popMatrix(); }
public void moveNormals() { changeMode(); pApplet.pushMatrix(); for (int j = 0; j < model.getSegmentCount(); j++) { Segment segment = model.getSegment(j); Face[] faces = segment.getFaces(); pApplet.beginShape(PConstants.QUADS); for (int i = 0; i < faces.length; i++) { PVector[] vertices = faces[i].getVertices(); PVector normal = faces[i].getNormal(); float nor = PApplet.abs(PApplet.sin(PApplet.radians((pApplet.frameCount + i))) * 100); for (PVector vertex : vertices) { pApplet.vertex( vertex.x + (normal.x * nor), vertex.y + (normal.y * nor), vertex.z + (normal.z * nor)); } } pApplet.endShape(); } pApplet.popMatrix(); }
/** * Draws the vertices to the screen. * * @param inpAudioFrameIdx The audio frame to reference for height data. */ public void drawSphere(int inpAudioFrameIdx) { _audioFrameDataVals = rtrvAudioFrameData(inpAudioFrameIdx); float prevAudioFrameLvlNbr, currAudioFrameLvlNbr; if (inpAudioFrameIdx > 0) { prevAudioFrameLvlNbr = rtrvAudioFrameData(inpAudioFrameIdx - 1)[0]; } else { prevAudioFrameLvlNbr = 0; } currAudioFrameLvlNbr = rtrvAudioFrameData(inpAudioFrameIdx)[0]; // _parApp.noStroke(); _parApp.stroke(_fillClrNbr); _lerpClrAmt = _parApp.frameCount / (float) _musicData.length; _fillClrNbr = (int) PApplet.lerpColor(FROM_CLR_NBR, TO_CLR_NBR, _lerpClrAmt, PApplet.RGB); _parApp.fill(_fillClrNbr); float newVertexHghtNbr = 0, adjacentLatitudeLnLatitudeDegNbr = 0, adjacentLatitudeLnLongitudeDegNbr = 0, adjacentLatitudeLnRadiusLenNbr = 0, currLatitudeLnLatitudeDegNbr = 0, currLatitudeLnLongitudeDegNbr = 0; PVector adjacentVertex, currVertex; int adjacentLatitudeVertexIdx = 0, currLatitudeVertexIdx = 0; for (int latitudeDegNbr = -90; latitudeDegNbr <= 90; latitudeDegNbr += _resNbr) { if (PApplet.abs(latitudeDegNbr) == 90) { // Create Triangle Fans for each of the poles. _parApp.beginShape(PApplet.TRIANGLE_FAN); // Draw the pole vertex. currLatitudeVertexIdx = calcVertexIdx(latitudeDegNbr, 0); newVertexHghtNbr = calcAndStoreNewVertexHghtNbr( currLatitudeVertexIdx, prevAudioFrameLvlNbr, currAudioFrameLvlNbr); currVertex = Main.toCartesian(latitudeDegNbr, 0, newVertexHghtNbr); // _parApp.text("Lat: " + latitudeDegNbr, currVertex.x, currVertex.y, currVertex.z + 20); _parApp.vertex(currVertex.x, currVertex.y, currVertex.z); float adjacentLatitudeDegNbr; if (latitudeDegNbr == -90) { adjacentLatitudeDegNbr = latitudeDegNbr + _resNbr; } else { adjacentLatitudeDegNbr = latitudeDegNbr - _resNbr; } // In order to complete the sphere, you have to go completely around the circle (i.e., // include both -180 and 180). for (int longitudeDegNbr = -180; longitudeDegNbr <= 180; longitudeDegNbr += _resNbr) { adjacentLatitudeVertexIdx = calcVertexIdx(adjacentLatitudeDegNbr, longitudeDegNbr); if (longitudeDegNbr == 180) { // When we complete the circle, use the heights that we used for longitude = -180 to // stitch the mesh together. newVertexHghtNbr = _radiusLenNbrs[calcVertexIdx(adjacentLatitudeDegNbr, -180)]; } else { // If we're building the second pole, we need to stitch it to the previous ring. if (adjacentLatitudeDegNbr == latitudeDegNbr - _resNbr) { adjacentLatitudeVertexIdx = calcVertexIdx(adjacentLatitudeDegNbr, longitudeDegNbr); newVertexHghtNbr = _radiusLenNbrs[adjacentLatitudeVertexIdx]; } else { newVertexHghtNbr = calcAndStoreNewVertexHghtNbr( adjacentLatitudeVertexIdx, prevAudioFrameLvlNbr, currAudioFrameLvlNbr); } } adjacentVertex = Main.toCartesian(adjacentLatitudeDegNbr, longitudeDegNbr, newVertexHghtNbr); _parApp.vertex(adjacentVertex.x, adjacentVertex.y, adjacentVertex.z); } _parApp.endShape(); } else if (latitudeDegNbr - _resNbr != -90) { // We already built a triangle fan for the first pole, so we do not want to build a triangle // strip over it. _parApp.beginShape(PConstants.TRIANGLE_STRIP); // In order to complete the sphere, you have to go completely around the circle (i.e., // include both -180 and 180). for (int longitudeDegNbr = -180; longitudeDegNbr <= 180; longitudeDegNbr += _resNbr) { if (PApplet.abs(latitudeDegNbr) < 90) { adjacentLatitudeVertexIdx = calcVertexIdx(latitudeDegNbr - _resNbr, longitudeDegNbr); adjacentLatitudeLnLatitudeDegNbr = _latitudeDegs[adjacentLatitudeVertexIdx]; adjacentLatitudeLnLongitudeDegNbr = _longitudeDegs[adjacentLatitudeVertexIdx]; adjacentLatitudeLnRadiusLenNbr = _radiusLenNbrs[adjacentLatitudeVertexIdx]; adjacentVertex = Main.toCartesian( adjacentLatitudeLnLatitudeDegNbr, adjacentLatitudeLnLongitudeDegNbr, adjacentLatitudeLnRadiusLenNbr); _parApp.vertex(adjacentVertex.x, adjacentVertex.y, adjacentVertex.z); } currLatitudeVertexIdx = calcVertexIdx(latitudeDegNbr, longitudeDegNbr); currLatitudeLnLatitudeDegNbr = _latitudeDegs[currLatitudeVertexIdx]; currLatitudeLnLongitudeDegNbr = _longitudeDegs[currLatitudeVertexIdx]; if (longitudeDegNbr == 180) { // When we complete the circle, use the heights that we used for longitude = -180 to // stitch the mesh together. newVertexHghtNbr = _radiusLenNbrs[calcVertexIdx(latitudeDegNbr, -180)]; } else { newVertexHghtNbr = calcAndStoreNewVertexHghtNbr( currLatitudeVertexIdx, prevAudioFrameLvlNbr, currAudioFrameLvlNbr); } currVertex = Main.toCartesian( currLatitudeLnLatitudeDegNbr, currLatitudeLnLongitudeDegNbr, newVertexHghtNbr); _parApp.vertex(currVertex.x, currVertex.y, currVertex.z); } _parApp.endShape(); } } }