-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSuperliminal.java
More file actions
211 lines (192 loc) · 5.17 KB
/
Superliminal.java
File metadata and controls
211 lines (192 loc) · 5.17 KB
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import nub.core.Graph;
import nub.core.Node;
import nub.primitives.Vector;
import nub.processing.Scene;
import processing.core.PApplet;
import processing.event.MouseEvent;
/**
* Superliminal (https://t.ly/_brt) gameplay
* implemented from graph sceneToPixelRatio method
*/
public class Superliminal extends PApplet {
Scene scene, lateralView, focus;
Node[] cubes;
boolean displayLateralView;
// whilst scene1 is either on-screen or not; scene2 and scene3 are off-screen
// test both cases here
boolean onScreen = false;
int w = 1920;
int h = 1080;
public void settings() {
size(w, h, P3D);
}
public void setup() {
scene = onScreen ? new Scene(g) : new Scene(createGraphics(w, h, P3D));
scene.eye().enableHint(Node.BOUNDS);
scene.eye().tagging = false;
scene.setRadius(200);
scene.fit(1000);
cubes = new Node[15];
for (int i = 0; i < cubes.length; i++) {
cubes[i] = new CustomNode();
//shapes[i].setHUD(this::hud);
//shapes[i].disablePicking(Node.SHAPE);
//shapes[i].enableHint(Node.BULLSEYE);
//shapes[i].disablePickingMode(Node.SHAPE);
scene.randomize(cubes[i]);
}
// Note that we pass the upper left corner coordinates where the scene1
// is to be drawn (see drawing code below) to its constructor.
lateralView = new Scene(createGraphics(w / 2, h, P3D));
lateralView.togglePerspective();
lateralView.eye().tagging = false;
lateralView.setRadius(400);
lateralView.fit();
/*
int si = int(vertTexCoord.s * binsize);
vec2(float(si) / binsize
// */
/*
float w = 600;
float binsize = 5;
float vertTexCoord;
float coef = w / binsize;
for(float i = 0; i < w; i++) {
vertTexCoord = i / w;
int si = (int) (vertTexCoord * coef);
println(vertTexCoord + " " + ((float)(si)) / coef);
}
// */
/*
float binsize = 5;
//float vertTexCoord;
for(float i = 0; i < 1; i+=1/600f) {
//vertTexCoord = i;
int si = (int) (i * binsize);
println(i + " " + ((float)(si)) / binsize);
}
// */
/*
float w = 600;
float binsize = 5;
//float vertTexCoord;
float coef = w / binsize;
for(float i = 0; i < w; i++) {
//vertTexCoord = i / w;
int si = (int) (i * coef);
println(i + " " + ((float)(si)) / coef);
}
// */
/*
float w = 600;
float binsize = 5;
float vertTexCoord;
float coef = w / binsize;
for(float i = 0; i < w; i++) {
vertTexCoord = i / w;
int si = (int) (vertTexCoord * binsize);
println(i + " " + vertTexCoord + " " + ((float)(si)) / binsize);
}
// */
}
class CustomNode extends Node {
//Add some attributes
float radiusInPixels = 50, radius;
int strokeCol = color(255, 255, 0), fillCol = color(0, 255, 255, 125);
public CustomNode() {
super();
setShape(pg -> {
//this.radius = this.radiusInPixels;
this.radius = this.radiusInPixels * scene.sceneToPixelRatio(worldPosition());
pg.pushStyle();
pg.stroke(strokeCol);
pg.fill(fillCol);
pg.box(radius);
pg.popStyle();
});
}
}
public void keyPressed() {
if (key == ' ')
displayLateralView = !displayLateralView;
if (key == 'f')
focus.fit(1000);
if (key == 't') {
if (focus == null)
return;
focus.togglePerspective();
}
}
@Override
public void mouseMoved() {
if (focus == null)
return;
focus.tag();
}
@Override
public void mouseDragged() {
if (focus == null)
return;
if (mouseButton == LEFT)
focus.spin();
else if (mouseButton == RIGHT)
focus.shift();
else {
focus.zoom(mouseX - pmouseX);
}
}
@Override
public void mouseWheel(MouseEvent event) {
Node node = scene.node();
Node eye = scene.eye();
if(node != null) {
float amount = event.getCount();
//scene.translateNode(node, 0, 0, amount / 50, Scene.inertia);
///*
if (scene.type() == Graph.Type.PERSPECTIVE) {
Vector v = Vector.subtract(node.worldPosition(), eye.worldPosition());
v.normalize();
v.multiply(amount * 10);
node.translate(v, Scene.inertia);
}
else {
scene.shift(node, 0, 0, amount / 50, Scene.inertia);
}
// */
}
else {
focus.moveForward(event.getCount() * 20);
}
}
@Override
public void mouseClicked(MouseEvent event) {
if (focus == null)
return;
if (event.getCount() == 2)
if (event.getButton() == LEFT)
focus.focus();
else
focus.align();
}
public void draw() {
focus = lateralView.hasFocus() ? lateralView : scene;
scene.openContext();
scene.context().background(75, 25, 15);
scene.render();
scene.closeContext();
scene.image();
//stroke(0, 225, 15);
//scene.drawGrid();
if (displayLateralView) {
lateralView.openContext();
lateralView.context().background(75, 25, 175);
lateralView.drawAxes();
lateralView.render();
lateralView.closeContext();
lateralView.image(w / 2, 0);
}
}
public static void main(String[] args) {
PApplet.main(new String[]{"Superliminal"});
}
}