import javax.media.j3d.*;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.Box;
import javax.vecmath.*;
import java.awt.*;
import java.awt.event.*;
public class game0504{
public static void main(String[] args) {
game0504 test = new game0504();
}
public game0504(){
Frame frame = new Frame();
frame.setSize(700,700);
frame.setTitle("game0504");
Panel cp = new Panel();
cp.setLayout(null);
frame.add(cp);
frame.addWindowListener(new stopwin());
GraphicsConfiguration g_config = SimpleUniverse.getPreferredConfiguration();
Canvas3D canvas = new Canvas3D(g_config);
canvas.setBounds(0,0,250,250);
cp.add(canvas);
SimpleUniverse universe = new SimpleUniverse(canvas);
frame.setVisible(true);
ViewingPlatform camera = universe.getViewingPlatform();
camera.setNominalViewingTransform();
Color3f light_color = new Color3f(1.0f,1.0f,1.0f);
Vector3f light_direction = new Vector3f(0.2f,-0.2f,-0.6f);
DirectionalLight light = new DirectionalLight(light_color,light_direction);
BoundingSphere bounds = new BoundingSphere();
light.setInfluencingBounds(bounds);
BranchGroup group2 = new BranchGroup();
group2.addChild(light);
universe.addBranchGraph(group2);
Appearance appearance = new Appearance();
Material material = new Material();
material.setDiffuseColor(0.9f,0.75f,0.75f);
appearance.setMaterial(material);
Box box = new Box(0.3f,0.3f,0.3f,appearance);
BranchGroup group1 = new BranchGroup();
TransformGroup transform_group = new TransformGroup();
transform_group.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
transform_group.addChild(box);
group1.addChild(transform_group);
universe.addBranchGraph(group1);
Vector3f vector1 = new Vector3f(0.4f,0.0f,0.0f);
Transform3D transform1 = new Transform3D();
transform1.setTranslation(vector1);
//TransformGroupにTransform3Dを登録。
transform_group.setTransform(transform1);
}
class stopwin extends WindowAdapter{
public void windowClosing(WindowEvent we){System.exit(0);}
}
}
最終更新:2011年02月23日 18:16