?? solarsystem.java
字號:
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.geometry.*;
import javax.media.j3d.*;
import javax.vecmath.*;
public class solarSystem
{ public solarSystem()
{SimpleUniverse su=new SimpleUniverse();
BranchGroup bg=new BranchGroup();
bg.addChild(Sun());
bg.addChild(Planet());
su.getViewingPlatform().setNominalViewingTransform();
su.addBranchGraph(bg);
}
public static void main(String[] args)
{ new solarSystem();
}
private TransformGroup Sun()
{ TransformGroup tg = new TransformGroup();
Appearance ap=new Appearance();
ColoringAttributes ca= new ColoringAttributes();
ca.setColor(1f,1f,0f);
ap.setColoringAttributes(ca);
Sphere theSun = new Sphere(0.2f,ap);
tg.addChild(theSun);
return tg;
}
/* first translation of center, then rotation around new center
private TransformGroup Planet()
{ TransformGroup tgPlanet = new TransformGroup();
tgPlanet.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
Transform3D tf1 = new Transform3D(); // set the translation matrix
Vector3f vect=new Vector3f(0.4f,0f,0f);
tf1.setTranslation(vect);
Alpha a=new Alpha(-1,5000);
RotationInterpolator ri=new RotationInterpolator(a,tgPlanet,tf1,0f,(float)(2*Math.PI));
BoundingSphere bs=new BoundingSphere();
ri.setSchedulingBounds(bs);
tgPlanet.addChild(ri);
Appearance ap=new Appearance();
ColoringAttributes ca= new ColoringAttributes();
ca.setColor(0f,0f,1f);
ap.setColoringAttributes(ca);
Sphere thePlanet = new Sphere(0.1f,ap);
tgPlanet.addChild(thePlanet);
return tgPlanet;
}
*/
private TransformGroup Planet()
{ // Build the general planet rotation
TransformGroup tgRot = new TransformGroup();
tgRot.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
Alpha a=new Alpha(-1,10000);
Transform3D tfRot = new Transform3D(); // set the translation matrix
Vector3f vect=new Vector3f(0f,0f,0f);
tfRot.setTranslation(vect);
RotationInterpolator ri=new RotationInterpolator(a,tgRot,tfRot,0f,(float)(2*Math.PI));
BoundingSphere bs=new BoundingSphere();
ri.setSchedulingBounds(bs);
tgRot.addChild(ri);
// Make the planet (translated with respect to the rotation center)
// No animation required in this model (planet does not spin around it's axis)
TransformGroup tgPlanet = new TransformGroup();
Transform3D tfPlanet = new Transform3D(); // set the Planets translation matrix
Vector3f vectPlanet=new Vector3f(0.9f,0.0f,0.0f);
tfPlanet.setTranslation(vectPlanet);
tgPlanet.setTransform(tfPlanet);
Appearance ap=new Appearance(); // make coloring possible
ColoringAttributes ca= new ColoringAttributes();
ca.setColor(0f,0f,1f);
ap.setColoringAttributes(ca);
Sphere thePlanet = new Sphere(0.041f,ap); // Make the Planet and link it to its animation
tgPlanet.addChild(thePlanet);
tgRot.addChild(tgPlanet);
return tgRot;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -