java left logo
java middle logo
java right logo
 

Home arrow Other API Tips
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4085
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
How to use the SimpleUniverse class to create a basic Java3D Application E-mail
User Rating: / 14
PoorBest 

Using the SimpleUniverse class in Java 3D programming significantly reduces the time and effort needed to create the view branch graph. Consequently, the programmer has more time to concentrate on the content.

This is what writing a Java 3D program is really about.

  1. Create a Canvas3D Object
  2. Create a SimpleUniverse object which references the earlier Canvas3D object
    • Customize the SimpleUniverse object
  3. Construct content branch
  4. Compile content branch graph
  5. Insert content branch graph into the Locale of the SimpleUniverse

To illustrate the simple recipe a "Hello Java3D" application is written here. The application will display a color cube in a frame. You can run this application by typing 'java HelloJava3D' in command line.

import java.awt.*;
import javax.swing.*;
import javax.media.j3d.*;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.*;

/**
 * This is the main class of the hello Java3D demo.
 */
public class HelloJava3D extends JFrame {
  public HelloJava3D() {
    GraphicsConfiguration config = SimpleUniverse
        .getPreferredConfiguration();
    Canvas3D canvas3D = new Canvas3D(config);

    BranchGroup scene = createSceneGraph();
    scene.compile();

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

    // This moves the ViewPlatform back a bit so the
    // objects in the scene can be viewed.
    simpleU.getViewingPlatform().setNominalViewingTransform();

    simpleU.addBranchGraph(scene);
    
    getContentPane().add(canvas3D,BorderLayout.CENTER);
  // end of HelloJava3D (constructor)

  public BranchGroup createSceneGraph() {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    // Create a simple shape leaf node, add it to the scene graph.
    // ColorCube is a Convenience Utility class
    objRoot.addChild(new ColorCube(0.4));

    return objRoot;
  // end of createSceneGraph method of HelloJava3D
  
  public static void main(String[] args){
    JFrame frame=new HelloJava3D();
    frame.setTitle("Hello Java3D");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBounds(0,0,400,300);
    frame.setVisible(true);
  }
// end of class HelloJava3D

 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.