Simple 3D Demo : 3D Basics « 3D « Java

Home
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 » 3D » 3D BasicsScreenshots 
Simple 3D Demo
Simple 3D Demo


import java.awt.BorderLayout;
import java.awt.Frame;

import javax.media.j3d.Alpha;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.RotationInterpolator;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Point3d;

import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;

public class HelloWorld {
  public static void main(String[] args) {
    Frame frame = new Frame();
    frame.setSize(640480);
    frame.setLayout(new BorderLayout());

    Canvas3D canvas = new Canvas3D(null);
    frame.add("Center", canvas);

    SimpleUniverse univ = new SimpleUniverse(canvas);
    univ.getViewingPlatform().setNominalViewingTransform();

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

    frame.show();
  }

  private static BranchGroup createSceneGraph() {
    // Make a scene graph branch
    BranchGroup branch = new BranchGroup();

    // Make a changeable 3D transform
    TransformGroup trans = new TransformGroup();
    trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    branch.addChild(trans);

    // Make a shape
    ColorCube demo = new ColorCube(0.4);
    trans.addChild(demo);

    // Make a behavor to spin the shape
    Alpha spinAlpha = new Alpha(-14000);
    RotationInterpolator spinner = new RotationInterpolator(spinAlpha,
        trans);
    spinner.setSchedulingBounds(new BoundingSphere(new Point3d()1000.0));
    trans.addChild(spinner);

    return branch;
  }
}


           
       
Related examples in the same category
1.Positioning the ObjectsPositioning the Objects
2.Basic steps needed to display 3D objectsBasic steps needed to display 3D objects
3.Basic ConstructBasic Construct
4.Appearance Scope
5.AppearanceAppearance
6.Appearance Mixed
7.Getting Started with the Java 3D API written in Java 3DGetting Started with the Java 3D API written in Java 3D
8.Simple RotationSimple Rotation
9.HelloJava3Db renders a single, rotated cubeHelloJava3Db renders a single, rotated cube
10.User Interfaces with Java
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.