KeyNavigatorApp renders a simple landscape : Mouse Keyboard Action « 3D « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » 3D » Mouse Keyboard ActionScreenshots 
KeyNavigatorApp renders a simple landscape
KeyNavigatorApp renders a simple landscape


/*
 * @(#)KeyNavigatorApp.java 1.0 99/04/15 11:42:40
 
 * Copyright (c) 1996-1999 Sun Microsystems, Inc. All Rights Reserved.
 
 * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
 * modify and redistribute this software in source and binary code form,
 * provided that i) this copyright notice and license appear on all copies of
 * the software; and ii) Licensee does not utilize the software in a manner
 * which is disparaging to Sun.
 
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
 * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
 * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
 * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
 * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY
 * OF SUCH DAMAGES.
 
 * This software is not designed or intended for use in on-line control of
 * aircraft, air traffic, aircraft navigation or aircraft communications; or in
 * the design, construction, operation or maintenance of any nuclear facility.
 * Licensee represents and warrants that it will not use or redistribute the
 * Software for such purposes.
 */

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Frame;

import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.GeometryArray;
import javax.media.j3d.IndexedTriangleArray;
import javax.media.j3d.LineArray;
import javax.media.j3d.Link;
import javax.media.j3d.Shape3D;
import javax.media.j3d.SharedGroup;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3f;

import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.behaviors.keyboard.KeyNavigatorBehavior;
import com.sun.j3d.utils.universe.SimpleUniverse;

//   KeyNavigatorApp renders a simple landscape

public class KeyNavigatorApp extends Applet {

  Shape3D createPyramid() {
    IndexedTriangleArray pyGeom = new IndexedTriangleArray(5,
        GeometryArray.COORDINATES | GeometryArray.COLOR_3, 12);

    pyGeom.setCoordinate(0new Point3f(0.0f0.7f0.0f));
    pyGeom.setCoordinate(1new Point3f(-0.4f0.0f, -0.4f));
    pyGeom.setCoordinate(2new Point3f(-0.4f0.0f0.4f));
    pyGeom.setCoordinate(3new Point3f(0.4f0.0f0.4f));
    pyGeom.setCoordinate(4new Point3f(0.4f0.0f, -0.4f));

    pyGeom.setCoordinateIndex(00);
    pyGeom.setCoordinateIndex(11);
    pyGeom.setCoordinateIndex(22);
    pyGeom.setCoordinateIndex(30);
    pyGeom.setCoordinateIndex(42);
    pyGeom.setCoordinateIndex(53);
    pyGeom.setCoordinateIndex(60);
    pyGeom.setCoordinateIndex(73);
    pyGeom.setCoordinateIndex(84);
    pyGeom.setCoordinateIndex(90);
    pyGeom.setCoordinateIndex(104);
    pyGeom.setCoordinateIndex(111);

    Color3f c = new Color3f(0.6f0.5f0.55f);
    pyGeom.setColor(0, c);
    pyGeom.setColor(1, c);
    pyGeom.setColor(2, c);
    pyGeom.setColor(3, c);
    pyGeom.setColor(4, c);

    Shape3D pyramid = new Shape3D(pyGeom);
    return pyramid;
  }

  Shape3D createLand() {
    LineArray landGeom = new LineArray(44, GeometryArray.COORDINATES
        | GeometryArray.COLOR_3);
    float l = -50.0f;
    for (int c = 0; c < 44; c += 4) {

      landGeom.setCoordinate(c + 0new Point3f(-50.0f0.0f, l));
      landGeom.setCoordinate(c + 1new Point3f(50.0f0.0f, l));
      landGeom.setCoordinate(c + 2new Point3f(l, 0.0f, -50.0f));
      landGeom.setCoordinate(c + 3new Point3f(l, 0.0f50.0f));
      l += 10.0f;
    }

    Color3f c = new Color3f(0.1f0.8f0.1f);
    for (int i = 0; i < 44; i++)
      landGeom.setColor(i, c);

    return new Shape3D(landGeom);
  }

  public BranchGroup createSceneGraph(SimpleUniverse su) {
    // Create the root of the branch graph
    TransformGroup vpTrans = null;

    BranchGroup objRoot = new BranchGroup();

    Vector3f translate = new Vector3f();
    Transform3D T3D = new Transform3D();
    TransformGroup TG = null;

    objRoot.addChild(createLand());

    SharedGroup share = new SharedGroup();
    share.addChild(createPyramid());

    float[][] position = { { 0.0f0.0f, -3.0f }6.0f0.0f0.0f },
        6.0f0.0f6.0f }3.0f0.0f, -10.0f },
        13.0f0.0f, -30.0f }-13.0f0.0f30.0f },
        -13.0f0.0f23.0f }13.0f0.0f3.0f } };

    for (int i = 0; i < position.length; i++) {
      translate.set(position[i]);
      T3D.setTranslation(translate);
      TG = new TransformGroup(T3D);
      TG.addChild(new Link(share));
      objRoot.addChild(TG);
    }
    vpTrans = su.getViewingPlatform().getViewPlatformTransform();
    translate.set(0.0f0.3f0.0f);
    T3D.setTranslation(translate);
    vpTrans.setTransform(T3D);
    KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(vpTrans);
    keyNavBeh
        .setSchedulingBounds(new BoundingSphere(new Point3d()1000.0));
    objRoot.addChild(keyNavBeh);

    // Let Java 3D perform optimizations on this scene graph.
    objRoot.compile();

    return objRoot;
  // end of CreateSceneGraph method of KeyNavigatorApp

  public KeyNavigatorApp() {
    setLayout(new BorderLayout());
    Canvas3D canvas3D = new Canvas3D(null);
    add("Center", canvas3D);

    // SimpleUniverse is a Convenience Utility class
    SimpleUniverse simpleU = new SimpleUniverse(canvas3D);

    BranchGroup scene = createSceneGraph(simpleU);

    simpleU.addBranchGraph(scene);
  // end of KeyNavigatorApp (constructor)

  //  The following allows this to be run as an application
  //  as well as an applet

  public static void main(String[] args) {
    System.out
        .print("KeyNavigatorApp.java \n- a demonstration of the KeyNavigatorBehavior ");
    System.out
        .println("class to provide keyboard navigation in a Java 3D scene.");
    System.out
        .println("When the app loads, you can use the arrow keys to move.");
    System.out
        .println("This is an example progam from The Java 3D API Tutorial.");
    System.out.println("The Java 3D Tutorial is available on the web at:");
    System.out.println("http://www.sun.com/desktop/java3d/collateral");
    Frame frame = new MainFrame(new KeyNavigatorApp()256256);
  // end of main (method of KeyNavigatorApp)

// end of class KeyNavigatorApp


           
       
Related examples in the same category
1. Navigation around the sceneNavigation around the scene
2. This is our first simple program that creates a cubeThis is our first simple program that creates a cube
3. Class Drag
4. Picking utilities on various GeometryArray subclasses and Morph objectPicking utilities on various GeometryArray subclasses and Morph object
5. Oriented TestOriented Test
6. Oriented Pt TestOriented Pt Test
7. Improved mouse behaviorsImproved mouse behaviors
8. Demonstrate the use of the mouse utility classesDemonstrate the use of the mouse utility classes
9. This application demonstrates the use of a billboard nodeThis application demonstrates the use of a billboard node
10. MouseBehaviorApp renders a single, interactively rotatable,translatable, and zoomable ColorCube objectMouseBehaviorApp renders a single, interactively rotatable,translatable, and zoomable ColorCube object
11. MouseRotate2App renders a single, interactively rotatable cubeMouseRotate2App renders a single, interactively rotatable cube
12. MouseNavigatorApp renders a single, interactively rotatable, traslatable, and zoomable ColorCube objectMouseNavigatorApp renders a single, interactively rotatable, traslatable, and zoomable ColorCube object
13. Rotate when any key is pressedRotate when any key is pressed
14. PickCallbackApp renders two interactively rotatable cubesPickCallbackApp renders two interactively rotatable cubes
15. MouseRotateApp renders a single, interactively rotatable cubeMouseRotateApp renders a single, interactively rotatable cube
16. MousePickApp renders two interactively rotatable cubesMousePickApp renders two interactively rotatable cubes
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.