-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrame.java
More file actions
executable file
·47 lines (38 loc) · 1.22 KB
/
Frame.java
File metadata and controls
executable file
·47 lines (38 loc) · 1.22 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
import javax.swing.JFrame;
import java.awt.*;
import javax.media.j3d.*;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.behaviors.vp.*;
import javax.vecmath.*;
public class Frame extends JFrame {
private Canvas3D canvas;
private SimpleUniverse universe;
public Frame(int width, int height, String title){
super(title);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
canvas = new Canvas3D(config);
canvas.setSize(new Dimension(width, height));
universe = new SimpleUniverse(canvas);
universe.getViewingPlatform().setNominalViewingTransform();
setBehavior();
add(canvas);
this.pack();
this.setVisible(true);
}
public void addTurtle(Turtle t){
t.setFrame(this);
}
public void addShape(Shape3D shape){
BranchGroup tmp = new BranchGroup();
tmp.addChild( shape );
tmp.compile();
universe.addBranchGraph(tmp);
}
private void setBehavior(){
OrbitBehavior orbit = new OrbitBehavior(canvas, OrbitBehavior.REVERSE_ALL);
orbit.setSchedulingBounds(
new BoundingSphere(new Point3d(0,0,0), 100));
universe.getViewingPlatform().setViewPlatformBehavior(orbit);
}
}