java left logo
java middle logo
java right logo
 

Home arrow Other API Tips arrow Java3D arrow How to use Axis class
 
 
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: 4100
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 Axis class E-mail
User Rating: / 2
PoorBest 

This Java tip shows how to use Axis class in Java3D.


Image

import java.applet.Applet;
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.Geometry;
import javax.media.j3d.GeometryArray;
import javax.media.j3d.IndexedLineArray;
import javax.media.j3d.RotationInterpolator;
import javax.media.j3d.Shape3D;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Point3d;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3f;

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

public class AxisClassDemoApp extends Applet {

  /////////////////////////////////////////////////
  //
  // create scene graph branch group
  //
  public BranchGroup createSceneGraph() {

    BranchGroup objRoot = new BranchGroup();
    objRoot.addChild(new Axis());

    // Create the transform group node and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime. Add it to the
    // root of the subgraph.
    TransformGroup objSpin = new TransformGroup();
    objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    // Create a new Behavior object that will perform the desired
    // operation on the specified transform object and add it into
    // the scene graph.
    Transform3D yAxis = new Transform3D();
    Alpha rotationAlpha = new Alpha(-14000);

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha,
        objSpin);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.00.00.0),
        100.0);
    rotator.setSchedulingBounds(bounds);

    Transform3D trans = new Transform3D();
    trans.set(new Vector3f(0.5f0.0f0.0f));
    TransformGroup objTrans = new TransformGroup(trans);
    objRoot.addChild(objSpin);
    objSpin.addChild(objTrans);
    objSpin.addChild(rotator);
    objTrans.addChild(new ColorCube(0.1));

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

    return objRoot;
  // end of CreateSceneGraph method of AxisClassDemoApp

  // Create a simple scene and attach it to the virtual universe

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

    BranchGroup scene = createSceneGraph();

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

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

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

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

  public static void main(String[] args) {
    Frame frame = new MainFrame(new AxisClassDemoApp()256256);
  // end of main method of AxisClassDemoApp

// end of class AxisClassDemoApp

/*
 * Getting Started with the Java 3D API written in Java 3D
 
 * This program demonstrates: 1. writing a visual object class In this program,
 * Axis class defines a visual object This particular class extends Shape3D See
 * the text for a discussion. 2. Using LineArray to draw 3D lines.
 */

class Axis extends Shape3D {

  ////////////////////////////////////////////
  //
  // create axis visual object
  //
  public Axis() {

    this.setGeometry(createGeometry());

  }

  private Geometry createGeometry() {
    // create line for X axis
    IndexedLineArray axisLines = new IndexedLineArray(18,
        GeometryArray.COORDINATES, 30);

    axisLines.setCoordinate(0new Point3f(-1.0f0.0f0.0f));
    axisLines.setCoordinate(1new Point3f(1.0f0.0f0.0f));
    axisLines.setCoordinate(2new Point3f(0.9f0.1f0.1f));
    axisLines.setCoordinate(3new Point3f(0.9f, -0.1f0.1f));
    axisLines.setCoordinate(4new Point3f(0.9f0.1f, -0.1f));
    axisLines.setCoordinate(5new Point3f(0.9f, -0.1f, -0.1f));
    axisLines.setCoordinate(6new Point3f(0.0f, -1.0f0.0f));
    axisLines.setCoordinate(7new Point3f(0.0f1.0f0.0f));
    axisLines.setCoordinate(8new Point3f(0.1f0.9f0.1f));
    axisLines.setCoordinate(9new Point3f(-0.1f0.9f0.1f));
    axisLines.setCoordinate(10new Point3f(0.1f0.9f, -0.1f));
    axisLines.setCoordinate(11new Point3f(-0.1f0.9f, -0.1f));
    axisLines.setCoordinate(12new Point3f(0.0f0.0f, -1.0f));
    axisLines.setCoordinate(13new Point3f(0.0f0.0f1.0f));
    axisLines.setCoordinate(14new Point3f(0.1f0.1f0.9f));
    axisLines.setCoordinate(15new Point3f(-0.1f0.1f0.9f));
    axisLines.setCoordinate(16new Point3f(0.1f, -0.1f0.9f));
    axisLines.setCoordinate(17new Point3f(-0.1f, -0.1f0.9f));

    axisLines.setCoordinateIndex(00);
    axisLines.setCoordinateIndex(11);
    axisLines.setCoordinateIndex(22);
    axisLines.setCoordinateIndex(31);
    axisLines.setCoordinateIndex(43);
    axisLines.setCoordinateIndex(51);
    axisLines.setCoordinateIndex(64);
    axisLines.setCoordinateIndex(71);
    axisLines.setCoordinateIndex(85);
    axisLines.setCoordinateIndex(91);
    axisLines.setCoordinateIndex(106);
    axisLines.setCoordinateIndex(117);
    axisLines.setCoordinateIndex(128);
    axisLines.setCoordinateIndex(137);
    axisLines.setCoordinateIndex(149);
    axisLines.setCoordinateIndex(157);
    axisLines.setCoordinateIndex(1610);
    axisLines.setCoordinateIndex(177);
    axisLines.setCoordinateIndex(1811);
    axisLines.setCoordinateIndex(197);
    axisLines.setCoordinateIndex(2012);
    axisLines.setCoordinateIndex(2113);
    axisLines.setCoordinateIndex(2214);
    axisLines.setCoordinateIndex(2313);
    axisLines.setCoordinateIndex(2415);
    axisLines.setCoordinateIndex(2513);
    axisLines.setCoordinateIndex(2616);
    axisLines.setCoordinateIndex(2713);
    axisLines.setCoordinateIndex(2817);
    axisLines.setCoordinateIndex(2913);

    return axisLines;  // end of Axis createGeometry()

// end of class Axis

 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.