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(); }
private void changeMode() { if (pApplet.key == '1') { pApplet.noFill(); model.shapeMode(PConstants.POINTS); } else if (pApplet.key == '2') { pApplet.noFill(); model.shapeMode(PConstants.LINES); } else if (pApplet.key == '3') { model.shapeMode(PConstants.POLYGON); } }
public void setup() { mFont = createFont("ArialRoundedMTBold-36", 48); size(1440, 900, OPENGL); background(0); frameRate(120); // model = new OBJModel(this, "alyson_laugh.obj", "absolute", TRIANGLES); model = new OBJModel(this, "alyson_scared.obj", "absolute", TRIANGLES); // model = new OBJModel(this, "alyson_crying.obj", "absolute", TRIANGLES); smooth(); colorMode(HSB); strokeWeight(4); model.scale(800); model.translateToCenter(); detailValue = 3; scaleValue = 10; vertices = new ArrayList(); ps = new ParticleSystem(this, scaleValue); PVector averagePosition = new PVector(0, 0, 0); for (int i = 0; i < model.getVertexCount(); i += detailValue) { PVector destinationPoint = model.getVertex(i); vertices.add(destinationPoint); averagePosition.add(destinationPoint); } averagePosition.div(vertices.size()); for (int i = 0; i < vertices.size(); i++) { PVector destination = (PVector) vertices.get(i); Particle p = new Particle(this, averagePosition, destination); ps.addParticle(p); } }
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(); }
public void display() { changeMode(); model.draw(); }
public AnimatedShape(PApplet pApplet, String s) { this.pApplet = pApplet; model = new OBJModel(pApplet, s, "relative", PConstants.POLYGON); model.scale(200); model.translateToCenter(); }