Strona główna > Computers & electronics > Jak Stworzyć Układ Słoneczny W Java 3D

Jak stworzyć Układ Słoneczny w Java 3D

Java 3D jest opartą na grafach aplikacją do modelowania dla platformy Java. Nie jest ona podobna do większości modelerów 3D, ponieważ nie tworzy się obiektów metodą przeciągania i upuszczania. W Java 3D koduje się ręcznie. Tworzenie układu słonecznego jest czasochłonne, ponieważ każdy obiekt musi być zakodowany osobno.

  • Java 3D jest opartą na grafach aplikacją do modelowania dla platformy Java.
  • Nie różni się od większości modelerów 3D, ponieważ nie tworzysz obiektów metodą przeciągania i upuszczania.

Poznaj kodowanie w Javie i Javie 3D. Kup książki na te tematy i zobacz linki w sekcji Zasoby.

Ściągnij, zainstaluj i uruchom modele układu słonecznego. Spójrz na kod źródłowy. Nie kopiuj kodu, gdyż jest to plagiat.

Otwórz aplikację Java 3D.

Utwórz słońce, centralny obiekt układu słonecznego. Wprowadź oświetlenie, aby nadać mu wrażenie trójwymiarowości. Input the following code from the website Java3D to create a ball with light hitting it:

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

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

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

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

import javax.media.j3d.*;

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

import javax.vecmath.*;

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

public class Ball {

public Ball() {

SimpleUniverse universe = new SimpleUniverse();

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

BranchGroup group = new BranchGroup();

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

Sphere sphere = new Sphere(0.5f);

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

group.addChild(sphere);

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

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

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

BoundingSphere bounds =

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

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

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

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

DirectionalLight light 1

               = new DirectionalLight(light1Color, light1Direction);             

light1.setInfluencingBounds(bounds);

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

group.addChild(light1);

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

universe.getViewingPlatform().setNominalViewingTransform();

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

universe.addBranchGraph(group);

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

}

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

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

}

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

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

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

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

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

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

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

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

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

               "LUMINANCE", new Container());             

Texture texture = loader.getTexture();

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

texture.setBoundaryModeS(Texture.WRAP);

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

texture.setBoundaryModeT(Texture.WRAP);

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

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

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

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:

  • Add code that alters the texture.
  • There are four ways a texture can be displayed; blended, decaled, replaced or modulated.
  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;
               TextureAttributes texAttr = new TextureAttributes();             

texAttr.setTextureMode(TextureAttributes.MODULATE);

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;
               Appearance ap = new Appearance();    ap.setTexture(texture);    ap.setTextureAttributes(texAttr);             

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

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

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

By Alurd Amuso

Jak ustawić czas na zegarku Casio Wr200m :: Prawda o szczelinowaniu i gazie łupkowym
Przydatne linki