⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 solarsystem.java

📁 Java3D程序,实现各种立体变换.适于基础编程.
💻 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 + -