package Excercise_02;
import java.awt.*;
import javax.media.j3d.*;
import javax.swing.JFrame;
import javax.vecmath.*;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
@SuppressWarnings("serial")
public class Problem_3D extends JFrame
{
// Attribute
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int wait_time = 10;
int t = 0;
float beschleunigung = 0.002f;
float abzug = 0.0001f;
float x = 0,y = 8,z = -40;
float grenze = -8;
Transform3D a;
TransformGroup A;
// Konstruktor
public Problem_3D()
{
setTitle("3D-Faszination-Gravitation");
setSize(d.width/2,d.height/2);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
Canvas3D canvas3D = new Canvas3D(config);
add("Center", canvas3D);
BranchGroup scene = createSceneGraph();
SimpleUniverse simpleU = new SimpleUniverse(canvas3D);
simpleU.getViewingPlatform().setNominalViewingTransform();
simpleU.addBranchGraph(scene);
setVisible(true);
new Thread()
{
public void run()
{
while(true)
{
abzug += beschleunigung;
y -= abzug;
if(y<grenze)
{
y += abzug;
}
a = new Transform3D();
a.setTranslation(new Vector3f(x,y,z));
A.setTransform(a);
try{Thread.sleep(10); t+=10;}catch(Exception e){}
}
}
}.start();
}
public BranchGroup createSceneGraph()
{
BranchGroup X = new BranchGroup();
a = new Transform3D();
a.setTranslation(new Vector3f(x,y,z));
A = new TransformGroup(a);
A.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
A.addChild(new ColorCube(1));
X.addChild(A);
return X;
}
public static void main(String[]args)
{
new Problem_3D();
}
}