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

The following examples show how to use processing.core.PGraphics#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: TiledTexture.java    From haxademic with MIT License 6 votes vote down vote up
public void drawDebug(PGraphics pg) {
		// fit to small box
		// draw background
		pg.stroke(0);
		pg.fill(0);
		pg.rect(0, 0, texture.width, texture.height);
		// draw image
		pg.image(texture, 0, 0, texture.width, texture.height);
		// show texture grab area
//		float halfSizeX = (sizeX * (float) texture.width) / 2f;
//		float halfSizeY = (sizeY * (float) texture.height) / 2f;
		pg.stroke(255, 0, 0, 200);
		pg.noFill();
		pg.beginShape();
		pg.vertex(tlX, tlY);
		pg.vertex(trX, trY);
		pg.vertex(brX, brY);
		pg.vertex(blX, blY);
		pg.vertex(tlX, tlY);
		pg.endShape();

		
	}
 
Example 2
Source File: Gradients.java    From haxademic with MIT License 6 votes vote down vote up
public static void quad( PGraphics p, float width, float height, int colorTL, int colorTR, int colorBR, int colorBL )
{
	p.pushMatrix();
	
	float halfW = width/2;
	float halfH = height/2;
	
	p.beginShape();
	p.fill(colorTL);
	p.vertex(-halfW, -halfH);
	p.fill(colorTR);
	p.vertex(halfW, -halfH);
	p.fill(colorBR);
	p.vertex(halfW, halfH);
	p.fill(colorBL);
	p.vertex(-halfW, halfH);
	p.endShape(P.CLOSE);
	
	p.popMatrix();
}
 
Example 3
Source File: Shapes.java    From haxademic with MIT License 6 votes vote down vote up
public static void drawDisc( PGraphics p, float radius, float innerRadius, int numSegments ) {
	p.pushMatrix();
	
	float segmentRads = P.TWO_PI / numSegments;
	for( int i = 0; i < numSegments; i++ ) {
		p.beginShape(P.TRIANGLES);
		
		p.vertex( P.cos( i * segmentRads ) * innerRadius, P.sin( i * segmentRads ) * innerRadius, 0 );
		p.vertex( P.cos( i * segmentRads ) * radius, P.sin( i * segmentRads ) * radius, 0 );
		p.vertex( P.cos( (i + 1) * segmentRads ) * radius, P.sin( (i + 1) * segmentRads ) * radius, 0 );
		
		p.vertex( P.cos( i * segmentRads ) * innerRadius, P.sin( i * segmentRads ) * innerRadius, 0 );
		p.vertex( P.cos( (i + 1) * segmentRads ) * innerRadius, P.sin( (i + 1) * segmentRads ) * innerRadius, 0 );
		p.vertex( P.cos( (i + 1) * segmentRads ) * radius, P.sin( (i + 1) * segmentRads ) * radius, 0 );
		p.endShape();
	}
	
	p.popMatrix();
}
 
Example 4
Source File: TiledGrid.java    From haxademic with MIT License 5 votes vote down vote up
public void draw(PGraphics pg, float cols, float rows, boolean drawOutline) {
	int prevRectMode = pg.rectMode;
	PG.setTextureRepeat(pg, true);
	pg.pushMatrix();
	float drawW = cols * tileSize + strokeWeight;
	float drawH = rows * tileSize + strokeWeight;
	pg.noStroke();
	pg.beginShape();
	pg.textureMode(P.IMAGE);
	pg.texture(gridCell);
	if(prevRectMode == PConstants.CENTER) pg.translate(P.round(-drawW/2), P.round(-drawH/2));
	pg.vertex(0, 0, 0,			offsetX * tileSize + 0, 		offsetY * tileSize + 0);
	pg.vertex(drawW, 0, 0, 		offsetX * tileSize + drawW, 	offsetY * tileSize + 0);
	pg.vertex(drawW, drawH, 0, 	offsetX * tileSize + drawW, 	offsetY * tileSize + drawH);
	pg.vertex(0, drawH, 0, 		offsetX * tileSize + 0, 		offsetY * tileSize + drawH);
	pg.endShape();
	
	if(drawOutline) {
		pg.rectMode(PConstants.CORNER); // make sure rect is drawing from the same top left
		pg.fill(colorStroke);
		pg.rect(0, 0, drawW, strokeWeight);	// top
		pg.rect(0, drawH - strokeWeight, drawW, strokeWeight);	// bottom
		pg.rect(0, 0, strokeWeight, drawH);	// left
		pg.rect(drawW - strokeWeight, 0, strokeWeight, drawH);	// right
		pg.rectMode(prevRectMode);		// reset rect mode to whatever it was before
	}
	
	pg.popMatrix();
}
 
Example 5
Source File: DwDisplayUtils.java    From PixelFlow with MIT License 5 votes vote down vote up
static public final void normal(PGraphics pg, DwParticle3D v0, float[] n, float len){
  if(pg.is2D()){
    pg.vertex(v0.cx           , v0.cy           ); 
    pg.vertex(v0.cx + n[0]*len, v0.cy + n[1]*len); 
  } else {
    pg.vertex(v0.cx           , v0.cy           , v0.cz           ); 
    pg.vertex(v0.cx + n[0]*len, v0.cy + n[1]*len, v0.cz + n[2]*len); 
  }
}
 
Example 6
Source File: DwDisplayUtils.java    From PixelFlow with MIT License 5 votes vote down vote up
static public final void normal(PGraphics pg,float[] v0, float[] n, float len){
  if(pg.is2D()){
    pg.vertex(v0[0]           , v0[1]           ); 
    pg.vertex(v0[0] + n[0]*len, v0[1] + n[1]*len); 
  } else {
    pg.vertex(v0[0]           , v0[1]           , v0[2]           ); 
    pg.vertex(v0[0] + n[0]*len, v0[1] + n[1]*len, v0[2] + n[2]*len); 
  }
}
 
Example 7
Source File: MappedTriangle.java    From haxademic with MIT License 5 votes vote down vote up
public void rawDrawPolygon( PGraphics pg ) {
	pg.beginShape(PConstants.TRIANGLE);
	pg.vertex(_x1.value(), _y1.value());
	pg.vertex(_x2.value(), _y2.value());
	pg.vertex(_x3.value(), _y3.value());
	pg.endShape();
}
 
Example 8
Source File: PGraphicsKeystone.java    From haxademic with MIT License 5 votes vote down vote up
public void fillSolidColor( PGraphics canvas, int fill ) {
	// default single mapped quad
	canvas.noStroke();
	canvas.fill(fill);
	canvas.beginShape(PConstants.QUAD);
	canvas.vertex(topLeft.x, topLeft.y, 0);
	canvas.vertex(topRight.x, topRight.y, 0);
	canvas.vertex(bottomRight.x, bottomRight.y, 0);
	canvas.vertex(bottomLeft.x, bottomLeft.y, 0);
	canvas.endShape();
}
 
Example 9
Source File: DwDisplayUtils.java    From PixelFlow with MIT License 5 votes vote down vote up
static public final void vertex(PGraphics pg, float[] v0, float[] t0){
  if(pg.is2D()){
    pg.vertex(v0[0], v0[1]       , t0[0], t0[1]); 
  } else {
    pg.vertex(v0[0], v0[1], v0[2], t0[0], t0[1]); 
  }
}
 
Example 10
Source File: TexturePoly.java    From haxademic with MIT License 5 votes vote down vote up
public void draw( PGraphics pg ) {
	if( _texture != null ) {
		pg.beginShape(PConstants.TRIANGLE);
		pg.texture(_texture);
		if( _mappingStyleIsFullImage == true ) {
			if( mappingOrientation == 0 ) {
				pg.vertex(x1, y1, 0, 		0, 0);
				pg.vertex(x2, y2, 0, 		_texture.width, _texture.height/2);
				pg.vertex(x3, y3, 0, 		0, _texture.height);
			} else if( mappingOrientation == 1 ) {
				pg.vertex(x1, y1, 0, 		0, 0);
				pg.vertex(x2, y2, 0, 		_texture.width, 0);
				pg.vertex(x3, y3, 0, 		_texture.width/2, _texture.height);
			} else if( mappingOrientation == 2 ) {
				pg.vertex(x1, y1, 0, 		0, _texture.height/2);
				pg.vertex(x2, y2, 0, 		_texture.width, 0);
				pg.vertex(x3, y3, 0, 		_texture.width, _texture.height);
			} else if( mappingOrientation == 3 ) {
				pg.vertex(x1, y1, 0, 		0, _texture.height);
				pg.vertex(x2, y2, 0, 		_texture.width/2, 0);
				pg.vertex(x3, y3, 0, 		_texture.width, _texture.height);
			}
		} else {
			float texScreenRatioW = (float) _texture.width / (float) pg.width;
			float texScreenRatioH = (float) _texture.height / (float) pg.height;
			pg.vertex(x1, y1, 0, 		x1 * texScreenRatioW, y1 * texScreenRatioH);
			pg.vertex(x2, y2, 0, 		x2 * texScreenRatioW, y2 * texScreenRatioH);
			pg.vertex(x3, y3, 0, 		x3 * texScreenRatioW, y3 * texScreenRatioH);
		}
		pg.endShape();
	}
}
 
Example 11
Source File: KinectSilhouetteBasic.java    From haxademic with MIT License 5 votes vote down vote up
protected void drawEdgeVertex(PGraphics canvas, float vertexX, float vertexY, float blobX, float blobY) {
	canvas.vertex( vertexX, vertexY );
	if(_hasParticles == true) {
		if(MathUtil.randRangeDecimal(0, 1) < 0.05f) {
			newParticle(vertexX, vertexY, blobX, blobY);
		}
	}
}
 
Example 12
Source File: RotateRectVertices.java    From haxademic with MIT License 5 votes vote down vote up
public void drawRect(PGraphics pg, float drawW, float drawH, float size, float rotation) {
	float halfDrawW = drawW / 2f;
	float halfDrawH = drawH / 2f;
	float halfSizeX = halfDrawW * size;
	float halfSizeY = halfDrawH * size;
			
	
	pg.noFill();
	pg.stroke(255,0,0);
	pg.beginShape();
	if(rotation == 0) {
		pg.vertex(-halfSizeX, -halfSizeY);
		pg.vertex(halfSizeX, -halfSizeY);
		pg.vertex(halfSizeX, halfSizeY);
		pg.vertex(-halfSizeX, halfSizeY);
		pg.vertex(-halfSizeX, -halfSizeY);
	} else {
		float curRot = rotation;
		float radius = MathUtil.getDistance(0, 0, halfSizeX, halfSizeY);
		float tlRads = -MathUtil.getRadiansToTarget(-halfSizeX, -halfSizeY, 0, 0) + curRot;
		float trRads = -MathUtil.getRadiansToTarget(halfSizeX, -halfSizeY, 0, 0) + curRot;
		float brRads = -MathUtil.getRadiansToTarget(halfSizeX, halfSizeY, 0, 0) + curRot;
		float blRads = -MathUtil.getRadiansToTarget(-halfSizeX, halfSizeY, 0, 0) + curRot;
		pg.vertex(radius * P.cos(tlRads), -radius * P.sin(tlRads));
		pg.vertex(radius * P.cos(trRads), -radius * P.sin(trRads));
		pg.vertex(radius * P.cos(brRads), -radius * P.sin(brRads));
		pg.vertex(radius * P.cos(blRads), -radius * P.sin(blRads));
		pg.vertex(radius * P.cos(tlRads), -radius * P.sin(tlRads));
	}
	pg.endShape();
}
 
Example 13
Source File: Shapes.java    From haxademic with MIT License 5 votes vote down vote up
public static void drawTexturedLine(PGraphics pg, PImage texture, float xStart, float yStart, float xEnd, float yEnd, int color, float thickness, float texOffset, float cornerRadius) {
	// calc textured rectangle rotation * distance
	float startToEndAngle = MathUtil.getRadiansToTarget(xStart, yStart, xEnd, yEnd);
	float dist = MathUtil.getDistance(xStart, yStart, xEnd, yEnd);
	float thicknessHalf = thickness/2f;
	float textureHeightHalf = texture.height/2f;
	
	// set context
	OpenGLUtil.setTextureRepeat(pg);
	pg.push();
	pg.translate(xStart, yStart);
	pg.rotate(startToEndAngle);
	
	// draw textured rect
	pg.noStroke();
	pg.beginShape();
	pg.texture(texture);
	pg.textureMode(P.IMAGE);
	pg.tint(color);
	if(cornerRadius <= 0) {
		pg.vertex(0, -thicknessHalf, 0, texOffset, 0);
		pg.vertex(dist, -thicknessHalf, 0, texOffset + dist, 0);
		pg.vertex(dist, thicknessHalf, 0, texOffset + dist, texture.height);
		pg.vertex(0, thicknessHalf, 0, texOffset, texture.height);
	} else {
		// diamond shape, left/center, clockwise to right/center
		pg.vertex(0, 0, 0, 									texOffset, textureHeightHalf);
		pg.vertex(cornerRadius, -thicknessHalf, 0, 			texOffset + cornerRadius, 0);
		pg.vertex(dist - cornerRadius, -thicknessHalf, 0, 	texOffset + dist - cornerRadius, 0);
		// right/center, clockwise to left/center
		pg.vertex(dist, 0, 0, 								texOffset + dist, textureHeightHalf);
		pg.vertex(dist - cornerRadius, thicknessHalf, 0, 	texOffset + dist - cornerRadius, texture.height);
		pg.vertex(cornerRadius, thicknessHalf, 0, 			texOffset + cornerRadius, texture.height);
	}
	pg.endShape();
	pg.noTint();
	pg.pop();
}
 
Example 14
Source File: QuadSurface.java    From sketch-mapper with MIT License 4 votes vote down vote up
/**
     * Actual rendering of the QUAD. Is called from the render method. Should
     * normally not be accessed directly.
     *
     * @param g
     * @param tex
     */
    private void renderQuad(PGraphics g, PImage tex) {

        tOffX = tex.width * textureWindow[0].x;
        tOffY = tex.height * textureWindow[0].y;
        tWidth = tex.width * (textureWindow[1].x);
        tHeight = tex.height * (textureWindow[1].y);


        if (this.isUsingEdgeBlend() || this.isUsingSurfaceMask()) {
//
//            if (bufferScreen == null || bufferScreen.width != this.getBufferScreenWidth()) {
//                bufferScreen = parent.createGraphics(this.getBufferScreenWidth(), this.getBufferScreenWidth());
//            }
//            bufferScreen.beginDraw();
//            bufferScreen.beginShape(PApplet.QUADS);
//            bufferScreen.texture(tex);
//            bufferScreen.vertex(0, 0, tOffX, tOffY);
//            bufferScreen.vertex(bufferScreen.width, 0, tWidth + tOffX, tOffY);
//            bufferScreen.vertex(bufferScreen.width, bufferScreen.height, tWidth + tOffX, tHeight + tOffY);
//            bufferScreen.vertex(0, bufferScreen.height, tOffX, tHeight + tOffY);
//            bufferScreen.endShape(PApplet.CLOSE);
//            bufferScreen.endDraw();
//
//
//            if (this.isUsingSurfaceMask()) {
////				maskFilter.setParameterValue("mask_factor", 0.0f);
////				maskFilter.apply(new GLTexture[]{bufferScreen.getTexture(), surfaceMask}, maskedTex);
////				applyEdgeBlendToTexture(maskedTex);
//            } else {
//                applyEdgeBlendToTexture(bufferScreen.get());
//            }
        }

        g.beginDraw();
        g.noStroke();
        g.beginShape(PApplet.QUADS);
        g.texture(tex);

        if (this.isUsingSurfaceMask() || this.isUsingEdgeBlend()) {
            g.texture(maskedTex);
            tOffX = 0;
            tOffY = 0;
            tWidth = maskedTex.width;
            tHeight = maskedTex.height;
        } else {
            g.texture(tex);
            if (bufferScreen != null) {
                bufferScreen = null;
            }
            if (blendScreen != null) {
                blendScreen = null;
            }
        }

        for (int i = 0; i < GRID_RESOLUTION - 1; i++) {
            for (int j = 0; j < GRID_RESOLUTION - 1; j++) {

                g.vertex(vertexPoints[i][j].x,
                        vertexPoints[i][j].y,
                        vertexPoints[i][j].z + currentZ,
                        ((float) i / (GRID_RESOLUTION - 1)) * tWidth + tOffX,
                        ((float) j / (GRID_RESOLUTION - 1)) * tHeight + tOffY);

                g.vertex(vertexPoints[i + 1][j].x,
                        vertexPoints[i + 1][j].y,
                        vertexPoints[i + 1][j].z + currentZ,
                        (((float) i + 1) / (GRID_RESOLUTION - 1)) * tWidth + tOffX,
                        ((float) j / (GRID_RESOLUTION - 1)) * tHeight + tOffY);

                g.vertex(vertexPoints[i + 1][j + 1].x,
                        vertexPoints[i + 1][j + 1].y,
                        vertexPoints[i + 1][j + 1].z + currentZ,
                        (((float) i + 1) / (GRID_RESOLUTION - 1)) * tWidth + tOffX,
                        (((float) j + 1) / (GRID_RESOLUTION - 1)) * tHeight + tOffY);

                g.vertex(vertexPoints[i][j + 1].x,
                        vertexPoints[i][j + 1].y,
                        vertexPoints[i][j + 1].z + currentZ,
                        ((float) i / (GRID_RESOLUTION - 1)) * tWidth + tOffX,
                        (((float) j + 1) / (GRID_RESOLUTION - 1)) * tHeight + tOffY);

            }
        }
        g.endShape(PApplet.CLOSE);
        g.endDraw();
    }
 
Example 15
Source File: MappedTriangle.java    From haxademic with MIT License 4 votes vote down vote up
public void draw( PGraphics pg ) {
		if( _texture != null ) {
			updateVertices();
			if( _mappingStyle == MAP_STYLE_CONTAIN_TEXTURE ) {
				pg.beginShape(PConstants.TRIANGLE);
				pg.texture(_texture);
				if( _mappingOrientation == 0 ) {
					setUVCoordinates(0, 0, _texture.width, _texture.height/2, 0, _texture.height);
				} else if( _mappingOrientation == 1 ) {
					setUVCoordinates(0, 0, _texture.width, 0, _texture.width/2, _texture.height);
				} else if( _mappingOrientation == 2 ) {
					setUVCoordinates(0, _texture.height/2, _texture.width, 0, _texture.width, _texture.height);
				} else if( _mappingOrientation == 3 ) {
					setUVCoordinates(0, _texture.height, _texture.width/2, 0, _texture.width, _texture.height);
				}
				pg.vertex(_x1.value(), _y1.value(), getZ(x1, y1), 		_UVx1.value(), _UVy1.value());
				pg.vertex(_x2.value(), _y2.value(), getZ(x2, y2), 		_UVx2.value(), _UVy2.value());
				pg.vertex(_x3.value(), _y3.value(), getZ(x3, y3), 		_UVx3.value(), _UVy3.value());
				pg.endShape();
			} else if( _mappingStyle == MAP_STYLE_MASK ) {
				pg.beginShape(PConstants.TRIANGLE);
				pg.texture(_texture);
				// map the screen coordinates to the texture coordinates
				// crop to fill the mapped area with the current texture
				setUVCoordinates(_maskTriangle[0].x, _maskTriangle[0].y, _maskTriangle[1].x, _maskTriangle[1].y, _maskTriangle[2].x, _maskTriangle[2].y);
				pg.vertex(_x1.value(), _y1.value(), getZ(x1, y1), 		_UVx1.value(), _UVy1.value());
				pg.vertex(_x2.value(), _y2.value(), getZ(x2, y2), 		_UVx2.value(), _UVy2.value());
				pg.vertex(_x3.value(), _y3.value(), getZ(x3, y3), 		_UVx3.value(), _UVy3.value());
				pg.endShape();
			} else if( _mappingStyle == MAP_STYLE_CONTAIN_RANDOM_TEX_AREA ) {
				pg.beginShape(PConstants.TRIANGLE);
				pg.texture(_texture);
				// map the polygon coordinates to the random sampling coordinates
				setUVCoordinates(_randTriangle[0].x, _randTriangle[0].y, _randTriangle[1].x, _randTriangle[1].y, _randTriangle[2].x, _randTriangle[2].y);
				pg.vertex(_x1.value(), _y1.value(), getZ(x1, y1), 		_UVx1.value(), _UVy1.value());
				pg.vertex(_x2.value(), _y2.value(), getZ(x2, y2), 		_UVx2.value(), _UVy2.value());
				pg.vertex(_x3.value(), _y3.value(), getZ(x3, y3), 		_UVx3.value(), _UVy3.value());
				pg.endShape();
			} else if( _mappingStyle == MAP_STYLE_EQ ) {
				_curColor = P.p.lerpColor(_curColor, _color, 0.1f);
				pg.beginShape(PConstants.TRIANGLE);
				pg.fill(pg.color(_curColor, P.constrain( AudioIn.audioFreq(_eqIndex) * 255, 0, 255 )));
				pg.vertex(_x1.value(), _y1.value(), getZ(x1, y1));
				pg.vertex(_x2.value(), _y2.value(), getZ(x2, y2));				
				pg.fill(pg.color(_curColor, P.constrain( AudioIn.audioFreq(_eqIndex) * 100, 0, 190 )));
				pg.vertex(_x3.value(), _y3.value(), getZ(x3, y3));
				pg.endShape();
			}
			
			
			// flash fade overlay
			drawFlashFadeOverlay(pg);
			
			// overlay with gradient, oscillating from white to black over time
			float whiteFade = P.sin(P.p.frameCount / _gradientFadeDivisor); //P.constrain( AudioIn.getEqBand((_eqIndex)) * 200 * _isFlash, 0, 50 );
			pg.noStroke();
			pg.beginShape(PConstants.TRIANGLE);
			pg.fill(255*whiteFade,fakeLightAlpha);
			pg.vertex(_x1.value(), _y1.value(), getZ(x1, y1));
			pg.fill(255*whiteFade,0);
			pg.vertex(_x2.value(), _y2.value(), getZ(x2, y2));				
			pg.vertex(_x3.value(), _y3.value(), getZ(x3, y3));
			pg.endShape();

//			// show debug info
//			pg.fill(255);
//			pg.textSize(20);
//			pg.text(_mappingStyle+"", _centerX, _centerY);
		}
	}
 
Example 16
Source File: TiledTexture.java    From haxademic with MIT License 4 votes vote down vote up
public void draw(PGraphics pg, float drawW, float drawH, boolean drawFromCenter) {
	PG.setTextureRepeat(pg, true);
	float halfDrawW = drawW / 2f;
	float halfDrawH = drawH / 2f;
	float halfSizeX = halfDrawW * sizeX;
	float halfSizeY = halfDrawH * sizeY;
			
	pg.noStroke();
	pg.beginShape();
	pg.textureMode(P.IMAGE);
	pg.texture(texture);
	if(rotation == 0) {
		tlX = uX - halfSizeX;
		tlY = vY - halfSizeY;
		trX = uX + halfSizeX;
		trY = vY - halfSizeY;
		brX = uX + halfSizeX;
		brY = vY + halfSizeY;
		blX = uX - halfSizeX;
		blY = vY + halfSizeY;
	} else {
		float curRot = rotation + P.PI;
		float radius = MathUtil.getDistance(0, 0, halfSizeX, halfSizeY);
		float tlRads = -MathUtil.getRadiansToTarget(uX - halfSizeX, vY - halfSizeY, uX, vY) + curRot;
		float trRads = -MathUtil.getRadiansToTarget(uX + halfSizeX, vY - halfSizeY, uX, vY) + curRot;
		float brRads = -MathUtil.getRadiansToTarget(uX + halfSizeX, vY + halfSizeY, uX, vY) + curRot;
		float blRads = -MathUtil.getRadiansToTarget(uX - halfSizeX, vY + halfSizeY, uX, vY) + curRot;
		tlX = uX + radius * P.cos(tlRads);
		tlY = vY - radius * P.sin(tlRads);
		trX = uX + radius * P.cos(trRads);
		trY = vY - radius * P.sin(trRads);
		brX = uX + radius * P.cos(brRads);
		brY = vY - radius * P.sin(brRads);
		blX = uX + radius * P.cos(blRads);
		blY = vY - radius * P.sin(blRads);
	}
	if(drawFromCenter) {
		pg.vertex(-halfDrawW, -halfDrawH, tlX, tlY);
		pg.vertex( halfDrawW, -halfDrawH, trX, trY);
		pg.vertex( halfDrawW,  halfDrawH, brX, brY);
		pg.vertex(-halfDrawW,  halfDrawH, blX, blY);
	} else {
		pg.vertex(0, 0, 		tlX, tlY);
		pg.vertex(drawW, 0, 	trX, trY);
		pg.vertex(drawW, drawH, brX, brY);
		pg.vertex(0, drawH, 	blX, blY);
	}
	pg.endShape();
}
 
Example 17
Source File: BezierSurface.java    From sketch-mapper with MIT License 4 votes vote down vote up
/**
 * Renders the grid in the surface. (useful in calibration mode)
 *
 * @param g
 */
private void renderGrid(PGraphics g) {
    g.beginDraw();


    g.fill(ccolor);

    g.noStroke();
    for (int i = 0; i < GRID_RESOLUTION; i++) {
        for (int j = 0; j < GRID_RESOLUTION; j++) {

            g.beginShape();
            g.vertex(vertexPoints[i][j].x, vertexPoints[i][j].y);
            g.vertex(vertexPoints[i + 1][j].x, vertexPoints[i + 1][j].y);
            g.vertex(vertexPoints[i + 1][j + 1].x, vertexPoints[i + 1][j + 1].y);
            g.vertex(vertexPoints[i][j + 1].x, vertexPoints[i][j + 1].y);
            g.endShape();

        }
    }

    g.textFont(sm.getIdFont());
    g.fill(255);
    g.textAlign(PApplet.CENTER, PApplet.CENTER);
    g.textSize(20);
    g.text("" + this.getSurfaceName(), (float) (this.getCenter().x), (float) this.getCenter().y);
    if (isLocked) {
        g.textSize(12);
        g.text("Surface locked", (float) this.getCenter().x, (float) this.getCenter().y + 26);
    }
    if (sketch != null) {
        g.textSize(10);
        g.text(sketch.getName(), (float) this.getCenter().x, (float) this.getCenter().y + 40);
    }


    g.noFill();
    g.stroke(BezierSurface.GRID_LINE_COLOR);
    g.strokeWeight(2);
    if (isSelected)
        g.stroke(BezierSurface.GRID_LINE_SELECTED_COLOR);

    if (!isLocked) {
        for (int i = 0; i <= GRID_RESOLUTION; i++) {
            for (int j = 0; j <= GRID_RESOLUTION; j++) {
                g.point(vertexPoints[i][j].x, vertexPoints[i][j].y, vertexPoints[i][j].z);
            }
        }
    }

    if (isSelected) {
        g.strokeWeight(4);
        g.stroke(BezierSurface.GRID_LINE_SELECTED_COLOR);

        //draw the outline here
        for (int i = 0; i < poly.npoints - 1; i++) {
            g.line(poly.xpoints[i], poly.ypoints[i], poly.xpoints[i + 1], poly.ypoints[i + 1]);
            if (i == poly.npoints - 2)
                g.line(poly.xpoints[i + 1], poly.ypoints[i + 1], poly.xpoints[0], poly.ypoints[0]);
        }
    }

    g.strokeWeight(1);
    g.stroke(SELECTED_OUTLINE_INNER_COLOR);
    //draw the outline here
    for (int i = 0; i < poly.npoints - 1; i++) {
        g.line(poly.xpoints[i], poly.ypoints[i], poly.xpoints[i + 1], poly.ypoints[i + 1]);
        if (i == poly.npoints - 2)
            g.line(poly.xpoints[i + 1], poly.ypoints[i + 1], poly.xpoints[0], poly.ypoints[0]);
    }


    if (!isLocked) {
        // Draw the control points.
        for (int i = 0; i < this.cornerPoints.length; i++) {
            this.renderCornerPoint(g, this.cornerPoints[i].x, this.cornerPoints[i].y, (this.activePoint == i), i);

        }

        for (int i = 0; i < this.bezierPoints.length; i++) {
            this.renderBezierPoint(g, this.bezierPoints[i].x, this.bezierPoints[i].y, (this.selectedBezierControl == i), i);
            g.strokeWeight(1);
            g.stroke(255);
            g.line(this.bezierPoints[i].x, this.bezierPoints[i].y, this.cornerPoints[(int) (i / 2)].x, this.cornerPoints[(int) (i / 2)].y);
        }

    }

    g.endDraw();
}
 
Example 18
Source File: Shapes.java    From haxademic with MIT License 4 votes vote down vote up
public static void drawTexturedCube(PGraphics pg, float size, PImage texture) {
	pg.beginShape(P.QUADS);
	pg.texture(texture);

	// BL, BR, TR, TL
	// front
	pg.vertex(-size,  size,  size, 		0, texture.height);
	pg.vertex( size,  size,  size, 		texture.width, texture.height);
	pg.vertex( size, -size,  size,		texture.width, 0);
	pg.vertex(-size, -size,  size,		0, 0);

	// back
	pg.vertex( size,  size, -size, 		0, texture.height);
	pg.vertex(-size,  size, -size, 		texture.width, texture.height);
	pg.vertex(-size, -size, -size,		texture.width, 0);
	pg.vertex( size, -size, -size,		0, 0);

	// left
	pg.vertex(-size,  size, -size, 		0, texture.height);
	pg.vertex(-size,  size,  size, 		texture.width, texture.height);
	pg.vertex(-size, -size,  size,		texture.width, 0);
	pg.vertex(-size, -size, -size,		0, 0);

	// right
	pg.vertex( size,  size,  size, 		0, texture.height);
	pg.vertex( size,  size, -size, 		texture.width, texture.height);
	pg.vertex( size, -size, -size,		texture.width, 0);
	pg.vertex( size, -size,  size,		0, 0);
	
	// floor
	pg.vertex(-size,  size, -size, 		0, 0);
	pg.vertex( size,  size, -size, 		texture.width, 0);
	pg.vertex( size,  size,  size,		texture.width, texture.height);
	pg.vertex(-size,  size,  size,		0, texture.height);

	// ceiling
	pg.vertex(-size, -size, -size, 		0, 0);
	pg.vertex( size, -size, -size, 		texture.width, 0);
	pg.vertex( size, -size,  size,		texture.width, texture.height);
	pg.vertex(-size, -size,  size,		0, texture.height);

	pg.endShape();
}
 
Example 19
Source File: Shapes.java    From haxademic with MIT License 4 votes vote down vote up
public static void drawTexturedCubeInside(PGraphics pg, float w, float h, float d, PImage texture1, PImage texture2, PImage texture3, PImage texture4, PImage floor, PImage ceiling) {
	// front - BR, BL, TL, TR
	pg.beginShape(P.QUAD);
	pg.texture(texture1);
	pg.vertex(-w,  h,  d, 		texture1.width, texture1.height);
	pg.vertex( w,  h,  d, 		0, texture1.height);
	pg.vertex( w, -h,  d,		0, 0);
	pg.vertex(-w, -h,  d,		texture1.width, 0);
	pg.endShape();

	// right
	pg.beginShape(P.QUAD);
	pg.texture(texture4);
	pg.vertex( w,  h,  d, 		texture4.width, texture4.height);
	pg.vertex( w,  h, -d, 		0, texture4.height);
	pg.vertex( w, -h, -d,		0, 0);
	pg.vertex( w, -h,  d,		texture4.width, 0);
	pg.endShape();

	// back
	pg.beginShape(P.QUAD);
	pg.texture(texture3);
	pg.vertex( w,  h, -d, 		texture3.width, texture3.height);
	pg.vertex(-w,  h, -d, 		0, texture3.height);
	pg.vertex(-w, -h, -d,		0, 0);
	pg.vertex( w, -h, -d,		texture3.width, 0);
	pg.endShape();

	// left
	pg.beginShape(P.QUAD);
	pg.texture(texture2);
	pg.vertex(-w,  h, -d, 		texture2.width, texture2.height);
	pg.vertex(-w,  h,  d, 		0, texture2.height);
	pg.vertex(-w, -h,  d,		0, 0);
	pg.vertex(-w, -h, -d,		texture2.width, 0);
	pg.endShape();

	// floor
	pg.beginShape(P.QUAD);
	pg.texture(floor);
	pg.vertex(-w,  h, -d, 		floor.width, floor.height);
	pg.vertex( w,  h, -d, 		0, floor.height);
	pg.vertex( w,  h,  d,		0, 0);
	pg.vertex(-w,  h,  d,		floor.width, 0);
	pg.endShape();

	// ceiling
	pg.beginShape(P.QUAD);
	pg.texture(ceiling);
	pg.vertex(-w, -h, -d, 		ceiling.width, ceiling.height);
	pg.vertex( w, -h, -d, 		0, ceiling.height);
	pg.vertex( w, -h,  d,		0, 0);
	pg.vertex(-w, -h,  d,		ceiling.width, 0);
	pg.endShape();
}
 
Example 20
Source File: KinectRegion.java    From haxademic with MIT License 4 votes vote down vote up
public void update(PGraphics debugGraphics) {
	IDepthCamera depthCamera = DepthCamera.instance().camera;
	
	float depthDivider = 0.3f;
       if(debugGraphics != null) {
       	debugGraphics.beginShape(PShapeTypes.QUADS);
   		debugGraphics.stroke(debugColor);
   		debugGraphics.fill( 255, pixelCount / minPixels * 10f );
       	debugGraphics.vertex(left, bottom, -near * depthDivider);
       	debugGraphics.vertex(right, bottom, -near * depthDivider);
       	debugGraphics.vertex(right, bottom, -far * depthDivider);
       	debugGraphics.vertex(left, bottom, -far * depthDivider);
       	debugGraphics.endShape();
       	debugGraphics.noStroke();
       }
       // find kinect readings in the region
	_isActive = false;
	if( depthCamera != null ) {
		pixelCount = 0;
		float controlXTotal = 0;
		float controlZTotal = 0;
		float pixelDepth = 0;
		for ( int x = left; x < right; x += pixelSkip ) {
			for ( int y = top; y < bottom; y += pixelSkip ) {
				pixelDepth = depthCamera.getDepthAt( x, y );
				if( pixelDepth != 0 && pixelDepth > near && pixelDepth < far ) {
			        if(debugGraphics != null) {
			        	debugGraphics.fill( debugColor, 127 );
			        	debugGraphics.pushMatrix();
			        	debugGraphics.translate(x, y, -pixelDepth * depthDivider);
			        	debugGraphics.box(pixelSkip, pixelSkip, pixelSkip);
			        	debugGraphics.popMatrix();
					}
					// add up for calculations
					pixelCount++;
					controlXTotal += x;
					controlZTotal += pixelDepth;
				}
			}
		}

		// if we have enough blocks in a region, update the player's joystick position
		if( pixelCount > minPixels ) {
			_isActive = true;
			// compute averages
			if( controlXTotal > 0 && controlZTotal > 0 ) {
				float avgX = controlXTotal / pixelCount;
				_controlX = (MathUtil.getPercentWithinRange(left, right, avgX) - 0.5f) * 2f;
				float avgZ = controlZTotal / pixelCount;
				_controlZ = (MathUtil.getPercentWithinRange(near, far, avgZ) - 0.5f) * 2f;

				// show debug
		        if(debugGraphics != null) {
					debugGraphics.fill( 255, 127 );
					debugGraphics.pushMatrix();
					debugGraphics.translate(avgX, bottom - 250, -avgZ * depthDivider);
					debugGraphics.box(20, 500, 20);
					debugGraphics.popMatrix();
				}
			}
		}
	}
}