-
Notifications
You must be signed in to change notification settings - Fork 7
/
SketchCubicle.java
executable file
·183 lines (153 loc) · 6.41 KB
/
SketchCubicle.java
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package de.hfkbremen.algorithmiccliches.examples;
import processing.core.PApplet;
import processing.core.PVector;
import teilchen.cubicle.CubicleWorld;
import teilchen.cubicle.ICubicleEntity;
import teilchen.util.CubicleWorldView;
import java.util.ArrayList;
public class SketchCubicle extends PApplet {
private static final int NUMBER_OF_PARTICLES_ADDED = 100;
private static final int WORLD_NUMBER_OF_CUBICLES_X = 1024 / 64;
private static final int WORLD_NUMBER_OF_CUBICLES_Y = 768 / 64;
private static final int WORLD_NUMBER_OF_CUBICLES_Z = 768 / 64;
private static final float WORLD_CUBICLE_SCALE = 32;
private final PVector mPosition = new PVector();
private boolean showCubicles = true;
private float mRotationZ = 0.1f;
private int numParticles = 1;
private CubicleWorld mCubicleWorld;
private CubicleWorldView mCubicleWorldView;
public void settings() {
size(1024, 768, P3D);
}
public void setup() {
textFont(createFont("Courier", 11));
hint(DISABLE_DEPTH_SORT);
hint(DISABLE_DEPTH_TEST);
/* setup world */
mCubicleWorld = new CubicleWorld(WORLD_NUMBER_OF_CUBICLES_X,
WORLD_NUMBER_OF_CUBICLES_Y,
WORLD_NUMBER_OF_CUBICLES_Z);
mCubicleWorld.cellscale().set(WORLD_CUBICLE_SCALE, WORLD_CUBICLE_SCALE, WORLD_CUBICLE_SCALE);
mCubicleWorld.transform().translation.set(-WORLD_NUMBER_OF_CUBICLES_X * mCubicleWorld.cellscale().x / 2,
-WORLD_NUMBER_OF_CUBICLES_Y * mCubicleWorld.cellscale().y / 2,
-WORLD_NUMBER_OF_CUBICLES_Z * mCubicleWorld.cellscale().z / 2);
mCubicleWorldView = new CubicleWorldView(mCubicleWorld);
mCubicleWorldView.color_empty = color(0, 1);
mCubicleWorldView.color_full = color(0, 4);
mCubicleWorld.add(new MCubicleEntity());
}
public void draw() {
/* get entities from cubicle world */
mCubicleWorld.update();
ArrayList<ICubicleEntity> mEntities = mCubicleWorld.getLocalEntities(mPosition, 1);
background(255);
pushMatrix();
translate(width / 2.0f, height / 2.0f, 0);
/* rotate */
if (mousePressed) {
mRotationZ += (mouseX * 0.01f - mRotationZ) * 0.05f;
} else {
mPosition.x = mouseX - width / 2.0f;
mPosition.y = mouseY - height / 2.0f;
}
rotateX(THIRD_PI);
rotateZ(mRotationZ);
/* draw cubicle world */
if (showCubicles) {
strokeWeight(0.05f);
stroke(0, 127);
noFill();
mCubicleWorldView.draw(g);
strokeWeight(1.0f);
}
/* draw entities */
int mNumberOfPointsSelected = 0;
stroke(0, 127, 255, 127);
noFill();
if (mEntities != null) {
mNumberOfPointsSelected = mEntities.size();
for (ICubicleEntity mEntity : mEntities) {
MCubicleEntity m = (MCubicleEntity) mEntity;
stroke(m.entity_color);
drawCross(mEntity.position(), 5.0f);
}
}
/* draw crosshair */
stroke(255, 0, 0, 63);
noFill();
beginShape(LINES);
vertex(mPosition.x, -WORLD_CUBICLE_SCALE * WORLD_NUMBER_OF_CUBICLES_Y / 2, 0);
vertex(mPosition.x, WORLD_CUBICLE_SCALE * WORLD_NUMBER_OF_CUBICLES_Y / 2, 0);
vertex(-WORLD_CUBICLE_SCALE * WORLD_NUMBER_OF_CUBICLES_Y / 2, mPosition.y, 0);
vertex(WORLD_CUBICLE_SCALE * WORLD_NUMBER_OF_CUBICLES_Y / 2, mPosition.y, 0);
endShape();
/* draw selection sphere */
stroke(255, 0, 0, 63);
noFill();
translate(mPosition.x, mPosition.y, 0);
box(WORLD_CUBICLE_SCALE);
popMatrix();
fill(0);
noStroke();
text("POINTS : " + numParticles, 10, 12);
text("SELECTED : " + mNumberOfPointsSelected, 10, 24);
text("FPS : " + frameRate, 10, 36);
}
public void keyPressed() {
switch (key) {
case ' ':
for (int i = 0; i < NUMBER_OF_PARTICLES_ADDED; i++) {
MCubicleEntity mEntity = new MCubicleEntity();
mEntity.position().x = random(-WORLD_CUBICLE_SCALE * WORLD_NUMBER_OF_CUBICLES_X / 2,
WORLD_CUBICLE_SCALE * WORLD_NUMBER_OF_CUBICLES_X / 2);
mEntity.position().y = random(-WORLD_CUBICLE_SCALE * WORLD_NUMBER_OF_CUBICLES_Y / 2,
WORLD_CUBICLE_SCALE * WORLD_NUMBER_OF_CUBICLES_Y / 2);
mEntity.position().z = random(-WORLD_CUBICLE_SCALE * WORLD_NUMBER_OF_CUBICLES_Z / 2,
WORLD_CUBICLE_SCALE * WORLD_NUMBER_OF_CUBICLES_Z / 2);
mCubicleWorld.add(mEntity);
}
numParticles += NUMBER_OF_PARTICLES_ADDED;
break;
case 'o':
showCubicles = !showCubicles;
break;
case 'c':
mCubicleWorld.removeAll();
numParticles = 0;
break;
default:
break;
}
}
private void drawCross(PVector v, float pRadius) {
line(v.x - pRadius, v.y, v.z, v.x + pRadius, v.y, v.z);
line(v.x, v.y - pRadius, v.z, v.x, v.y + pRadius, v.z);
line(v.x, v.y, v.z - pRadius, v.x, v.y, v.z + pRadius);
}
class MCubicleEntity
implements ICubicleEntity {
private final teilchen.util.Vector3i mCubicalPosition;
private final PVector mPosition;
int entity_color = color(0, 127, random(0, 255), 127);
public MCubicleEntity() {
mCubicalPosition = new teilchen.util.Vector3i();
mPosition = new PVector();
}
public teilchen.util.Vector3i cubicle() {
return mCubicalPosition;
}
public PVector position() {
return mPosition;
}
public boolean leaving(int theX, int theY, int theZ) {
return theX != cubicle().x || theY != cubicle().y || theZ != cubicle().z;
}
public boolean isActive() {
return true;
}
}
public static void main(String[] args) {
PApplet.main(new String[]{SketchCubicle.class.getName()});
}
}