-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCustomNodeInteraction.pde
More file actions
89 lines (79 loc) · 2.06 KB
/
CustomNodeInteraction.pde
File metadata and controls
89 lines (79 loc) · 2.06 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
/**
* Custom Node Interaction.
* by Jean Pierre Charalambos.
*
* This example illustrates how to customize the toruses behaviors
* by overriding the interact(Object... gesture) method and
* sending gesture data to the node with the scene
* interact(Object... gesture) method.
*
* The toruses color and number of faces are controlled with the
* keys and the mouse. To pick a torus press the [0..9] keys
* or double-click on it; press other key or double-click on the
* the background to reset your picking selection. Once a torus
* is picked try the key arrows, the mouse wheel or a single
* mouse click, to control its color and number of faces.
*/
import nub.primitives.*;
import nub.core.*;
import nub.processing.*;
Scene scene;
Torus[] shapes;
PFont font36;
int totalShapes;
//Choose P2D or P3D
String renderer = P3D;
void settings() {
size(1200, 700, renderer);
}
void setup() {
font36 = loadFont("FreeSans-36.vlw");
scene = new Scene(this);
shapes = new Torus[10];
for (int i = 0; i < shapes.length; i++) {
shapes[i] = new Torus();
}
}
void draw() {
background(0);
scene.render();
scene.drawAxes();
}
void keyPressed() {
int value = Character.getNumericValue(key);
if (value >= 0 && value < 10)
scene.tag("key", shapes[value].node);
if (key == ' ')
scene.removeTag("key");
if (key == CODED)
if (keyCode == UP)
scene.shift("key", 0, -10, 0);
else if (keyCode == DOWN)
scene.shift("key", 0, 10, 0);
else if (keyCode == LEFT)
scene.interact("key", "menos");
else if (keyCode == RIGHT)
scene.interact("key", "mas");
}
void mouseDragged() {
if (scene.node("key") != null) {
if (mouseButton == LEFT)
scene.spin("key");
else if (mouseButton == CENTER)
scene.zoom("key", scene.mouseDX());
else
scene.shift("key");
}
else {
scene.spin();
}
}
void mouseWheel(MouseEvent event) {
scene.interact("key", event.getCount());
}
void mouseClicked(MouseEvent event) {
if (event.getCount() == 1)
scene.interact("key");
if (event.getCount() == 2)
scene.tag("key");
}