I forgot to attach the complete source to the previous message. Here it is, just in case.
//Comment out the following package statement to compile separately. // package com.javaworld.media.j3d; import java.awt.*;import java.util.*;import java.awt.event.*;import javax.media.j3d.*;import javax.vecmath.*;import com.sun.j3d.utils.geometry.*;import com.sun.j3d.utils.universe.*; /** * Example04 illustrated interpolated behaviors by rotating the * text of the word "JavaWorld". * <P> * This version is compliant with Java 1.2 and * Java 3D 1.1 Beta 2, Nov 1998. Please refer to: <BR> * http://www.javaworld.com/javaworld/jw-01-1999/jw-01-media.html * <P> * * @author Bill Day <[EMAIL PROTECTED]> * @version 1.0 * @see com.javaworld.media.j3d.Example03 * @see com.sun.j3d.utils.universe.ViewingPlatform **/ public class Experiment1 extends Frame implements Runnable { /** * Instantiates an Example04 object. **/ public static void main(String args[]) { new Experiment1(); } Thread animThread; public Transform3D myTransform3D; public TransformGroup contentTransformGroup; Vector leftTeamTransform; Vector leftTeamGeometry; Vector rightTeamTransform; Vector rightTeamGeometry; /** * The Experiment1 constructor sets the frame's size, adds the * visual components, and then makes them visible to the user. * <P> * We place a Canvas3D object into the Frame so that Java 3D * has the heavyweight component it needs to render 3D * graphics into. We then call methods to construct the * View and Content branches of our scene graph. **/ public Experiment1() { //Title our frame and set its size. super("Java 3D Experiment1"); setSize(400,300); leftTeamTransform = new Vector(); rightTeamTransform = new Vector(); //Here is our first Java 3d-specific code. We add a //Canvas3D to our Frame so that we can render our 3D //graphics. Java 3D requires a heavyweight component //Canvas3D into which to render. Canvas3D myCanvas3D = new Canvas3D(null); add(myCanvas3D,BorderLayout.CENTER); //Turn on the visibility of our frame. setVisible(true); //We want to be sure we properly dispose of resources //this frame is using when the window is closed. We use //an anonymous inner class adapter for this. addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {dispose(); System.exit(0);} } ); //Use SimpleUniverse as before. SimpleUniverse myUniverse = new SimpleUniverse(myCanvas3D); BranchGroup contentBranchGroup = constructContentBranch(); myUniverse.addBranchGraph(contentBranchGroup); //Now, move the viewing position back a little bit, so that //we can see everything in our scene. We use the universe's //ViewingPlatform to get the view transform group and set //its transform. //Note: ViewingPlatform is a different class from //javax.media.j3d.ViewPlatform ViewingPlatform myView = myUniverse.getViewingPlatform(); TransformGroup myViewTransformGroup = myView.getViewPlatformTransform(); Transform3D myViewTransform = new Transform3D(); myViewTransform.setTranslation(new Vector3f(2.0f,0.0f,11.0f)); myViewTransformGroup.setTransform(myViewTransform); //System.out.println("About to run start() method"); start(); //System.out.println("About to run run() method"); run(); } // Starts a thread for the animation. public void start() { if (animThread == null) { animThread = new Thread(this, "anim"); animThread.start(); } } public void run(){ float phase=0; while (animThread != null){ int index = 0; int ltLength=leftTeamTransform.size(); int rtLength=rightTeamTransform.size(); while (index<ltLength){ Transform3D thisTransform3D=new Transform3D(); thisTransform3D.setTranslation(new Vector3f(2f+2*(float)Math.sin(phase+(double)index/2),2*(float)Math.cos(phase+(double)index/2)-1f,-8f)); thisTransform3D.setRotation(new Quat4f(-5f,(float)Math.sin((double)index/4+phase/2)*10,-2.3f,1f)); TransformGroup thisTransfromGroup=(TransformGroup)leftTeamTransform.elementAt(index); thisTransfromGroup.setTransform(thisTransform3D); index++; } phase+=0.05; try { animThread.sleep(20); } catch (InterruptedException e){ } } } /** * constructContentBranch() is where we specify the 3D graphics * content to be rendered. We return the content branch group * for use with our SimpleUniverse. We have added a RotationInterpolator * to Example03 so that in this case, our "JavaWorld" text rotates * about the origin. We have also removed the scaling and static * rotation from the text, and the scaling from our ColorCube. **/ private BranchGroup constructContentBranch() { Font myFont = new Font("TimesRoman",Font.PLAIN,2); Font3D myFont3D = new Font3D(myFont,new FontExtrusion()); Text3D myText3D = new Text3D(myFont3D, "T"); Appearance ltAppearance = new Appearance(); ltAppearance.setColoringAttributes(new ColoringAttributes(0.8f,0.1f,0.2f,ColoringAttributes.NICEST)); Appearance rtAppearance = new Appearance(); rtAppearance.setColoringAttributes(new ColoringAttributes(0.7f,0.7f,0.1f,ColoringAttributes.NICEST)); BranchGroup contentBranchGroup = new BranchGroup(); for (int i=0; i<12; i++){ Shape3D myShape3D = new Shape3D(myText3D, ltAppearance); myTransform3D = new Transform3D(); contentTransformGroup = new TransformGroup(myTransform3D); contentTransformGroup.addChild(myShape3D); contentTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); contentBranchGroup.addChild(contentTransformGroup); if (contentTransformGroup==null) System.out.println("null TG (!)"); leftTeamTransform.addElement(contentTransformGroup); } //myTransform3D.setTranslation(new Vector3f(-0.5f,-0.5f,-2.3f)); return(contentBranchGroup); } }
