-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathOrbit.java
More file actions
101 lines (88 loc) · 2.67 KB
/
Orbit.java
File metadata and controls
101 lines (88 loc) · 2.67 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
import nub.core.Node;
import nub.primitives.Quaternion;
import nub.primitives.Vector;
import nub.processing.Scene;
import processing.core.PApplet;
import processing.core.PGraphics;
import processing.core.PShape;
import processing.event.MouseEvent;
/**
* Orbit around axis
*/
public class Orbit extends PApplet {
Scene scene;
Node shape1, shape2;
Vector axis;
public void settings() {
size(800, 800, P3D);
}
public void setup() {
rectMode(CENTER);
scene = new Scene(this, 1000);
scene.fit(1000);
shape1 = new Node((PGraphics pGraphics) -> {
Scene.drawAxes(pGraphics, scene.radius() / 3);
pGraphics.pushStyle();
pGraphics.rectMode(CENTER);
pGraphics.fill(255, 0, 255);
if (scene.is3D())
Scene.drawCylinder(pGraphics, 30, scene.radius() / 4, 200);
else
pGraphics.rect(10, 10, 200, 200);
pGraphics.popStyle();
});
shape1.setOrientation(Quaternion.random());
shape1.translate(-375, 175, -275);
//shape2 = new Node(shape1);
shape2 = new Node();
shape2.setShape(shape());
shape2.translate(275, 275, 275);
scene.tag(shape2);
axis = Vector.random();
axis.multiply(scene.radius() / 3);
}
public void draw() {
background(0);
stroke(0, 255, 0, 125);
scene.drawArrow(axis);
scene.drawAxes();
scene.render();
}
public void keyPressed() {
if (key == 'i')
scene.tag(scene.hasTag(shape1) ? shape2 : shape1);
if (key == 'f')
Scene.leftHanded = !Scene.leftHanded;
}
public void mouseDragged() {
if (mouseButton == LEFT) {
if (shape2.isTagged(scene))
//shape2.rotate((mouseX-pmouseX)* PI / width, 0, 0, shape1);
//shape2.rotateAround(new Quaternion(new Vector(0, 1, 0), (mouseX - pmouseX) * PI / width), shape1);
//shape2.rotateAround(new Quaternion(new Vector(0, 1, 0), (mouseX - pmouseX) * PI / width), shape1);
//shape2.orbit(new Quaternion(new Vector(0, 1, 0), (mouseX - pmouseX) * PI / width), shape1);
shape2.orbit(axis, (mouseX - pmouseX) * PI / width);
else
scene.spin();
} else if (mouseButton == RIGHT)
scene.spin();
//scene.translate();
//scene.mousePan();
}
public void mouseWheel(MouseEvent event) {
scene.zoom(event.getCount() * 20);
}
public void mouseClicked(MouseEvent event) {
if (event.getCount() == 2)
scene.focus();
}
PShape shape() {
PShape fig = scene.is3D() ? createShape(BOX, 150) : createShape(RECT, 0, 0, 150, 150);
fig.setStroke(255);
fig.setFill(color(random(0, 255), random(0, 255), random(0, 255)));
return fig;
}
public static void main(String[] args) {
PApplet.main(new String[]{"Orbit"});
}
}