-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeetskincube.pde
91 lines (77 loc) · 2.27 KB
/
beetskincube.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* Texture Cube
* by Dave Bollinger.
*
* Drag mouse to rotate cube. Demonstrates use of u/v coords in
* vertex() and effect on texture(). The textures get distorted using
* the P3D renderer as you can see, but they look great using OPENGL.
*/
// The next line is needed if running in JavaScript Mode with Processing.js
/* @pjs preload="berlin-1.jpg"; */
PImage tex;
float rotx = PI/4;
float roty = PI/4;
void setup() {
size(640, 360, P3D);
tex = loadImage("beetskin1.jpg");
textureMode(NORMAL);
fill(255);
stroke(color(44,48,32));
}
void draw() {
background(0);
noStroke();
translate(width/2.5, height/2.0, -100);
rotateX(rotx);
rotateY(roty);
scale(30);
TexturedCube(tex);
}
void TexturedCube(PImage tex) {
beginShape(QUADS);
texture(tex);
// 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, 2, 0, 0);
vertex( 1, -1, 2, 1, 0);
vertex( 1, 1, 2, 1, 1);
vertex(-1, 1, 2, 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, 2, 0, 0);
vertex( 1, 1, 2, 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, 2, 1, 1);
vertex(-1, -1, 2, 0, 1);
// +X "right" face
vertex( 1, -1, 2, 0, 0);
vertex( 1, -1, -1, 1, 0);
vertex( 1, 1, -1, 1, 1);
vertex( 1, 1, 2, 0, 1);
// -X "left" face
vertex(-1, -1, -1, 0, 0);
vertex(-1, -1, 2, 1, 0);
vertex(-1, 1, 2, 1, 1);
vertex(-1, 1, -1, 0, 1);
endShape();
}
void mouseDragged() {
float rate = 0.01;
rotx += (pmouseY-mouseY) * rate;
roty += (mouseX-pmouseX) * rate;
}