Hi Renoir: That is another great help. Thank you! When I run the program you give me, I found that if I start the program and press the escape key to quit, it did not work (This might be why I could not get it working before). To quit I have to use the mouse to rotate the image once. This means that I have to evoke the MouseRotate behavior at least once before I can successfully quit the program. Can I avoid that? What I mean is just simply quit by pressing escape key without touching mouse? Thank you! I have a box of beer for you, if you visit Brisbane. Guang Bin Liu VTHRC Univ. of Queensland St Lucia 4072 Brisbane, Australia >import java.awt.*; >import java.awt.event.*; >import javax.swing.*; >import javax.media.j3d.*; >import javax.vecmath.*; > >public class EyeWindow extends JWindow >{ > BorderLayout borderLayout1 = new BorderLayout(); > > /** > @param set to {@link EyeWindow#RIGHT_EYE} or {@link >EyeWindow#LEFT_EYE} > */ > public EyeWindow( final int eyeSide, final Group group ) > { > enableEvents(AWTEvent.WINDOW_EVENT_MASK); > try > { > itsEyeSide = eyeSide; > jbInit(); > > // both windows + blank interval must fill the screen > Dimension screenSize = Toolkit . getDefaultToolkit() . >getScreenSize( ); > int height = ( screenSize . height / 2 ) - ( BLANK_INTERVAL / 2 >); > this.setSize(new Dimension( screenSize . width, height ) ); > // set window on top half or bottom half of screen depending >which > // eye view it will show > // if you don't see a steroscopic effect, it is possible that you >have > // to swap the position of the window for each eye ( top -> >bottom and > // vice versa) > // another good thing would be to fill the blank interal with the >same > // color as the background to avoid stripes on the screen when >the > // monitor beam is reseted but the image buffer is still read > if( eyeSide == LEFT_EYE ) > { > this . setLocation( 0, height + BLANK_INTERVAL ); > } > else > { > this . setLocation( 0, 0 ); > } > > graphicsInit( group ); > > setVisible( true ); > } > catch(Exception e) > { > e.printStackTrace(); > } > } > > //Init (generated by JBuilder) > private void jbInit() throws Exception > { > this.getContentPane().setLayout(borderLayout1); > this.addKeyListener(new java.awt.event.KeyAdapter() > { > public void keyTyped(KeyEvent e) > { > this_keyTyped(e); > } > }); > } > > private void > graphicsInit( final Group group ) > { > final GraphicsEnvironment theEnvironment = > GraphicsEnvironment . getLocalGraphicsEnvironment( ); > final GraphicsConfiguration[] configs = > theEnvironment . getDefaultScreenDevice( ) . getConfigurations( >); > final GraphicsConfigTemplate3D configTemplate = > new GraphicsConfigTemplate3D( ); > final GraphicsConfiguration usedConfig = > configTemplate . getBestConfiguration( configs ); > itsCanvas3D = new Canvas3D( usedConfig ); > getContentPane( ) . add( itsCanvas3D ); > > itsCanvas3D.addKeyListener(new java.awt.event.KeyAdapter() > { > public void keyPressed(KeyEvent e) > { > if (e.getKeyCode() == KeyEvent.VK_ESCAPE) System.exit(0); > } > } > ); > > // seems not to work in compatibility mode > // does it work if compatibility mode is off ? (Haven't tried it >yet) >/* if( itsEyeSide == RIGHT_EYE ) > { > itsCanvas3D . setMonoscopicViewPolicy( View.RIGHT_EYE_VIEW ); > } > else > { > itsCanvas3D .setMonoscopicViewPolicy( View.LEFT_EYE_VIEW ); > } >*/ > > final ViewPlatform viewPlatform = new ViewPlatform( ); > group . addChild( viewPlatform ); > > itsView . setCompatibilityModeEnable( true ); > itsView . setProjectionPolicy( View .PERSPECTIVE_PROJECTION ); > itsView . setPhysicalBody( new PhysicalBody( ) ); > itsView . setPhysicalEnvironment( new PhysicalEnvironment( ) ); > itsView . addCanvas3D( itsCanvas3D ); > itsView . attachViewPlatform( viewPlatform ); > setCameraPosition( ); > > // set viewing frustum > Transform3D cameraView = new Transform3D( ); > // frustum takes parameters top, bottom, left, right > // relation of ( top - bottom ) : (right - left ) should equal > // ( 2 * height ) : width of Canvas3D to avoid distortions > // why 2 * height: picture will be stretched when turning >sterographic > // mode on; (not realized here) > cameraView . frustum( -0.45, 0.45, -0.45, 0.45, 1.0, 50.0 ); > itsView . setLeftProjection( cameraView ); > itsView . setRightProjection( cameraView ); > } > > private void > setCameraPosition( ) > { > // position camera > // use < > keys to change paralax > Transform3D cameraPosition = new Transform3D( ); > if( itsEyeSide == RIGHT_EYE ) > { > cameraPosition . lookAt > ( > new Point3d( itsParalax, 0, DISTANCE_TO_EYE_FOCUS ) > , new Point3d( 0.0, 0.0, 0.0 ) > , new Vector3d( 0.0, 1.0, 0.0 ) > ); > } > else > { > cameraPosition . lookAt > ( > new Point3d( -itsParalax, 0, DISTANCE_TO_EYE_FOCUS ) > , new Point3d( 0.0, 0.0, 0.0 ) > , new Vector3d( 0.0, 1.0, 0.0 ) > ); > } > > itsView . setVpcToEc( cameraPosition ); > } > > protected void processWindowEvent(WindowEvent e) > { > super.processWindowEvent(e); > if(e.getID() == WindowEvent.WINDOW_CLOSING) > { > System.exit(0); > } > } > > /** > use < > keys to change paralax > */ > void this_keyTyped(KeyEvent e) > { > if( e .getKeyChar() == '<' ) > { > itsParalax += 0.01; > } > else if( e .getKeyChar() == '>' ) > { > itsParalax = ( itsParalax > 0.01 ) ? ( itsParalax - 0.01 ) : >itsParalax; > } > setCameraPosition( ); > } > > Canvas3D itsCanvas3D = null; > > public static final int RIGHT_EYE = 0; > public static final int LEFT_EYE = 1; > > /** > change this constant until the 2 windows appear as one in stereo >mode > viewing > depends on screen resolution and frequency > real applications should enable the user to set this value >interactively > */ > private static final int BLANK_INTERVAL = 44; > > private static final double DISTANCE_TO_EYE_FOCUS = 20.0; > > private double itsParalax = 0.3; > private int itsEyeSide = RIGHT_EYE; > > final View itsView = new View( ); >} >//Titel: Stereo Test >//Version: >//Copyright: Copyright (c) 1999 >//Autor: Dipl. Ing. P. Szawlowski >//Organisation: IMC, Universität Wien > >import javax.swing.UIManager; >import java.awt.*; >import javax.media.j3d.*; >import javax.vecmath.*; >import com.sun.j3d.utils.geometry.Sphere; >import com.sun.j3d.utils.geometry.ColorCube; >import com.sun.j3d.utils.behaviors.mouse.*; > >public class StereoTestMain >{ > boolean packFrame = false; > > public StereoTestMain() > { > // viewpoint can be rotated with mouse ( hold left button and move ) > graphicsInit( ); > // instead of using two windows one could put 2 Canvas3D in one >window. > // But the 2 Canvases must be vertically symetrical in relation to >the the > // screen middle > EyeWindow rightEye = new EyeWindow( EyeWindow.RIGHT_EYE, >itsViewRotator ); > EyeWindow leftEye = new EyeWindow( EyeWindow.LEFT_EYE, >itsViewRotator ); > itsCameraBranchGroup . compile( ); > itsLocale . addBranchGraph( itsCameraBranchGroup ); > } > > public static void main( String[ ] args ) > { > try > { > UIManager.setLookAndFeel( UIManager . >getSystemLookAndFeelClassName( ) ); > } > catch( Exception e ) > { > } > new StereoTestMain( ); > } > > private void > graphicsInit( ) > { > // bounding sphere for animation and interactivity > final BoundingSphere bounds = > new BoundingSphere( new Point3d(0.0,0.0,0.0), 100.0 ); > > // some stuff to allow rotation of the viewpoint > itsViewRotator .setCapability( TransformGroup . >ALLOW_TRANSFORM_WRITE ); > itsViewRotator .setCapability( TransformGroup . ALLOW_TRANSFORM_READ >); > itsCameraBranchGroup .addChild( itsViewRotator ); > > MouseRotate rotBehavior = new MouseRotate( itsViewRotator ); > rotBehavior . setSchedulingBounds( bounds ); > itsCameraBranchGroup . addChild( rotBehavior ); > > // objects in scene > Alpha upDownAlpha = new Alpha > ( > -1 > , Alpha . DECREASING_ENABLE | Alpha . INCREASING_ENABLE > , 0 > , 0 > , 5000 > , 0 > , 0 > , 5000 > , 0 > , 0 > ); > > TransformGroup pulsatingTransformGroup = new TransformGroup( ); > pulsatingTransformGroup . setCapability( TransformGroup . >ALLOW_TRANSFORM_WRITE ); >// pulsatingTransformGroup . setCapability( TransformGroup . >ALLOW_TRANSFORM_WRITE ); > ScaleInterpolator scaleSource = new ScaleInterpolator > ( > upDownAlpha > , pulsatingTransformGroup > , new Transform3D( ) > , 1.0f > , 2.0f > ); > scaleSource . setSchedulingBounds( bounds ); > pulsatingTransformGroup . addChild( new ColorCube( 0.5f ) ); > > Transform3D translation1 = new Transform3D( ); > translation1 . setRotation( new AxisAngle4d( 1, 1, 0, 3.14 / 2 ) ); > translation1 . setTranslation( new Vector3d( 0.0, 0.0, 3.0 ) ); > TransformGroup orbitTransformGroup1 = new TransformGroup( >translation1 ); > orbitTransformGroup1 . addChild( new ColorCube( 0.5f ) ); > > Transform3D translation2 = new Transform3D( ); > translation2 . setRotation( new AxisAngle4d( 0, 1, 1, 3.14 ) ); > translation2 . setTranslation( new Vector3d( 0.0, 1.0, 5.0 ) ); > TransformGroup orbitTransformGroup2 = new TransformGroup( >translation2 ); > orbitTransformGroup2 . addChild( new ColorCube( 0.5f ) ); > > Transform3D translation3 = new Transform3D( ); > translation3 . setRotation( new AxisAngle4d( 1, 0, 1, 3.14 / 3 ) ); > translation3 . setTranslation( new Vector3d( 0.2, 0.0, 7.0 ) ); > TransformGroup orbitTransformGroup3 = new TransformGroup( >translation3 ); > orbitTransformGroup3 . addChild( new ColorCube( 0.5f ) ); > > TransformGroup rotatingTransformGroup = new TransformGroup( ); > rotatingTransformGroup .setCapability( TransformGroup . >ALLOW_TRANSFORM_WRITE ); >// rotatingTransformGroup .setCapability( TransformGroup . >ALLOW_TRANSFORM_READ ); > Alpha rotAlpha = new Alpha( -1, 5000 ); > RotationInterpolator rotationSource = > new RotationInterpolator( rotAlpha, rotatingTransformGroup ); > rotationSource . setSchedulingBounds( bounds ); > rotatingTransformGroup .addChild( orbitTransformGroup3 ); > > itsRootBranchGroup . addChild( orbitTransformGroup2 ); > itsRootBranchGroup . addChild( orbitTransformGroup1 ); > itsRootBranchGroup . addChild( pulsatingTransformGroup ); > itsRootBranchGroup . addChild( rotatingTransformGroup ); > itsRootBranchGroup . addChild( rotationSource ); > itsRootBranchGroup . addChild( scaleSource ); > > itsRootBranchGroup . compile( ); > itsLocale . addBranchGraph( itsRootBranchGroup ); > } > > private final Locale itsLocale = new Locale( new >VirtualUniverse( ) ); > private final BranchGroup itsCameraBranchGroup = new BranchGroup( >); > private final TransformGroup itsViewRotator = new TransformGroup( ); > private final BranchGroup itsRootBranchGroup = new BranchGroup( ); >} _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.aspHi Liu,
I've attached the correctly working files, add package declarations at the top.
I did the following in EyeWindow.java:
- Changed JFrame to JWindow.
- I removed the setDefaultCloseOperation as this is not available for JWindow
- I added a KeyListener to the itCanvas3D object and overrode the keyPressed method.
Regards,
Renoir
--
Renoir Sewjee
Software Engineer
ISS International (Welkom)
Tel: +27 (0)57 912 2702
Fax: +27 (0)57 912 2652
--