Java Code Examples for processing.core.PGraphics#texture()
The following examples show how to use
processing.core.PGraphics#texture() .
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: Shapes.java From haxademic with MIT License | 6 votes |
public static void drawDiscTextured(PGraphics pg, float radius, float innerRadius, int numSegments, PImage texture) { pg.pushMatrix(); float segmentRads = P.TWO_PI / numSegments; for( int i = 0; i < numSegments; i++ ) { float curRads = i * segmentRads; float nextRads = (i+1) * segmentRads; float progress = curRads / P.TWO_PI; float progressNext = nextRads / P.TWO_PI; pg.beginShape(P.TRIANGLES); pg.textureMode(P.NORMAL); pg.texture(texture); pg.vertex( P.cos(curRads) * innerRadius, P.sin(curRads) * innerRadius, 0, progress, 1 ); pg.vertex( P.cos(curRads) * radius, P.sin(curRads) * radius, 0, progress, 0 ); pg.vertex( P.cos(nextRads) * radius, P.sin(nextRads) * radius, 0, progressNext, 0 ); pg.vertex( P.cos(curRads) * innerRadius, P.sin(curRads) * innerRadius, 0, progress, 1 ); pg.vertex( P.cos(nextRads) * innerRadius, P.sin(nextRads) * innerRadius, 0, progressNext, 1 ); pg.vertex( P.cos(nextRads) * radius, P.sin(nextRads) * radius, 0, progressNext, 0 ); pg.endShape(); } pg.popMatrix(); }
Example 2
Source File: TiledGrid.java From haxademic with MIT License | 5 votes |
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 3
Source File: DwFoldingTile.java From PixelFlow with MIT License | 5 votes |
public void displayMesh(PGraphics pg, DwIndexedFaceSet ifs){ // pg.beginShape(PConstants.TRIANGLES); pg.textureMode(PConstants.NORMAL); pg.texture(DEF.style.texture); pg.noStroke(); int s0,s1,s2; int i0,i1,i2; float[] t0,t1,t2; float[] v0,v1,v2; for(int i = 0; i < DEF.FACES_COUNT; i++){ i0 = faces[i][0]; v0 = ifs.verts[i0]; i1 = faces[i][1]; v1 = ifs.verts[i1]; i2 = faces[i][2]; v2 = ifs.verts[i2]; i0 = DEF.FACES[i][0]; s0 = DEF.HILO[i0]; t0 = DEF.TEX_COORDS[i0]; i1 = DEF.FACES[i][1]; s1 = DEF.HILO[i1]; t1 = DEF.TEX_COORDS[i1]; i2 = DEF.FACES[i][2]; s2 = DEF.HILO[i2]; t2 = DEF.TEX_COORDS[i2]; int ci = DEF.FACES_COL[i]; if(DEF.style.texture != null){ DwDisplayUtils.vertex(pg, v0, t0); DwDisplayUtils.vertex(pg, v1, t1); DwDisplayUtils.vertex(pg, v2, t2); } else { // pg.fill(DEF.style.COL[s0]); DwDisplayUtils.vertex(pg, v0); // pg.fill(DEF.style.COL[s1]); DwDisplayUtils.vertex(pg, v1); // pg.fill(DEF.style.COL[s2]); DwDisplayUtils.vertex(pg, v2); pg.fill(DEF.style.RGBS[ci][s0]); DwDisplayUtils.vertex(pg, v0); pg.fill(DEF.style.RGBS[ci][s1]); DwDisplayUtils.vertex(pg, v1); pg.fill(DEF.style.RGBS[ci][s2]); DwDisplayUtils.vertex(pg, v2); } } // pg.endShape(); }
Example 4
Source File: Shapes.java From haxademic with MIT License | 5 votes |
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 5
Source File: Shapes.java From haxademic with MIT License | 5 votes |
public static void drawTexturedRect(PGraphics pg, PImage texture) { pg.beginShape(P.QUAD); pg.textureMode(P.NORMAL); pg.texture(texture); pg.vertex(-texture.width/2, -texture.height/2, 0, 0); pg.vertex( texture.width/2, -texture.height/2, 1, 0); pg.vertex( texture.width/2, texture.height/2, 1, 1); pg.vertex(-texture.width/2, texture.height/2, 0, 1); pg.endShape(); }
Example 6
Source File: TexturePoly.java From haxademic with MIT License | 5 votes |
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 7
Source File: DwFoldingTile.java From PixelFlow with MIT License | 5 votes |
public void displayMesh(PGraphics pg, DwParticle3D[] particles){ // pg.beginShape(PConstants.TRIANGLES); pg.textureMode(PConstants.NORMAL); pg.texture(DEF.style.texture); pg.noStroke(); int s0,s1,s2; int i0,i1,i2; float[] t0,t1,t2; DwParticle3D v0,v1,v2; for(int i = 0; i < DEF.FACES_COUNT; i++){ i0 = faces[i][0]; v0 = particles[i0]; if(v0.all_springs_deactivated) continue; i1 = faces[i][1]; v1 = particles[i1]; if(v1.all_springs_deactivated) continue; i2 = faces[i][2]; v2 = particles[i2]; if(v2.all_springs_deactivated) continue; i0 = DEF.FACES[i][0]; s0 = DEF.HILO[i0]; t0 = DEF.TEX_COORDS[i0]; i1 = DEF.FACES[i][1]; s1 = DEF.HILO[i1]; t1 = DEF.TEX_COORDS[i1]; i2 = DEF.FACES[i][2]; s2 = DEF.HILO[i2]; t2 = DEF.TEX_COORDS[i2]; int ci = DEF.FACES_COL[i]; if(DEF.style.texture != null){ DwDisplayUtils.vertex(pg, v0, t0); DwDisplayUtils.vertex(pg, v1, t1); DwDisplayUtils.vertex(pg, v2, t2); } else { // pg.fill(DEF.style.COL[s0]); DwDisplayUtils.vertex(pg, v0); // pg.fill(DEF.style.COL[s1]); DwDisplayUtils.vertex(pg, v1); // pg.fill(DEF.style.COL[s2]); DwDisplayUtils.vertex(pg, v2); pg.fill(DEF.style.RGBS[ci][s0]); DwDisplayUtils.vertex(pg, v0); pg.fill(DEF.style.RGBS[ci][s1]); DwDisplayUtils.vertex(pg, v1); pg.fill(DEF.style.RGBS[ci][s2]); DwDisplayUtils.vertex(pg, v2); } } // pg.endShape(); }
Example 8
Source File: MappedQuad.java From haxademic with MIT License | 4 votes |
public void draw( PGraphics pg ) { if( _texture != null ) { if( _mappingStyle == MAP_STYLE_CONTAIN_TEXTURE ) { if( _mappingOrientation == 0 ) { pg.beginShape(PConstants.QUAD); pg.texture(_texture); pg.vertex(x1, y1, 0, 0, 0); pg.vertex(x2, y2, 0, _texture.width, 0); pg.vertex(x3, y3, 0, _texture.width, _texture.height); pg.vertex(x4, y4, 0, 0, _texture.height); pg.endShape(); } 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 if( _mappingStyle == MAP_STYLE_MASK ) { pg.beginShape(PConstants.QUAD); pg.texture(_texture); // map the screen coordinates to the texture coordinates // crop to fill the mapped area with the current texture pg.vertex(x1, y1, 0, _maskRect[0].x, _maskRect[0].y); pg.vertex(x2, y2, 0, _maskRect[1].x, _maskRect[1].y); pg.vertex(x3, y3, 0, _maskRect[2].x, _maskRect[2].y); pg.vertex(x4, y4, 0, _maskRect[3].x, _maskRect[3].y); pg.endShape(); } else if( _mappingStyle == MAP_STYLE_CONTAIN_RANDOM_TEX_AREA ) { pg.beginShape(PConstants.QUAD); pg.texture(_texture); // map the polygon coordinates to the random sampling coordinates pg.vertex(x1, y1, 0, _randRect.x, _randRect.y); pg.vertex(x2, y2, 0, _randRect.x + _randRect.width, _randRect.y); pg.vertex(x3, y3, 0, _randRect.x + _randRect.width, _randRect.y + _randRect.height); pg.vertex(x4, y4, 0, _randRect.x, _randRect.y + _randRect.height); pg.endShape(); } else if( _mappingStyle == MAP_STYLE_EQ ) { pg.beginShape(PConstants.QUAD); pg.fill(pg.color(_color, P.constrain( AudioIn.audioFreq(_eqIndex) * 255, 0, 255 ))); pg.vertex(x1, y1, 0); pg.vertex(x2, y2, 0); pg.vertex(x3, y3, 0); pg.fill(pg.color(_color, P.constrain( AudioIn.audioFreq(_eqIndex) * 100, 0, 190 ))); pg.vertex(x4, y4, 0); 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.QUAD); pg.fill(255*whiteFade,fakeLightAlpha); pg.vertex(x2, y2, 0); pg.vertex(x3, y3, 0); pg.fill(255*whiteFade,0); pg.vertex(x4, y4, 0); pg.vertex(x1, y1, 0); pg.endShape(); } // show debug info // pg.fill(255); // pg.textSize(20); // pg.text(_mappingStyle+"", _centerX, _centerY); }
Example 9
Source File: MappedTriangle.java From haxademic with MIT License | 4 votes |
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 10
Source File: Demo_TexturedStrips.java From haxademic with MIT License | 4 votes |
protected void update(PGraphics pg) { // update props easedSpeed.update(true); // update location pos.add(P.cos(easedDir.value()) * easedSpeed.value(), P.sin(easedDir.value()) * easedSpeed.value()); tail[0].set(pos); // copy to top tail if(tailEnd.x < -BORDER || tailEnd.x > pg.width + BORDER || tailEnd.y < -BORDER || tailEnd.y > pg.height + BORDER) reset(); // get pixel color int pixelColor = ImageUtil.getPixelColor(bwMap, (int) pos.x, (int) pos.y); float r = ColorUtil.redFromColorInt(pixelColor) / 255f; if(r < 0.1f && onBlack == false) { // on black! onBlack = true; float turnRads = P.PI * MathUtil.randRangeDecimal(0.9f, 1.1f); if(MathUtil.randBoolean() == true) turnRads *= -1f; easedDir.setTarget(easedDir.target() +turnRads); tailLerp.setTarget(TAIL_LERP_BLACK); resetSpeed(); } else if(r >= 0.1f && onBlack == true) { // on white! onBlack = false; easedSpeed.setTarget(SPEED_SLOW); tailLerp.setTarget(TAIL_LERP_SLOW); } // update extra params after updating position easedDir.update(true); tailLerp.update(true); // copy up tail for (int i = tail.length - 2; i >= 0; i--) { tail[i+1].lerp(tail[i], tailLerp.value()); } // draw tail! // pg.point(pos.x, pos.y, pos.z); pg.fill(255); pg.noStroke(); pg.beginShape(P.QUADS); pg.texture(texture); float textureY = 0; float segmentDir = easedDir.value(); for (int i = 0; i < tail.length - 2; i++) { // get rect points float leftXCur = tail[i].x + TAIL_W * P.cos(segmentDir - P.HALF_PI); float leftYCur = tail[i].y + TAIL_W * P.sin(segmentDir - P.HALF_PI); float rightXCur = tail[i].x + TAIL_W * P.cos(segmentDir + P.HALF_PI); float rightYCur = tail[i].y + TAIL_W * P.sin(segmentDir + P.HALF_PI); segmentDir = MathUtil.getRadiansToTarget(tail[i+1].x, tail[i+1].y, tail[i].x, tail[i].y); float leftXNext = tail[i+1].x + TAIL_W * P.cos(segmentDir - P.HALF_PI); float leftYNext = tail[i+1].y + TAIL_W * P.sin(segmentDir - P.HALF_PI); float rightXNext = tail[i+1].x + TAIL_W * P.cos(segmentDir + P.HALF_PI); float rightYNext = tail[i+1].y + TAIL_W * P.sin(segmentDir + P.HALF_PI); pg.vertex(leftXCur, leftYCur, 0, textureY); pg.vertex(rightXCur, rightYCur, texture.width, textureY); textureY += (float) texture.height / (float) tail.length; pg.vertex(rightXNext, rightYNext, texture.width, textureY); pg.vertex(leftXNext, leftYNext, 0, textureY); // old test draw // pg.line(leftXCur, leftYCur, rightXCur, rightYCur); // pg.line(tail[i].x, tail[i].y, tail[i].z, tail[i+1].x, tail[i+1].y, tail[i+1].z); } pg.endShape(); }
Example 11
Source File: Shapes.java From haxademic with MIT License | 4 votes |
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 12
Source File: Shapes.java From haxademic with MIT License | 4 votes |
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 13
Source File: BezierSurface.java From sketch-mapper with MIT License | 4 votes |
/** * Actual rendering of the surface. Is called from the render method. * Should normally not be accessed directly. * * @param g * @param tex */ private void renderSurface(PGraphics g, PImage tex) { float tWidth = 1; float tHeight = 1; float tOffX = 0; float tOffY = 0; tWidth = tex.width * (textureWindow[1].x); tHeight = tex.height * (textureWindow[1].y); tOffX = tex.width * textureWindow[0].x; tOffY = tex.height * textureWindow[0].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); 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; } for (int i = 0; i < GRID_RESOLUTION; i++) { for (int j = 0; j < GRID_RESOLUTION; j++) { g.vertex(vertexPoints[i][j].x, vertexPoints[i][j].y, vertexPoints[i][j].z + currentZ, ((float) i / GRID_RESOLUTION) * tWidth + tOffX, ((float) j / GRID_RESOLUTION) * 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) * tWidth + tOffX, ((float) j / GRID_RESOLUTION) * 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) * tWidth + tOffX, (((float) j + 1) / GRID_RESOLUTION) * tHeight + tOffY); g.vertex(vertexPoints[i][j + 1].x, vertexPoints[i][j + 1].y, vertexPoints[i][j + 1].z + currentZ, ((float) i / GRID_RESOLUTION) * tWidth + tOffX, (((float) j + 1) / GRID_RESOLUTION) * tHeight + tOffY); } } g.endShape(PApplet.CLOSE); g.endDraw(); }
Example 14
Source File: Shapes.java From haxademic with MIT License | 4 votes |
public static void textureQuadSubdivided(PGraphics pg, PImage texture, int subDivideSteps, float x1, float y1, float z1, float u1, float v1, float x2, float y2, float z2, float u2, float v2, float x3, float y3, float z3, float u3, float v3, float x4, float y4, float z4, float u4, float v4 ) { pg.beginShape(P.QUAD); pg.textureMode(PConstants.NORMAL); pg.texture(texture); // subdivide quad for better resolution // vertices go top-left, clockwise to bottom left float stepsX = subDivideSteps; float segmentX = 1f / subDivideSteps; float stepsY = subDivideSteps; float segmentY = 1f / stepsY; // draw a subdivided grid for( float x=0; x < stepsX; x++ ) { // calculate spread of mesh grid and uv coordinates float xNorm = x * segmentX; float xNormNext = (x+1) * segmentX; for( float y=0; y < stepsY; y++ ) { // calculate grid cells' uv coordinates float yNorm = y * segmentY; float yNormNext = (y+1) * segmentY; // calc grid positions based on interpolating columns between corners // we only need the xProgress for this, since we're slicing by column float colTopX = P.lerp(x1, x2, xNorm); float colTopY = P.lerp(y1, y2, xNorm); float colTopZ = P.lerp(z1, z2, xNorm); float colTopU = P.lerp(u1, u2, xNorm); float colTopV = P.lerp(v1, v2, xNorm); float colBotX = P.lerp(x4, x3, xNorm); float colBotY = P.lerp(y4, y3, xNorm); float colBotZ = P.lerp(z4, z3, xNorm); float colBotU = P.lerp(u4, u3, xNorm); float colBotV = P.lerp(v4, v3, xNorm); float nextColTopX = P.lerp(x1, x2, xNormNext); float nextColTopY = P.lerp(y1, y2, xNormNext); float nextColTopZ = P.lerp(z1, z2, xNormNext); float nextColTopU = P.lerp(u1, u2, xNormNext); float nextColTopV = P.lerp(v1, v2, xNormNext); float nextColBotX = P.lerp(x4, x3, xNormNext); float nextColBotY = P.lerp(y4, y3, xNormNext); float nextColBotZ = P.lerp(z4, z3, xNormNext); float nextColBotU = P.lerp(u4, u3, xNormNext); float nextColBotV = P.lerp(v4, v3, xNormNext); // calc quad coords float quadTopLeftX = P.lerp(colTopX, colBotX, yNorm); float quadTopLeftY = P.lerp(colTopY, colBotY, yNorm); float quadTopLeftZ = P.lerp(colTopZ, colBotZ, yNorm); float quadTopLeftU = P.lerp(colTopU, colBotU, yNorm); float quadTopLeftV = P.lerp(colTopV, colBotV, yNorm); float quadTopRightX = P.lerp(nextColTopX, nextColBotX, yNorm); float quadTopRightY = P.lerp(nextColTopY, nextColBotY, yNorm); float quadTopRightZ = P.lerp(nextColTopZ, nextColBotZ, yNorm); float quadTopRightU = P.lerp(nextColTopU, nextColBotU, yNorm); float quadTopRightV = P.lerp(nextColTopV, nextColBotV, yNorm); float quadBotRightX = P.lerp(nextColTopX, nextColBotX, yNormNext); float quadBotRightY = P.lerp(nextColTopY, nextColBotY, yNormNext); float quadBotRightZ = P.lerp(nextColTopZ, nextColBotZ, yNormNext); float quadBotRightU = P.lerp(nextColTopU, nextColBotU, yNormNext); float quadBotRightV = P.lerp(nextColTopV, nextColBotV, yNormNext); float quadBotLeftX = P.lerp(colTopX, colBotX, yNormNext); float quadBotLeftY = P.lerp(colTopY, colBotY, yNormNext); float quadBotLeftZ = P.lerp(colTopZ, colBotZ, yNormNext); float quadBotLeftU = P.lerp(colTopU, colBotU, yNormNext); float quadBotLeftV = P.lerp(colTopV, colBotV, yNormNext); // draw subdivided quads pg.vertex(quadTopLeftX, quadTopLeftY, quadTopLeftZ, quadTopLeftU, quadTopLeftV); pg.vertex(quadTopRightX, quadTopRightY, quadTopRightZ, quadTopRightU, quadTopRightV); pg.vertex(quadBotRightX, quadBotRightY, quadBotRightZ, quadBotRightU, quadBotRightV); pg.vertex(quadBotLeftX, quadBotLeftY, quadBotLeftZ, quadBotLeftU, quadBotLeftV); } } pg.endShape(P.CLOSE); }
Example 15
Source File: QuadSurface.java From sketch-mapper with MIT License | 4 votes |
/** * 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 16
Source File: ImageUtil.java From haxademic with MIT License | 4 votes |
public static void drawTextureMappedRect(PGraphics dest, PImage texture, int subdivideX, int subdivideY, float topLeftX, float topLeftY, float topRightX, float topRightY, float bottomRightX, float bottomRightY, float bottomLeftX, float bottomLeftY) { // draw to screen with pinned corner coords // generalized version ported from PGraphicsKeystone // inspired by: https://github.com/davidbouchard/keystone & http://marcinignac.com/blog/projectedquads-source-code/ dest.textureMode(PConstants.IMAGE); dest.noStroke(); dest.fill(255); dest.beginShape(PConstants.QUAD); dest.texture(texture); if(subdivideX > 0) { // subdivide quad for better resolution float stepsX = subdivideX; float stepsY = subdivideY; for( float x=0; x < stepsX; x += 1f ) { // calculate spread of mesh grid and uv coordinates float xPercent = x/stepsX; float xPercentNext = (x+1f)/stepsX; if( xPercentNext > 1 ) xPercentNext = 1; float uPercent = xPercent; float uPercentNext = xPercentNext; for( float y=0; y < stepsY; y += 1f ) { // calculate spread of mesh grid and uv coordinates float yPercent = y/stepsY; float yPercentNext = (y+1f)/stepsY; if( yPercentNext > 1 ) yPercentNext = 1; float vPercent = yPercent; float vPercentNext = yPercentNext; // calc grid positions based on interpolating columns between corners float colTopX = interp(topLeftX, topRightX, xPercent); float colTopY = interp(topLeftY, topRightY, xPercent); float colBotX = interp(bottomLeftX, bottomRightX, xPercent); float colBotY = interp(bottomLeftY, bottomRightY, xPercent); float nextColTopX = interp(topLeftX, topRightX, xPercentNext); float nextColTopY = interp(topLeftY, topRightY, xPercentNext); float nextColBotX = interp(bottomLeftX, bottomRightX, xPercentNext); float nextColBotY = interp(bottomLeftY, bottomRightY, xPercentNext); // calc quad coords float quadTopLeftX = interp(colTopX, colBotX, yPercent); float quadTopLeftY = interp(colTopY, colBotY, yPercent); float quadTopRightX = interp(nextColTopX, nextColBotX, yPercent); float quadTopRightY = interp(nextColTopY, nextColBotY, yPercent); float quadBotRightX = interp(nextColTopX, nextColBotX, yPercentNext); float quadBotRightY = interp(nextColTopY, nextColBotY, yPercentNext); float quadBotLeftX = interp(colTopX, colBotX, yPercentNext); float quadBotLeftY = interp(colTopY, colBotY, yPercentNext); // draw subdivided quads dest.vertex(quadTopLeftX, quadTopLeftY, 0, texture.width * uPercent, texture.height * vPercent); dest.vertex(quadTopRightX, quadTopRightY, 0, texture.width * uPercentNext, texture.height * vPercent); dest.vertex(quadBotRightX, quadBotRightY, 0, texture.width * uPercentNext, texture.height * vPercentNext); dest.vertex(quadBotLeftX, quadBotLeftY, 0, texture.width * uPercent, texture.height * vPercentNext); } } } else { // default single mapped quad dest.vertex(topLeftX, topLeftY, 0, 0, 0); dest.vertex(topRightX, topRightY, 0, texture.width, 0); dest.vertex(bottomRightX, bottomRightY, 0, texture.width, texture.height); dest.vertex(bottomLeftX, bottomLeftY, 0, 0, texture.height); } dest.endShape(); }
Example 17
Source File: TiledTexture.java From haxademic with MIT License | 4 votes |
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(); }