SHARE
TWEET

Untitled

a guest Jun 12th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import com.sun.j3d.utils.geometry.Cone;
  2. import com.sun.j3d.utils.geometry.Cylinder;
  3. import com.sun.j3d.utils.geometry.Sphere;
  4. import javax.media.j3d.*;
  5. import javax.swing.*;
  6. import java.awt.*;
  7. import com.sun.j3d.utils.universe.SimpleUniverse;
  8. //import javafx.scene.shape.Sphere;
  9. import javax.media.j3d.Transform3D;
  10. import javax.vecmath.AxisAngle4f;
  11. import javax.vecmath.Color3f;
  12. import javax.vecmath.Point3d;
  13. import javax.vecmath.Point3f;
  14. import javax.vecmath.Vector3f;
  15.  
  16.  
  17.  
  18. public class NewClass extends JFrame{
  19.  
  20.     NewClass(){
  21.  
  22.           super("NewClass");
  23.  
  24.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  25.         setResizable(false);
  26.  
  27.  
  28.         GraphicsConfiguration config =
  29.            SimpleUniverse.getPreferredConfiguration();
  30.  
  31.         Canvas3D canvas3D = new Canvas3D(config);
  32.         canvas3D.setPreferredSize(new Dimension(800,600));
  33.  
  34.         add(canvas3D);
  35.         pack();
  36.         setVisible(true);
  37.  
  38.         BranchGroup scena = utworzScene();
  39.         scena.compile();
  40.  
  41.         SimpleUniverse simpleU = new SimpleUniverse(canvas3D);
  42.  
  43.         Transform3D przesuniecie_obserwatora = new Transform3D();
  44.         przesuniecie_obserwatora.set(new Vector3f(0.0f,0.0f,5.0f));
  45.  
  46.         simpleU.getViewingPlatform().getViewPlatformTransform().setTransform(przesuniecie_obserwatora);
  47.  
  48.         simpleU.addBranchGraph(scena);
  49.     }
  50.  
  51.     BranchGroup utworzScene(){
  52.  
  53.         BranchGroup wezel_scena = new BranchGroup();
  54.        
  55.         //walec
  56.         Appearance wyglad_walca = new Appearance();
  57.         wyglad_walca.setMaterial(new Material(new Color3f(0.1f,1.0f,0.3f), new Color3f(2f,0.2f,0.0f),
  58.                 new Color3f(0.2f,0.1f,0.0f),new Color3f(0.0f,0.1f,0.2f),89f));
  59.         Cylinder walec=new Cylinder(0.12f,0.4f,80,wyglad_walca);
  60.         TransformGroup trans_walca=new TransformGroup();
  61.         Transform3D przesuniecie_walca=new Transform3D();
  62.         przesuniecie_walca.set(new Vector3f(-10.0f,8.7f,8.0f));
  63.         trans_walca.setTransform(przesuniecie_walca);
  64.         wezel_scena.addChild(trans_walca);
  65.         //trans_walca.addChild(walec);
  66.        
  67.         //kula
  68.         Appearance wyglad_kuli= new Appearance();
  69.         wyglad_kuli.setMaterial(new Material(new Color3f(0.5f, 0.3f,0.2f),
  70.           new Color3f(0.1f,0.1f,0.1f), new Color3f(0.8f, 0.3f, 0.5f),
  71.                  new Color3f(0.2f, 0.2f, 0.2f), 20.0f));
  72.         Sphere kula=new Sphere(0.2f,Sphere.GENERATE_NORMALS,80,wyglad_kuli);
  73.         TransformGroup trans_kuli=new TransformGroup();
  74.         Transform3D przesuniecie_kuli=new Transform3D();
  75.         przesuniecie_kuli.set(new Vector3f(0.0f,0.3f,0.0f));
  76.         trans_kuli.setTransform(przesuniecie_kuli);
  77.         wezel_scena.addChild(trans_kuli);
  78.         //trans_kuli.addChild(kula);
  79.        
  80.         //stozek
  81.         Appearance wyglad_stozka=new Appearance();
  82.         wyglad_stozka.setMaterial(new Material(new Color3f(0.5f, 0.3f,0.2f),
  83.           new Color3f(0.1f,0.1f,0.1f), new Color3f(0.8f, 0.3f, 0.5f),
  84.                  new Color3f(0.2f, 0.2f, 0.2f), 20.0f));
  85.         Cone stozek=new Cone(0.2f,0.2f,wyglad_stozka);
  86.         TransformGroup trans_stozka=new TransformGroup();
  87.         Transform3D przesuniecie_stozka=new Transform3D();
  88.         przesuniecie_stozka.set(new Vector3f(0.0f,-0.4f,0.0f));
  89.         trans_kuli.setTransform(przesuniecie_stozka);
  90.         wezel_scena.addChild(trans_stozka);
  91.         //trans_kuli.addChild(stozek);
  92.        
  93.         //obracanie
  94.         Point3d pkt=new Point3d(0.0f,0.0f,0.0f);
  95.        
  96.         TransformGroup obrot_animacja=new TransformGroup();
  97.         obrot_animacja.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
  98.         wezel_scena.addChild(obrot_animacja);
  99.        
  100.         Alpha alpha=new Alpha(-1,5000);
  101.         RotationInterpolator obracacz=new RotationInterpolator(alpha,obrot_animacja);
  102.        
  103.         BoundingSphere bound=new BoundingSphere(pkt,10);
  104.         obracacz.setSchedulingBounds(bound);
  105.         obrot_animacja.addChild(obracacz);
  106.        
  107.         Transform3D p_walca=new Transform3D();
  108.         p_walca.set(new Vector3f(0.6f,0.0f,0.0f));
  109.         TransformGroup transformacja=new TransformGroup(p_walca); //kurwa pamietaj zeby tu wrzucic p_walca do srodka..
  110.        
  111.         transformacja.addChild(walec);
  112.         obrot_animacja.addChild(transformacja);
  113.        
  114.         Transform3D p_kuli=new Transform3D();
  115.         p_kuli.set(new Vector3f(0.6f,0.8f,0.0f));
  116.         TransformGroup transformacja1=new TransformGroup(p_kuli);
  117.        
  118.         transformacja1.addChild(kula);
  119.         obrot_animacja.addChild(transformacja1);
  120.        
  121.         Transform3D p_stozka=new Transform3D();
  122.         p_stozka.set(new Vector3f(0.6f,-0.8f,0.0f));
  123.         TransformGroup transformacja2=new TransformGroup(p_stozka);
  124.        
  125.         transformacja2.addChild(stozek);
  126.         obrot_animacja.addChild(transformacja2);
  127.        
  128.         //swiatla :)
  129.         Color3f kolor_swiatla_kier     = new Color3f(1.0f, 1.0f, 1.0f);
  130.         Vector3f kierunek_swiatla_kier = new Vector3f(-0.4f, -1.4f, 0.7f);
  131.         BoundingSphere obszar_ogr=new BoundingSphere(new Point3d(0.0d,0.0d,0.0d), 10.0d);
  132.         DirectionalLight swiatlo_kier = new DirectionalLight(kolor_swiatla_kier,
  133.                  kierunek_swiatla_kier);
  134.         swiatlo_kier.setInfluencingBounds(obszar_ogr);
  135.         wezel_scena.addChild(swiatlo_kier);
  136.        
  137.         return wezel_scena;
  138.  
  139.     }
  140.  
  141.      public static void main(String args[]){
  142.       new NewClass();
  143.  
  144.    }
  145.  
  146. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top