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

📄 solarsystem2.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 solarSystem2
{public static void main(String[] args)
  { new solarSystem2();
  }

public solarSystem2()
   {SimpleUniverse su=new SimpleUniverse();
    BranchGroup bg=new BranchGroup();
    
    bg.addChild(Sun(0.4f));
    bg.addChild(Planet());
    // add more planets here ...
      
    su.getViewingPlatform().setNominalViewingTransform();
    su.addBranchGraph(bg);
   }


  
  private TransformGroup Sun(float size)
   { TransformGroup tg = new TransformGroup();
     Appearance ap=new Appearance();
     ColoringAttributes ca= new ColoringAttributes();
     ca.setColor(1f,1f,0f);
     ap.setColoringAttributes(ca);
     Sphere theSun = new Sphere(size,ap);
     tg.addChild(theSun);
     return tg;
   }
  
  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,0.5f,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 translation matrix
    Vector3f vectPlanet=new Vector3f(1.2f,0.0f,0.0f);
    tfPlanet.setTranslation(vectPlanet);
    tgPlanet.setTransform(tfPlanet);
    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);
    tgRot.addChild(tgPlanet);
    
    return tgRot;
  }
 
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -