class Block { private int id; private PVector position; private PVector rotation; float scale; public Block(int id, float x, float y, float z) { this.id = id; this.position = new PVector(x, y, z); this.rotation = new PVector(0, 0, 0); this.scale = 1; } public void rotate(float deltaX, float deltaY) { this.rotation.x += deltaX; this.rotation.y += deltaY; } public void zoom(float delta) { this.scale += delta; } public void draw() { pushMatrix(); translate(position.x, position.y, position.z); rotateX(this.rotation.x); rotateY(this.rotation.y); scale(this.scale); beginShape(QUADS); texture(blockTextures.get(this.id)); // Given one texture and six faces, we can easily set up the uv coordinates // such that four of the faces tile "perfectly" along either u or v, but the other // two faces cannot be so aligned. This code tiles "along" u, "around" the X/Z faces // and fudges the Y faces - the Y faces are arbitrarily aligned such that a // rotation along the X axis will put the "top" of either texture at the "top" // of the screen, but is not otherwised aligned with the X/Z faces. (This // just affects what type of symmetry is required if you need seamless // tiling all the way around the cube) // +Z "front" face vertex(-1, -1, 1, 0, 0); vertex( 1, -1, 1, 1, 0); vertex( 1, 1, 1, 1, 1); vertex(-1, 1, 1, 0, 1); // -Z "back" face vertex( 1, -1, -1, 0, 0); vertex(-1, -1, -1, 1, 0); vertex(-1, 1, -1, 1, 1); vertex( 1, 1, -1, 0, 1); // +Y "bottom" face vertex(-1, 1, 1, 0, 0); vertex( 1, 1, 1, 1, 0); vertex( 1, 1, -1, 1, 1); vertex(-1, 1, -1, 0, 1); // -Y "top" face vertex(-1, -1, -1, 0, 0); vertex( 1, -1, -1, 1, 0); vertex( 1, -1, 1, 1, 1); vertex(-1, -1, 1, 0, 1); // +X "right" face vertex( 1, -1, 1, 0, 0); vertex( 1, -1, -1, 1, 0); vertex( 1, 1, -1, 1, 1); vertex( 1, 1, 1, 0, 1); // -X "left" face vertex(-1, -1, -1, 0, 0); vertex(-1, -1, 1, 1, 0); vertex(-1, 1, 1, 1, 1); vertex(-1, 1, -1, 0, 1); endShape(); popMatrix(); } }