[XoL]
2015-04-24 01:50:51
/*
*/
import java.applet.Applet;
import java.awt.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.behaviors.keyboard.*;
public class Assignment8 extends Applet {
SimpleUniverse simpleU=null;
public BranchGroup createSceneGraph() {
// Create the root of the branch graph
BranchGroup objRoot = new BranchGroup();
AmbientLight lightA = new AmbientLight();
BoundingSphere bs = new BoundingSphere(new Point3d(0.0,0.0,0.0),1000.0);
lightA.setInfluencingBounds(bs);
objRoot.addChild(lightA);
// The Sea Floor.
Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
Appearance appX = new Appearance();
Color3f colorX = new Color3f(0.1f, 0.9f, 0.9f);
appX.setMaterial(new Material(colorX, black, colorX, white, 80.0f));
Box xaxis = new Box(20.0f, 1.0f, 20.0f, appX);
objRoot.addChild(xaxis);
// The trendy roof's.
Appearance appS = new Appearance();
Color3f colorS = new Color3f(0.02f, 0.02f, 0.7f);
appS.setMaterial(new Material(colorS, black, colorS, white, 80.0f));
Sphere s1 = new Sphere(1.0f, appS);
Sphere s2 = new Sphere(0.9f, appS);
Transform3D tS = new Transform3D();
Transform3D tG = new Transform3D();
tS.setTranslation(new Vector3f(4.0f, 3.0f, 1.5f));
tG.setTranslation(new Vector3f(-4.0f, 3.0f, 1.5f));
TransformGroup tgS = new TransformGroup(tG);
TransformGroup tgs2 = new TransformGroup(tS);
tgS.addChild(s2);
tgs2.addChild(s1);
objRoot.addChild(tgS);
objRoot.addChild(tgs2);
// Green Homes.
Appearance appB = new Appearance();
Color3f colorB = new Color3f(0.02f, 0.7f, 0.02f);
appB.setMaterial(new Material(colorB, black, colorB, white, 80.0f));
Box b1 = new Box(0.7f, 0.7f, 0.7f, appB);
Transform3D tB = new Transform3D();
tB.setTranslation(new Vector3f(4.0f, 2.0f, 1.5f));
TransformGroup tgB = new TransformGroup(tB);
tgB.addChild(b1);
objRoot.addChild(tgB);
Appearance appC = new Appearance();
Color3f colorC = new Color3f(0.05f, 0.12f, 0.12f);
appC.setMaterial(new Material(colorC, black, colorC, black, 80.0f));
Box b2 = new Box(0.7f, 0.7f, 0.7f, appB);
Transform3D tC = new Transform3D();
tC.setTranslation(new Vector3f(-4.0f, 2.0f, 1.5f));
TransformGroup tgC = new TransformGroup(tC);
tgC.addChild(b2);
objRoot.addChild(tgC);
return objRoot;
} // end of CreateSceneGraph method of assignment8
public Assignment8() {
setLayout(new BorderLayout());
Canvas3D canvas3D = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
add("Center", canvas3D);
//Zoom out a little bit to see the entire landscape
// SimpleUniverse is a Convenience Utility class
simpleU = new SimpleUniverse(canvas3D);
BranchGroup scene = createSceneGraph();
//...and, set up a KeyNavigator to let us move about
//
TransformGroup vpTrans = simpleU.getViewingPlatform().getViewPlatformTransform();
KeyNavigatorBehavior keyNav = new KeyNavigatorBehavior(vpTrans);
keyNav.setSchedulingBounds(new BoundingSphere(new Point3d(), 1000.0));
scene.addChild(keyNav);
scene.compile();
simpleU.addBranchGraph(scene);
}
// The following allows this to be run as an application
// as well as an applet
public static void main(String[] args) {
Frame frame = new MainFrame(new Assignment8(), 256, 256);
}
}
I am trying to add this cube to it, smaller and above the boxes and circles
http://www.java2s.com/Code/Java/3D/SimpleRotation.htm
Anyone able to do this? I took a few stabs, but I keep getting errors when it runs.