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

📄 fourbyfour.java

📁 java 3d编程的一些例子源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
      // Create a universe with the Java3D universe utility.      universe = new SimpleUniverse(canvas3D);      universe.addBranchGraph(scene3D);        // Use parallel projection.      View view = universe.getViewer().getView();      view.setProjectionPolicy(View.PARALLEL_PROJECTION);      // Set the universe Transform3D object.      TransformGroup tg =          universe.getViewingPlatform().getViewPlatformTransform();      Transform3D transform = new Transform3D();      transform.set(65.f, new Vector3f(0.0f, 0.0f, 400.0f));      tg.setTransform(transform);      // Create the canvas container.      c_container = new Panel();      c_container.setSize(720, 360);      c_container.setLocation(0, 0);      c_container.setVisible(true);      c_container.setLayout(null);      add(c_container);      // Add the 2D and 3D canvases to the container.      c_container.add(canvas2D);      c_container.add(canvas3D);      // Turn off the layout manager, widgets will be sized       // and positioned explicitly.      setLayout(null);      // Create the button container.      b_container = new Panel();      b_container.setSize(720, 70);      b_container.setLocation(0, 360);      b_container.setVisible(true);      b_container.setLayout(null);      // Create the buttons.      instruct_button = new Button("Instructions");      instruct_button.setSize(135, 25);      instruct_button.setLocation(10, 10);      instruct_button.setVisible(true);      instruct_button.addActionListener(this);      new_button = new Button("New Game");      new_button.setSize(135, 25);      new_button.setLocation(150, 10);      new_button.setVisible(true);      new_button.addActionListener(this);      undo_button = new Button("Undo Move");      undo_button.setSize(135, 25);      undo_button.setLocation(290, 10);      undo_button.setVisible(true);      undo_button.addActionListener(this);      skill_button = new Button("Skill Level");      skill_button.setSize(135, 25);      skill_button.setLocation(430, 10);      skill_button.setVisible(true);      skill_button.addActionListener(this);      high_button = new Button("High Scores");      high_button.setSize(135, 25);      high_button.setLocation(570, 10);      high_button.setVisible(true);      high_button.addActionListener(this);      b_container.add(new_button);      b_container.add(undo_button);      b_container.add(skill_button);      b_container.add(high_button);      b_container.add(instruct_button);      // Add the button container to the applet.      add(b_container);      // Create the "Skill Level" dialog box.      skill_panel = new Panel();      skill_panel.setSize(400, 300);      skill_panel.setLocation(200, 20);      skill_panel.setLayout(null);      skill_label = new Label("Pick your skill level:");      skill_label.setSize(200, 25);      skill_label.setLocation(25, 20);      skill_label.setVisible(true);      skill_panel.add(skill_label);      group = new CheckboxGroup();      Checkbox skill_1 = new Checkbox("Babe in the Woods        ", group, false);      Checkbox skill_2 = new Checkbox("Walk and Chew Gum        ", group, false);      Checkbox skill_3 = new Checkbox("Jeopardy Contestant      ", group, false);      Checkbox skill_4 = new Checkbox("Rocket Scientist         ", group, false);      Checkbox skill_5 = new Checkbox("Be afraid, be very afraid", group, true);      skill_1.setSize(170, 25);      skill_1.setLocation(80, 60);      skill_1.setVisible(true);      skill_2.setSize(170, 25);      skill_2.setLocation(80, 100);      skill_2.setVisible(true);      skill_3.setSize(170, 25);      skill_3.setLocation(80, 140);      skill_3.setVisible(true);      skill_4.setSize(170, 25);      skill_4.setLocation(80, 180);      skill_4.setVisible(true);      skill_5.setSize(170, 25);      skill_5.setLocation(80, 220);      skill_5.setVisible(true);      skill_return_button = new Button("Return");      skill_return_button.setSize(120, 25);      skill_return_button.setLocation(300, 370);      skill_return_button.setVisible(false);      skill_return_button.addActionListener(this);      skill_panel.add(skill_1);      skill_panel.add(skill_2);      skill_panel.add(skill_3);      skill_panel.add(skill_4);      skill_panel.add(skill_5);      skill_panel.setVisible(false);      add(skill_return_button);      add(skill_panel);      // Create the "Instructions" panel.      instruct_return_button = new Button("Return");      instruct_return_button.setLocation(300, 370);      instruct_return_button.setSize(120, 25);      instruct_return_button.setVisible(false);      instruct_return_button.addActionListener(this);      instruct_text =          new TextArea(textString, 100, 200, TextArea.SCROLLBARS_VERTICAL_ONLY);      instruct_text.setSize(715, 350);      instruct_text.setLocation(0, 0);      instruct_text.setVisible(false);      add(instruct_text);      add(instruct_return_button);      high_panel = new Panel();      high_panel.setSize(715, 350);      high_panel.setLocation(0, 0);      high_panel.setVisible(false);      high_panel.setLayout(null);      high_label = new Label("High Scores");      high_label.setLocation(330, 5);      high_label.setSize(200, 30);      high_label.setVisible(true);      high_panel.add(high_label);      high_places = new Label[20];      high_names  = new Label[20];      high_scores = new Label[20];      for (int i=0; i<20; i++) {         high_places[i] = new Label(Integer.toString(i+1));         high_places[i].setSize(20, 30);         high_places[i].setVisible(true);         high_names[i] = new Label(names[i]);         high_names[i].setSize(150, 30);         high_names[i].setVisible(true);         high_scores[i] = new Label(Integer.toString(scores[i]));         high_scores[i].setSize(150, 30);         high_scores[i].setVisible(true);         if (i<10) {            high_places[i].setLocation(70, i*30+40);            high_names[i].setLocation(100, i*30+40);            high_scores[i].setLocation(260, i*30+40);         }         else {            high_places[i].setLocation(425, (i-10)*30+40);            high_names[i].setLocation(455, (i-10)*30+40);            high_scores[i].setLocation(615, (i-10)*30+40);         }         high_panel.add(high_places[i]);         high_panel.add(high_names[i]);         high_panel.add(high_scores[i]);      }      high_return_button = new Button("Return");      high_return_button.setSize(120, 25);      high_return_button.setLocation(300, 370);      high_return_button.setVisible(false);      high_return_button.addActionListener(this);      add(high_return_button);      add(high_panel);      // Create the "Winner" dialog box      winner_panel = new Panel();      winner_panel.setLayout(null);      winner_panel.setSize(600, 500);      winner_panel.setLocation(0, 0);      winner_return_button = new Button("Return");      winner_return_button.setSize(120, 25);      winner_return_button.setLocation(300, 360);      winner_return_button.addActionListener(this);      winner_panel.add(winner_return_button);      winner_label = new Label("");      winner_label.setSize(200, 30);      winner_label.setLocation(270, 110);      winner_score_label = new Label("");      winner_score_label.setSize(200, 30);      winner_top_label = new Label("You have a score in the top 20.");      winner_top_label.setSize(200, 25);      winner_top_label.setLocation(260, 185);      winner_top_label.setVisible(false); winner_name_label = new Label("Enter your name here:");      winner_name_label.setSize(150, 25);      winner_name_label.setLocation(260, 210);      winner_name_label.setVisible(false);      winner_name = new TextField("");      winner_name.setSize(200, 30);      winner_name.setLocation(260, 240);      winner_name.setVisible(false);      winner_panel.add(winner_label);      winner_panel.add(winner_score_label);      winner_panel.add(winner_top_label);      winner_panel.add(winner_name_label);      winner_panel.add(winner_name);      winner_panel.setVisible(false);      add(winner_panel);   }    public void destroy() {	universe.cleanup();    }   /**    *  Create the scenegraph for the 3D view.    */   public BranchGroup createScene3D() {      // Define colors      Color3f white = new Color3f(1.0f, 1.0f, 1.0f);      Color3f black = new Color3f(0.0f, 0.0f, 0.0f);      Color3f red   = new Color3f(0.80f, 0.20f, 0.2f);      Color3f ambient = new Color3f(0.25f, 0.25f, 0.25f);      Color3f diffuse = new Color3f(0.7f, 0.7f, 0.7f);      Color3f specular = new Color3f(0.9f, 0.9f, 0.9f);      Color3f ambientRed = new Color3f(0.2f, 0.05f, 0.0f);      Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f);      // Create the branch group      BranchGroup branchGroup = new BranchGroup();      // Create the bounding leaf node      BoundingSphere bounds =         new BoundingSphere(new Point3d(0.0,0.0,0.0), 1000.0);      BoundingLeaf boundingLeaf = new BoundingLeaf(bounds);      branchGroup.addChild(boundingLeaf);      // Create the background      Background bg = new Background(bgColor);      bg.setApplicationBounds(bounds);      branchGroup.addChild(bg);      // Create the ambient light      AmbientLight ambLight = new AmbientLight(white);      ambLight.setInfluencingBounds(bounds);      branchGroup.addChild(ambLight);      // Create the directional light      Vector3f dir = new Vector3f(-1.0f, -1.0f, -1.0f);      DirectionalLight dirLight = new DirectionalLight(white, dir);      dirLight.setInfluencingBounds(bounds);      branchGroup.addChild(dirLight);      // Create the pole appearance      Material poleMaterial =         new Material(ambient, black, diffuse, specular, 110.f);      poleMaterial.setLightingEnable(true);      Appearance poleAppearance = new Appearance();      poleAppearance.setMaterial(poleMaterial);      // Create the transform group node      TransformGroup transformGroup = new TransformGroup();      transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);      transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);      branchGroup.addChild(transformGroup);      // Create the poles      Poles poles = new Poles(poleAppearance);      transformGroup.addChild(poles.getChild());      // Add the position markers to the transform group      transformGroup.addChild(positions.getChild());

⌨️ 快捷键说明

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