Java Code Examples for processing.core.PShape#vertex()

The following examples show how to use processing.core.PShape#vertex() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShaderVertexTrigDeform.java    From haxademic with MIT License 6 votes vote down vote up
PShape createCylinder(float r, float h, int detail, PImage tex) {
	textureMode(NORMAL);
	PShape sh = createShape();
	sh.beginShape(QUAD_STRIP);
	sh.noStroke();
	sh.texture(tex);
	for (int i = 0; i <= detail; i++) {
		float angle = TWO_PI / detail;
		float x = sin(i * angle);
		float z = cos(i * angle);
		float u = (float)i / detail;
		sh.normal(x, 0, z);
		sh.vertex(x * r, -h/2, z * r, u, 0);
		sh.vertex(x * r, +h/2, z * r, u, 1);    
	}
	sh.endShape(); 
	return sh;
}
 
Example 2
Source File: Shapes.java    From haxademic with MIT License 6 votes vote down vote up
public static PShape createSheetPoints(int detail, float width, float height) {
	PShape sh = P.p.createShape();
	sh.beginShape(PConstants.POINTS);
	sh.stroke(255);
	sh.strokeWeight(1);
	sh.noFill();
	float cellW = width / detail;
	float cellH = height / detail;
	// int numVertices = 0;
	for (int col = 0; col < detail; col++) {
		for (int row = 0; row < detail; row++) {
			float xU = col * cellW;
			float yV = row * cellH;
			float x = -width/2f + col * cellW;
			float y = -height/2f + row * cellH;
			float z = 0;
			sh.normal(x, y, z);
			sh.vertex(x, y, z, P.map(xU, 0, width, 0, 1), P.map(yV, 0, height, 0, 1));
			// numVertices += 1;
		}
	}
	// P.println("createSheet() vertices:", numVertices);
	sh.endShape(); 
	return sh;
}
 
Example 3
Source File: PShapeUtil.java    From haxademic with MIT License 6 votes vote down vote up
public static PShape svgToUniformPointsShape(String fileName, float spacing) {
	// load svg and polygonize with Geomerative
	if(!RG.initialized()) RG.init(P.p);
	RShape rShape = RG.loadShape(fileName);
	rShape = RG.centerIn(rShape, P.p.g);

	RG.setPolygonizer(RG.UNIFORMLENGTH);
	RG.setPolygonizerLength(spacing);
	RPoint[] points = rShape.getPoints();

	// create PShape
	PShape svg = P.p.createShape();
	svg.beginShape(PConstants.POINTS);
	svg.stroke(255);
	svg.strokeWeight(1);
	svg.noFill();

	for(int i=0; i < points.length; i++){
		svg.vertex(points[i].x, points[i].y);
	}
	svg.endShape(P.CLOSE);

	return svg;
}
 
Example 4
Source File: DwDisplayUtils.java    From PixelFlow with MIT License 5 votes vote down vote up
static public final void vertex(PShape pg, DwParticle3D v0, float[] t0){
  if(pg.is2D()){
    pg.vertex(v0.cx, v0.cy       , t0[0], t0[1]); 
  } else {
    pg.vertex(v0.cx, v0.cy, v0.cz, t0[0], t0[1]); 
  }
}
 
Example 5
Source File: TextureEQLinesTerrain.java    From haxademic with MIT License 5 votes vote down vote up
public TextureEQLinesTerrain( int width, int height ) {
	super(width, height);
	
	// build scrolling audio map history
	eqHistory = PG.newPG(256, 256, false, false);
	eqHistory.noSmooth();
	OpenGLUtil.setTextureQualityLow(eqHistory);
	eqHistoryCopy = PG.newPG(256, 256);
	eqHistoryCopy.noSmooth();
	OpenGLUtil.setTextureQualityLow(eqHistoryCopy);

	// build sheet mesh
	shape = P.p.createShape(P.GROUP);
	int rows = eqHistory.height;
	int cols = eqHistory.width;
	for (int y = 0; y < rows; y++) {
		PShape line = P.p.createShape();
		line.beginShape();
		line.stroke(255);
		line.strokeWeight(1);
		line.noFill();
		for (int x = 0; x < cols; x++) {
			line.vertex(x * 20f, y * 20f, 0);
		}
		line.endShape();
		shape.addChild(line);
	}

	// normalize & texture mesh
	PShapeUtil.centerShape(shape);
	PShapeUtil.scaleShapeToHeight(shape, height * 1f);
	PShapeUtil.addTextureUVToShape(shape, eqHistory);
	shapeExtent = PShapeUtil.getMaxExtent(shape);
	shape.disableStyle();
	shape.setTexture(eqHistory);
}
 
Example 6
Source File: DwDisplayUtils.java    From PixelFlow with MIT License 5 votes vote down vote up
static public final void vertex(PShape pg, DwParticle3D v0){
  if(pg.is2D()){
    pg.vertex(v0.cx, v0.cy); 
  } else {
    pg.vertex(v0.cx, v0.cy, v0.cz); 
  }
}
 
Example 7
Source File: Shapes.java    From haxademic with MIT License 5 votes vote down vote up
public static PShape createSheet(int cols, int rows, PImage tex) {
	P.p.textureMode(P.NORMAL); 
	// P.println("Shapes.createSheet() setting textureMode is weird to do here... Maybe should be PAppletHax default?");
	PShape sh = P.p.createShape();
	sh.beginShape(P.QUADS);
	sh.noStroke();
	sh.texture(tex);
	float cellW = (float) tex.width / (float) cols;
	float cellH = (float) tex.height / (float) rows;
	// int numVertices = 0;
	for (int col = 0; col < cols; col++) {
		for (int row = 0; row < rows; row++) {
			float xU = col * cellW;
			float yV = row * cellH;
			float x = -tex.width/2f + col * cellW;
			float y = -tex.height/2f + row * cellH;
			float z = 0;
			sh.normal(x, y, z);
			sh.vertex(x, y, z, 					P.map(xU, 0, tex.width, 0, 1), 			P.map(yV, 0, tex.height, 0, 1));
			sh.vertex(x, y + cellH, z, 			P.map(xU, 0, tex.width, 0, 1), 			P.map(yV + cellH, 0, tex.height, 0, 1));    
			sh.vertex(x + cellW, y + cellH, z, 	P.map(xU + cellW, 0, tex.width, 0, 1), 	P.map(yV + cellH, 0, tex.height, 0, 1));    
			sh.vertex(x + cellW, y, z, 			P.map(xU + cellW, 0, tex.width, 0, 1), 	P.map(yV, 0, tex.height, 0, 1));
			// numVertices++;
		}
	}
	// P.println("createSheet() vertices:", numVertices);
	sh.endShape(); 
	P.p.textureMode(P.IMAGE); 	// reset 
	return sh;
}
 
Example 8
Source File: Shapes.java    From haxademic with MIT License 5 votes vote down vote up
public static PShape createRectSingleUV(float size, float uvX, float uvY) {
	PShape sh = P.p.createShape();
	sh.beginShape(P.QUADS);
	sh.textureMode(P.NORMAL);
	
	// BL, BR, TR, TL
	sh.vertex(-size,  size,  0, 		uvX, uvY);
	sh.vertex( size,  size,  0, 		uvX, uvY);
	sh.vertex( size, -size,  0,		uvX, uvY);
	sh.vertex(-size, -size,  0,		uvX, uvY);
	
	sh.endShape();
	return sh;
}
 
Example 9
Source File: PShapeUtil.java    From haxademic with MIT License 5 votes vote down vote up
public static void repairMissingSVGVertex(PShape shape) {
	PVector v1 = shape.getVertex(0);
	PVector v2 = shape.getVertex(0);
	PVector v3 = shape.getVertex(shape.getVertexCount() - 1);
	
	shape.beginShape();
	shape.fill(255, 255, 255);
	shape.noStroke();
	shape.vertex(v1.x, v1.y, v1.z);
	shape.vertex(v2.x, v2.y, v2.z);
	shape.vertex(v3.x, v3.y, v3.z);
	shape.endShape();
}
 
Example 10
Source File: PShapeUtil.java    From haxademic with MIT License 5 votes vote down vote up
public static PShape clonePShape(PApplet p, PShape tesselation) {
	PShape newShape = p.createShape();
	newShape.beginShape(P.TRIANGLES);
	for (int i = 0; i < tesselation.getVertexCount(); i++) {
		PVector v = tesselation.getVertex(i);
		newShape.vertex(v.x, v.y);
	}
	newShape.endShape(P.CLOSE);
	newShape.setStroke(false);
	return newShape;
}
 
Example 11
Source File: TextToPShape.java    From haxademic with MIT License 5 votes vote down vote up
public PShape stringToShape2d(String text, String fontFile) {
	// if letter is in the cache, just send it back
	if(textShape2d.get(text) != null) return textShape2d.get(text);

	// geomerative builds a mesh from text & cached font
	if(fontsCache.get(fontFile) == null) fontsCache.put(fontFile, new RFont(fontFile, 100, RFont.CENTER)); // 
	RFont font = fontsCache.get(fontFile);
	RGroup grp = font.toGroup(text);
	RMesh rMesh = grp.toMesh();
	
	// convert to triangle strips from geomerative strips
	PShape newShape = P.p.createShape(P.GROUP);
	newShape.setName(text);
	for ( int i = 0; i < rMesh.strips.length; i++ ) {
		
		RPoint[] meshPoints = rMesh.strips[i].getPoints();
		PShape triangle = P.p.createShape();
		triangle.beginShape(P.TRIANGLE_STRIP);
		triangle.fill(255);
		triangle.noStroke();
		for ( int ii = 0; ii < meshPoints.length; ii++ ) {
			triangle.vertex(meshPoints[ii].x, meshPoints[ii].y, 0);
		}
		triangle.endShape();
		newShape.addChild(triangle);
	}
	
	// center it
	PShapeUtil.centerShape(newShape);
	
	// cache & return
	textShape2d.put(text, newShape);
	return newShape;
}
 
Example 12
Source File: Demo_LinesDeformAndTextureFilter.java    From haxademic with MIT License 5 votes vote down vote up
protected void firstFrame() {
	// load texture
	perlin = new PerlinTexture(p, 256, 256);
	texture = perlin.texture();
	DebugView.setTexture("texture", texture);
	
	// build sheet mesh
	shape = p.createShape(P.GROUP);
	int rows = 200;
	int cols = 500;
	for (int y = 0; y < rows; y++) {
		PShape line = P.p.createShape();
		line.beginShape();
		line.stroke(255);
		line.strokeWeight(1);
		line.noFill();
		for (int x = 0; x < cols; x++) {
			line.vertex(x * 10f, y * 10f, 0);
		}
		line.endShape();
		shape.addChild(line);
	}
	PShapeUtil.centerShape(shape);
	PShapeUtil.scaleShapeToHeight(shape, p.height * 2f);
	PShapeUtil.addTextureUVToShape(shape, texture);
	shapeExtent = PShapeUtil.getMaxExtent(shape);
	shape.disableStyle();

	shape.setTexture(texture);
	DebugView.setValue("shape.getVertexCount();", PShapeUtil.vertexCount(shape));
}
 
Example 13
Source File: PShapeUtil.java    From haxademic with MIT License 5 votes vote down vote up
public static PShape pointsShapeForGPUData(int w, int h) {
	int vertices = w * h;
	PShape shape = P.p.createShape();
	shape.beginShape(PConstants.POINTS);
	for (int i = 0; i < vertices; i++) {
		float x = i % w;
		float y = P.floor(i / w);
		shape.vertex(x/(w-1f), y/(h-1f), 0); // x/y coords are used as UV coords for position map (0-1)
	}
	shape.endShape();
	return shape;
}
 
Example 14
Source File: PShapeUtil.java    From haxademic with MIT License 4 votes vote down vote up
public static PShape createExtrudedShape(PShape shape, float depth, PShape newShape) {
	if(newShape == null) newShape = P.p.createShape();

	newShape.beginShape(P.TRIANGLES);
	// top
	for (int i = 0; i < shape.getVertexCount() - 3; i+=3) {
		// copy triangle vertices & UV coords
		PVector v1 = shape.getVertex(i);
		PVector v2 = shape.getVertex(i+1);
		PVector v3 = shape.getVertex(i+2);
		float texU1 = shape.getTextureU(i);
		float texV1 = shape.getTextureU(i);
		float texU2 = shape.getTextureU(i+1);
		float texV2 = shape.getTextureU(i+1);
		float texU3 = shape.getTextureU(i+2);
		float texV3 = shape.getTextureU(i+2);
		
		// half depth to keep new model centered on z-axis
		float halfDepth = depth / 2f;
		
		// top
		newShape.vertex(v1.x, v1.y, halfDepth, texU1, texV1);
		newShape.vertex(v2.x, v2.y, halfDepth, texU2, texV2);
		newShape.vertex(v3.x, v3.y, halfDepth, texU3, texV3);
		
		// bottom
		newShape.vertex(v1.x, v1.y, -halfDepth, texU1, texV1);
		newShape.vertex(v2.x, v2.y, -halfDepth, texU2, texV2);
		newShape.vertex(v3.x, v3.y, -halfDepth, texU3, texV3);
		
		// walls
		// wall 1
		newShape.vertex(v1.x, v1.y,  halfDepth, texU1, texV1);
		newShape.vertex(v1.x, v1.y, -halfDepth, texU1, texV1);
		newShape.vertex(v2.x, v2.y,  halfDepth, texU2, texV2);

		newShape.vertex(v1.x, v1.y, -halfDepth, texU1, texV1);
		newShape.vertex(v2.x, v2.y, -halfDepth, texU2, texV2);
		newShape.vertex(v2.x, v2.y,  halfDepth, texU2, texV2);

		// wall 2
		newShape.vertex(v2.x, v2.y,  halfDepth, texU2, texV2);
		newShape.vertex(v2.x, v2.y, -halfDepth, texU2, texV2);
		newShape.vertex(v3.x, v3.y,  halfDepth, texU3, texV3);
		
		newShape.vertex(v2.x, v2.y, -halfDepth, texU2, texV2);
		newShape.vertex(v3.x, v3.y, -halfDepth, texU3, texV3);
		newShape.vertex(v3.x, v3.y,  halfDepth, texU3, texV3);
		
		// wall 3
		newShape.vertex(v3.x, v3.y,  halfDepth, texU3, texV3);
		newShape.vertex(v3.x, v3.y, -halfDepth, texU3, texV3);
		newShape.vertex(v1.x, v1.y,  halfDepth, texU1, texV1);
		
		newShape.vertex(v3.x, v3.y, -halfDepth, texU3, texV3);
		newShape.vertex(v1.x, v1.y, -halfDepth, texU1, texV1);
		newShape.vertex(v1.x, v1.y,  halfDepth, texU1, texV1);
	}
	
	newShape.endShape();
	
	// recurse through original shape children if nested shapes
	for (int j = 0; j < shape.getChildCount(); j++) {
		PShape subShape = shape.getChild(j);
		createExtrudedShape(subShape, depth, newShape);
	}

	return newShape;
}
 
Example 15
Source File: ParticleSystem.java    From PixelFlow with MIT License 4 votes vote down vote up
public PShape createParticleShape(DwParticle2D particle, PImage sprite_img){
    
    final float rad = particle.rad;

    PShape shp_particle = papplet.createShape(PShape.GROUP);
    
    if( PARTICLE_SHAPE_IDX >= 0 && PARTICLE_SHAPE_IDX < 4){
      
      PShape sprite = papplet.createShape(PShape.GEOMETRY);
      sprite.beginShape(PConstants.QUAD);
      sprite.noStroke();
      sprite.noFill();
      sprite.textureMode(PConstants.NORMAL);
      sprite.texture(sprite_img);
      sprite.normal(0, 0, 1);
      sprite.vertex(-rad, -rad, 0, 0);
      sprite.vertex(+rad, -rad, 1, 0);
      sprite.vertex(+rad, +rad, 1, 1);
      sprite.vertex(-rad, +rad, 0, 1);
      sprite.endShape();
      
      shp_particle.addChild(sprite);
    }
    else if( PARTICLE_SHAPE_IDX == 4){   
      
      float threshold1 = 1;   // radius shortening for arc segments
      float threshold2 = 140; // arc between segments
      
      double arc1 = Math.acos(Math.max((rad-threshold1), 0) / rad);
      double arc2 = (180 - threshold2) * Math.PI / 180;
      double arc = Math.min(arc1, arc2);
      
      int num_vtx = (int)Math.ceil(2*Math.PI/arc);
      
//      System.out.println(num_vtx);

      PShape circle = papplet.createShape(PShape.GEOMETRY);
      circle.beginShape();
      circle.noStroke();
      circle.fill(200,100);
      for(int i = 0; i < num_vtx; i++){
        float vx = (float) Math.cos(i * 2*Math.PI/num_vtx) * rad;
        float vy = (float) Math.sin(i * 2*Math.PI/num_vtx) * rad;
        circle.vertex(vx, vy);
      }
      circle.endShape(PConstants.CLOSE);

      PShape line = papplet.createShape(PShape.GEOMETRY);
      line.beginShape(PConstants.LINES);
      line.stroke(0, 100);
      line.strokeWeight(1);
      line.vertex(0, 0);
      line.vertex(-(rad-1), 0);
      line.endShape();
      
//      PShape circle = papplet.createShape(PConstants.ELLIPSE, 0, 0, rad*2, rad*2);
//      circle.setStroke(false);
//      circle.setFill(papplet.color(200,100));
//
//      PShape line = papplet.createShape(PConstants.LINE, 0, 0, -(rad-1), 0);
//      line.setStroke(papplet.color(0,200));
//      line.setStrokeWeight(1); 
      
      shp_particle.addChild(circle);
      shp_particle.addChild(line);
    }
    
    return shp_particle;
    
  }
 
Example 16
Source File: Skylight_ClothSimulation.java    From PixelFlow with MIT License 4 votes vote down vote up
public void displayAABB(PGraphics3D canvas, float[] aabb){
  if(shp_aabb == null){
    float xmin = aabb[0], xmax = aabb[3];
    float ymin = aabb[1], ymax = aabb[4];
    float zmin = aabb[2], zmax = aabb[5];
    
    shp_aabb = createShape(GROUP);
    
    PShape plane_zmin = createShape();
    plane_zmin.beginShape(QUAD);
    plane_zmin.stroke(0);
    plane_zmin.strokeWeight(1);
    plane_zmin.fill(16,96,192);
    plane_zmin.normal(0, 0, 1); plane_zmin.vertex(xmin, ymin, zmin);
    plane_zmin.normal(0, 0, 1); plane_zmin.vertex(xmax, ymin, zmin);
    plane_zmin.normal(0, 0, 1); plane_zmin.vertex(xmax, ymax, zmin);
    plane_zmin.normal(0, 0, 1); plane_zmin.vertex(xmin, ymax, zmin);
    plane_zmin.endShape(CLOSE);
    shp_aabb.addChild(plane_zmin);
    
    PShape plane_zmax = createShape();
    plane_zmax.beginShape(QUAD);
    plane_zmax.noFill();
    plane_zmax.stroke(0);
    plane_zmax.strokeWeight(1);
    plane_zmax.vertex(xmin, ymin, zmax);
    plane_zmax.vertex(xmax, ymin, zmax);
    plane_zmax.vertex(xmax, ymax, zmax);
    plane_zmax.vertex(xmin, ymax, zmax);
    plane_zmax.endShape(CLOSE);
    shp_aabb.addChild(plane_zmax);
    
    PShape vert_lines = createShape();
    vert_lines.beginShape(LINES);
    vert_lines.stroke(0);
    vert_lines.strokeWeight(1);
    vert_lines.vertex(xmin, ymin, zmin);  vert_lines.vertex(xmin, ymin, zmax);
    vert_lines.vertex(xmax, ymin, zmin);  vert_lines.vertex(xmax, ymin, zmax);
    vert_lines.vertex(xmax, ymax, zmin);  vert_lines.vertex(xmax, ymax, zmax);
    vert_lines.vertex(xmin, ymax, zmin);  vert_lines.vertex(xmin, ymax, zmax);
    vert_lines.endShape();
    shp_aabb.addChild(vert_lines);
    
    PShape corners = createShape();
    corners.beginShape(POINTS);
    corners.stroke(0);
    corners.strokeWeight(7);
    corners.vertex(xmin, ymin, zmin);  corners.vertex(xmin, ymin, zmax);
    corners.vertex(xmax, ymin, zmin);  corners.vertex(xmax, ymin, zmax);
    corners.vertex(xmax, ymax, zmin);  corners.vertex(xmax, ymax, zmax);
    corners.vertex(xmin, ymax, zmin);  corners.vertex(xmin, ymax, zmax);
    corners.endShape();
    shp_aabb.addChild(corners);
  }
  canvas.shape(shp_aabb);
}
 
Example 17
Source File: PShapeUtil.java    From haxademic with MIT License 4 votes vote down vote up
public static PShape shapeFromImage(PImage img) {
		img.loadPixels();
		PShape newShape = P.p.createShape(P.GROUP);
		newShape.setStroke(false);
		
		for( int x=0; x < img.width; x++ ){
			for(int y=0; y < img.height; y++){
				int pixelColor = ImageUtil.getPixelColor( img, x, y );
//				float pixelBrightness = P.p.brightness( pixelColor );
				if(pixelColor != ImageUtil.TRANSPARENT_PNG) {
//				if( pixelColor != ImageUtil.EMPTY_WHITE_INT && pixelColor != ImageUtil.WHITE_INT ) {
					P.p.fill(EasingColor.redFromColorInt(pixelColor), EasingColor.greenFromColorInt(pixelColor), EasingColor.blueFromColorInt(pixelColor), 255);
					P.p.noStroke();
					
					PShape sh = P.p.createShape();
					sh.beginShape(P.TRIANGLES);
					sh.fill( EasingColor.redFromColorInt(pixelColor), EasingColor.greenFromColorInt(pixelColor), EasingColor.blueFromColorInt(pixelColor), 255 );
					
					// BL, BR, TR, TL
					float size = 0.5f;

					// front
					sh.vertex(x - size, y + size,  size);
					sh.vertex(x + size, y + size,  size);
					sh.vertex(x + size, y - size,  size);
					
					sh.vertex(x - size, y + size,  size);
					sh.vertex(x + size, y - size,  size);
					sh.vertex(x - size, y - size,  size);

					// back
					sh.vertex(x - size, y + size,  -size);
					sh.vertex(x + size, y + size,  -size);
					sh.vertex(x + size, y - size,  -size);
					
					sh.vertex(x - size, y + size,  -size);
					sh.vertex(x + size, y - size,  -size);
					sh.vertex(x - size, y - size,  -size);

					// left
					sh.vertex(x - size, y + size, -size);
					sh.vertex(x - size, y + size,  size);
					sh.vertex(x - size, y - size,  size);

					sh.vertex(x - size, y + size, -size);
					sh.vertex(x - size, y - size,  size);
					sh.vertex(x - size, y - size, -size);

					// right
					sh.vertex(x + size, y + size, -size);
					sh.vertex(x + size, y + size,  size);
					sh.vertex(x + size, y - size,  size);

					sh.vertex(x + size, y + size, -size);
					sh.vertex(x + size, y - size,  size);
					sh.vertex(x + size, y - size, -size);
					
					// floor
					sh.vertex(x - size, y + size, -size);
					sh.vertex(x + size, y + size, -size);
					sh.vertex(x + size, y + size,  size);

					sh.vertex(x + size, y + size,  size);
					sh.vertex(x - size, y + size,  size);
					sh.vertex(x - size, y + size, -size);

					// ceiling
					sh.vertex(x - size, y - size, -size);
					sh.vertex(x + size, y - size, -size);
					sh.vertex(x + size, y - size,  size);

					sh.vertex(x + size, y - size,  size);
					sh.vertex(x - size, y - size,  size);
					sh.vertex(x - size, y - size, -size);

					sh.endShape();

					newShape.addChild(sh);
				}
			}
		}
		
		return newShape;
	}
 
Example 18
Source File: Shapes.java    From haxademic with MIT License 4 votes vote down vote up
public static PShape createBox(float size) {
	PShape sh = P.p.createShape();
	sh.beginShape(P.QUADS);
	
	// BL, BR, TR, TL
	// front
	sh.vertex(-size,  size,  size, 		0, 1);
	sh.vertex( size,  size,  size, 		1, 1);
	sh.vertex( size, -size,  size,		1, 0);
	sh.vertex(-size, -size,  size,		0, 0);

	// back
	sh.vertex( size,  size, -size, 		0, 1);
	sh.vertex(-size,  size, -size, 		1, 1);
	sh.vertex(-size, -size, -size,		1, 0);
	sh.vertex( size, -size, -size,		0, 0);

	// left
	sh.vertex(-size,  size, -size, 		0, 1);
	sh.vertex(-size,  size,  size, 		1, 1);
	sh.vertex(-size, -size,  size,		1, 0);
	sh.vertex(-size, -size, -size,		0, 0);

	// right
	sh.vertex( size,  size,  size, 		0, 1);
	sh.vertex( size,  size, -size, 		1, 1);
	sh.vertex( size, -size, -size,		1, 0);
	sh.vertex( size, -size,  size,		0, 0);
	
	// floor
	sh.vertex(-size,  size, -size, 		0, 0);
	sh.vertex( size,  size, -size, 		1, 0);
	sh.vertex( size,  size,  size,		1, 1);
	sh.vertex(-size,  size,  size,		0, 1);

	// ceiling
	sh.vertex(-size, -size, -size, 		0, 0);
	sh.vertex( size, -size, -size, 		1, 0);
	sh.vertex( size, -size,  size,		1, 1);
	sh.vertex(-size, -size,  size,		0, 1);

	sh.endShape();
	return sh;
}
 
Example 19
Source File: Softbody3D_ParticleCollisionSystem.java    From PixelFlow with MIT License 4 votes vote down vote up
public void displayAABB(float[] aabb){
  if(shp_aabb == null){
    float xmin = aabb[0], xmax = aabb[3];
    float ymin = aabb[1], ymax = aabb[4];
    float zmin = aabb[2], zmax = aabb[5];
    
    shp_aabb = createShape(GROUP);
    
    PShape plane_zmin = createShape();
    plane_zmin.beginShape(QUAD);
    plane_zmin.stroke(0);
    plane_zmin.strokeWeight(1);
    plane_zmin.fill(192);
    plane_zmin.normal(0, 0, 1); plane_zmin.vertex(xmin, ymin, zmin);
    plane_zmin.normal(0, 0, 1); plane_zmin.vertex(xmax, ymin, zmin);
    plane_zmin.normal(0, 0, 1); plane_zmin.vertex(xmax, ymax, zmin);
    plane_zmin.normal(0, 0, 1); plane_zmin.vertex(xmin, ymax, zmin);
    plane_zmin.endShape(CLOSE);
    shp_aabb.addChild(plane_zmin);
    
    PShape plane_zmax = createShape();
    plane_zmax.beginShape(QUAD);
    plane_zmax.noFill();
    plane_zmax.stroke(0);
    plane_zmax.strokeWeight(1);
    plane_zmax.vertex(xmin, ymin, zmax);
    plane_zmax.vertex(xmax, ymin, zmax);
    plane_zmax.vertex(xmax, ymax, zmax);
    plane_zmax.vertex(xmin, ymax, zmax);
    plane_zmax.endShape(CLOSE);
    shp_aabb.addChild(plane_zmax);
    
    PShape vert_lines = createShape();
    vert_lines.beginShape(LINES);
    vert_lines.stroke(0);
    vert_lines.strokeWeight(1);
    vert_lines.vertex(xmin, ymin, zmin);  vert_lines.vertex(xmin, ymin, zmax);
    vert_lines.vertex(xmax, ymin, zmin);  vert_lines.vertex(xmax, ymin, zmax);
    vert_lines.vertex(xmax, ymax, zmin);  vert_lines.vertex(xmax, ymax, zmax);
    vert_lines.vertex(xmin, ymax, zmin);  vert_lines.vertex(xmin, ymax, zmax);
    vert_lines.endShape();
    shp_aabb.addChild(vert_lines);
    
    PShape corners = createShape();
    corners.beginShape(POINTS);
    corners.stroke(0);
    corners.strokeWeight(7);
    corners.vertex(xmin, ymin, zmin);  corners.vertex(xmin, ymin, zmax);
    corners.vertex(xmax, ymin, zmin);  corners.vertex(xmax, ymin, zmax);
    corners.vertex(xmax, ymax, zmin);  corners.vertex(xmax, ymax, zmax);
    corners.vertex(xmin, ymax, zmin);  corners.vertex(xmin, ymax, zmax);
    corners.endShape();
    shp_aabb.addChild(corners);
  }
  shape(shp_aabb);
}
 
Example 20
Source File: ParticleSystem.java    From PixelFlow with MIT License 4 votes vote down vote up
public PShape createParticleShape(DwParticle2D particle, PImage sprite_img){
    
    final float rad = particle.rad;

    PShape shp_particle = papplet.createShape(PShape.GROUP);
    
    if( PARTICLE_SHAPE_IDX >= 0 && PARTICLE_SHAPE_IDX < 4){
      
      PShape sprite = papplet.createShape(PShape.GEOMETRY);
      sprite.beginShape(PConstants.QUAD);
      sprite.noStroke();
      sprite.noFill();
      sprite.textureMode(PConstants.NORMAL);
      sprite.texture(sprite_img);
      sprite.normal(0, 0, 1);
      sprite.vertex(-rad, -rad, 0, 0);
      sprite.vertex(+rad, -rad, 1, 0);
      sprite.vertex(+rad, +rad, 1, 1);
      sprite.vertex(-rad, +rad, 0, 1);
      sprite.endShape();
      
      shp_particle.addChild(sprite);
    }
    else if( PARTICLE_SHAPE_IDX == 4){   
      
      float threshold1 = 1;   // radius shortening for arc segments
      float threshold2 = 140; // arc between segments
      
      double arc1 = Math.acos(Math.max((rad-threshold1), 0) / rad);
      double arc2 = (180 - threshold2) * Math.PI / 180;
      double arc = Math.min(arc1, arc2);
      
      int num_vtx = (int)Math.ceil(2*Math.PI/arc);
      
//      System.out.println(num_vtx);

      PShape circle = papplet.createShape(PShape.GEOMETRY);
      circle.beginShape();
      circle.noStroke();
      circle.fill(200,100);
      for(int i = 0; i < num_vtx; i++){
        float vx = (float) Math.cos(i * 2*Math.PI/num_vtx) * rad;
        float vy = (float) Math.sin(i * 2*Math.PI/num_vtx) * rad;
        circle.vertex(vx, vy);
      }
      circle.endShape(PConstants.CLOSE);

      PShape line = papplet.createShape(PShape.GEOMETRY);
      line.beginShape(PConstants.LINES);
      line.stroke(0, 100);
      line.strokeWeight(1);
      line.vertex(0, 0);
      line.vertex(-(rad-1), 0);
      line.endShape();
      
//      PShape circle = papplet.createShape(PConstants.ELLIPSE, 0, 0, rad*2, rad*2);
//      circle.setStroke(false);
//      circle.setFill(papplet.color(200,100));
//
//      PShape line = papplet.createShape(PConstants.LINE, 0, 0, -(rad-1), 0);
//      line.setStroke(papplet.color(0,200));
//      line.setStrokeWeight(1); 
      
      shp_particle.addChild(circle);
      shp_particle.addChild(line);
    }
    
    return shp_particle;
    
  }