-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSceneBuffers.java
More file actions
144 lines (129 loc) · 3.49 KB
/
SceneBuffers.java
File metadata and controls
144 lines (129 loc) · 3.49 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
import nub.core.Node;
import nub.processing.Scene;
import processing.core.PApplet;
import processing.core.PGraphics;
import processing.core.PShape;
import processing.event.MouseEvent;
/**
* Picking buffer debugging
*/
public class SceneBuffers extends PApplet {
Scene scene;
Node root, cajas, bolas;
Node[] shapes;
//Choose one of P3D for a 3D scene or P2D for a 2D one.
String renderer = P3D;
int w = 1200;
int h = 1200;
public void settings() {
size(w, h, renderer);
}
public void setup() {
rectMode(CENTER);
scene = new Scene(createGraphics(w, h / 2, renderer), max(w, h));
//scene = new Scene(createGraphics(w, h, renderer), max(w, h));
//scene = new Scene(this, 1200);
cajas = new Node();
bolas = new Node();
scene.randomize(cajas);
scene.randomize(bolas);
shapes = new Node[10];
for (int i = 0; i < shapes.length; i++) {
if (i%2==0) {
shapes[i] = new Node(cajas, caja());
}
else {
shapes[i] = new Node(bolas, bola());
}
scene.randomize(shapes[i]);
//shapes[i].enableHint(Node.CAMERA);
shapes[i].enableHint(Node.AXES);
shapes[i].setHUD(this::hud);
}
scene.fit(1000);
}
public void hud(PGraphics pg) {
pg.pushStyle();
pg.rectMode(CENTER);
pg.fill(255, 0, 255, 125);
pg.stroke(0,0,255);
pg.strokeWeight(3);
pg.rect(0, 0, 80, 50);
pg.popStyle();
}
public void draw() {
// 1. Fill in and display front-buffer
/*
background(0);
scene.render(bolas);
scene.render(cajas);
// */
// /*
scene.display(color(125), bolas);
scene.display(cajas);
// */
/*
scene.openContext();
scene.context().background(125);
scene.drawAxes();
scene.render(cajas);
//scene.render(bolas);
scene.closeContext();
//scene.image();
// */
/*
scene.openContext();
//scene.context().background(125);
//scene.drawAxes();
//scene.render(cajas);
scene.render(bolas);
scene.closeContext();
scene.image();
// */
//scene.display(125, root);
// 2. Display back buffer
scene.displayBackBuffer(color(255, 0, 0),0, h / 2);
}
public void mouseMoved() {
scene.tag();
}
public void mouseDragged() {
if (mouseButton == LEFT)
scene.spin();
else if (mouseButton == RIGHT)
scene.shift();
else
scene.zoom(mouseX - pmouseX);
}
public void mouseWheel(MouseEvent event) {
if (scene.is3D())
scene.moveForward(event.getCount() * 20);
else
scene.zoom(event.getCount() * 20);
}
public void keyPressed() {
if (key == '0')
root = null;
if (key == '1')
root = cajas;
if (key == '2')
root = bolas;
}
PShape caja() {
PShape caja = scene.is3D() ? createShape(BOX, random(60, 100)) : createShape(RECT, 0, 0, random(60, 100), random(60, 100));
caja.setStrokeWeight(3);
caja.setStroke(color(random(0, 255), random(0, 255), random(0, 255)));
caja.setFill(color(random(0, 255), random(0, 255), random(0, 255), random(0, 255)));
return caja;
}
PShape bola() {
PShape bola = scene.is3D() ? createShape(SPHERE, random(60, 100)) : createShape(ELLIPSE, 0, 0, random(60, 100), random(60, 100));
//bola.noStroke();
bola.setStroke(color(random(0, 255), random(0, 255), random(0, 255)));
bola.setFill(color(random(0, 255), random(0, 255), random(0, 255), random(0, 255)));
return bola;
}
public static void main(String args[]) {
PApplet.main(new String[]{"SceneBuffers"});
}
}