We Value Your Privacy

We and our partners use technology such as cookies on our site to personalise content and ads, provide social media features, and analyse our traffic. Click below to consent to the use of this technology across the web. You can change your mind and change your consent choices at anytime by returning to this site.

Update Consent
Loading ...

How to Create the Solar System in Java 3D

Updated July 20, 2017

Java 3D is a graph-based modelling application for the Java platform. It is unlike most 3D modelers as you do not create objects by dragging and dropping. In Java 3D, you code manually. Creating a solar system is time-consuming as each object must be coded individually.

Loading ...
  1. Study Java and Java 3D coding. Purchase books on these topics and see the links under Resources.

  2. Download, install and run solar system models. Look at the source code. Do not copy the code, as that is plagiarism.

  3. Open the Java 3D application.

  4. Create the sun, the central object of the solar system. Code in lighting to give it a 3D feel. Input the following code from the website Java3D to create a ball with light hitting it:

  5. import com.sun.j3d.utils.geometry.*;

  6. import com.sun.j3d.utils.universe.*;

  7. import javax.media.j3d.*;

  8. import javax.vecmath.*;

  9. public class Ball {

  10. public Ball() {

  11. SimpleUniverse universe = new SimpleUniverse();

  12. BranchGroup group = new BranchGroup();

  13. Sphere sphere = new Sphere(0.5f);

  14. group.addChild(sphere);

  15. Color3f light1Color = new Color3f(1.8f, 0.1f, 0.1f);

  16. BoundingSphere bounds =

  17. new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);

  18. Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);

  19. DirectionalLight light 1

  20. light1.setInfluencingBounds(bounds);

  21. group.addChild(light1);

  22. universe.getViewingPlatform().setNominalViewingTransform();

  23. universe.addBranchGraph(group);

  24. }

  25. public static void main(String[] args) { new Ball(); }

  26. }

  27. Place the sun in the middle. Typically the coordinates will be (0,0,0) unless you want your solar system angled.

  28. Set the object's texture and colour. This makes the object look more realistic. Choose colours to mix with the following code:

  29. Color3f black = new Color3f(0.0f, 0.0f, 0.0f);

  30. Color3f white = new Color3f(1.0f, 1.0f, 1.0f);

  31. Color3f yellow = new Color3f(0.7f, .15f, .15f);

  32. TextureLoader loader = new TextureLoader("K:\3d\Arizona.jpg",

  33. Texture texture = loader.getTexture();

  34. texture.setBoundaryModeS(Texture.WRAP);

  35. texture.setBoundaryModeT(Texture.WRAP);

  36. texture.setBoundaryColor( new Color4f( 0.0f, 1.0f, 0.0f, 0.0f ) );

  37. Add code that alters the texture. There are four ways a texture can be displayed; blended, decaled, replaced or modulated. The modulated option provides the most realistic result. Here is sample code for modulating:

  38. texAttr.setTextureMode(TextureAttributes.MODULATE);

  39. ap.setMaterial(new Material(red, black, red, black, 1.0f));

  40. Repeat Steps 4-7 for every object in the solar system.

Loading ...

About the Author

Antonin Korenek

Antonin Korenek has been writing professionally since 2008. On eHow and Answerbag he specializes in everything geeky and DIY home repair and maintenance. In college he was awarded the Loughead-Eldredge Scholarship in Creative Writing two years in a row. Korenek graduated from Wayne State University with a bachelor's degree in English.

Loading ...
Loading ...