diff options
author | kcr <kcr@28c7f869-5b4e-e670-f602-82bfaf57f300> | 2006-03-07 17:42:45 +0000 |
---|---|---|
committer | kcr <kcr@28c7f869-5b4e-e670-f602-82bfaf57f300> | 2006-03-07 17:42:45 +0000 |
commit | d2f4b6c478a34d0089711a7bb8286bd0d04abbfb (patch) | |
tree | 535d86f45afccd54017d7f9a647302d1409d4312 | |
parent | 19e30a5771eb1ec413e562c0d99b6263978dfba0 (diff) |
Merged changes between 1.4.0-beta4 and 1.4.0-fcs into dev-1_5 branch
65 files changed, 2738 insertions, 4012 deletions
diff --git a/README-build.html b/README-build.html index d813751..ec62fea 100644 --- a/README-build.html +++ b/README-build.html @@ -80,10 +80,10 @@ work.We have built j3d-examples on the following operating environments:<br> </ul> <p>The following software must be installed:</p> <ul> - <li><a href="http://java.sun.com/j2se">JDK 1.4.2</a> </li> + <li><a href="http://java.sun.com/j2se">JDK 1.5.0</a> </li> <li><a href="http://jakarta.apache.org/ant">Apache Ant 1.6.1</a> </li> - <li><a href="http://java.sun.com/products/java-media/3D/">Java 3D -1.3.1</a> or later. </li> + <li><a href="https://java3d.dev.java.net/">Java 3D +1.5.0</a> or later. </li> </ul> <h3><span style="text-decoration: underline;">Building j3d-examples</span><span @@ -96,7 +96,8 @@ following directories:</p> <li><ant-root-dir>/bin</li> <li><jdk-root_dir>/bin</li> </ul> -<p>NOTE that Java 3D must be installed into the JDK that you have in +<p>NOTE that Java 3D must be installed into the JDK that you have +in your path <span style="font-weight: bold;">OR</span> you must put the Java 3D and vecmath jar files (j3dcore.jar, j3dutils.jar and vecmath.jar) in your CLASSPATH and the directory containing the @@ -110,33 +111,29 @@ PATH (Windows).<br> </ul> <p> </p> -<p>This will build all example programs, each one being placed in the -corresponding <code>src/<ExampleProgram></code> directory. -You may run -ant from a subdirectory in order to just build that program. For -example, to build the HelloUniverse program:<br> -</p> -<ul> - <code>cd <cvs-root-dir>/j3d-examples/src/HelloUniverse</code><br> - <code>ant</code> -</ul> -<p> +<p>This will build all example programs and bundle them into a single +jar +file,<code> j3d-examples.jar</code>, placed in the <code>dist</code> +directory. <br> </p> <h3><span style="text-decoration: underline;">Running j3d-examples</span></h3> -<p>To run an example program, cd to the desired directory and execute -java from there. You must ensure that CLASSPATH is either not set, or -contains "." in its list of directories. For example, to run the +<p>To run an example program, you must ensure that your CLASSPATH +contains <code>dist/j3d-examples.jar </code>in its list. For example, +to run the HelloUniverse program:<br> </p> <ul> - <code>cd <cvs-root-dir>/j3d-examples/src/HelloUniverse</code><br> - <code>java HelloUniverse<br> + <code>cd <cvs-root-dir>/j3d-examples<br> + </code> <code>java +org.jdesktop.j3d.examples.hello_universe.HelloUniverse<br> </code> </ul> <p> </p> -<p>You may also point your Java-enabled web browser at the -<code>src/index.html</code> page and run Java 3D example programs +<p>You may also point your Java-enabled web browser at some Java 3D +applet +examples, such as the <code>src/classes/org/jdesktop/j3d/examples/FourByFour.html</code> +page, and run the Java 3D applet example programs from within your browser. Java 3D must be installed into the JDK in order to run Java 3D programs from within a browser.<br> <br> diff --git a/THIRDPARTY-LICENSE-3DLABS.txt b/THIRDPARTY-LICENSE-3DLABS.txt index 90a7ec1..394e2c6 100644 --- a/THIRDPARTY-LICENSE-3DLABS.txt +++ b/THIRDPARTY-LICENSE-3DLABS.txt @@ -1,7 +1,7 @@ The following additional provisions apply to third party software included as part of this product. - src/GLSLShaderTest/ + src/classes/org/jdesktop/j3d/examples/glsl_shader/ dimple.frag - shader for ObjLoadGLSL.java dimple.vert - shader for ObjLoadGLSL.java polkadot3d.frag - shader for ObjLoadGLSL.java @@ -44,4 +44,4 @@ included as part of this product. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * * POSSIBILITY OF SUCH DAMAGE. * * * -************************************************************************/
\ No newline at end of file +************************************************************************/ @@ -54,6 +54,7 @@ <property name="build" location="build"/> <property name="dist" location="dist"/> <property name="output.jar" location="dist/j3d-examples.jar"/> + <property name="output.zip" location="dist/j3d-examples-1_5_0-src.zip"/> </target> <target name="compile" depends="init"> @@ -68,22 +69,47 @@ debug="true" deprecation="off"> </javac> + + <!-- Copy resources to build in preparation for jarring --> + <copy todir="${build}/classes/org/jdesktop/j3d/examples/resources"> + <fileset dir="${src}/resources"/> + </copy> + + <!-- Copy all non class files from src to build --> + <copy todir="${build}/classes/org/jdesktop/j3d/examples"> + <fileset dir="${src}/classes/org/jdesktop/j3d/examples" + includes ="**/*.vert **/*.frag **/*.cg **/*.cfg **/*.html **/*.txt"/> + </copy> + </target> <target name="jar" depends="init,compile"> <!-- Create the dist directory --> <mkdir dir="${dist}"/> - + <!-- Create the jar file --> <jar jarfile="${output.jar}" manifest="manifest.mf" update="no" - compress="false"> + compress="true"> <fileset dir="${build}/classes" includes="org/**/*"/> </jar> </target> - <target name="all" depends="init,jar"> + <target name="zip" depends="init"> + <mkdir dir="${dist}"/> + <zip destfile="${output.zip}"> + <fileset dir=".." includes="j3d-examples/src/**"/> + <fileset dir=".." includes="j3d-examples/COPYRIGHT.txt"/> + <fileset dir=".." includes="j3d-examples/README*.*"/> + <fileset dir=".." includes="j3d-examples/*LICENSE*.*"/> + <fileset dir=".." includes="j3d-examples/build.xml"/> + <fileset dir=".." includes="j3d-examples/manifest.mf"/> + <fileset dir=".." includes="j3d-examples/nbproject/**" excludes="j3d-examples/nbproject/private/**"/> + </zip> + </target> + + <target name="all" depends="init,jar,zip"> </target> <target name="clean" depends="init"> @@ -106,24 +132,293 @@ ************************************************** --> + <target name="run.AppearanceMixed" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.appearance.AppearanceMixed"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.AppearanceTest" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.appearance.AppearanceTest"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.Applet3D" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.applet3d.Applet3D"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.BackgroundGeometry" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.background.BackgroundGeometry"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.ConfigObjLoad" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.configured_universe.ConfigObjLoad"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.DepthFuncTest" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.depth_func.DepthFuncTest"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.DistortGlyphTest" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.distort_glyph.DistortGlyphTest"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.Dot3Demo" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.dot3.Dot3Demo"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.EnvironmentMappingGLSL" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.glsl_shader.EnvironmentMappingGLSL"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.FourByFour" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.four_by_four.FourByFour"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.FPSCounterDemo" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.fps_counter.FPSCounterDemo"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.GearBox" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.gears.GearBox"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.GearTest" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.gears.GearTest"> + <classpath refid="run.classpath"/> + </java> + </target> + <target name="run.HelloUniverse" depends="init-run"> - <java classpath="${run.classpath}" - fork="true" + <java fork="true" classname="org.jdesktop.j3d.examples.hello_universe.HelloUniverse"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.ImageComponentByReferenceTest" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.geometry_by_ref.ImageComponentByReferenceTest"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.InterleavedNIOBuffer" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.geometry_by_ref.InterleavedNIOBuffer"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.InterleavedTest" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.geometry_by_ref.InterleavedTest"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.LOD" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.lod.LOD"> + <classpath refid="run.classpath"/> </java> </target> + <target name="run.Morphing" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.morphing.Morphing"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.MultiTextureTest" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.texture.MultiTextureTest"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.ObjLoad" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.objload.ObjLoad"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.ObjLoadCg" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.cg_shader.ObjLoadCg"> + <classpath refid="run.classpath"/> + <sysproperty key="j3d.shadingLanguage" value="Cg"/> + </java> + </target> + + <target name="run.ObjLoadGLSL" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.glsl_shader.ObjLoadGLSL"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.OrientedPtTest" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.oriented_shape3d.OrientedPtTest"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.OrientedTest" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.oriented_shape3d.OrientedTest"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.PrintCanvas3D" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.print_canvas3d.PrintCanvas3D"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.PhongShadingGLSL" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.glsl_shader.PhongShadingGLSL"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.PureImmediate" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.pure_immediate.PureImmediate"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.PureImmediateStereo" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.pure_immediate.PureImmediateStereo"> + <classpath refid="run.classpath"/> + </java> + </target> + +<target name="run.Pyramid2Cube" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.morphing.Pyramid2Cube"> + <classpath refid="run.classpath"/> + </java> + </target> + <target name="run.QueryProperties" depends="init-run"> - <java classpath="${run.classpath}" - fork="true" + <java fork="true" classname="org.jdesktop.j3d.examples.package_info.QueryProperties"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.SamplerTestGLSL" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.glsl_shader.SamplerTestGLSL"> + <classpath refid="run.classpath"/> </java> </target> - <target name="run.SphereMotion" depends="init-run"> - <java classpath="${run.classpath}" - fork="true" + <target name="run.ShaderTestGLSL" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.glsl_shader.ShaderTestGLSL"> + <classpath refid="run.classpath"/> + </java> + </target> + +<target name="run.SphereMotion" depends="init-run"> + <java fork="true" classname="org.jdesktop.j3d.examples.sphere_motion.SphereMotion"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.SphereGLSL" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.glsl_shader.SphereGLSL"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.SphereCg" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.cg_shader.SphereCg"> + <classpath refid="run.classpath"/> + <sysproperty key="j3d.shadingLanguage" value="Cg"/> + </java> + </target> + + <target name="run.TextureByReference" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.texture_by_ref.TextureByReference"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.TextureImage" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.texture.TextureImage"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.TickTockCollision" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.collision.TickTockCollision"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.VertexAttrTestGLSL" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.glsl_shader.VertexAttrTestGLSL"> + <classpath refid="run.classpath"/> + </java> + </target> + + <target name="run.VertexAttrTestCg" depends="init-run"> + <java fork="true" + classname="org.jdesktop.j3d.examples.cg_shader.VertexAttrTestCg"> + <classpath refid="run.classpath"/> + <sysproperty key="j3d.shadingLanguage" value="Cg"/> </java> </target> diff --git a/manifest.mf b/manifest.mf index dc0b38e..4ca12ca 100644 --- a/manifest.mf +++ b/manifest.mf @@ -1,5 +1,5 @@ Manifest-Version: 1.0 Implementation-Title: Java 3D Example Programs -Implementation-Version: 1.4.0 +Implementation-Version: 1.5.0 Implementation-Vendor: Sun Microsystems, Inc. Main-Class: org.jdesktop.j3d.examples.hello_universe.HelloUniverse diff --git a/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceMixed.java b/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceMixed.java index 578401e..598f5cb 100644 --- a/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceMixed.java +++ b/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceMixed.java @@ -44,23 +44,19 @@ package org.jdesktop.j3d.examples.appearance; -import java.applet.Applet; -import java.awt.*; -import java.awt.event.*; -import java.awt.GraphicsConfiguration; -import com.sun.j3d.utils.applet.MainFrame; -import com.sun.j3d.utils.universe.*; import com.sun.j3d.utils.image.TextureLoader; -import com.sun.j3d.utils.geometry.ColorCube; +import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; +import java.awt.GraphicsConfiguration; +import org.jdesktop.j3d.examples.Resources; -public class AppearanceMixed extends Applet { - - private java.net.URL bgImage; - private java.net.URL texImage; +public class AppearanceMixed extends javax.swing.JFrame { - private SimpleUniverse u = null; + private java.net.URL texImage = null; + private java.net.URL bgImage = null; + private SimpleUniverse univ = null; + private BranchGroup scene = null; static class MyCanvas3D extends Canvas3D { private GraphicsContext3D gc; @@ -433,76 +429,96 @@ public class AppearanceMixed extends Applet { } - public AppearanceMixed() { - } - - public AppearanceMixed(java.net.URL bgurl, java.net.URL texurl) { - bgImage = bgurl; - texImage = texurl; - } - public void init() { - if (bgImage == null) { - // the path to the image for an applet - try { - bgImage = new java.net.URL(getCodeBase().toString() + - "../images/bg.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - } - - if (texImage == null) { - // the path to the image for an applet - try { - texImage = new java.net.URL(getCodeBase().toString() + - "../images/apimage.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - } - setLayout(new BorderLayout()); - GraphicsConfiguration config = - SimpleUniverse.getPreferredConfiguration(); + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); + // Create a MyCanvas3D using the preferred configuration MyCanvas3D c = new MyCanvas3D(config); - add("Center", c); - // Create a simple scene and attach it to the virtual universe - BranchGroup scene = createSceneGraph(); - u = new SimpleUniverse(c); + // Create simple universe with view branch + univ = new SimpleUniverse(c); - // This will move the ViewPlatform back a bit so the - // objects in the scene can be viewed. - u.getViewingPlatform().setNominalViewingTransform(); + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + univ.getViewingPlatform().setNominalViewingTransform(); - u.addBranchGraph(scene); - } + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); - public void destroy() { - u.cleanup(); + return c; } + /** + * Creates new form AppearanceMixed + */ + public AppearanceMixed() { - // - // The following allows AppearanceMixed to be run as an application - // as well as an applet - // - public static void main(String[] args) { - // the path to the image file for an application - java.net.URL bgurl = null; - java.net.URL texurl = null; - try { - bgurl = new java.net.URL("file:../images/bg.jpg"); - texurl = new java.net.URL("file:../images/apimage.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - new MainFrame(new AppearanceMixed(bgurl, texurl), 700, 700); + if (bgImage == null) { + // the path to the image for an applet + bgImage = Resources.getResource("resources/images/bg.jpg"); + if (bgImage == null) { + System.err.println("resources/images/bg.jpg not found"); + System.exit(1); + } + } + + if (texImage == null) { + // the path to the image for an applet + texImage = Resources.getResource("resources/images/stone.jpg"); + if (texImage == null) { + System.err.println("resources/images/stone.jpg not found"); + System.exit(1); + } + } + + // Initialize the GUI components + initComponents(); + + // Create Canvas3D and SimpleUniverse; add canvas to drawing panel + Canvas3D c = createUniverse(); + drawingPanel.add(c, java.awt.BorderLayout.CENTER); + + // Create the content branch and add it to the universe + scene = createSceneGraph(); + univ.addBranchGraph(scene); + } + + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("AppearanceMixed"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// </editor-fold>//GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new AppearanceMixed().setVisible(true); + } + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceTest.java b/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceTest.java index 8d57c48..1ef7471 100644 --- a/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceTest.java +++ b/src/classes/org/jdesktop/j3d/examples/appearance/AppearanceTest.java @@ -44,21 +44,19 @@ package org.jdesktop.j3d.examples.appearance; -import java.applet.Applet; -import java.awt.*; -import java.awt.event.*; -import com.sun.j3d.utils.applet.MainFrame; -import com.sun.j3d.utils.universe.*; import com.sun.j3d.utils.image.TextureLoader; +import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; +import java.awt.GraphicsConfiguration; +import org.jdesktop.j3d.examples.Resources; -public class AppearanceTest extends Applet { +public class AppearanceTest extends javax.swing.JFrame { private java.net.URL texImage = null; private java.net.URL bgImage = null; - - private SimpleUniverse u = null; + private SimpleUniverse univ = null; + private BranchGroup scene = null; private BranchGroup createSceneGraph() { // Create the root of the branch graph @@ -110,7 +108,6 @@ public class AppearanceTest extends Applet { return objRoot; } - private Appearance createAppearance(int idx) { Appearance app = new Appearance(); @@ -305,78 +302,96 @@ public class AppearanceTest extends Applet { return objTrans; } + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); - public AppearanceTest() { - } - - public AppearanceTest(java.net.URL bgurl, java.net.URL texurl) { - bgImage = bgurl; - texImage = texurl; - } - - public void init() { - if (bgImage == null) { - // the path to the image for an applet - try { - bgImage = new java.net.URL(getCodeBase().toString() + - "../images/bg.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - } - - if (texImage == null) { - // the path to the image for an applet - try { - texImage = new java.net.URL(getCodeBase().toString() + - "../images/apimage.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - } - setLayout(new BorderLayout()); - GraphicsConfiguration config = - SimpleUniverse.getPreferredConfiguration(); + // Create a Canvas3D using the preferred configuration + Canvas3D c = new Canvas3D(config); - Canvas3D c = new Canvas3D(config); - add("Center", c); + // Create simple universe with view branch + univ = new SimpleUniverse(c); - // Create a simple scene and attach it to the virtual universe - BranchGroup scene = createSceneGraph(); - u = new SimpleUniverse(c); + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + univ.getViewingPlatform().setNominalViewingTransform(); - // This will move the ViewPlatform back a bit so the - // objects in the scene can be viewed. - u.getViewingPlatform().setNominalViewingTransform(); + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); - u.addBranchGraph(scene); + return c; } - public void destroy() { - u.cleanup(); - } + /** + * Creates new form AppearanceTest + */ + public AppearanceTest() { + if (bgImage == null) { + // the path to the image for an applet + bgImage = Resources.getResource("resources/images/bg.jpg"); + if (bgImage == null) { + System.err.println("resources/images/bg.jpg not found"); + System.exit(1); + } + } + + if (texImage == null) { + // the path to the image for an applet + texImage = Resources.getResource("resources/images/stone.jpg"); + if (texImage == null) { + System.err.println("resources/images/stone.jpg not found"); + System.exit(1); + } + } + + // Initialize the GUI components + initComponents(); + + // Create Canvas3D and SimpleUniverse; add canvas to drawing panel + Canvas3D c = createUniverse(); + drawingPanel.add(c, java.awt.BorderLayout.CENTER); + + // Create the content branch and add it to the universe + scene = createSceneGraph(); + univ.addBranchGraph(scene); + } - // - // The following allows AppearanceTest to be run as an application - // as well as an applet - // - public static void main(String[] args) { - // the path to the image file for an application - java.net.URL bgurl = null; - java.net.URL texurl = null; - try { - bgurl = new java.net.URL("file:../images/bg.jpg"); - texurl = new java.net.URL("file:../images/apimage.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - new MainFrame(new AppearanceTest(bgurl, texurl), 700, 700); + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("AppearanceTest"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// </editor-fold>//GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new AppearanceTest().setVisible(true); + } + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/applet3d/Applet3D.html b/src/classes/org/jdesktop/j3d/examples/applet3d/Applet3D.html index 8ab3a5d..9cb15a4 100644 --- a/src/classes/org/jdesktop/j3d/examples/applet3d/Applet3D.html +++ b/src/classes/org/jdesktop/j3d/examples/applet3d/Applet3D.html @@ -3,7 +3,7 @@ <TITLE>Hello, Universe</TITLE> </HEAD> <BODY BGCOLOR="#000000"> -<applet align=middle code="Applet3D.class" width=256 height=256> +<applet align=middle codebase="../../../../.." code="org.jdesktop.j3d.examples.applet3d.Applet3D" width=256 height=256> <blockquote> <hr> If you were using a Java-capable browser, diff --git a/src/classes/org/jdesktop/j3d/examples/applet3d/Applet3D_plugin.html b/src/classes/org/jdesktop/j3d/examples/applet3d/Applet3D_plugin.html deleted file mode 100644 index e47eecc..0000000 --- a/src/classes/org/jdesktop/j3d/examples/applet3d/Applet3D_plugin.html +++ /dev/null @@ -1,39 +0,0 @@ -<HTML> -<HEAD> -<TITLE>Hello, Universe!</TITLE> -</HEAD> -<BODY BGCOLOR="#000000"> -<!--"CONVERTED_APPLET"--> -<!-- CONVERTER VERSION 1.3 --> -<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" -WIDTH = 256 HEIGHT = 256 ALIGN = middle codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0"> -<PARAM NAME = CODE VALUE = "Applet3D.class" > - -<PARAM NAME="type" VALUE="application/x-java-applet;version=1.2.2"> -<PARAM NAME="scriptable" VALUE="false"> -<COMMENT> -<EMBED type="application/x-java-applet;version=1.2.2" CODE = "Applet3D.class" WIDTH = 256 HEIGHT = 256 ALIGN = middle scriptable=false pluginspage="http://java.sun.com/products/plugin/1.3/plugin-install.html"><NOEMBED></COMMENT> -<blockquote> -<hr> -If you were using a Java-capable browser, -you would see Hello Universe! instead of this paragraph. -<hr> -</blockquote> -</NOEMBED></EMBED> -</OBJECT> - -<!-- -<APPLET CODE = "Applet3D.class" WIDTH = 256 HEIGHT = 256 ALIGN = middle> -<blockquote> -<hr> -If you were using a Java-capable browser, -you would see Hello Universe! instead of this paragraph. -<hr> -</blockquote> - -</APPLET> ---> -<!--"END_CONVERTED_APPLET"--> - -</BODY> -</HTML> diff --git a/src/classes/org/jdesktop/j3d/examples/background/BackgroundGeometry.java b/src/classes/org/jdesktop/j3d/examples/background/BackgroundGeometry.java index e6ea23c..cdf656c 100644 --- a/src/classes/org/jdesktop/j3d/examples/background/BackgroundGeometry.java +++ b/src/classes/org/jdesktop/j3d/examples/background/BackgroundGeometry.java @@ -46,22 +46,19 @@ package org.jdesktop.j3d.examples.background; import com.sun.j3d.utils.image.TextureLoader; import com.sun.j3d.utils.behaviors.mouse.*; -import java.applet.Applet; -import java.awt.*; -import java.awt.event.*; -import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; +import java.awt.GraphicsConfiguration; +import org.jdesktop.j3d.examples.Resources; -public class BackgroundGeometry extends Applet { - - BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); +public class BackgroundGeometry extends javax.swing.JFrame { + private SimpleUniverse univ = null; + private BranchGroup scene = null; private java.net.URL bgImage = null; - - private SimpleUniverse u = null; + private BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); public BranchGroup createSceneGraph() { @@ -153,49 +150,32 @@ public class BackgroundGeometry extends Applet { lgt2.setInfluencingBounds(bounds); objScale.addChild(lgt1); objScale.addChild(lgt2); - return objRoot; } - public BackgroundGeometry (){ - } + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); - public BackgroundGeometry(java.net.URL bgurl) { - bgImage = bgurl; - } - - public void init() { + // Create a Canvas3D using the preferred configuration + Canvas3D c = new Canvas3D(config); - if (bgImage == null) { - // the path to the image for an applet - try { - bgImage = new java.net.URL(getCodeBase().toString() + - "../images/bg.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - } - setLayout(new BorderLayout()); - GraphicsConfiguration config = - SimpleUniverse.getPreferredConfiguration(); + // Create simple universe with view branch + univ = new SimpleUniverse(c); - Canvas3D c = new Canvas3D(config); - add("Center", c); - - BranchGroup scene = createSceneGraph(); - u = new SimpleUniverse(c); + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + univ.getViewingPlatform().setNominalViewingTransform(); - // This will move the ViewPlatform back a bit so the - // objects in the scene can be viewed. - u.getViewingPlatform().setNominalViewingTransform(); + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); TransformGroup viewTrans = - u.getViewingPlatform().getViewPlatformTransform(); - - // Create the rotate behavior node + univ.getViewingPlatform().getViewPlatformTransform(); + + // Create the rotate behavior node MouseRotate behavior1 = new MouseRotate(viewTrans); scene.addChild(behavior1); behavior1.setSchedulingBounds(bounds); @@ -210,29 +190,74 @@ public class BackgroundGeometry extends Applet { scene.addChild(behavior3); behavior3.setSchedulingBounds(bounds); + return c; + } + + /** + * Creates new form BackgroundGeometry + */ + public BackgroundGeometry() { + + if (bgImage == null) { + // the path to the image for an applet + bgImage = Resources.getResource("resources/images/bg.jpg"); + if (bgImage == null) { + System.err.println("resources/images/bg.jpg not found"); + System.exit(1); + } + } + + // Initialize the GUI components + initComponents(); + + // Create the content branch and add it to the universe + scene = createSceneGraph(); + + // Create Canvas3D and SimpleUniverse; add canvas to drawing panel + Canvas3D c = createUniverse(); + drawingPanel.add(c, java.awt.BorderLayout.CENTER); + // Let Java 3D perform optimizations on this scene graph. scene.compile(); - u.addBranchGraph(scene); + univ.addBranchGraph(scene); } - public void destroy() { - u.cleanup(); - } - - public static void main(String argv[]) { - System.out.println("Usage: mouse buttons to rotate, zoom or translate the view platform transform"); - System.out.println(" Note that the background geometry only changes with rotation"); - // the path to the image file for an application - java.net.URL bgurl = null; - try { - bgurl = new java.net.URL("file:../images/bg.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - new MainFrame(new BackgroundGeometry(bgurl), 750, 750); + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("BackgroundGeometry"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setOpaque(false); + drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// </editor-fold>//GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new BackgroundGeometry().setVisible(true); + } + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } - diff --git a/src/classes/org/jdesktop/j3d/examples/cg_shader/ObjLoadCg.java b/src/classes/org/jdesktop/j3d/examples/cg_shader/ObjLoadCg.java index 02d02a1..1e10b8d 100644 --- a/src/classes/org/jdesktop/j3d/examples/cg_shader/ObjLoadCg.java +++ b/src/classes/org/jdesktop/j3d/examples/cg_shader/ObjLoadCg.java @@ -49,28 +49,32 @@ import com.sun.j3d.loaders.ParsingErrorException; import com.sun.j3d.loaders.IncorrectFormatException; import com.sun.j3d.loaders.Scene; import com.sun.j3d.utils.shader.StringIO; -import java.applet.Applet; -import java.awt.*; -import java.awt.event.*; -import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; +import java.awt.GraphicsConfiguration; +import java.net.MalformedURLException; import java.util.Enumeration; import java.io.*; -import com.sun.j3d.utils.behaviors.vp.*; import java.net.URL; -import java.net.MalformedURLException; +import com.sun.j3d.utils.behaviors.vp.*; +import java.io.FileNotFoundException; +import javax.swing.JOptionPane; +import org.jdesktop.j3d.examples.Resources; -public class ObjLoadCg extends Applet { +/** + * Simple Java 3D example program to display an .obj object with shader programs. + */ +public class ObjLoadCg extends javax.swing.JFrame { private boolean spin = false; private boolean noTriangulate = false; private boolean noStripify = false; private double creaseAngle = 60.0; private URL filename = null; - private SimpleUniverse u; - private BoundingSphere bounds; + + private SimpleUniverse univ = null; + private BranchGroup scene = null; public BranchGroup createSceneGraph() { // Create the root of the branch graph @@ -119,8 +123,8 @@ public class ObjLoadCg extends Applet { String vertexProgram = null; String fragmentProgram = null; try { - vertexProgram = StringIO.readFully("./simple_vp.cg"); - fragmentProgram = StringIO.readFully("./simple_fp.cg"); + vertexProgram = StringIO.readFully(Resources.getResource("cg_shader/simple_vp.cg")); + fragmentProgram = StringIO.readFully(Resources.getResource("cg_shader/simple_fp.cg")); } catch (IOException e) { e.printStackTrace(); @@ -139,7 +143,7 @@ public class ObjLoadCg extends Applet { objTrans.addChild(s.getSceneGroup()); - bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); + BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); if (spin) { Transform3D yAxis = new Transform3D(); @@ -163,49 +167,32 @@ public class ObjLoadCg extends Applet { return objRoot; } - - private void usage() - { - System.out.println( - "Usage: java ObjLoadCg [-s] [-n] [-t] [-c degrees] <.obj file>"); - System.out.println(" -s Spin (no user interaction)"); - System.out.println(" -n No triangulation"); - System.out.println(" -t No stripification"); - System.out.println( - " -c Set crease angle for normal generation (default is 60 without"); - System.out.println( - " smoothing group info, otherwise 180 within smoothing groups)"); - System.exit(0); - } // End of usage - - - - public void init() { - if (filename == null) { - // Applet - try { - URL path = getCodeBase(); - filename = new URL(path.toString() + "./galleon.obj"); - } - catch (MalformedURLException e) { - System.err.println(e); - System.exit(1); + + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); + + // Create a Canvas3D using the preferred configuration + Canvas3D canvas3d = new Canvas3D(config); + + // Create simple universe with view branch + univ = new SimpleUniverse(canvas3d); + BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); + + // Add a ShaderErrorListener + univ.addShaderErrorListener(new ShaderErrorListener() { + public void errorOccurred(ShaderError error) { + error.printVerbose(); + JOptionPane.showMessageDialog(ObjLoadCg.this, + error.toString(), + "ShaderError", + JOptionPane.ERROR_MESSAGE); } - } + }); - setLayout(new BorderLayout()); - GraphicsConfiguration config = - SimpleUniverse.getPreferredConfiguration(); - - Canvas3D c = new Canvas3D(config); - add("Center", c); - - // Create a simple scene and attach it to the virtual universe - BranchGroup scene = createSceneGraph(); - u = new SimpleUniverse(c); - // add mouse behaviors to the ViewingPlatform - ViewingPlatform viewingPlatform = u.getViewingPlatform(); + ViewingPlatform viewingPlatform = univ.getViewingPlatform(); PlatformGeometry pg = new PlatformGeometry(); @@ -216,10 +203,10 @@ public class ObjLoadCg extends Applet { pg.addChild(ambientLightNode); // Set up the directional lights - Color3f light1Color = new Color3f(1.0f, 0.2f, 0.4f); - Vector3f light1Direction = new Vector3f(-1.0f, -1.0f, -1.0f); - Color3f light2Color = new Color3f(1.0f, 1.0f, 0.9f); - Vector3f light2Direction = new Vector3f(1.0f, 1.0f, 1.0f); + Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f); + Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f); + Color3f light2Color = new Color3f(1.0f, 1.0f, 1.0f); + Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -1.0f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); @@ -238,22 +225,31 @@ public class ObjLoadCg extends Applet { viewingPlatform.setNominalViewingTransform(); if (!spin) { - OrbitBehavior orbit = new OrbitBehavior(c, + OrbitBehavior orbit = new OrbitBehavior(canvas3d, OrbitBehavior.REVERSE_ALL); - BoundingSphere bounds = - new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); orbit.setSchedulingBounds(bounds); viewingPlatform.setViewPlatformBehavior(orbit); - } + } + + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); - /* - // Limit the frame rate to 100 Hz - u.getViewer().getView().setMinimumFrameCycleTime(10); - */ - - u.addBranchGraph(scene); + return canvas3d; } + private void usage() { + System.out.println( + "Usage: java ObjLoadCg [-s] [-n] [-t] [-c degrees] <.obj file>"); + System.out.println(" -s Spin (no user interaction)"); + System.out.println(" -n No triangulation"); + System.out.println(" -t No stripification"); + System.out.println( + " -c Set crease angle for normal generation (default is 60 without"); + System.out.println( + " smoothing group info, otherwise 180 within smoothing groups)"); + System.exit(0); + } // End of usage + // Set shader program for all nodes in specified branch graph private void setShaderProgram(BranchGroup g, ShaderProgram shaderProgram) { ShaderAppearance myApp = new ShaderAppearance(); @@ -283,63 +279,99 @@ public class ObjLoadCg extends Applet { } } - // Caled if running as a program - public ObjLoadCg(String[] args) { - if (args.length != 0) { - for (int i = 0 ; i < args.length ; i++) { - if (args[i].startsWith("-")) { - if (args[i].equals("-s")) { - spin = true; - } else if (args[i].equals("-n")) { - noTriangulate = true; - } else if (args[i].equals("-t")) { - noStripify = true; - } else if (args[i].equals("-c")) { - if (i < args.length - 1) { - creaseAngle = (new Double(args[++i])).doubleValue(); - } else usage(); - } else { - usage(); - } - } else { - try { - if ((args[i].indexOf("file:") == 0) || - (args[i].indexOf("http") == 0)) { - filename = new URL(args[i]); - } - else if (args[i].charAt(0) != '/') { - filename = new URL("file:./" + args[i]); - } - else { - filename = new URL("file:" + args[i]); - } + /** + * Creates new form ObjLoadCg + */ + public ObjLoadCg(String args[]) { + if (args.length != 0) { + for (int i = 0 ; i < args.length ; i++) { + if (args[i].startsWith("-")) { + if (args[i].equals("-s")) { + spin = true; + } else if (args[i].equals("-n")) { + noTriangulate = true; + } else if (args[i].equals("-t")) { + noStripify = true; + } else if (args[i].equals("-c")) { + if (i < args.length - 1) { + creaseAngle = (new Double(args[++i])).doubleValue(); + } else usage(); + } else { + usage(); + } + } else { + try { + if ((args[i].indexOf("file:") == 0) || + (args[i].indexOf("http") == 0)) { + filename = new URL(args[i]); + } else if (args[i].charAt(0) != '/') { + filename = new URL("file:./" + args[i]); + } else { + filename = new URL("file:" + args[i]); + } + } catch (MalformedURLException e) { + System.err.println(e); + System.exit(1); + } + } } - catch (MalformedURLException e) { - System.err.println(e); - System.exit(1); - } - } - } - } - } - - - - // Running as an applet - public ObjLoadCg() { - } - - public void destroy() { - u.cleanup(); + } + + if (filename == null) { + filename = Resources.getResource("resources/geometry/galleon.obj"); + if (filename == null) { + System.err.println("resources/geometry/galleon.obj not found"); + System.exit(1); + } + } + + // Initialize the GUI components + initComponents(); + + // Create Canvas3D and SimpleUniverse; add canvas to drawing panel + Canvas3D c = createUniverse(); + drawingPanel.add(c, java.awt.BorderLayout.CENTER); + + // Create the content branch and add it to the universe + scene = createSceneGraph(); + univ.addBranchGraph(scene); } - - - // - // The following allows ObjLoadCg to be run as an application - // as well as an applet - // - public static void main(String[] args) { - new MainFrame(new ObjLoadCg(args), 700, 700); + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("ObjLoadCg"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// </editor-fold>//GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(final String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + ObjLoadCg objLoadCg = new ObjLoadCg(args); + objLoadCg.setVisible(true); + } + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/cg_shader/SphereCg.java b/src/classes/org/jdesktop/j3d/examples/cg_shader/SphereCg.java index 2757006..51becfc 100644 --- a/src/classes/org/jdesktop/j3d/examples/cg_shader/SphereCg.java +++ b/src/classes/org/jdesktop/j3d/examples/cg_shader/SphereCg.java @@ -44,23 +44,20 @@ package org.jdesktop.j3d.examples.cg_shader; -import java.applet.Applet; -import java.awt.*; -import java.io.*; -import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.geometry.Sphere; import com.sun.j3d.utils.shader.StringIO; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; -import java.util.Enumeration; -import java.net.URL; -import java.net.MalformedURLException; +import java.awt.GraphicsConfiguration; +import java.io.*; +import javax.swing.JOptionPane; +import org.jdesktop.j3d.examples.Resources; /** - * Simple CG Shader test program + * Simple Java 3D example program with programmable shader. */ -public class SphereCg extends Applet { +public class SphereCg extends javax.swing.JFrame { // Constants for type of light to use private static final int DIRECTIONAL_LIGHT = 0; @@ -70,10 +67,10 @@ public class SphereCg extends Applet { // Flag indicates type of lights: directional, point, or spot // lights. This flag is set based on command line argument private static int lightType = DIRECTIONAL_LIGHT; + private SimpleUniverse univ = null; + private BranchGroup scene = null; - private SimpleUniverse u = null; - - public BranchGroup createSceneGraph(SimpleUniverse u) { + public BranchGroup createSceneGraph() { Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f); Color3f sColor = new Color3f(1.0f, 1.0f, 1.0f); Color3f objColor = new Color3f(0.6f, 0.6f, 0.6f); @@ -109,15 +106,11 @@ public class SphereCg extends Applet { ShaderAppearance a = new ShaderAppearance(); Material m = new Material(objColor, eColor, objColor, sColor, 100.0f); m.setLightingEnable(true); - Texture t2d = new Texture2D(); - a.setTexture(t2d); - a.setCapability(Appearance.ALLOW_TEXTURE_WRITE); - String vertexProgram = null; String fragmentProgram = null; try { - vertexProgram = StringIO.readFully("./simple_vp.cg"); - fragmentProgram = StringIO.readFully("./simple_fp.cg"); + vertexProgram = StringIO.readFully(Resources.getResource("cg_shader/simple_vp.cg")); + fragmentProgram = StringIO.readFully(Resources.getResource("cg_shader/simple_fp.cg")); } catch (IOException e) { e.printStackTrace(); @@ -163,7 +156,6 @@ public class SphereCg extends Applet { TransformGroup l2Trans = new TransformGroup(t); l2RotTrans.addChild(l2Trans); - /* // Create Geometry for point lights ColoringAttributes caL1 = new ColoringAttributes(); ColoringAttributes caL2 = new ColoringAttributes(); @@ -175,7 +167,6 @@ public class SphereCg extends Applet { appL2.setColoringAttributes(caL2); l1Trans.addChild(new Sphere(0.05f, appL1)); l2Trans.addChild(new Sphere(0.05f, appL2)); - */ // Create lights AmbientLight aLgt = new AmbientLight(alColor); @@ -252,7 +243,7 @@ public class SphereCg extends Applet { // Create a position interpolator and attach it to the view // platform TransformGroup vpTrans = - u.getViewingPlatform().getViewPlatformTransform(); + univ.getViewingPlatform().getViewPlatformTransform(); Transform3D axisOfTranslation = new Transform3D(); Alpha transAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | @@ -274,75 +265,92 @@ public class SphereCg extends Applet { return objRoot; } - - public SphereCg() { - } - - public void init() { - setLayout(new BorderLayout()); - GraphicsConfiguration config = - SimpleUniverse.getPreferredConfiguration(); - - Canvas3D c = new Canvas3D(config); - add("Center", c); - - u = new SimpleUniverse(c); - BranchGroup scene = createSceneGraph(u); + + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); + + // Create a Canvas3D using the preferred configuration + Canvas3D canvas3d = new Canvas3D(config); + + // Create simple universe with view branch + univ = new SimpleUniverse(canvas3d); + BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); + + // Add a ShaderErrorListener + univ.addShaderErrorListener(new ShaderErrorListener() { + public void errorOccurred(ShaderError error) { + error.printVerbose(); + JOptionPane.showMessageDialog(SphereCg.this, + error.toString(), + "ShaderError", + JOptionPane.ERROR_MESSAGE); + } + }); // This will move the ViewPlatform back a bit so the - // objects in the scene can be viewed. - u.getViewingPlatform().setNominalViewingTransform(); - - /* - // Limit the frame rate to 100 Hz - u.getViewer().getView().setMinimumFrameCycleTime(10); - */ + // objects in the scene can be viewed. + univ.getViewingPlatform().setNominalViewingTransform(); + + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); - u.addBranchGraph(scene); + return canvas3d; } - public void destroy() { - u.cleanup(); - } - // - // The following allows SphereCg to be run as an application - // as well as an applet - // - public static void main(String[] args) { - // Parse the Input Arguments - String usage = "Usage: java SphereCg [-point | -spot | -dir]"; - for (int i = 0; i < args.length; i++) { - if (args[i].startsWith("-")) { - if (args[i].equals("-point")) { - /* - System.out.println("Using point lights"); - lightType = POINT_LIGHT; - */ - System.out.println("Point lights not yet implemented, option ignored"); - } - else if (args[i].equals("-spot")) { - /* - System.out.println("Using spot lights"); - lightType = SPOT_LIGHT; - */ - System.out.println("Spot lights not yet implemented, option ignored"); - } - else if (args[i].equals("-dir")) { - System.out.println("Using directional lights"); - lightType = DIRECTIONAL_LIGHT; - } - else { - System.out.println(usage); - System.exit(0); - } + /** + * Creates new form SphereCg + */ + public SphereCg() { + + // Initialize the GUI components + initComponents(); + + // Create Canvas3D and SimpleUniverse; add canvas to drawing panel + Canvas3D c = createUniverse(); + drawingPanel.add(c, java.awt.BorderLayout.CENTER); + + // Create the content branch and add it to the universe + scene = createSceneGraph(); + univ.addBranchGraph(scene); } + + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("SphereCg"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// </editor-fold>//GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(final String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + SphereCg sphereCg = new SphereCg(); + sphereCg.setVisible(true); } - else { - System.out.println(usage); - System.exit(0); - } - } - - new MainFrame(new SphereCg(), 700, 700); + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/collision/TickTockCollision.java b/src/classes/org/jdesktop/j3d/examples/collision/TickTockCollision.java index 731dff7..86fbf44 100644 --- a/src/classes/org/jdesktop/j3d/examples/collision/TickTockCollision.java +++ b/src/classes/org/jdesktop/j3d/examples/collision/TickTockCollision.java @@ -44,19 +44,22 @@ package org.jdesktop.j3d.examples.collision; -import java.applet.Applet; import java.awt.*; import java.awt.event.*; -import com.sun.j3d.utils.applet.MainFrame; -import com.sun.j3d.utils.geometry.ColorCube; import com.sun.j3d.utils.universe.*; +import com.sun.j3d.utils.geometry.ColorCube; import javax.media.j3d.*; import javax.vecmath.*; +import java.awt.GraphicsConfiguration; -public class TickTockCollision extends Applet { +/** + * Simple Java 3D example program to display how collision work. + */ +public class TickTockCollision extends javax.swing.JFrame { + + private SimpleUniverse univ = null; + private BranchGroup scene = null; - private SimpleUniverse u = null; - public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); @@ -149,7 +152,6 @@ public class TickTockCollision extends Applet { return objRoot; } - private Group createBox(double scale, Vector3d pos) { // Create a transform group node to scale and position the object. Transform3D t = new Transform3D(); @@ -182,38 +184,77 @@ public class TickTockCollision extends Applet { return objTrans; } + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); - public TickTockCollision() { - } - - public void init() { - setLayout(new BorderLayout()); - GraphicsConfiguration config = - SimpleUniverse.getPreferredConfiguration(); + // Create a Canvas3D using the preferred configuration + Canvas3D c = new Canvas3D(config); - Canvas3D c = new Canvas3D(config); - add("Center", c); + // Create simple universe with view branch + univ = new SimpleUniverse(c); - // Create a simple scene and attach it to the virtual universe - BranchGroup scene = createSceneGraph(); - u = new SimpleUniverse(c); + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + univ.getViewingPlatform().setNominalViewingTransform(); - // This will move the ViewPlatform back a bit so the - // objects in the scene can be viewed. - u.getViewingPlatform().setNominalViewingTransform(); + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); - u.addBranchGraph(scene); + return c; } - public void destroy() { - u.cleanup(); + /** + * Creates new form TickTockCollision + */ + public TickTockCollision() { + // Initialize the GUI components + initComponents(); + + // Create Canvas3D and SimpleUniverse; add canvas to drawing panel + Canvas3D c = createUniverse(); + drawingPanel.add(c, java.awt.BorderLayout.CENTER); + + // Create the content branch and add it to the universe + scene = createSceneGraph(); + univ.addBranchGraph(scene); } - // - // The following allows TickTockCollision to be run as an application - // as well as an applet - // - public static void main(String[] args) { - new MainFrame(new TickTockCollision(), 700, 700); + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("TickTockCollision"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// </editor-fold>//GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new TickTockCollision().setVisible(true); + } + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/configured_universe/ConfigObjLoad.java b/src/classes/org/jdesktop/j3d/examples/configured_universe/ConfigObjLoad.java index f96b2ed..16d1060 100644 --- a/src/classes/org/jdesktop/j3d/examples/configured_universe/ConfigObjLoad.java +++ b/src/classes/org/jdesktop/j3d/examples/configured_universe/ConfigObjLoad.java @@ -48,9 +48,7 @@ import com.sun.j3d.loaders.objectfile.ObjectFile; import com.sun.j3d.loaders.ParsingErrorException; import com.sun.j3d.loaders.IncorrectFormatException; import com.sun.j3d.loaders.Scene; -import java.awt.*; import java.awt.event.*; -import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; @@ -60,6 +58,7 @@ import com.sun.j3d.utils.behaviors.sensor.Mouse6DPointerBehavior; import java.net.URL; import java.net.MalformedURLException; import java.util.Map; +import org.jdesktop.j3d.examples.Resources; public class ConfigObjLoad { @@ -167,7 +166,7 @@ public class ConfigObjLoad { private void usage() { System.out.println( - "Usage: java ObjLoad [-s] [-n] [-t] [-c degrees] <.obj file>"); + "Usage: java ConfigObjLoad [-s] [-n] [-t] [-c degrees] <.obj file>"); System.out.println(" -s Spin (no user interaction)"); System.out.println(" -n No triangulation"); System.out.println(" -t No stripification"); @@ -181,21 +180,20 @@ public class ConfigObjLoad { public void init() { if (filename == null) { - try { - filename = new URL("file:../geometry/galleon.obj"); + filename = Resources.getResource("resources/geometry/galleon.obj"); + if (filename == null) { + System.err.println("resources/geometry/galleon.obj not found"); + System.exit(1); } - catch (MalformedURLException e) { - System.err.println(e); - System.exit(1); - } - } + } // Get the config file URL from the j3d.configURL property or use the // default config file "j3d1x1-window" in the current directory. - URL configURL = ConfiguredUniverse.getConfigURL("file:j3d1x1-window"); - + //URL configURL = ConfiguredUniverse.getConfigURL("file:j3d1x1-window"); + URL configURL = Resources.getResource("configured_universe/j3d1x1-windows.cfg"); // Create a simple scene and attach it to the virtual universe BranchGroup scene = createSceneGraph(); + u = new ConfiguredUniverse(configURL); // Get the ViewingPlatform. diff --git a/src/classes/org/jdesktop/j3d/examples/configured_universe/README.txt b/src/classes/org/jdesktop/j3d/examples/configured_universe/README.txt index fd2af8e..5aa2197 100644 --- a/src/classes/org/jdesktop/j3d/examples/configured_universe/README.txt +++ b/src/classes/org/jdesktop/j3d/examples/configured_universe/README.txt @@ -72,7 +72,7 @@ It also differs in the following other respects: into their own user interfaces. The configuration file to load is specified by the j3d.configURL - property. If one is not specified, it will load the file j3d1x1-window + property. If one is not specified, it will load the file j3d1x1-window.cfg in this directory. Alternative custom view platform behaviors other than OrbitBehavior can @@ -89,44 +89,44 @@ command line: java -Dj3d.configURL=<URL string> ConfigObjLoad <args> <obj file> -For example, to load j3d1x2-rot30 in the current directory, run +For example, to load j3d1x2-rot30.cfg in the current directory, run - java -Dj3d.configURL=file:j3d1x2-rot30 ConfigObjLoad <args> <obj file> + java -Dj3d.configURL=file:j3d1x2-rot30.cfg ConfigObjLoad <args> <obj file> This directory includes the following sample configuration files. Normally a configuration file is site-specific but many of these can used as-is. Others may need customization for screen sizes, available input devices, and PhysicalBody parameters. - j3d1x1: single fullscreen desktop configuration. + j3d1x1.cfg: single fullscreen desktop configuration. - j3d1x1-behavior: single fullscreen desktop configuration with a + j3d1x1-behavior.cfg: single fullscreen desktop configuration with a configurable view platform behavior. - j3d1x1-stereo: single fullscreen desktop configuration with stereo + j3d1x1-stereo.cfg: single fullscreen desktop configuration with stereo viewing. - j3d1x1-vr: single fullscreen desktop configuration with stereo viewing, + j3d1x1-vr.cfg: single fullscreen desktop configuration with stereo viewing, head tracker, and 6DOF mouse. - j3d1x1-window: single screen windowed desktop configuration. + j3d1x1-window.cfg: single screen windowed desktop configuration. - j3d1x2-flat: dual-screen flat desktop configuration. + j3d1x2-flat.cfg: dual-screen flat desktop configuration. - j3d1x2-rot30: dual-screen desktop configuration with each screen rotated + j3d1x2-rot30.cfg: dual-screen desktop configuration with each screen rotated toward the other by 30 degrees about Y. - j3d1x3-cave: 3-projector configuration with screens to the left, front, + j3d1x3-cave.cfg: 3-projector configuration with screens to the left, front, and right of the user. - j3d1x3-cave-vr: 3-projector configuration with screens to the left, + j3d1x3-cave-vr.cfg: 3-projector configuration with screens to the left, front, and right of the user. Includes head tracking and stereo viewing. - j3d1x3-rot45: 3-screen desktop configuration with left and right screens + j3d1x3-rot45.cfg: 3-screen desktop configuration with left and right screens angled by 45 degrees from the center screen. - j3d2x2-flat: 4-screen projector configuration arranged in a 2x2 power + j3d2x2-flat.cfg: 4-screen projector configuration arranged in a 2x2 power wall. Note: JDK 1.4 or newer is required when configuring multiple screens if the diff --git a/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x1 b/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x1 deleted file mode 100644 index 41173e3..0000000 --- a/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x1 +++ /dev/null @@ -1,98 +0,0 @@ -/* - * $RCSfile$ - * - * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any - * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND - * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY - * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL - * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF - * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS - * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR - * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, - * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND - * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR - * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed, licensed or - * intended for use in the design, construction, operation or - * maintenance of any nuclear facility. - * - * $Revision$ - * $Date$ - * $State$ - */ - -/* - ************************************************************************ - * - * Java 3D configuration file for a single fullscreen desktop configuration. - * - ************************************************************************ - */ - -// Create a new screen object and associate it with a logical name and a -// number. This number is used as an index to retrieve the AWT GraphicsDevice -// from the array that GraphicsEnvironment.getScreenDevices() returns. -// -// NOTE: The GraphicsDevice order in the array is specific to the local -// site and display system. -// -(NewScreen center 0) - -// Create a fullscreen window -// -(ScreenAttribute center WindowSize NoBorderFullScreen) - -// Set the available image area for the full screen. This is important when an -// explicit ScreenScale view attribute is defined for precise scaling between -// objects in the virtual world and their projections into the physical world. -// The defaults are 0.365 meters for width and 0.292 meters for height. -// -(ScreenAttribute center PhysicalScreenWidth 0.360) -(ScreenAttribute center PhysicalScreenHeight 0.288) - -// Set the TrackerBaseToImagePlate transform for this screen. The coexistence -// to tracker base transform is identity by default, so the tracker base origin -// and orientation will also set the origin and orientation of coexistence -// coordinates in the physical world. This is the primary purpose of setting -// this transform when neither head tracking nor multiple screens are being -// used. -// -// The tracker base and center of coexistence are set here to the middle of the -// screen's image plate. Their basis vectors are aligned with the image plate -// basis vectors. The physical eyepoint position will be set relative to -// coexistence coordinates below. -// -(ScreenAttribute center TrackerBaseToImagePlate - (Translate 0.180 0.144 0.000)) - -// Create a view using the defined screen. -// -(NewView view0) -(ViewAttribute view0 Screen center) - -// Set the eyepoint relative to coexistence coordinates. Here it is set 45cm -// toward the user along +Z. Skewed projections can be created by offsetting -// the eyepoint along X and/or Y. -// -(ViewAttribute view0 CenterEyeInCoexistence (0.0 0.0 0.45)) diff --git a/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x1-behavior b/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x1-behavior deleted file mode 100644 index d291913..0000000 --- a/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x1-behavior +++ /dev/null @@ -1,149 +0,0 @@ -/* - * $RCSfile$ - * - * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any - * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND - * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY - * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL - * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF - * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS - * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR - * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, - * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND - * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR - * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed, licensed or - * intended for use in the design, construction, operation or - * maintenance of any nuclear facility. - * - * $Revision$ - * $Date$ - * $State$ - */ - -/* - ************************************************************************ - * - * Java 3D configuration file for single fullscreen desktop configuration. - * A view platform behavior is created and configured here as well. - * - ************************************************************************ - */ - -// Create a new screen object and associate it with a logical name and a -// number. This number is used as an index to retrieve the AWT GraphicsDevice -// from the array that GraphicsEnvironment.getScreenDevices() returns. -// -// NOTE: The GraphicsDevice order in the array is specific to the local -// site and display system. -// -(NewScreen center 0) - -// Create a fullscreen window -// -(ScreenAttribute center WindowSize NoBorderFullScreen) - -// Set the available image area for the full screen. -// -(ScreenAttribute center PhysicalScreenWidth 0.360) -(ScreenAttribute center PhysicalScreenHeight 0.288) - -// Set the TrackerBaseToImagePlate transform for this screen. The coexistence -// to tracker base transform is identity by default, so the tracker base origin -// and orientation will also set the origin and orientation of coexistence -// coordinates in the physical world. This is the primary purpose of setting -// this transform when neither head tracking nor multiple screens are being -// used. -// -// The tracker base and center of coexistence are set here to the middle of the -// screen's image plate. Their basis vectors are aligned with the image plate -// basis vectors. The physical eyepoint position will be set relative to -// coexistence coordinates below. -// -(ScreenAttribute center TrackerBaseToImagePlate - (Translate 0.180 0.144 0.000)) - -// Create a view using the defined screen. -// -(NewView view0) -(ViewAttribute view0 Screen center) - -// Set the eyepoint relative to coexistence coordinates. Here it is set 45cm -// toward the user along +Z. Skewed projections can be set by by offsetting -// the eyepoint along X and Y. -// -(ViewAttribute view0 CenterEyeInCoexistence (0.0 0.0 0.45)) - -// Create a view platform behavior. Here we use OrbitBehavior, although any -// concrete subclass of the abstract ViewPlatformBehavior with a parameterless -// constructor could be used. The logical name to assign to this behavior is -// specified by the 2nd argument to the NewViewPlatformBehavior command, while -// the 3rd argument is the name of the ViewPlatformBehavior subclass. It is -// instantiated through introspection. -// -// Attributes defined by the abstract ViewPlatformBehavior superclass itself -// can be set directly with the ViewPlatformBehaviorAttribute command. The -// details of the subclass implementation are not known to ConfiguredUniverse, -// so any configuration information needed by such a subclass is set by the -// ViewPlatformBehaviorProperty command. The property name specified by that -// command is taken to be a method name of the subclass and invoked through -// introspection. -// -// View platform behaviors often need sensors or canvases as event sources to -// drive the behavior action. An implementation of ViewPlatformBehavior always -// gets the current ViewingPlatform through the setViewingPlatform() method. -// The canvases used by the ViewingPlatform can be retrieved by calling its -// getViewers() method and then calling each Viewer's getCanvas3Ds() -// method. Sensors can be retrived by calling the ViewingPlatform method -// getUniverse(), checking to see if the returned SimpleUniverse is a -// ConfiguredUniverse, and then calling its getNamedSensors() method. -// -(NewViewPlatformBehavior vpb com.sun.j3d.utils.behaviors.vp.OrbitBehavior) - -// Set the scheduling bounds to be a BoundingSphere with its center at -// (0.0 0.0 0.0) and a radius of 100 meters. -// -(ViewPlatformBehaviorAttribute vpb SchedulingBounds - (BoundingSphere (0.0 0.0 0.0) 100.0)) - -// Set properties specific to OrbitBehavior. All arguments following the -// method name are wrapped and passed to the specified method as an array of -// Objects. Strings "true" and "false" get turned into Boolean, and number -// strings get turned into Double. Constructs such as (0.0 1.0 2.0) and -// ((0.0 1.0 2.0 0.5) (3.0 4.0 5.0 1.0) (6.0 7.0 8.0 0.0)) get converted to -// Point3d and Matrix4d respectively. Note that last row of a Matrix4d doesn't -// need to be specified; it is implicitly (0.0 0.0 0.0 1.0). -// -// The REVERSE_ALL flags are usually passed to the OrbitBehavior constructor. -// Since it is being instantiated with its parameterless constructor the -// reverse flags are set here explicitly. -// -(ViewPlatformBehaviorProperty vpb ReverseTranslate true) -(ViewPlatformBehaviorProperty vpb ReverseRotate true) -(ViewPlatformBehaviorProperty vpb ReverseZoom true) - -// Create a new view platform and set the view platform behavior. -// -(NewViewPlatform vp) -(ViewPlatformAttribute vp ViewPlatformBehavior vpb) diff --git a/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x1-stereo b/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x1-stereo deleted file mode 100644 index 3db4070..0000000 --- a/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x1-stereo +++ /dev/null @@ -1,113 +0,0 @@ -/* - * $RCSfile$ - * - * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any - * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND - * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY - * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL - * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF - * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS - * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR - * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, - * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND - * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR - * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed, licensed or - * intended for use in the design, construction, operation or - * maintenance of any nuclear facility. - * - * $Revision$ - * $Date$ - * $State$ - */ - -/* - ************************************************************************ - * - * Java 3D configuration file for single fullscreen stereo desktop - * configuration with no head tracking. - * - ************************************************************************ - */ - -// Create a new screen object and associate it with a logical name and a -// number. This number is used as an index to retrieve the AWT GraphicsDevice -// from the array that GraphicsEnvironment.getScreenDevices() returns. -// -// NOTE: The GraphicsDevice order in the array is specific to the local -// site and display system. -// -(NewScreen center 0) - -// Create a fullscreen window -// -(ScreenAttribute center WindowSize NoBorderFullScreen) - -// Set the available image area for the full screen. -// -(ScreenAttribute center PhysicalScreenWidth 0.360) -(ScreenAttribute center PhysicalScreenHeight 0.288) - -// Set the TrackerBaseToImagePlate transform for this screen. The coexistence -// to tracker base transform is identity by default, so the tracker base origin -// and orientation will also set the origin and orientation of coexistence -// coordinates in the physical world. This is the primary purpose of setting -// this transform when neither head tracking nor multiple screens are being -// used. -// -// The tracker base and center of coexistence are set here to the middle of the -// screen's image plate. Their basis vectors are aligned with the image plate -// basis vectors. The physical eyepoint position will be set relative to -// coexistence coordinates below. -// -(ScreenAttribute center TrackerBaseToImagePlate - (Translate 0.180 0.144 0.000)) - -// Define the physical body. -// -// The head origin is halfway between the eyes, with X extending to the right, -// Y up, and positive Z extending into the skull. -// -(NewPhysicalBody SiteUser) - -// Set the interpupilary distance. This sets the LeftEyePosition and -// RightEyePosition to offsets of half this distance along both directions of -// the X axis. -// -(PhysicalBodyAttribute SiteUser StereoEyeSeparation 0.066) - -// Create a view using the defined screen and physical body. -// -(NewView view0) -(ViewAttribute view0 Screen center) -(ViewAttribute view0 PhysicalBody SiteUser) - -// Set the eyepoint relative to coexistence coordinates. Here it is set 45cm -// toward the user along +Z. -// -(ViewAttribute view0 CenterEyeInCoexistence (0.0 0.0 0.45)) - -// Enable stereo viewing. -// -(ViewAttribute view0 StereoEnable true) diff --git a/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x1-vr b/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x1-vr deleted file mode 100644 index 587f481..0000000 --- a/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x1-vr +++ /dev/null @@ -1,212 +0,0 @@ -/* - * $RCSfile$ - * - * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any - * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND - * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY - * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL - * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF - * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS - * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR - * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, - * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND - * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR - * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed, licensed or - * intended for use in the design, construction, operation or - * maintenance of any nuclear facility. - * - * $Revision$ - * $Date$ - * $State$ - */ - -/* - ************************************************************************ - * - * Java 3D configuration file for a single screen stereo desktop display - * using a head tracker and 6DOF mouse. - * - ************************************************************************ - */ - -// Configure the head tracker. The NewDevice command binds a logical name -// (the 2nd argument) to an InputDevice implementation whose class name is -// specified in the 3rd argument. The InputDevice implementation for a head -// tracker must generate position and orientation data relative to a fixed -// frame of reference in the physical world, the "tracker base" of the Java -// 3D view model. -// -// The InputDevice is instantiated through introspection of the class name. -// Available InputDevice implementations are site-specific, so substitute -// the class name in a NewDevice command below with one that is available at -// the local site. -// -// Note that properties are used to configure an InputDevice instead of -// attributes. The details of an InputDevice implementation are not known to -// ConfiguredUniverse, so the property name is invoked as a method through -// introspection. The example properties below must be replaced with the ones -// needed, if any, by specific InputDevice implementations. -// -// All property arguments following the method name are wrapped and passed to -// the specified method as an array of Objects. Strings "true" and "false" -// get wrapped into Boolean, and number strings get wrapped into Double. -// Construct such as (0.0 1.0 2.0) and ((0.0 1.0 2.0 0.5) (3.0 4.0 5.0 1.0) -// (6.0 7.0 8.0 0.0)) get converted to Point3d and Matrix4d respectively. -// Note that last row of a Matrix4d doesn't need to be specified; it is -// implicitly (0.0 0.0 0.0 1.0). -// -(NewDevice glasses LogitechRedBarron) -(DeviceProperty glasses SerialPort "/dev/ttya") // Unix paths need quoting. -(DeviceProperty glasses ReceiverBaseline 0.1450) -(DeviceProperty glasses ReceiverLeftLeg 0.0875) -(DeviceProperty glasses ReceiverHeight 0.0470) -(DeviceProperty glasses ReceiverTopOffset 0.0000) - -// Configure an InputDevice to use for a 6 degree of freedom mouse if -// required. In some implementations the same InputDevice instance can be -// used both for head tracking and multiple peripheral sensing devices. -// This example assumes an implementation that requires multiple instances, -// one for each sensor, sharing the same physical hardware used for the -// tracker base. In either case all the sensors must generate position and -// orientation relative to the same fixed tracker base frame of reference. -// -(NewDevice wand LogitechRedBarron) -(DeviceProperty wand SerialPort "/dev/ttyb") -(DeviceProperty wand ReceiverBaseline 0.0700) -(DeviceProperty wand ReceiverLeftLeg 0.0625) -(DeviceProperty wand ReceiverHeight 0.0510) -(DeviceProperty wand ReceiverTopOffset 0.0000) - -// Create logical names for the available sensors in the specified input -// devices. The last argument is the sensor's index in the input device. -// -(NewSensor head glasses 0) -(NewSensor mouse6d wand 0) - -// Set the 6DOF mouse sensor hotspot in the local sensor coordinate system. -// The hotspot is simply the "active" point relative to the sensor origin -// which interacts with the virtual world, such as the point used for picking -// or grabbing an object. Its interpretation is up to the sensor behavior. -// -// It is set here to 10 centimeters from the base to allow reaching into the -// screen without bumping the device into the glass, and to prevent the device -// itself from obscuring the pointer echo. -// -(SensorAttribute mouse6d Hotspot (0.0 0.0 -0.10)) - - -// Create a new screen object and associate it with a logical name and a -// number. This number is used as an index to retrieve the AWT GraphicsDevice -// from the array that GraphicsEnvironment.getScreenDevices() returns. -// -// NOTE: The GraphicsDevice order in the array is specific to the local -// site and display system. -// -(NewScreen center 0) - -// Set the actual available image area. This measured as 0.350 meters in -// width and 0.245 meters in height for the monitor in the sample setup when -// running in stereo resolution. -// -(ScreenAttribute center PhysicalScreenWidth 0.350) -(ScreenAttribute center PhysicalScreenHeight 0.245) -(ScreenAttribute center WindowSize NoBorderFullScreen) - -// Set the TrackerBaseToImagePlate transform for this screen. This transforms -// points in tracker base coordinates to image plate coordinates. -// -// For this sample setup the tracker base is leaning at 50 degrees about its -// X-axis over the top edge of the monitor. The middle of the tracker base -// (its origin) is offset by (0.175, 0.345, 0.020) from the lower left -// corner of the screen (origin of the image plate). -// -(ScreenAttribute center TrackerBaseToImagePlate - (RotateTranslate (Rotate 50.000 0.000 0.000) - (Translate 0.175 0.345 0.020))) - - -// Create a physical environment. This contains the available input devices, -// audio devices, and sensors, and defines the coexistence coordinate system. -// -(NewPhysicalEnvironment SampleSite) - -// Register the input devices defined in this file. -// -(PhysicalEnvironmentAttribute SampleSite InputDevice glasses) -(PhysicalEnvironmentAttribute SampleSite InputDevice wand) - -// Register the sensor which will drive head tracking. -// -(PhysicalEnvironmentAttribute SampleSite HeadTracker head) - -// Define coexistence coordinates. -// -// Coexistence coordinates are defined relative to the tracker base to simplify -// calibration measurements, just as the tracker base is used as the common -// reference frame for the TrackerBaseToImagePlate calibration. -// -// Here the coexistence origin is set to the middle of the center screen, using -// the same basis vectors as its image plate. This will put the tracker base -// origin at (0.0 0.220 0.020) relative to the coexistence origin along its -// basis vectors. -// -(PhysicalEnvironmentAttribute SampleSite CoexistenceToTrackerBase - (TranslateRotate (Translate 0.0 -0.220 -0.020) - (Rotate -50.0 0.0 0.0))) - -// Define the physical body. -// -// The head origin is halfway between the eyes, with X extending to the right, -// Y up, and positive Z extending into the skull. -// -(NewPhysicalBody SiteUser) - -// Set the interpupilary distance. This sets the LeftEyePosition and -// RightEyePosition to offsets of half this distance along both directions of -// the X axis. -// -(PhysicalBodyAttribute SiteUser StereoEyeSeparation 0.066) - -// Define the position and orientation of the head relative to the tracker -// mounted on the head. -// -(PhysicalBodyAttribute SiteUser HeadToHeadTracker ((1.0 0.0 0.0 0.000) - (0.0 1.0 0.0 0.020) - (0.0 0.0 1.0 0.018))) - - -// Create a view using the defined screens, PhysicalEnvironment, and -// PhysicalBody. -// -(NewView view0) -(ViewAttribute view0 Screen center) -(ViewAttribute view0 PhysicalEnvironment SampleSite) -(ViewAttribute view0 PhysicalBody SiteUser) - -// Enable stereo viewing. Enable head tracking to get the position of the eyes -// with respect to coexistence. -// -(ViewAttribute view0 StereoEnable true) -(ViewAttribute view0 TrackingEnable True) diff --git a/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x1-window b/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x1-window deleted file mode 100644 index eec0e31..0000000 --- a/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x1-window +++ /dev/null @@ -1,89 +0,0 @@ -/* - * $RCSfile$ - * - * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any - * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND - * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY - * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL - * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF - * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS - * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR - * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, - * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND - * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR - * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed, licensed or - * intended for use in the design, construction, operation or - * maintenance of any nuclear facility. - * - * $Revision$ - * $Date$ - * $State$ - */ - -/* - ************************************************************************ - * - * Java 3D configuration file for a conventional single screen, windowed - * desktop configuration. - * - ************************************************************************ - */ - -// Create a new screen object and associate it with a logical name and a -// number. This number is used as an index to retrieve the AWT GraphicsDevice -// from the array that GraphicsEnvironment.getScreenDevices() returns. -// -// NOTE: The GraphicsDevice order in the array is specific to the local -// site and display system. -// -(NewScreen center 0) - -// Create a 700x700 pixel window on the screen. -// -(ScreenAttribute center WindowSize (700.0 700.0)) - -// Create a view using the defined screen. -// -(NewView view0) -(ViewAttribute view0 Screen center) - -// ConfiguredUniverse is oriented toward multi-screen viewing environments, so -// it sets the following attributes to those listed. For a conventional window -// on a single screen desktop configuration we need to set them back to their -// normal defaults. -// -// View.windowEyePointPolicy RELATIVE_TO_COEXISTENCE -// View.windowMovementPolicy VIRTUAL_WORLD -// View.windowResizePolicy VIRTUAL_WORLD -// View.coexistenceCenteringEnable false -// ViewPlatform.viewAttachPolicy NOMINAL_SCREEN -// -(ViewAttribute view0 WindowEyepointPolicy RELATIVE_TO_FIELD_OF_VIEW) -(ViewAttribute view0 WindowMovementPolicy PHYSICAL_WORLD) -(ViewAttribute view0 WindowResizePolicy PHYSICAL_WORLD) -(ViewAttribute view0 CoexistenceCenteringEnable true) - -(NewViewPlatform vp) -(ViewPlatformAttribute vp ViewAttachPolicy NOMINAL_HEAD) diff --git a/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x2-flat b/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x2-flat deleted file mode 100644 index 667ea52..0000000 --- a/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x2-flat +++ /dev/null @@ -1,134 +0,0 @@ -/* - * $RCSfile$ - * - * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any - * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND - * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY - * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL - * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF - * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS - * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR - * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, - * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND - * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR - * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed, licensed or - * intended for use in the design, construction, operation or - * maintenance of any nuclear facility. - * - * $Revision$ - * $Date$ - * $State$ - */ - -/* - ************************************************************************ - * - * Java 3D configuration file for dual-screen (flat) desktop configuration - * with no head tracking. - * - ************************************************************************ - */ - -// Create new screen objects and associate them with logical names and numbers. -// These numbers are used as indices to retrieve the AWT GraphicsDevice from -// the array that GraphicsEnvironment.getScreenDevices() returns. -// -// NOTE: The GraphicsDevice order in the array is specific to the local -// site and display system. -// -(NewScreen left 0) -(NewScreen right 1) - -// Set the screen dimensions. -// -(ScreenAttribute left PhysicalScreenWidth 0.360) -(ScreenAttribute left PhysicalScreenHeight 0.288) - -(ScreenAttribute right PhysicalScreenWidth 0.360) -(ScreenAttribute right PhysicalScreenHeight 0.288) - -// Specify full screen windows. -// -(ScreenAttribute left WindowSize NoBorderFullScreen) -(ScreenAttribute right WindowSize NoBorderFullScreen) - -// Set the TrackerBaseToImagePlate transforms for these screens. This -// transforms points in tracker base coordinates to each screen's image plate -// coordinates, where the origin of the image plate is defined to be the lower -// left corner of the screen with X increasing to the right, Y increasing to -// the top, and Z increasing away from the screen. -// -// Without head or sensor tracking the tracker base is still needed as a fixed -// frame of reference for describing the orientation and position of each -// screen to the others. The coexistence to tracker base transform is set to -// identity by default, so the tracker base origin and orientation will also -// set the origin and orientation of coexistence coordinates in the physical -// world. -// -// The tracker base and center of coexistence is set here to the middle of the -// edge shared by the two screens. -// -(ScreenAttribute left TrackerBaseToImagePlate - (Translate 0.360 0.144 0.0)) -(ScreenAttribute right TrackerBaseToImagePlate - (Translate 0.000 0.144 0.0)) - -// Sometimes it is desirable to include the bevels in between the monitors in -// the TrackerBaseToImagePlate transforms, so that the abutting bevels obscure -// the view of the virtual world instead of stretching it out between the -// monitors. For a bevel width of 4.5 cm on each monitor, the above commands -// would become the following: -// -// (ScreenAttribute left TrackerBaseToImagePlate -// (Translate 0.405 0.144 0.0)) -// (ScreenAttribute right TrackerBaseToImagePlate -// (Translate -0.045 0.144 0.0)) -// -// Conversely, a similar technique may be used to include overlap between the -// screens. This is useful for projection systems which use edge blending -// to provide seamless integration between screens. - - -// Create a view using the defined screens. -// -(NewView view0) -(ViewAttribute view0 Screen left) -(ViewAttribute view0 Screen right) - -// Set the eyepoint relative to coexistence coordinates. Here it is set 45cm -// toward the user along Z, extending out from the midpoint of the edge shared -// by the two screens. This will create the appropriate skewed projection -// frustums for each image plate. -// -// If a planar display surface is all that is required, the same effect could -// be achieved in a virtual screen enviroment such as Xinerama by simply -// creating a canvas that spans both screens. In some display environments the -// use of a canvas that spans multiple physical screens may cause significant -// performance degradation, however. -// -// See j3d1x2-rot30 for an example of a non-planar configuration that cannot be -// achieved through a single canvas spanning both screens. -// -(ViewAttribute view0 CenterEyeInCoexistence (0.0 0.0 0.45)) diff --git a/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x2-rot30 b/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x2-rot30 deleted file mode 100644 index 68f4a6e..0000000 --- a/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x2-rot30 +++ /dev/null @@ -1,99 +0,0 @@ -/* - * $RCSfile$ - * - * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any - * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND - * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY - * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL - * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF - * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS - * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR - * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, - * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND - * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR - * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed, licensed or - * intended for use in the design, construction, operation or - * maintenance of any nuclear facility. - * - * $Revision$ - * $Date$ - * $State$ - */ - -/* - ************************************************************************ - * - * Java 3D configuration file for a dual-screen desktop configuration - * with each screen rotated toward the other by 30 degrees about Y from - * planar. The inside angle between them is 120 degrees. - * - ************************************************************************ - */ - -// Create new screen objects and associate them with logical names and numbers. -// These numbers are used as indices to retrieve the AWT GraphicsDevice from -// the array that GraphicsEnvironment.getScreenDevices() returns. -// -// NOTE: The GraphicsDevice order in the array is specific to the local -// site and display system. -// -(NewScreen left 0) -(NewScreen right 1) - -// Set the available image areas for full screens. -// -(ScreenAttribute left PhysicalScreenWidth 0.360) -(ScreenAttribute left PhysicalScreenHeight 0.288) - -(ScreenAttribute right PhysicalScreenWidth 0.360) -(ScreenAttribute right PhysicalScreenHeight 0.288) - -// Specify full screen windows. -// -(ScreenAttribute left WindowSize NoBorderFullScreen) -(ScreenAttribute right WindowSize NoBorderFullScreen) - -// Set the TrackerBaseToImagePlate transforms for these screens. -// -// The tracker base is set here to the middle of the edge shared by the two -// screens. Each screen is rotated 30 degrees toward the other about the -// tracker base +Y axis, so that the tracker base +Z is centered between the -// two screens. -// -(ScreenAttribute left TrackerBaseToImagePlate - (RotateTranslate (Rotate 0.000 -30.000 0.0) - (Translate 0.360 0.144 0.0))) - -(ScreenAttribute right TrackerBaseToImagePlate - (RotateTranslate (Rotate 0.000 30.000 0.0) - (Translate 0.000 0.144 0.0))) - - -// Create a view using the defined screens. -// -(NewView view0) -(ViewAttribute view0 Screen left) -(ViewAttribute view0 Screen right) -(ViewAttribute view0 CenterEyeInCoexistence (0.0 0.0 0.45)) diff --git a/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x3-cave b/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x3-cave deleted file mode 100644 index afc532c..0000000 --- a/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x3-cave +++ /dev/null @@ -1,171 +0,0 @@ -/* - * $RCSfile$ - * - * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any - * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND - * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY - * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL - * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF - * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS - * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR - * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, - * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND - * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR - * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed, licensed or - * intended for use in the design, construction, operation or - * maintenance of any nuclear facility. - * - * $Revision$ - * $Date$ - * $State$ - */ - -/* - ************************************************************************ - * - * Java 3D configuration file for a cave environment. This cave - * consists of 3 projectors with 3 screens to the left, front, and right - * of the user, all at 90 degrees to each other. - * - * The projectors in the VirtualPortal sample site are actually turned - * on their sides to get more height. Screen 0 is rotated 90 degrees - * counter-clockwise, while screens 1 and 2 are rotated 90 degrees - * clockwise. - * - ************************************************************************ - */ - -// Create new screen objects and associate them with logical names and numbers. -// These numbers are used as indices to retrieve the AWT GraphicsDevice from -// the array that GraphicsEnvironment.getScreenDevices() returns. -// -// NOTE: The GraphicsDevice order in the array is specific to the local -// site and display system. -// -(NewScreen left 0) -(NewScreen center 1) -(NewScreen right 2) - - -// Set the available image areas as well as their positition and orientation -// relative to the tracker base. Although this config file doesn't enable -// head tracking, the tracker base is still needed as a point of reference to -// describe the position and orientation of the screens relative to the -// environment. -// -// From the orientation of a user standing within this VirtualPortal site and -// facing the center screen, the tracker base is along the vertical midline of -// the screen, 0.248 meters down from the top edge, and 1.340 meters in front -// of it. The tracker base is oriented so that its +X axis points to the left, -// its +Y axis points toward the screen, and its +Z axis points toward the -// floor. -// -(ScreenAttribute left PhysicalScreenWidth 2.480) -(ScreenAttribute left PhysicalScreenHeight 1.705) -(ScreenAttribute left WindowSize NoBorderFullScreen) -(ScreenAttribute left TrackerBaseToImagePlate - (( 0.0 0.0 -1.0 2.230) - ( 0.0 -1.0 0.0 1.340) - (-1.0 0.0 0.0 0.885))) - -(ScreenAttribute center PhysicalScreenWidth 2.485) -(ScreenAttribute center PhysicalScreenHeight 1.745) -(ScreenAttribute center WindowSize NoBorderFullScreen) -(ScreenAttribute center TrackerBaseToImagePlate - (( 0.0 0.0 1.0 0.248) - (-1.0 0.0 0.0 0.885) - ( 0.0 -1.0 0.0 1.340))) - -(ScreenAttribute right PhysicalScreenWidth 2.480) -(ScreenAttribute right PhysicalScreenHeight 1.775) -(ScreenAttribute right WindowSize NoBorderFullScreen) -(ScreenAttribute right TrackerBaseToImagePlate - (( 0.0 0.0 1.0 0.2488) - ( 0.0 -1.0 0.0 1.340) - ( 1.0 0.0 0.0 0.860))) - -// Set the location of the center of coexistence relative to the tracker base. -// Here it set to the center of the center screen. This config file will set -// the location of the user's eyes relative to this point. The default view -// attach policy of NOMINAL_SCREEN used by ConfiguredUniverse will place the -// origin of the view platform in coexistence coordinates at the center of -// coexistence. -// -(NewPhysicalEnvironment VirtualPortal) -(PhysicalEnvironmentAttribute VirtualPortal - CoexistenceToTrackerBase - ((-1.0 0.0 0.0 0.000) - ( 0.0 0.0 -1.0 1.340) - ( 0.0 -1.0 0.0 0.994))) - -// The above center of coexistence is appropriate for the sample geometry -// files available in the programs/examples directory. Often a more -// immersive point of view is required for larger virtual worlds. This can be -// achieved by placing the center of coexistence closer to the nominal position -// of the user's head, so that the view platform origin in coexistence -// coordinates will map there as well. -// -// Here we set the location of the center of coexistence 0.5 meters along the -// tracker base +Z axis, 1.737 meters from the floor (about 5 ft 8.4 inches). -// -// (PhysicalEnvironmentAttribute VirtualPortal -// CoexistenceToTrackerBase -// ((-1.0 0.0 0.0 0.0) -// ( 0.0 0.0 -1.0 0.0) -// ( 0.0 -1.0 0.0 0.5))) - - -// Now define the view. -// -(NewView view0) -(ViewAttribute view0 Screen left) -(ViewAttribute view0 Screen center) -(ViewAttribute view0 Screen right) -(ViewAttribute view0 PhysicalEnvironment VirtualPortal) - -// Set the user eye position in the display environment. It is set here to -// 1.340 meters back from the center screen (directly under the tracker), and -// 1.737 meters from the floor (about 5 ft 8.4 inches). -// -(ViewAttribute view0 CenterEyeInCoexistence (0.0 0.494 1.340)) - -// Here is an alternative center eye position to use with the immersive -// coexistence coordinate system defined in comments above. -// -// (ViewAttribute view0 CenterEyeInCoexistence (0.0 0.0 0.0)) - -// Set the screen scale. This is scale factor from virtual to physical -// coordinates. -// -(ViewAttribute view0 ScreenScalePolicy SCALE_SCREEN_SIZE) - -// Alternative for explict scaling. -// -// (ViewAttribute view0 ScreenScalePolicy SCALE_EXPLICIT) -// (ViewAttribute view0 ScreenScale 5.00) - -// No stereo viewing for this configuration. -// -(ViewAttribute view0 StereoEnable False) diff --git a/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x3-cave-vr b/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x3-cave-vr deleted file mode 100644 index 029decf..0000000 --- a/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x3-cave-vr +++ /dev/null @@ -1,222 +0,0 @@ -/* - * $RCSfile$ - * - * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any - * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND - * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY - * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL - * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF - * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS - * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR - * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, - * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND - * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR - * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed, licensed or - * intended for use in the design, construction, operation or - * maintenance of any nuclear facility. - * - * $Revision$ - * $Date$ - * $State$ - */ - -/* - ************************************************************************ - * - * Java 3D configuration file for a cave environment with head tracking and - * stereo viewing. This cave consists of 3 projectors with 3 screens to the - * left, front, and right of the user, all at 90 degrees to each other. - * - * The projectors in the VirtualPortal sample site are actually turned - * on their sides to get more height. Screen 0 is rotated 90 degrees - * counter-clockwise, while screens 1 and 2 are rotated 90 degrees - * clockwise. - * - ************************************************************************ - */ - -// Configure the head tracker. The NewDevice command binds a logical name -// (the 2nd argument) to an InputDevice implementation whose class name is -// specified in the 3rd argument. The InputDevice implementation for a head -// tracker must generate position and orientation data relative to a fixed -// frame of reference in the physical world, the "tracker base" of the Java -// 3D view model. -// -// The InputDevice is instantiated through introspection of the class name. -// Available InputDevice implementations are site-specific, so substitute -// the class name in a NewDevice command below with one that is available at -// the local site. -// -// Note that properties are used to configure an InputDevice instead of -// attributes. The details of an InputDevice implementation are not known to -// ConfiguredUniverse, so the property name is invoked as a method through -// introspection. The example properties below must be replaced with the ones -// needed, if any, by specific InputDevice implementations. All arguments -// following the method name are wrapped and passed to the specified method as -// an array of Objects. -// -// All property arguments following the method name are wrapped and passed to -// the specified method as an array of Objects. Strings "true" and "false" -// get wrapped into Boolean, and number strings get wrapped into Double. -// Construct such as (0.0 1.0 2.0) and ((0.0 1.0 2.0 0.5) (3.0 4.0 5.0 1.0) -// (6.0 7.0 8.0 0.0)) get converted to Point3d and Matrix4d respectively. -// Note that last row of a Matrix4d doesn't need to be specified; it is -// implicitly (0.0 0.0 0.0 1.0). -// -(NewDevice glasses LogitechRedBarron) -(DeviceProperty glasses SerialPort "/dev/ttya") // Unix paths need quoting. -(DeviceProperty glasses TransmitterBaseline 0.4600) -(DeviceProperty glasses TransmitterLeftLeg 0.4400) -(DeviceProperty glasses TransmitterCalibrationDistance 0.4120) - -// Create a logical name for the head tracker sensor. The last argument is -// the sensor's index in the input device. -// -(NewSensor head glasses 0) - -// Create new screen objects and associate them with logical names and numbers. -// These numbers are used as indices to retrieve the AWT GraphicsDevice from -// the array that GraphicsEnvironment.getScreenDevices() returns. -// -// NOTE: The GraphicsDevice order in the array is specific to the local -// site and display system. -// -(NewScreen left 0) -(NewScreen center 1) -(NewScreen right 2) - - -// Set the available image areas as well as their positition and orientation -// relative to the tracker base. From the orientation of a user standing -// within this VirtualPortal site and facing the center screen, the tracker -// base is along the vertical midline of the screen, 0.248 meters down from -// the top edge, and 1.340 meters in front of it. The tracker base is -// oriented so that its +X axis points to the left, its +Y axis points toward -// the screen, and its +Z axis points toward the floor. -// -(ScreenAttribute left PhysicalScreenWidth 2.480) -(ScreenAttribute left PhysicalScreenHeight 1.705) -(ScreenAttribute left WindowSize NoBorderFullScreen) -(ScreenAttribute left TrackerBaseToImagePlate - (( 0.0 0.0 -1.0 2.230) - ( 0.0 -1.0 0.0 1.340) - (-1.0 0.0 0.0 0.885))) - -(ScreenAttribute center PhysicalScreenWidth 2.485) -(ScreenAttribute center PhysicalScreenHeight 1.745) -(ScreenAttribute center WindowSize NoBorderFullScreen) -(ScreenAttribute center TrackerBaseToImagePlate - (( 0.0 0.0 1.0 0.248) - (-1.0 0.0 0.0 0.885) - ( 0.0 -1.0 0.0 1.340))) - -(ScreenAttribute right PhysicalScreenWidth 2.480) -(ScreenAttribute right PhysicalScreenHeight 1.775) -(ScreenAttribute right WindowSize NoBorderFullScreen) -(ScreenAttribute right TrackerBaseToImagePlate - (( 0.0 0.0 1.0 0.2488) - ( 0.0 -1.0 0.0 1.340) - ( 1.0 0.0 0.0 0.860))) - -// Create a physical environment. This contains the available input devices, -// audio devices, and sensors, and defines the coexistence coordinate system -// for mapping between the virtual and physical worlds. -// -(NewPhysicalEnvironment VirtualPortal) - -// Register the input device defined in this file and the sensor which will -// drive head tracking. -// -(PhysicalEnvironmentAttribute VirtualPortal InputDevice glasses) -(PhysicalEnvironmentAttribute VirtualPortal HeadTracker head) - -// Set the location of the center of coexistence relative to the tracker base. -// Here it set to the center of the center screen. The default view attach -// policy of NOMINAL_SCREEN used by ConfiguredUniverse will place the origin of -// the view platform in coexistence coordinates at the center of coexistence. -// -(PhysicalEnvironmentAttribute VirtualPortal - CoexistenceToTrackerBase - ((-1.0 0.0 0.0 0.000) - ( 0.0 0.0 -1.0 1.340) - ( 0.0 -1.0 0.0 0.994))) - -// The above center of coexistence is appropriate for the sample geometry -// files available in the programs/examples directory. Often a more -// immersive point of view is required for larger virtual worlds. This can be -// achieved by placing the center of coexistence closer to the nominal position -// of the user's head, so that the view platform origin in coexistence -// coordinates will map there as well. -// -// Here we set the location of the center of coexistence 0.5 meters along the -// tracker base +Z axis, 1.737 meters from the floor (about 5 ft 8.4 inches). -// -// (PhysicalEnvironmentAttribute VirtualPortal -// CoexistenceToTrackerBase -// ((-1.0 0.0 0.0 0.0) -// ( 0.0 0.0 -1.0 0.0) -// ( 0.0 -1.0 0.0 0.5))) - - -// Define the physical body. -// -// The head origin is halfway between the eyes, with X extending to the right, -// Y up, and positive Z extending into the skull. -// -(NewPhysicalBody LabRat) -(PhysicalBodyAttribute LabRat StereoEyeSeparation .07) - -// Define the position and orientation of the head relative to the tracker -// mounted on the head. -// -(PhysicalBodyAttribute LabRat HeadToHeadTracker - ((-1.0 0.0 0.0 0.00) - ( 0.0 0.0 -1.0 0.05) - ( 0.0 -1.0 0.0 0.11))) -// Now define the view. -// -(NewView view0) -(ViewAttribute view0 Screen left) -(ViewAttribute view0 Screen center) -(ViewAttribute view0 Screen right) -(ViewAttribute view0 PhysicalBody LabRat) -(ViewAttribute view0 PhysicalEnvironment VirtualPortal) - -// Set the screen scale. This is scale factor from virtual to physical -// coordinates. -// -(ViewAttribute view0 ScreenScalePolicy SCALE_SCREEN_SIZE) - -// Alternative for explict scaling. -// -//(ViewAttribute view0 ScreenScalePolicy SCALE_EXPLICIT) -//(ViewAttribute view0 ScreenScale 5.00) - -// Enable stereo viewing. Enable head tracking to get the position of the eyes -// with respect to coexistence. Boolean values may be specified as either -// true, True, false, or False. -// -(ViewAttribute view0 StereoEnable true) -(ViewAttribute view0 TrackingEnable True) diff --git a/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x3-rot45 b/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x3-rot45 deleted file mode 100644 index d221e74..0000000 --- a/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d1x3-rot45 +++ /dev/null @@ -1,110 +0,0 @@ -/* - * $RCSfile$ - * - * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any - * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND - * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY - * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL - * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF - * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS - * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR - * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, - * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND - * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR - * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed, licensed or - * intended for use in the design, construction, operation or - * maintenance of any nuclear facility. - * - * $Revision$ - * $Date$ - * $State$ - */ - -/* - ************************************************************************ - * - * Java 3D configuration file for 3 screens. Left and right screens are - * rotated 45 degrees from the center screen. - * - ************************************************************************ - */ - -// Create new screen objects and associate them with logical names and numbers. -// These numbers are used as indices to retrieve the AWT GraphicsDevice from -// the array that GraphicsEnvironment.getScreenDevices() returns. -// -// NOTE: The GraphicsDevice order in the array is specific to the local -// site and display system. -// -(NewScreen left 0) -(NewScreen center 1) -(NewScreen right 2) - -// Set the available image areas for full screens. -// -(ScreenAttribute left PhysicalScreenWidth 0.360) -(ScreenAttribute left PhysicalScreenHeight 0.288) - -(ScreenAttribute center PhysicalScreenWidth 0.360) -(ScreenAttribute center PhysicalScreenHeight 0.288) - -(ScreenAttribute right PhysicalScreenWidth 0.360) -(ScreenAttribute right PhysicalScreenHeight 0.288) - -// Specify full screen windows. -// -(ScreenAttribute left WindowSize NoBorderFullScreen) -(ScreenAttribute center WindowSize NoBorderFullScreen) -(ScreenAttribute right WindowSize NoBorderFullScreen) - -// Set the TrackerBaseToImagePlate transforms for these screens. -// -// The tracker base and center of coexistence are set here to the middle of the -// center screen. The basis vectors are aligned with the center screen image -// plate. The left and right screens are rotated 45 degrees toward each other -// about their shared edges with the center screen. -// -(ScreenAttribute center TrackerBaseToImagePlate - (Translate 0.180000 0.144000 0.000000)) - -// cos(45) * 0.360 * 0.5 = 0.127279; 0.360 + 0.127279 = 0.487279 -(ScreenAttribute left TrackerBaseToImagePlate - (RotateTranslate - (Rotate 0.000000 -45.000000 0.000000) - (Translate 0.487279 0.144000 0.127279))) - -// cos(45) * 0.360 * 0.5 = 0.127279 -(ScreenAttribute right TrackerBaseToImagePlate - (RotateTranslate - (Rotate 0.000000 45.000000 0.000000) - (Translate -0.127279 0.144000 0.127279))) - -// Create a view using the defined screens. -// -(NewView view0) -(ViewAttribute view0 Screen left) -(ViewAttribute view0 Screen center) -(ViewAttribute view0 Screen right) -(ViewAttribute view0 CenterEyeInCoexistence (0.0 0.0 0.5)) diff --git a/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d2x2-flat b/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d2x2-flat deleted file mode 100644 index 46df9a3..0000000 --- a/src/classes/org/jdesktop/j3d/examples/configured_universe/j3d2x2-flat +++ /dev/null @@ -1,135 +0,0 @@ -/* - * $RCSfile$ - * - * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any - * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND - * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY - * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL - * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF - * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS - * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR - * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, - * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND - * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR - * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed, licensed or - * intended for use in the design, construction, operation or - * maintenance of any nuclear facility. - * - * $Revision$ - * $Date$ - * $State$ - */ - -/* - ************************************************************************ - * - * Java 3D configuration file for 4 screen projection configuration - * arranged in a 2x2 power wall. - * - ************************************************************************ - */ - -// Create new screen objects and associate them with logical names and numbers. -// These numbers are used as indices to retrieve the AWT GraphicsDevice from -// the array that GraphicsEnvironment.getScreenDevices() returns. -// -// NOTE: The GraphicsDevice order in the array is specific to the local -// site and display system. -// -(NewScreen topleft 0) -(NewScreen topright 1) -(NewScreen bottomleft 3) -(NewScreen bottomright 2) - -// Set the available image areas for full screens. This is important when -// precise scaling between objects in the virtual world and their projections -// into the physical world is desired through use of explicit ScreenScale view -// attributes. The defaults are 0.365 meters for width and 0.292 meters for -// height. -// -(ScreenAttribute topleft PhysicalScreenWidth 0.912) -(ScreenAttribute topleft PhysicalScreenHeight 0.680) - -(ScreenAttribute topright PhysicalScreenWidth 0.912) -(ScreenAttribute topright PhysicalScreenHeight 0.680) - -(ScreenAttribute bottomleft PhysicalScreenWidth 0.912) -(ScreenAttribute bottomleft PhysicalScreenHeight 0.685) - -(ScreenAttribute bottomright PhysicalScreenWidth 0.912) -(ScreenAttribute bottomright PhysicalScreenHeight 0.685) - - -// Specify full screen windows. -// -(ScreenAttribute topleft WindowSize NoBorderFullScreen) -(ScreenAttribute topright WindowSize NoBorderFullScreen) -(ScreenAttribute bottomleft WindowSize NoBorderFullScreen) -(ScreenAttribute bottomright WindowSize NoBorderFullScreen) - -// Set the TrackerBaseToImagePlate transforms for these screens. This -// transforms points in tracker base coordinates to each screen's image plate -// coordinates, where the origin of the image plate is defined to be the lower -// left corner of the screen with X increasing to the right, Y increasing to -// the top, and Z increasing away from the screen. -// -// Without head or sensor tracking the tracker base is still needed as a point -// of reference for describing the orientation and position of each screen to -// the others. The coexistence to tracker base transform is set to identity by -// default, so the tracker base origin and orientation will also set the origin -// and orientation of coexistence coordinates in the physical world. -// -// The tracker base and center of coexistence are set here to the center of the -// 2x2 array with its basis vectors aligned to image plate coordinates. -// -(ScreenAttribute topleft TrackerBaseToImagePlate - (Translate 0.912 0.000 0.0)) -(ScreenAttribute topright TrackerBaseToImagePlate - (Translate 0.000 0.000 0.0)) -(ScreenAttribute bottomleft TrackerBaseToImagePlate - (Translate 0.912 0.685 0.0)) -(ScreenAttribute bottomright TrackerBaseToImagePlate - (Translate 0.000 0.685 0.0)) - -// Create a view using the defined screens. -// -(NewView view0) -(ViewAttribute view0 Screen topleft) -(ViewAttribute view0 Screen topright) -(ViewAttribute view0 Screen bottomleft) -(ViewAttribute view0 Screen bottomright) - -// Set the screen scale. This is scale factor from virtual to physical -// coordinates. The default policy of SCALE_SCREEN_SIZE doesn't work well here -// since in the 2x2 arrangement the individual screens are too small. The -// explicit scale factor below assumes a normalized range of object coordinates -// of [-1.0 .. +1.0]. -// -(ViewAttribute view0 ScreenScalePolicy SCALE_EXPLICIT) -(ViewAttribute view0 ScreenScale 0.912) - -// Set the user eye position in the display environment. -// -(ViewAttribute view0 CenterEyeInCoexistence (0.0 0.0 1.0)) diff --git a/src/classes/org/jdesktop/j3d/examples/distort_glyph/DistortGlyphTest.java b/src/classes/org/jdesktop/j3d/examples/distort_glyph/DistortGlyphTest.java index afada2e..add3002 100644 --- a/src/classes/org/jdesktop/j3d/examples/distort_glyph/DistortGlyphTest.java +++ b/src/classes/org/jdesktop/j3d/examples/distort_glyph/DistortGlyphTest.java @@ -44,43 +44,21 @@ package org.jdesktop.j3d.examples.distort_glyph; -import java.applet.Applet; +import com.sun.j3d.utils.behaviors.mouse.*; +import com.sun.j3d.utils.image.TextureLoader; +import com.sun.j3d.utils.universe.*; import java.awt.Font; -import java.awt.Frame; import java.awt.GraphicsConfiguration; import java.awt.GraphicsEnvironment; +import javax.media.j3d.*; +import javax.vecmath.*; +import org.jdesktop.j3d.examples.Resources; -import javax.media.j3d.AmbientLight; -import javax.media.j3d.Appearance; -import javax.media.j3d.BoundingSphere; -import javax.media.j3d.BranchGroup; -import javax.media.j3d.Canvas3D; -import javax.media.j3d.DirectionalLight; -import javax.media.j3d.Font3D; -import javax.media.j3d.FontExtrusion; -import javax.media.j3d.GeometryArray; -import javax.media.j3d.GraphicsConfigTemplate3D; -import javax.media.j3d.Light; -import javax.media.j3d.Material; -import javax.media.j3d.PointLight; -import javax.media.j3d.Shape3D; -import javax.media.j3d.TexCoordGeneration; -import javax.media.j3d.Texture; -import javax.media.j3d.TransformGroup; - -import javax.vecmath.Color3f; -import javax.vecmath.Point3d; -import javax.vecmath.Point3f; -import javax.vecmath.Vector3f; - -import com.sun.j3d.utils.applet.MainFrame; -import com.sun.j3d.utils.behaviors.mouse.MouseRotate; -import com.sun.j3d.utils.behaviors.mouse.MouseTranslate; -import com.sun.j3d.utils.behaviors.mouse.MouseZoom; -import com.sun.j3d.utils.image.TextureLoader; -import com.sun.j3d.utils.universe.SimpleUniverse; +public class DistortGlyphTest extends javax.swing.JFrame { + + private SimpleUniverse univ = null; + private BranchGroup scene = null; -public class DistortGlyphTest extends Applet { // get a nice graphics config private static GraphicsConfiguration getGraphicsConfig() { GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D(); @@ -88,7 +66,7 @@ public class DistortGlyphTest extends Applet { GraphicsConfiguration gcfg = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getBestConfiguration(template); return gcfg; } - + private void setupLights(BranchGroup root) { // set up the BoundingSphere for all the lights BoundingSphere bounds = new BoundingSphere(new Point3d(), 100.0); @@ -117,7 +95,7 @@ public class DistortGlyphTest extends Applet { pointLight2.setInfluencingBounds(bounds); root.addChild(pointLight2); } - + public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); @@ -135,7 +113,7 @@ public class DistortGlyphTest extends Applet { Color3f objColor = new Color3f(1.0f, 0.7f, 0.8f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, black, 80.0f)); - Texture txtr = new TextureLoader("gold.jpg",this).getTexture(); + Texture txtr = new TextureLoader(Resources.getResource("resources/images/gold.jpg"),this).getTexture(); app.setTexture(txtr); TexCoordGeneration tcg = new TexCoordGeneration(TexCoordGeneration.SPHERE_MAP,TexCoordGeneration.TEXTURE_COORDINATE_2); app.setTexCoordGeneration(tcg); @@ -180,31 +158,75 @@ public class DistortGlyphTest extends Applet { return objRoot; } + + private Canvas3D createUniverse() { + + // Create a Canvas3D using a nice configuration + Canvas3D c = new Canvas3D(getGraphicsConfig()); - // Create a simple scene and attach it to the virtual universe - public DistortGlyphTest() { - //setLayout(new BorderLayout()); - GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); + // Create simple universe with view branch + univ = new SimpleUniverse(c); + + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + univ.getViewingPlatform().setNominalViewingTransform(); - Canvas3D canvas3D = new Canvas3D(getGraphicsConfig()); - canvas3D.setBounds(0, 0, 800, 600); - add("Center", canvas3D); + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); - BranchGroup scene = createSceneGraph(); + return c; + } - // SimpleUniverse is a Convenience Utility class - SimpleUniverse simpleU = new SimpleUniverse(canvas3D); + /** + * Creates new form DistortGlyphTest2 + */ + public DistortGlyphTest() { + // Initialize the GUI components + initComponents(); - // This will move the ViewPlatform back a bit so the - // objects in the scene can be viewed. - simpleU.getViewingPlatform().setNominalViewingTransform(); + // Create Canvas3D and SimpleUniverse; add canvas to drawing panel + Canvas3D c = createUniverse(); + drawingPanel.add(c, java.awt.BorderLayout.CENTER); - simpleU.addBranchGraph(scene); + // Create the content branch and add it to the universe + scene = createSceneGraph(); + univ.addBranchGraph(scene); } - // 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 DistortGlyphTest(), 800, 600); + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("DistortGlyphTest"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// </editor-fold>//GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new DistortGlyphTest().setVisible(true); + } + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/four_by_four/FourByFour.html b/src/classes/org/jdesktop/j3d/examples/four_by_four/FourByFour.html index 8adb168..db06814 100644 --- a/src/classes/org/jdesktop/j3d/examples/four_by_four/FourByFour.html +++ b/src/classes/org/jdesktop/j3d/examples/four_by_four/FourByFour.html @@ -3,7 +3,7 @@ <TITLE>Drag the mouse in the window</TITLE> </HEAD> <BODY BGCOLOR="#0C0C33"> -<applet align=middle code="FourByFour.class" width=716 height=410> +<applet align=middle codebase="../../../../.." code="org.jdesktop.j3d.examples.four_by_four.FourByFour" width=716 height=410> <blockquote> <hr> If you were using a Java-capable browser, diff --git a/src/classes/org/jdesktop/j3d/examples/four_by_four/FourByFour.java b/src/classes/org/jdesktop/j3d/examples/four_by_four/FourByFour.java index 744086c..c1faf63 100644 --- a/src/classes/org/jdesktop/j3d/examples/four_by_four/FourByFour.java +++ b/src/classes/org/jdesktop/j3d/examples/four_by_four/FourByFour.java @@ -53,6 +53,7 @@ import javax.media.j3d.*; import javax.vecmath.*; import com.sun.j3d.utils.universe.SimpleUniverse; import com.sun.j3d.utils.applet.MainFrame; +import org.jdesktop.j3d.examples.Resources; /** * Class FourByFour @@ -64,6 +65,9 @@ import com.sun.j3d.utils.applet.MainFrame; */ public class FourByFour extends Applet implements ActionListener { + // To write scores to scores file + private static final boolean writeScoresFile = false; + String host; // Host from which this applet came from int port; // Port number for writing high scores Image backbuffer2D; // Backbuffer image used for 2D double buffering @@ -106,7 +110,6 @@ public class FourByFour extends Applet implements ActionListener { Button high_return_button; // Return button for high scores panel CheckboxGroup group; // CheckboxGroup object for skill level panel InputStream inStream; // Input stream for reading instructions and high scores - OutputStream outStream; // Output stream for writing high scores static boolean appletFlag = true; // Applet flag boolean winner_flag = false; // Winner flag byte text[]; // Temporary storage area for reading instructions file @@ -147,8 +150,8 @@ public class FourByFour extends Applet implements ActionListener { host = getCodeBase().getHost(); try { - inStream = new BufferedInputStream - (new URL(getCodeBase(), "instructions.txt").openStream(), 8192); + URL instrURL = Resources.getResource("four_by_four/instructions.txt"); + inStream = new BufferedInputStream((instrURL).openStream(), 8192); text = new byte[5000]; int character = inStream.read(); int count = 0; @@ -166,8 +169,8 @@ public class FourByFour extends Applet implements ActionListener { else { try { - inStream = new BufferedInputStream - (new FileInputStream("instructions.txt")); + URL instrURL = Resources.getResource("four_by_four/instructions.txt"); + inStream = new BufferedInputStream((instrURL).openStream(), 8192); text = new byte[5000]; int character = inStream.read(); int count = 0; @@ -189,8 +192,8 @@ public class FourByFour extends Applet implements ActionListener { names = new String[20]; if (appletFlag) { try { - inStream = new BufferedInputStream - (new URL(getCodeBase(), "scores.txt").openStream(), 8192); + URL scoreURL = Resources.getResource("four_by_four/scores.txt"); + inStream = new BufferedInputStream((scoreURL).openStream(), 8192); Reader read = new BufferedReader(new InputStreamReader(inStream)); StreamTokenizer st = new StreamTokenizer(read); st.whitespaceChars(32,44); @@ -222,8 +225,8 @@ public class FourByFour extends Applet implements ActionListener { } else { try { - inStream = new BufferedInputStream - (new FileInputStream("scores.txt")); + URL scoreURL = Resources.getResource("four_by_four/scores.txt"); + inStream = new BufferedInputStream((scoreURL).openStream(), 8192); Reader read = new BufferedReader(new InputStreamReader(inStream)); StreamTokenizer st = new StreamTokenizer(read); st.whitespaceChars(32,44); @@ -631,64 +634,35 @@ public class FourByFour extends Applet implements ActionListener { scoresString += "\n"; } - if (appletFlag) { - // Use this section of code when writing the high - // scores file back to a server. Requires the use - // of a deamon on the server to receive the socket - // connection. - // - // Create the output stream. - // try { - // Socket socket = new Socket(host, port); - // outStream = new BufferedOutputStream - // (socket.getOutputStream(), 8192); - // } - // catch(IOException ioe) { - // System.out.println("Error: " + ioe.toString()); - // } - // System.out.println("Output stream opened"); - // - // Write the scores to the file back on the server. - // outText = scoresString.getBytes(); - // try { - // outStream.write(outText); - // outStream.flush(); - // outStream.close(); - // outStream = null; - // } - // catch (IOException ioe) { - // System.out.println("Error: " + ioe.toString()); - // } - // System.out.println("Output stream written"); - - try { - OutputStreamWriter outFile = - new OutputStreamWriter(new FileOutputStream("scores.txt")); - outFile.write(scoresString); - outFile.flush(); - outFile.close(); - outFile = null; - } - catch (IOException ioe) { - System.out.println("Error: " + ioe.toString()); - } - catch (Exception e) { - System.out.println("Error: " + e.toString()); - } - } - else { - - try { - OutputStreamWriter outFile = - new OutputStreamWriter(new FileOutputStream("scores.txt")); - outFile.write(scoresString); - outFile.flush(); - outFile.close(); - outFile = null; - } - catch (IOException ioe) { - System.out.println("Error: " + ioe.toString()); - } + if(writeScoresFile) { + if (appletFlag) { + try { + OutputStreamWriter outFile = + new OutputStreamWriter(new FileOutputStream("scores.txt")); + outFile.write(scoresString); + outFile.flush(); + outFile.close(); + outFile = null; + } catch (IOException ioe) { + System.out.println("Error: " + ioe.toString()); + } catch (Exception e) { + System.out.println("Error: " + e.toString()); + } + + } else { + + try { + + OutputStreamWriter outFile = + new OutputStreamWriter(new FileOutputStream("scores.txt")); + outFile.write(scoresString); + outFile.flush(); + outFile.close(); + outFile = null; + } catch (IOException ioe) { + System.out.println("Error: " + ioe.toString()); + } + } } } winner_panel.setVisible(false); @@ -737,8 +711,8 @@ public class FourByFour extends Applet implements ActionListener { // Read the high scores file. if (appletFlag) { try { - inStream = new BufferedInputStream - (new URL(getCodeBase(), "scores.txt").openStream(), 8192); + URL scoreURL = Resources.getResource("four_by_four/scores.txt"); + inStream = new BufferedInputStream(scoreURL.openStream(), 8192); Reader read = new BufferedReader(new InputStreamReader(inStream)); StreamTokenizer st = new StreamTokenizer(read); st.whitespaceChars(32,44); @@ -770,8 +744,8 @@ public class FourByFour extends Applet implements ActionListener { } else { try { - inStream = new BufferedInputStream - (new FileInputStream("scores.txt")); + URL scoreURL = Resources.getResource("four_by_four/scores.txt"); + inStream = new BufferedInputStream(scoreURL.openStream(), 8192); Reader read = new BufferedReader(new InputStreamReader(inStream)); StreamTokenizer st = new StreamTokenizer(read); st.whitespaceChars(32,44); diff --git a/src/classes/org/jdesktop/j3d/examples/four_by_four/FourByFour_plugin.html b/src/classes/org/jdesktop/j3d/examples/four_by_four/FourByFour_plugin.html deleted file mode 100644 index 55e1cf4..0000000 --- a/src/classes/org/jdesktop/j3d/examples/four_by_four/FourByFour_plugin.html +++ /dev/null @@ -1,39 +0,0 @@ -<HTML> -<HEAD> -<TITLE>Drag the mouse in the window</TITLE> -</HEAD> -<BODY BGCOLOR="#0C0C33"> -<!--"CONVERTED_APPLET"--> -<!-- CONVERTER VERSION 1.3 --> -<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" -WIDTH = 716 HEIGHT = 410 ALIGN = middle codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0"> -<PARAM NAME = CODE VALUE = "FourByFour.class" > - -<PARAM NAME="type" VALUE="application/x-java-applet;version=1.2.2"> -<PARAM NAME="scriptable" VALUE="false"> -<COMMENT> -<EMBED type="application/x-java-applet;version=1.2.2" CODE = "FourByFour.class" WIDTH = 716 HEIGHT = 410 ALIGN = middle scriptable=false pluginspage="http://java.sun.com/products/plugin/1.3/plugin-install.html"><NOEMBED></COMMENT> -<blockquote> -<hr> -If you were using a Java-capable browser, -you would see "FourByFour" instead of this paragraph. -<hr> -</blockquote> -</NOEMBED></EMBED> -</OBJECT> - -<!-- -<APPLET CODE = "FourByFour.class" WIDTH = 716 HEIGHT = 410 ALIGN = middle> -<blockquote> -<hr> -If you were using a Java-capable browser, -you would see "FourByFour" instead of this paragraph. -<hr> -</blockquote> - -</APPLET> ---> -<!--"END_CONVERTED_APPLET"--> - -</BODY> -</HTML> diff --git a/src/classes/org/jdesktop/j3d/examples/fps_counter/FPSCounterDemo.java b/src/classes/org/jdesktop/j3d/examples/fps_counter/FPSCounterDemo.java index f73be9d..d7f8ee9 100644 --- a/src/classes/org/jdesktop/j3d/examples/fps_counter/FPSCounterDemo.java +++ b/src/classes/org/jdesktop/j3d/examples/fps_counter/FPSCounterDemo.java @@ -44,31 +44,29 @@ package org.jdesktop.j3d.examples.fps_counter; -import java.applet.Applet; -import java.awt.BorderLayout; -import java.awt.event.*; -import java.awt.GraphicsConfiguration; -import com.sun.j3d.utils.applet.JMainFrame; -import com.sun.j3d.utils.geometry.ColorCube; import com.sun.j3d.utils.universe.*; +import com.sun.j3d.utils.geometry.ColorCube; import javax.media.j3d.*; import javax.vecmath.*; +import java.awt.GraphicsConfiguration; import javax.swing.JOptionPane; -/** This program demonstrates the use of the frames per second counter. +/** + * This program demonstrates the use of the frames per second counter. * The program displays a rotating cube and sets up the FPSCounter to compute * the frame rate. The FPSCounter is set up with default values: * - run indefinitely - * - 2 sec. warmup time - * - display average frame rate every fifth sampling interval. + * - 2 sec. warmup time + * - display average frame rate every fifth sampling interval. * The default values can be changed through the command line - * arguments. Use FPSCounterDemo -h for help on the various arguments. + * arguments. Use FPSCounterDemo1 -h for help on the various arguments. */ +public class FPSCounterDemo extends javax.swing.JFrame { -public class FPSCounterDemo extends Applet { - private SimpleUniverse u = null; + private SimpleUniverse univ = null; + private BranchGroup scene = null; private FPSCounter fpsCounter = new FPSCounter(); - + BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); @@ -105,60 +103,53 @@ public class FPSCounterDemo extends Applet { return objRoot; } + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); - public FPSCounterDemo(String args[]) { - } - - public FPSCounterDemo() { - } - - public void init() { - setLayout(new BorderLayout()); - GraphicsConfiguration config = - SimpleUniverse.getPreferredConfiguration(); - - Canvas3D c = new Canvas3D(config); - add("Center", c); - - // Create a simple scene and attach it to the virtual universe - BranchGroup scene = createSceneGraph(); - - // Parse the command line to set the various parameters + // Create a Canvas3D using the preferred configuration + Canvas3D c = new Canvas3D(config); - // Have Java 3D perform optimizations on this scene graph. - scene.compile(); - u = new SimpleUniverse(c); + // Create simple universe with view branch + univ = new SimpleUniverse(c); - // This will move the ViewPlatform back a bit so the - // objects in the scene can be viewed. - u.getViewingPlatform().setNominalViewingTransform(); + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + univ.getViewingPlatform().setNominalViewingTransform(); - u.addBranchGraph(scene); + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); - JOptionPane.showMessageDialog(this, - ("This program measures the number of frames rendered per second.\n" + - "Note that the frame rate is limited by the refresh rate of the monitor.\n" + - "To get the true frame rate you need to disable vertical retrace.\n\n" + - "On Windows(tm) you do this through the Control Panel.\n\n" + - "On Solaris set the environment variable OGL_NO_VBLANK"), - "Frame Counter", - JOptionPane.INFORMATION_MESSAGE); - } - - public void destroy() { - u.cleanup(); - } - - // - // The following allows FPSCounterDemo to be run as an application - // as well as an applet - // - public static void main(String[] args) { - FPSCounterDemo fp = new FPSCounterDemo(); - fp.parseArgs(args); - JMainFrame frame = new JMainFrame(fp, 256, 256); - } + return c; + } + /** + * Creates new form FPSCounterDemo + */ + public FPSCounterDemo() { + // Initialize the GUI components + initComponents(); + + // Create Canvas3D and SimpleUniverse; add canvas to drawing panel + Canvas3D c = createUniverse(); + drawingPanel.add(c, java.awt.BorderLayout.CENTER); + + // Create the content branch and add it to the universe + scene = createSceneGraph(); + univ.addBranchGraph(scene); + + JOptionPane.showMessageDialog(this, + ("This program measures the number of frames rendered per second.\n" + + "Note that the frame rate is limited by the refresh rate of the monitor.\n" + + "To get the true frame rate you need to disable vertical retrace.\n\n" + + "On Windows(tm) you do this through the Control Panel.\n\n" + + "On Solaris set the environment variable OGL_NO_VBLANK"), + "Frame Counter", + JOptionPane.INFORMATION_MESSAGE); + + } + /** Parses the commandline for the various switches to set the FPSCounter * variables. * All arguments are of the form <i>-name value</i>. @@ -217,5 +208,43 @@ public class FPSCounterDemo extends Applet { } } } - + + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("FPSCounterDemo"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(250, 250)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// </editor-fold>//GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(final String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + FPSCounterDemo fp = new FPSCounterDemo(); + fp.parseArgs(args); + fp.setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/gears/GearBox.java b/src/classes/org/jdesktop/j3d/examples/gears/GearBox.java index a3b0a84..ba18906 100644 --- a/src/classes/org/jdesktop/j3d/examples/gears/GearBox.java +++ b/src/classes/org/jdesktop/j3d/examples/gears/GearBox.java @@ -45,23 +45,23 @@ package org.jdesktop.j3d.examples.gears; import com.sun.j3d.utils.behaviors.mouse.*; -import java.applet.Applet; -import java.awt.*; -import java.awt.event.*; -import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; import java.lang.Integer; import com.sun.j3d.utils.behaviors.vp.*; +import java.awt.GraphicsConfiguration; -public class GearBox extends Applet { +/** + * Simple Java 3D example program to display a spinning cube. + */ +public class GearBox extends javax.swing.JFrame { - static final int defaultToothCount = 48; - private int toothCount; - private SimpleUniverse u = null; + private SimpleUniverse univ = null; + private BranchGroup scene = null; + private int toothCount = 48; - public BranchGroup createGearBox(int toothCount) { + public BranchGroup createSceneGraph() { Transform3D tempTransform = new Transform3D(); // Create the root of the branch graph @@ -177,7 +177,7 @@ public class GearBox extends Applet { } // Define the gear base information. Again, these arrays exist to - // make the process of changing the GearBox via an editor faster + // make the process of changing the GearBox1 via an editor faster int gearCount = 5; float valleyToCircularPitchRatio = .15f; float pitchCircleRadius = 1.0f; @@ -282,75 +282,113 @@ public class GearBox extends Applet { return branchRoot; } - public GearBox() { - this(defaultToothCount); - } + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); - public GearBox(int toothCount) { - this.toothCount = toothCount; - } - - public void init() { - setLayout(new BorderLayout()); - GraphicsConfiguration config = - SimpleUniverse.getPreferredConfiguration(); - - Canvas3D c = new Canvas3D(config); - add("Center", c); - - // Create the gearbox and attach it to the virtual universe - BranchGroup scene = createGearBox(toothCount); - u = new SimpleUniverse(c); + // Create a Canvas3D using the preferred configuration + Canvas3D c = new Canvas3D(config); + // Create simple universe with view branch + univ = new SimpleUniverse(c); + // add mouse behaviors to the ViewingPlatform - ViewingPlatform viewingPlatform = u.getViewingPlatform(); - - // This will move the ViewPlatform back a bit so the - // objects in the scene can be viewed. - viewingPlatform.setNominalViewingTransform(); + ViewingPlatform viewingPlatform = univ.getViewingPlatform(); - // add orbit behavior to the ViewingPlatform + // add orbit behavior to the ViewingPlatform OrbitBehavior orbit = new OrbitBehavior(c, OrbitBehavior.REVERSE_ALL); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); orbit.setSchedulingBounds(bounds); viewingPlatform.setViewPlatformBehavior(orbit); - u.addBranchGraph(scene); - } + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + univ.getViewingPlatform().setNominalViewingTransform(); - public void destroy() { - u.cleanup(); - } + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); - // - // The following allows GearBox to be run as an application - // as well as an applet - // - public static void main(String[] args) { + return c; + } + + + /** + * Creates new form GearBox + */ + public GearBox(String args[]) { int value; if (args.length > 1) { - System.out.println("Usage: java GearBox #teeth (LCD 4)"); - System.exit(0); - } else if (args.length == 0) { - new MainFrame(new GearBox(), 700, 700); - } else - { - try{ - value = Integer.parseInt(args[0]); - } catch (NumberFormatException e) { - System.out.println("Illegal integer specified"); - System.out.println("Usage: java GearBox #teeth (LCD 4)"); - value = 0; - System.exit(0); - } - if (value <= 0 | (value % 4) != 0) { - System.out.println("Integer not a positive multiple of 4"); - System.out.println("Usage: java GearBox #teeth (LCD 4)"); - System.exit(0); - } - new MainFrame(new GearBox(value), 700, 700); - } + System.out.println("Usage: java GearBox #teeth (LCD 4)"); + System.exit(0); + } else if (args.length == 1) { + { + try{ + value = Integer.parseInt(args[0]); + } catch (NumberFormatException e) { + System.out.println("Illegal integer specified"); + System.out.println("Usage: java GearBox #teeth (LCD 4)"); + value = 0; + System.exit(0); + } + if (value <= 0 | (value % 4) != 0) { + System.out.println("Integer not a positive multiple of 4"); + System.out.println("Usage: java GearBox #teeth (LCD 4)"); + System.exit(0); + } + toothCount = value; + } + } + + // Initialize the GUI components + initComponents(); + + // Create Canvas3D and SimpleUniverse; add canvas to drawing panel + Canvas3D c = createUniverse(); + drawingPanel.add(c, java.awt.BorderLayout.CENTER); + + // Create the content branch and add it to the universe + scene = createSceneGraph(); + univ.addBranchGraph(scene); } + + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("GearBox"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// </editor-fold>//GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(final String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + GearBox gb = new GearBox(args); + gb.setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/gears/GearTest.java b/src/classes/org/jdesktop/j3d/examples/gears/GearTest.java index 29ecca9..b6ffc85 100644 --- a/src/classes/org/jdesktop/j3d/examples/gears/GearTest.java +++ b/src/classes/org/jdesktop/j3d/examples/gears/GearTest.java @@ -44,23 +44,22 @@ package org.jdesktop.j3d.examples.gears; -import java.applet.Applet; -import java.awt.*; -import java.awt.event.*; -import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; +import com.sun.j3d.utils.geometry.ColorCube; import javax.media.j3d.*; import javax.vecmath.*; +import java.awt.GraphicsConfiguration; -public class GearTest extends Applet { - - static final int defaultToothCount = 24; - - private int toothCount; +/** + * Simple Java 3D example program to display a spinning cube. + */ +public class GearTest extends javax.swing.JFrame { - private SimpleUniverse u = null; + private int toothCount = 24; + private SimpleUniverse univ = null; + private BranchGroup scene = null; - public BranchGroup createSceneGraph(int toothCount) { + public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); @@ -144,65 +143,101 @@ public class GearTest extends Applet { return objRoot; } - public GearTest() { - this(defaultToothCount); - } - - public GearTest(int toothCount) { - this.toothCount = toothCount; - } - - public void init() { - setLayout(new BorderLayout()); + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); - Canvas3D c = new Canvas3D(config); - add("Center", c); + // Create a Canvas3D using the preferred configuration + Canvas3D c = new Canvas3D(config); - // Create a simple scene and attach it to the virtual universe - BranchGroup scene = createSceneGraph(toothCount); - u = new SimpleUniverse(c); + // Create simple universe with view branch + univ = new SimpleUniverse(c); - // This will move the ViewPlatform back a bit so the - // objects in the scene can be viewed. - u.getViewingPlatform().setNominalViewingTransform(); + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + univ.getViewingPlatform().setNominalViewingTransform(); - u.addBranchGraph(scene); - } + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); - public void destroy() { - u.cleanup(); + return c; } - // - // The following allows GearTest to be run as an application - // as well as an applet - // - public static void main(String[] args) { + /** + * Creates new form GearTest + */ + public GearTest(String args[]) { int value; if (args.length > 1) { - System.out.println("Usage: java GearTest [#teeth]"); - System.exit(0); - } else if (args.length == 0) { - new MainFrame(new GearTest(), 700, 700); - } else - { - try { - value = Integer.parseInt(args[0]); - } catch (NumberFormatException e) { - System.out.println("Illegal integer specified"); - System.out.println("Usage: java GearTest [#teeth]"); - value = 0; - System.exit(0); - } - if (value <= 0) { - System.out.println("Integer must be positive (> 0)"); - System.out.println("Usage: java GearBox [#teeth]"); - System.exit(0); - } - new MainFrame(new GearTest(value), 700, 700); - } + System.out.println("Usage: java GearTest [#teeth]"); + System.exit(0); + } else if (args.length == 1) { + try { + value = Integer.parseInt(args[0]); + } catch (NumberFormatException e) { + System.out.println("Illegal integer specified"); + System.out.println("Usage: java GearTest [#teeth]"); + value = 0; + System.exit(0); + } + if (value <= 0) { + System.out.println("Integer must be positive (> 0)"); + System.out.println("Usage: java GearBox [#teeth]"); + System.exit(0); + } + toothCount = value; + + } + + // Initialize the GUI components + initComponents(); + + // Create Canvas3D and SimpleUniverse; add canvas to drawing panel + Canvas3D c = createUniverse(); + drawingPanel.add(c, java.awt.BorderLayout.CENTER); + + // Create the content branch and add it to the universe + scene = createSceneGraph(); + univ.addBranchGraph(scene); + } + + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("GearTest"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// </editor-fold>//GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(final String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + GearTest gt = new GearTest(args); + gt.setVisible(true); + } + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/geometry_by_ref/ImageComponentByReferenceTest.java b/src/classes/org/jdesktop/j3d/examples/geometry_by_ref/ImageComponentByReferenceTest.java index aa649f7..d3f581a 100644 --- a/src/classes/org/jdesktop/j3d/examples/geometry_by_ref/ImageComponentByReferenceTest.java +++ b/src/classes/org/jdesktop/j3d/examples/geometry_by_ref/ImageComponentByReferenceTest.java @@ -44,25 +44,17 @@ package org.jdesktop.j3d.examples.geometry_by_ref; -import java.applet.Applet; import java.awt.*; import java.awt.event.*; import com.sun.j3d.utils.applet.MainFrame; -import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; import javax.swing.*; -import javax.swing.event.*; -import javax.swing.border.*; -import com.sun.j3d.utils.behaviors.mouse.*; import com.sun.j3d.utils.image.TextureLoader; -import com.sun.j3d.utils.geometry.Sphere; import com.sun.j3d.utils.geometry.Box; -import com.sun.j3d.utils.geometry.ColorCube; import java.awt.image.*; -import java.awt.color.ColorSpace; -import com.sun.j3d.utils.geometry.*; +import org.jdesktop.j3d.examples.Resources; public class ImageComponentByReferenceTest extends JApplet implements ActionListener { @@ -251,33 +243,28 @@ public class ImageComponentByReferenceTest extends JApplet implements ActionList } public void init() { + + texImage = Resources.getResource("resources/images/one.jpg"); if (texImage == null) { - // the path to the image for an applet - try { - texImage = new java.net.URL(getCodeBase().toString() + - "../images/one.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - } - + System.err.println("resources/images/one.jpg not found"); + System.exit(1); + } + Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); - BranchGroup scene = createSceneGraph();u = new SimpleUniverse(c); + BranchGroup scene = createSceneGraph();u = new SimpleUniverse(c); u.getViewingPlatform().setNominalViewingTransform(); u.addBranchGraph(scene); - Container contentPane = getContentPane(); - JPanel p = new JPanel(); - BoxLayout boxlayout = new BoxLayout(p, - BoxLayout.Y_AXIS); - p.setLayout(boxlayout); + Container contentPane = getContentPane(); + JPanel p = new JPanel(); + BoxLayout boxlayout = new BoxLayout(p, + BoxLayout.Y_AXIS); + p.setLayout(boxlayout); contentPane.add("Center", c); - - contentPane.add("South", p); - - p.add(createImagePanel()); - + + contentPane.add("South", p); + + p.add(createImagePanel()); + } public void destroy() { @@ -287,21 +274,16 @@ public class ImageComponentByReferenceTest extends JApplet implements ActionList public static void main(String[] args) { java.net.URL url = null; // the path to the image file for an application - try { - url = new java.net.URL("file:../images/one.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - + url = Resources.getResource("resources/images/one.jpg"); + if (url == null) { + System.err.println("resources/images/one.jpg not found"); + System.exit(1); + } + new MainFrame(new ImageComponentByReferenceTest(url), 800, 700); } void createRaster( BranchGroup scene) { - - - // Create raster geometries and shapes Vector3f trans = new Vector3f( ); Transform3D tr = new Transform3D( ); @@ -319,9 +301,6 @@ public class ImageComponentByReferenceTest extends JApplet implements ActionList raster.setImage( image[2] ); Shape3D sh = new Shape3D( raster, new Appearance( ) ); scene.addChild( sh ); - - - } } diff --git a/src/classes/org/jdesktop/j3d/examples/geometry_by_ref/InterleavedNIOBuffer.java b/src/classes/org/jdesktop/j3d/examples/geometry_by_ref/InterleavedNIOBuffer.java index 78edf99..464ae1a 100644 --- a/src/classes/org/jdesktop/j3d/examples/geometry_by_ref/InterleavedNIOBuffer.java +++ b/src/classes/org/jdesktop/j3d/examples/geometry_by_ref/InterleavedNIOBuffer.java @@ -44,20 +44,18 @@ package org.jdesktop.j3d.examples.geometry_by_ref; -import java.applet.Applet; import java.awt.*; import java.awt.event.*; import com.sun.j3d.utils.applet.MainFrame; -import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.universe.*; import com.sun.j3d.utils.image.TextureLoader; import javax.media.j3d.*; import javax.vecmath.*; import javax.swing.*; -import javax.swing.event.*; import javax.swing.border.*; import com.sun.j3d.utils.behaviors.vp.*; import java.nio.*; +import org.jdesktop.j3d.examples.Resources; public class InterleavedNIOBuffer extends JApplet implements ActionListener { @@ -336,31 +334,18 @@ public class InterleavedNIOBuffer extends JApplet implements ActionListener { public void init() { // create textures - + texImage1 = Resources.getResource("resources/images/bg.jpg"); if (texImage1 == null) { - // the path to the image for an applet - try { - texImage1 = new java.net.URL(getCodeBase().toString() + - "../images/bg.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); + System.err.println("resources/images/bg.jpg not found"); System.exit(1); - } } + texImage2 = Resources.getResource("resources/images/one.jpg"); if (texImage2 == null) { - // the path to the image for an applet - try { - texImage2 = new java.net.URL(getCodeBase().toString() + - "../images/one.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); + System.err.println("resources/images/one.jpg not found"); System.exit(1); - } } - + Container contentPane = getContentPane(); Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); @@ -431,13 +416,16 @@ public class InterleavedNIOBuffer extends JApplet implements ActionListener { java.net.URL texURL1 = null; java.net.URL texURL2 = null; // the path to the image for an application - try { - texURL1 = new java.net.URL("file:../images/bg.jpg"); - texURL2 = new java.net.URL("file:../images/one.jpg"); + texURL1 = Resources.getResource("resources/images/bg.jpg"); + if (texURL1 == null) { + System.err.println("resources/images/bg.jpg not found"); + System.exit(1); } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); + + texURL2 = Resources.getResource("resources/images/one.jpg"); + if (texURL2 == null) { + System.err.println("resources/images/one.jpg not found"); + System.exit(1); } Frame frame = new MainFrame(new InterleavedNIOBuffer(texURL1, texURL2), diff --git a/src/classes/org/jdesktop/j3d/examples/geometry_by_ref/InterleavedTest.java b/src/classes/org/jdesktop/j3d/examples/geometry_by_ref/InterleavedTest.java index 788e1f6..bc570d0 100644 --- a/src/classes/org/jdesktop/j3d/examples/geometry_by_ref/InterleavedTest.java +++ b/src/classes/org/jdesktop/j3d/examples/geometry_by_ref/InterleavedTest.java @@ -44,19 +44,17 @@ package org.jdesktop.j3d.examples.geometry_by_ref; -import java.applet.Applet; import java.awt.*; import java.awt.event.*; import com.sun.j3d.utils.applet.MainFrame; -import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.universe.*; import com.sun.j3d.utils.image.TextureLoader; import javax.media.j3d.*; import javax.vecmath.*; import javax.swing.*; -import javax.swing.event.*; import javax.swing.border.*; import com.sun.j3d.utils.behaviors.vp.*; +import org.jdesktop.j3d.examples.Resources; public class InterleavedTest extends JApplet implements ActionListener { @@ -315,29 +313,16 @@ public class InterleavedTest extends JApplet implements ActionListener { public void init() { // create textures - + texImage1 = Resources.getResource("resources/images/bg.jpg"); if (texImage1 == null) { - // the path to the image for an applet - try { - texImage1 = new java.net.URL(getCodeBase().toString() + - "../images/bg.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); + System.err.println("resources/images/bg.jpg not found"); System.exit(1); - } } + texImage2 = Resources.getResource("resources/images/one.jpg"); if (texImage2 == null) { - // the path to the image for an applet - try { - texImage2 = new java.net.URL(getCodeBase().toString() + - "../images/one.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); + System.err.println("resources/images/one.jpg not found"); System.exit(1); - } } Container contentPane = getContentPane(); @@ -410,13 +395,16 @@ public class InterleavedTest extends JApplet implements ActionListener { java.net.URL texURL1 = null; java.net.URL texURL2 = null; // the path to the image for an application - try { - texURL1 = new java.net.URL("file:../images/bg.jpg"); - texURL2 = new java.net.URL("file:../images/one.jpg"); + texURL1 = Resources.getResource("resources/images/bg.jpg"); + if (texURL1 == null) { + System.err.println("resources/images/bg.jpg not found"); + System.exit(1); } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); + + texURL2 = Resources.getResource("resources/images/one.jpg"); + if (texURL2 == null) { + System.err.println("resources/images/one.jpg not found"); + System.exit(1); } Frame frame = new MainFrame(new InterleavedTest(texURL1, texURL2), diff --git a/src/classes/org/jdesktop/j3d/examples/glsl_shader/ObjLoadGLSL.java b/src/classes/org/jdesktop/j3d/examples/glsl_shader/ObjLoadGLSL.java index 9841a52..034fdf8 100644 --- a/src/classes/org/jdesktop/j3d/examples/glsl_shader/ObjLoadGLSL.java +++ b/src/classes/org/jdesktop/j3d/examples/glsl_shader/ObjLoadGLSL.java @@ -49,20 +49,23 @@ import com.sun.j3d.loaders.ParsingErrorException; import com.sun.j3d.loaders.IncorrectFormatException; import com.sun.j3d.loaders.Scene; import com.sun.j3d.utils.shader.StringIO; -import java.applet.Applet; -import java.awt.*; -import java.awt.event.*; -import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; +import java.awt.GraphicsConfiguration; +import java.net.MalformedURLException; import java.util.Enumeration; import java.io.*; -import com.sun.j3d.utils.behaviors.vp.*; import java.net.URL; -import java.net.MalformedURLException; +import com.sun.j3d.utils.behaviors.vp.*; +import java.io.FileNotFoundException; +import javax.swing.JOptionPane; +import org.jdesktop.j3d.examples.Resources; -public class ObjLoadGLSL extends Applet { +/** + * Simple Java 3D example program to display an .obj object with shader programs. + */ +public class ObjLoadGLSL extends javax.swing.JFrame { private String shaderName = "polkadot3d"; private boolean spin = false; @@ -70,8 +73,9 @@ public class ObjLoadGLSL extends Applet { private boolean noStripify = false; private double creaseAngle = 60.0; private URL filename = null; - private SimpleUniverse u; - private BoundingSphere bounds; + + private SimpleUniverse univ = null; + private BranchGroup scene = null; public BranchGroup createSceneGraph() { // Create the root of the branch graph @@ -98,27 +102,30 @@ public class ObjLoadGLSL extends Applet { if (!noTriangulate) flags |= ObjectFile.TRIANGULATE; if (!noStripify) flags |= ObjectFile.STRIPIFY; ObjectFile f = new ObjectFile(flags, - (float)(creaseAngle * Math.PI / 180.0)); + (float)(creaseAngle * Math.PI / 180.0)); Scene s = null; try { - s = f.load(filename); + s = f.load(filename); } catch (FileNotFoundException e) { - throw new RuntimeException(e); + System.err.println(e); + System.exit(1); } catch (ParsingErrorException e) { - throw new RuntimeException(e); + System.err.println(e); + System.exit(1); } catch (IncorrectFormatException e) { - throw new RuntimeException(e); + System.err.println(e); + System.exit(1); } - + // Set vertex and fragment shader program for all Shape3D nodes in scene String vertexProgram = null; String fragmentProgram = null; try { - vertexProgram = StringIO.readFully(shaderName + ".vert"); - fragmentProgram = StringIO.readFully(shaderName + ".frag"); + vertexProgram = StringIO.readFully(Resources.getResource("glsl_shader/" + shaderName + ".vert")); + fragmentProgram = StringIO.readFully(Resources.getResource("glsl_shader/" + shaderName + ".frag")); } catch (IOException e) { throw new RuntimeException(e); @@ -136,20 +143,20 @@ public class ObjLoadGLSL extends Applet { objTrans.addChild(s.getSceneGroup()); - bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); + BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); if (spin) { - Transform3D yAxis = new Transform3D(); - Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, - 0, 0, - 4000, 0, 0, - 0, 0, 0); - - RotationInterpolator rotator = - new RotationInterpolator(rotationAlpha, objTrans, yAxis, - 0.0f, (float) Math.PI*2.0f); - rotator.setSchedulingBounds(bounds); - objTrans.addChild(rotator); + Transform3D yAxis = new Transform3D(); + Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, + 0, 0, + 4000, 0, 0, + 0, 0, 0); + + RotationInterpolator rotator = + new RotationInterpolator(rotationAlpha, objTrans, yAxis, + 0.0f, (float) Math.PI*2.0f); + rotator.setSchedulingBounds(bounds); + objTrans.addChild(rotator); } // Set up the background @@ -160,49 +167,32 @@ public class ObjLoadGLSL extends Applet { return objRoot; } - - private void usage() - { - System.out.println( - "Usage: java ObjLoadGLSL [-s] [-S shaderName] [-n] [-t] [-c degrees] <.obj file>"); - System.out.println(" -s Spin (no user interaction)"); - System.out.println(" -S Set shader name (default is 'simple')"); - System.out.println(" -n No triangulation"); - System.out.println(" -t No stripification"); - System.out.println( - " -c Set crease angle for normal generation (default is 60 without"); - System.out.println( - " smoothing group info, otherwise 180 within smoothing groups)"); - System.exit(0); - } // End of usage - - - - public void init() { - if (filename == null) { - // Applet - try { - URL path = getCodeBase(); - filename = new URL(path.toString() + "./galleon.obj"); - } - catch (MalformedURLException e) { - throw new RuntimeException(e); - } - } - - setLayout(new BorderLayout()); - GraphicsConfiguration config = + + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); - Canvas3D c = new Canvas3D(config); - add("Center", c); + // Create a Canvas3D using the preferred configuration + Canvas3D canvas3d = new Canvas3D(config); + + // Create simple universe with view branch + univ = new SimpleUniverse(canvas3d); + BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); + + // Add a ShaderErrorListener + univ.addShaderErrorListener(new ShaderErrorListener() { + public void errorOccurred(ShaderError error) { + error.printVerbose(); + JOptionPane.showMessageDialog(ObjLoadGLSL.this, + error.toString(), + "ShaderError", + JOptionPane.ERROR_MESSAGE); + } + }); - // Create a simple scene and attach it to the virtual universe - BranchGroup scene = createSceneGraph(); - u = new SimpleUniverse(c); - // add mouse behaviors to the ViewingPlatform - ViewingPlatform viewingPlatform = u.getViewingPlatform(); + ViewingPlatform viewingPlatform = univ.getViewingPlatform(); PlatformGeometry pg = new PlatformGeometry(); @@ -213,10 +203,10 @@ public class ObjLoadGLSL extends Applet { pg.addChild(ambientLightNode); // Set up the directional lights - Color3f light1Color = new Color3f(1.0f, 0.2f, 0.4f); - Vector3f light1Direction = new Vector3f(-1.0f, -1.0f, -1.0f); - Color3f light2Color = new Color3f(1.0f, 1.0f, 0.9f); - Vector3f light2Direction = new Vector3f(1.0f, 1.0f, 1.0f); + Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f); + Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f); + Color3f light2Color = new Color3f(1.0f, 1.0f, 1.0f); + Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -1.0f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); @@ -235,23 +225,32 @@ public class ObjLoadGLSL extends Applet { viewingPlatform.setNominalViewingTransform(); if (!spin) { - OrbitBehavior orbit = new OrbitBehavior(c, + OrbitBehavior orbit = new OrbitBehavior(canvas3d, OrbitBehavior.REVERSE_ALL); - BoundingSphere bounds = - new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); orbit.setSchedulingBounds(bounds); viewingPlatform.setViewPlatformBehavior(orbit); - } - - /* - // Limit the frame rate to 100 Hz - u.getViewer().getView().setMinimumFrameCycleTime(10); - */ + } + + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); - u.addBranchGraph(scene); + return canvas3d; } - // Set shader program for all nodes in specified branch graph + private void usage() { + System.out.println("Usage: java ObjLoadGLSL [-s] [-S shaderName] [-n] [-t] [-c degrees] <.obj file>"); + System.out.println(" -s Spin (no user interaction)"); + System.out.println(" -S Set shader name (default is 'simple')"); + System.out.println(" -n No triangulation"); + System.out.println(" -t No stripification"); + System.out.println( + " -c Set crease angle for normal generation (default is 60 without"); + System.out.println( + " smoothing group info, otherwise 180 within smoothing groups)"); + System.exit(0); + } // End of usage + + // Set shader program for all nodes in specified branch graph private void setShaderProgram(BranchGroup g, ShaderProgram shaderProgram) { ShaderAppearance myApp = new ShaderAppearance(); Material mat = new Material(); @@ -277,66 +276,103 @@ public class ObjLoadGLSL extends Applet { } } - // Caled if running as a program - public ObjLoadGLSL(String[] args) { - if (args.length != 0) { - for (int i = 0 ; i < args.length ; i++) { - if (args[i].startsWith("-")) { - if (args[i].equals("-s")) { - spin = true; - } else if (args[i].equals("-n")) { - noTriangulate = true; - } else if (args[i].equals("-t")) { - noStripify = true; - } else if (args[i].equals("-c")) { - if (i < args.length - 1) { - creaseAngle = (new Double(args[++i])).doubleValue(); - } else usage(); - } else if (args[i].equals("-S")) { - if (i < args.length - 1) { - shaderName = args[++i]; - } else usage(); - } else { - usage(); - } - } else { - try { - if ((args[i].indexOf("file:") == 0) || - (args[i].indexOf("http") == 0)) { - filename = new URL(args[i]); - } - else if (args[i].charAt(0) != '/') { - filename = new URL("file:./" + args[i]); - } - else { - filename = new URL("file:" + args[i]); - } - } - catch (MalformedURLException e) { - throw new RuntimeException(e); - } - } - } - } - } - - - - // Running as an applet - public ObjLoadGLSL() { - } - - public void destroy() { - u.cleanup(); + /** + * Creates new form ObjLoadGLSL + */ + public ObjLoadGLSL(String args[]) { + if (args.length != 0) { + for (int i = 0 ; i < args.length ; i++) { + if (args[i].startsWith("-")) { + if (args[i].equals("-s")) { + spin = true; + } else if (args[i].equals("-n")) { + noTriangulate = true; + } else if (args[i].equals("-t")) { + noStripify = true; + } else if (args[i].equals("-c")) { + if (i < args.length - 1) { + creaseAngle = (new Double(args[++i])).doubleValue(); + } else usage(); + } else if (args[i].equals("-S")) { + if (i < args.length - 1) { + shaderName = args[++i]; + } else usage(); + } else { + usage(); + } + } else { + try { + if ((args[i].indexOf("file:") == 0) || + (args[i].indexOf("http") == 0)) { + filename = new URL(args[i]); + } else if (args[i].charAt(0) != '/') { + filename = new URL("file:./" + args[i]); + } else { + filename = new URL("file:" + args[i]); + } + } catch (MalformedURLException e) { + System.err.println(e); + System.exit(1); + } + } + } + } + + if (filename == null) { + filename = Resources.getResource("resources/geometry/galleon.obj"); + if (filename == null) { + System.err.println("resources/geometry/galleon.obj not found"); + System.exit(1); + } + } + + // Initialize the GUI components + initComponents(); + + // Create Canvas3D and SimpleUniverse; add canvas to drawing panel + Canvas3D c = createUniverse(); + drawingPanel.add(c, java.awt.BorderLayout.CENTER); + + // Create the content branch and add it to the universe + scene = createSceneGraph(); + univ.addBranchGraph(scene); } - - - // - // The following allows ObjLoadGLSL to be run as an application - // as well as an applet - // - public static void main(String[] args) { - new MainFrame(new ObjLoadGLSL(args), 700, 700); + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("ObjLoadGLSL"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// </editor-fold>//GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(final String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + ObjLoadGLSL objLoadGLSL = new ObjLoadGLSL(args); + objLoadGLSL.setVisible(true); + } + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/glsl_shader/PhongShadingGLSL.java b/src/classes/org/jdesktop/j3d/examples/glsl_shader/PhongShadingGLSL.java index 4f93a77..91cf585 100644 --- a/src/classes/org/jdesktop/j3d/examples/glsl_shader/PhongShadingGLSL.java +++ b/src/classes/org/jdesktop/j3d/examples/glsl_shader/PhongShadingGLSL.java @@ -48,9 +48,11 @@ import com.sun.j3d.utils.geometry.Sphere; import com.sun.j3d.utils.shader.StringIO; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; +import javax.swing.JOptionPane; import javax.vecmath.*; import java.awt.GraphicsConfiguration; import java.io.IOException; +import org.jdesktop.j3d.examples.Resources; /** * @@ -66,7 +68,7 @@ public class PhongShadingGLSL extends javax.swing.JFrame { // Flag indicates type of lights: directional, point, or spot lights. private static int lightType = DIRECTIONAL_LIGHT; - private SimpleUniverse u = null; + private SimpleUniverse univ = null; private ShaderAppearance sApp = null; private ShaderProgram gouraudSP = null; @@ -126,8 +128,8 @@ public class PhongShadingGLSL extends javax.swing.JFrame { String[] attrNames = { "numLights" }; try { - vertexProgram = StringIO.readFully("./gouraud.vert"); - fragmentProgram = StringIO.readFully("./gouraud.frag"); + vertexProgram = StringIO.readFully(Resources.getResource("glsl_shader/gouraud.vert")); + fragmentProgram = StringIO.readFully(Resources.getResource("glsl_shader/gouraud.frag")); } catch (IOException e) { throw new RuntimeException(e); @@ -142,8 +144,8 @@ public class PhongShadingGLSL extends javax.swing.JFrame { gouraudSP.setShaders(shaders); try { - vertexProgram = StringIO.readFully("./phong.vert"); - fragmentProgram = StringIO.readFully("./phong.frag"); + vertexProgram = StringIO.readFully(Resources.getResource("glsl_shader/phong.vert")); + fragmentProgram = StringIO.readFully(Resources.getResource("glsl_shader/phong.frag")); } catch (IOException e) { throw new RuntimeException(e); @@ -298,14 +300,25 @@ public class PhongShadingGLSL extends javax.swing.JFrame { Canvas3D c = new Canvas3D(config); - u = new SimpleUniverse(c); + univ = new SimpleUniverse(c); + + // Add a ShaderErrorListener + univ.addShaderErrorListener(new ShaderErrorListener() { + public void errorOccurred(ShaderError error) { + error.printVerbose(); + JOptionPane.showMessageDialog(PhongShadingGLSL.this, + error.toString(), + "ShaderError", + JOptionPane.ERROR_MESSAGE); + } + }); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. - u.getViewingPlatform().setNominalViewingTransform(); + univ.getViewingPlatform().setNominalViewingTransform(); BranchGroup scene = createSceneGraph(); - u.addBranchGraph(scene); + univ.addBranchGraph(scene); return c; } @@ -322,6 +335,7 @@ public class PhongShadingGLSL extends javax.swing.JFrame { drawingPanel.add(c, java.awt.BorderLayout.CENTER); } + // ---------------------------------------------------------------- /** This method is called from within the constructor to diff --git a/src/classes/org/jdesktop/j3d/examples/glsl_shader/ShaderTestGLSL.java b/src/classes/org/jdesktop/j3d/examples/glsl_shader/ShaderTestGLSL.java index ba4e0f6..1d77a8e 100644 --- a/src/classes/org/jdesktop/j3d/examples/glsl_shader/ShaderTestGLSL.java +++ b/src/classes/org/jdesktop/j3d/examples/glsl_shader/ShaderTestGLSL.java @@ -51,6 +51,8 @@ import javax.media.j3d.*; import javax.vecmath.*; import java.awt.GraphicsConfiguration; import java.io.IOException; +import javax.swing.JOptionPane; +import org.jdesktop.j3d.examples.Resources; public class ShaderTestGLSL extends javax.swing.JFrame { @@ -70,7 +72,7 @@ public class ShaderTestGLSL extends javax.swing.JFrame { "BrickColor", "LightPosition" }; - private SimpleUniverse u = null; + private SimpleUniverse univ = null; private View view; private BranchGroup transpObj; private BranchGroup scene = null; @@ -114,20 +116,20 @@ public class ShaderTestGLSL extends javax.swing.JFrame { try { switch (index) { case DIMPLE_SHADER: - vertexProgram = StringIO.readFully("./dimple.vert"); - fragmentProgram = StringIO.readFully("./dimple.frag"); + vertexProgram = StringIO.readFully(Resources.getResource("glsl_shader/dimple.vert")); + fragmentProgram = StringIO.readFully(Resources.getResource("glsl_shader/dimple.frag")); break; case BRICK_SHADER: - vertexProgram = StringIO.readFully("./aabrick.vert"); - fragmentProgram = StringIO.readFully("./aabrick.frag"); + vertexProgram = StringIO.readFully(Resources.getResource("glsl_shader/aabrick.vert")); + fragmentProgram = StringIO.readFully(Resources.getResource("glsl_shader/aabrick.frag")); break; case WOOD_SHADER: - vertexProgram = StringIO.readFully("./wood.vert"); - fragmentProgram = StringIO.readFully("./wood.frag"); + vertexProgram = StringIO.readFully(Resources.getResource("glsl_shader/wood.vert")); + fragmentProgram = StringIO.readFully(Resources.getResource("glsl_shader/wood.frag")); break; case POLKADOT3D_SHADER: - vertexProgram = StringIO.readFully("./polkadot3d.vert"); - fragmentProgram = StringIO.readFully("./polkadot3d.frag"); + vertexProgram = StringIO.readFully(Resources.getResource("glsl_shader/polkadot3d.vert")); + fragmentProgram = StringIO.readFully(Resources.getResource("glsl_shader/polkadot3d.frag")); break; default: } @@ -280,7 +282,7 @@ public class ShaderTestGLSL extends javax.swing.JFrame { // Create a position interpolator and attach it to the view // platform TransformGroup vpTrans = - u.getViewingPlatform().getViewPlatformTransform(); + univ.getViewingPlatform().getViewPlatformTransform(); Transform3D axisOfTranslation = new Transform3D(); Alpha transAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | @@ -309,14 +311,25 @@ public class ShaderTestGLSL extends javax.swing.JFrame { Canvas3D c = new Canvas3D(config); - u = new SimpleUniverse(c); - - ViewingPlatform viewingPlatform = u.getViewingPlatform(); + univ = new SimpleUniverse(c); + + // Add a ShaderErrorListener + univ.addShaderErrorListener(new ShaderErrorListener() { + public void errorOccurred(ShaderError error) { + error.printVerbose(); + JOptionPane.showMessageDialog(ShaderTestGLSL.this, + error.toString(), + "ShaderError", + JOptionPane.ERROR_MESSAGE); + } + }); + + ViewingPlatform viewingPlatform = univ.getViewingPlatform(); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. viewingPlatform.setNominalViewingTransform(); - view = u.getViewer().getView(); + view = univ.getViewer().getView(); return c; } @@ -605,7 +618,7 @@ public class ShaderTestGLSL extends javax.swing.JFrame { private void AttachButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AttachButtonActionPerformed if (scene == null) { scene = createSceneGraph(1); - u.addBranchGraph(scene); + univ.addBranchGraph(scene); replaceSPButton.setEnabled(true); shaderSelected = BRICK_SHADER; } diff --git a/src/classes/org/jdesktop/j3d/examples/glsl_shader/SphereGLSL.java b/src/classes/org/jdesktop/j3d/examples/glsl_shader/SphereGLSL.java index 0865f93..66bf311 100644 --- a/src/classes/org/jdesktop/j3d/examples/glsl_shader/SphereGLSL.java +++ b/src/classes/org/jdesktop/j3d/examples/glsl_shader/SphereGLSL.java @@ -44,23 +44,20 @@ package org.jdesktop.j3d.examples.glsl_shader; -import java.applet.Applet; -import java.awt.*; -import java.io.*; -import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.geometry.Sphere; import com.sun.j3d.utils.shader.StringIO; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; -import java.util.Enumeration; -import java.net.URL; -import java.net.MalformedURLException; +import java.awt.GraphicsConfiguration; +import java.io.*; +import javax.swing.JOptionPane; +import org.jdesktop.j3d.examples.Resources; /** - * Simple GLSL Shader test program + * Simple Java 3D example program with programmable shader. */ -public class SphereGLSL extends Applet { +public class SphereGLSL extends javax.swing.JFrame { // Constants for type of light to use private static final int DIRECTIONAL_LIGHT = 0; @@ -70,10 +67,10 @@ public class SphereGLSL extends Applet { // Flag indicates type of lights: directional, point, or spot // lights. This flag is set based on command line argument private static int lightType = DIRECTIONAL_LIGHT; + private SimpleUniverse univ = null; + private BranchGroup scene = null; - private SimpleUniverse u = null; - - public BranchGroup createSceneGraph(SimpleUniverse u) { + public BranchGroup createSceneGraph() { Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f); Color3f sColor = new Color3f(1.0f, 1.0f, 1.0f); Color3f objColor = new Color3f(0.6f, 0.6f, 0.6f); @@ -112,8 +109,8 @@ public class SphereGLSL extends Applet { String vertexProgram = null; String fragmentProgram = null; try { - vertexProgram = StringIO.readFully("./simple.vert"); - fragmentProgram = StringIO.readFully("./simple.frag"); + vertexProgram = StringIO.readFully(Resources.getResource("glsl_shader/simple.vert")); + fragmentProgram = StringIO.readFully(Resources.getResource("glsl_shader/simple.frag")); } catch (IOException e) { throw new RuntimeException(e); @@ -245,7 +242,7 @@ public class SphereGLSL extends Applet { // Create a position interpolator and attach it to the view // platform TransformGroup vpTrans = - u.getViewingPlatform().getViewPlatformTransform(); + univ.getViewingPlatform().getViewPlatformTransform(); Transform3D axisOfTranslation = new Transform3D(); Alpha transAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | @@ -267,75 +264,92 @@ public class SphereGLSL extends Applet { return objRoot; } - - public SphereGLSL() { - } - - public void init() { - setLayout(new BorderLayout()); - GraphicsConfiguration config = - SimpleUniverse.getPreferredConfiguration(); - - Canvas3D c = new Canvas3D(config); - add("Center", c); - - u = new SimpleUniverse(c); - BranchGroup scene = createSceneGraph(u); + + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); + + // Create a Canvas3D using the preferred configuration + Canvas3D canvas3d = new Canvas3D(config); + + // Create simple universe with view branch + univ = new SimpleUniverse(canvas3d); + BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); + + // Add a ShaderErrorListener + univ.addShaderErrorListener(new ShaderErrorListener() { + public void errorOccurred(ShaderError error) { + error.printVerbose(); + JOptionPane.showMessageDialog(SphereGLSL.this, + error.toString(), + "ShaderError", + JOptionPane.ERROR_MESSAGE); + } + }); // This will move the ViewPlatform back a bit so the - // objects in the scene can be viewed. - u.getViewingPlatform().setNominalViewingTransform(); - - /* - // Limit the frame rate to 100 Hz - u.getViewer().getView().setMinimumFrameCycleTime(10); - */ + // objects in the scene can be viewed. + univ.getViewingPlatform().setNominalViewingTransform(); + + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); - u.addBranchGraph(scene); + return canvas3d; } - public void destroy() { - u.cleanup(); - } - // - // The following allows SphereGLSL to be run as an application - // as well as an applet - // - public static void main(String[] args) { - // Parse the Input Arguments - String usage = "Usage: java SphereGLSL [-point | -spot | -dir]"; - for (int i = 0; i < args.length; i++) { - if (args[i].startsWith("-")) { - if (args[i].equals("-point")) { - /* - System.out.println("Using point lights"); - lightType = POINT_LIGHT; - */ - System.out.println("Point lights not yet implemented, option ignored"); - } - else if (args[i].equals("-spot")) { - /* - System.out.println("Using spot lights"); - lightType = SPOT_LIGHT; - */ - System.out.println("Spot lights not yet implemented, option ignored"); - } - else if (args[i].equals("-dir")) { - System.out.println("Using directional lights"); - lightType = DIRECTIONAL_LIGHT; - } - else { - System.out.println(usage); - System.exit(0); - } + /** + * Creates new form SphereGLSL + */ + public SphereGLSL() { + + // Initialize the GUI components + initComponents(); + + // Create Canvas3D and SimpleUniverse; add canvas to drawing panel + Canvas3D c = createUniverse(); + drawingPanel.add(c, java.awt.BorderLayout.CENTER); + + // Create the content branch and add it to the universe + scene = createSceneGraph(); + univ.addBranchGraph(scene); } + + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("SphereGLSL"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// </editor-fold>//GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(final String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + SphereGLSL sphereGLSL = new SphereGLSL(); + sphereGLSL.setVisible(true); } - else { - System.out.println(usage); - System.exit(0); - } - } - - new MainFrame(new SphereGLSL(), 700, 700); + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/lightwave/Viewer.java b/src/classes/org/jdesktop/j3d/examples/lightwave/Viewer.java index 8959d4d..9b99466 100644 --- a/src/classes/org/jdesktop/j3d/examples/lightwave/Viewer.java +++ b/src/classes/org/jdesktop/j3d/examples/lightwave/Viewer.java @@ -160,7 +160,12 @@ public class Viewer extends Applet { public void destroy() { u.cleanup(); } - + + private static void usage() { + System.out.println("Usage: java Viewer <.lws>") ; + System.exit(0) ; + } + /** * The main method of the application takes one argument in the * args array; the filname that you want to load. Note that the @@ -190,15 +195,7 @@ public class Viewer extends Applet { } } else { - // the path to the image for an application - try { - url = new java.net.URL("file:./ballcone.lws"); - } - catch (java.net.MalformedURLException ex) { - System.err.println(ex.getMessage()); - ex.printStackTrace(); - System.exit(1); - } + usage(); } new MainFrame(new Viewer(url), 500, 500); } diff --git a/src/classes/org/jdesktop/j3d/examples/lod/LOD.java b/src/classes/org/jdesktop/j3d/examples/lod/LOD.java index 45381f4..0d50284 100644 --- a/src/classes/org/jdesktop/j3d/examples/lod/LOD.java +++ b/src/classes/org/jdesktop/j3d/examples/lod/LOD.java @@ -44,20 +44,21 @@ package org.jdesktop.j3d.examples.lod; -import java.applet.Applet; -import java.awt.*; -import java.awt.event.*; -import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.behaviors.vp.*; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; +import java.awt.GraphicsConfiguration; -public class LOD extends Applet { +/** + * Simple Java 3D example program to display a spinning cube. + */ +public class LOD extends javax.swing.JFrame { + + private SimpleUniverse univ = null; + private BranchGroup scene = null; - private SimpleUniverse u = null; - public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); @@ -129,24 +130,19 @@ public class LOD extends Applet { graphRoot.addChild(lgt1); } + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); - public LOD() { - } - - public void init() { - setLayout(new BorderLayout()); - GraphicsConfiguration config = - SimpleUniverse.getPreferredConfiguration(); - - Canvas3D c = new Canvas3D(config); - add("Center", c); + // Create a Canvas3D using the preferred configuration + Canvas3D c = new Canvas3D(config); - // Create a simple scene and attach it to the virtual universe - BranchGroup scene = createSceneGraph(); - u = new SimpleUniverse(c); + // Create simple universe with view branch + univ = new SimpleUniverse(c); - // only add zoom mouse behavior to viewingPlatform - ViewingPlatform viewingPlatform = u.getViewingPlatform(); + // only add zoom mouse behavior to viewingPlatform + ViewingPlatform viewingPlatform = univ.getViewingPlatform(); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. @@ -161,21 +157,68 @@ public class LOD extends Applet { BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); orbit.setSchedulingBounds(bounds); - viewingPlatform.setViewPlatformBehavior(orbit); + viewingPlatform.setViewPlatformBehavior(orbit); + + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + univ.getViewingPlatform().setNominalViewingTransform(); + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); - u.addBranchGraph(scene); + return c; } - public void destroy() { - u.cleanup(); + /** + * Creates new form LOD + */ + public LOD() { + // Initialize the GUI components + initComponents(); + + // Create Canvas3D and SimpleUniverse; add canvas to drawing panel + Canvas3D c = createUniverse(); + drawingPanel.add(c, java.awt.BorderLayout.CENTER); + + // Create the content branch and add it to the universe + scene = createSceneGraph(); + univ.addBranchGraph(scene); } - // - // The following allows LOD to be run as an application - // as well as an applet - // - public static void main(String[] args) { - new MainFrame(new LOD(), 512, 512); + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("LOD"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// </editor-fold>//GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new LOD().setVisible(true); + } + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/morphing/Morphing.java b/src/classes/org/jdesktop/j3d/examples/morphing/Morphing.java index cbca643..612c5df 100644 --- a/src/classes/org/jdesktop/j3d/examples/morphing/Morphing.java +++ b/src/classes/org/jdesktop/j3d/examples/morphing/Morphing.java @@ -44,25 +44,23 @@ package org.jdesktop.j3d.examples.morphing; -import java.applet.Applet; -import java.awt.*; -import java.awt.event.*; -import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; +import java.awt.GraphicsConfiguration; import java.io.*; import com.sun.j3d.loaders.objectfile.ObjectFile; import com.sun.j3d.loaders.Scene; import com.sun.j3d.loaders.ParsingErrorException; import com.sun.j3d.loaders.IncorrectFormatException; +import org.jdesktop.j3d.examples.Resources; -public class Morphing extends Applet { +public class Morphing extends javax.swing.JFrame { + private SimpleUniverse univ = null; + private BranchGroup scene = null; private java.net.URL[] objFiles = null; - private SimpleUniverse u = null; - private BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); @@ -201,62 +199,89 @@ public class Morphing extends Applet { return objRoot; } - public Morphing() {} - public Morphing(java.net.URL[] urls) { - objFiles = urls; - } + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); - public void init() { - if (objFiles == null) { - objFiles = new java.net.URL[3]; - // the path to the image for an applet - String path = getCodeBase().toString(); - try { - objFiles[0] = new java.net.URL(path + "hand1.obj"); - objFiles[1] = new java.net.URL(path + "hand2.obj"); - objFiles[2] = new java.net.URL(path + "hand3.obj"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - } + // Create a Canvas3D using the preferred configuration + Canvas3D c = new Canvas3D(config); - setLayout(new BorderLayout()); - GraphicsConfiguration config = - SimpleUniverse.getPreferredConfiguration(); - - Canvas3D c = new Canvas3D(config); - add("Center", c); - - // Create a simple scene and attach it to the virtual universe - BranchGroup scene = createSceneGraph(); - u = new SimpleUniverse(c); + // Create simple universe with view branch + univ = new SimpleUniverse(c); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. - u.getViewingPlatform().setNominalViewingTransform(); + univ.getViewingPlatform().setNominalViewingTransform(); + + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); - u.addBranchGraph(scene); + return c; } - public void destroy() { - u.cleanup(); + /** + * Creates new form LOD + */ + public Morphing(String args[]) { + + objFiles = new java.net.URL[3]; + for(int i=0; i<3; i++) { + objFiles[i] = Resources.getResource("resources/geometry/hand" + (i+1) + ".obj"); + if (objFiles[i] == null) { + System.err.println("resources/geometry/hand" + (i+1) + ".obj not found"); + System.exit(1); + } + } + + // Initialize the GUI components + initComponents(); + + // Create Canvas3D and SimpleUniverse; add canvas to drawing panel + Canvas3D c = createUniverse(); + drawingPanel.add(c, java.awt.BorderLayout.CENTER); + + // Create the content branch and add it to the universe + scene = createSceneGraph(); + univ.addBranchGraph(scene); } - public static void main(String[] args) { - java.net.URL[] urls = new java.net.URL[3]; - // the path to the image file for an application - try { - urls[0] = new java.net.URL("file:./hand1.obj"); - urls[1] = new java.net.URL("file:./hand2.obj"); - urls[2] = new java.net.URL("file:./hand3.obj"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - new MainFrame(new Morphing(urls), 700, 700); + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("Morphing"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// </editor-fold>//GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(final String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + Morphing morphing = new Morphing(args); + morphing.setVisible(true); + } + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/morphing/Pyramid2Cube.java b/src/classes/org/jdesktop/j3d/examples/morphing/Pyramid2Cube.java index e4d86ee..d8a6612 100644 --- a/src/classes/org/jdesktop/j3d/examples/morphing/Pyramid2Cube.java +++ b/src/classes/org/jdesktop/j3d/examples/morphing/Pyramid2Cube.java @@ -44,17 +44,15 @@ package org.jdesktop.j3d.examples.morphing; -import java.applet.Applet; -import java.awt.*; -import java.awt.event.*; -import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; +import java.awt.GraphicsConfiguration; -public class Pyramid2Cube extends Applet { +public class Pyramid2Cube extends javax.swing.JFrame { - private SimpleUniverse u = null; + private SimpleUniverse univ = null; + private BranchGroup scene = null; private BranchGroup createSceneGraph() { // Create the root of the branch graph @@ -161,34 +159,78 @@ public class Pyramid2Cube extends Applet { return objRoot; } + + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); - public Pyramid2Cube() { - } - - public void init() { - setLayout(new BorderLayout()); - GraphicsConfiguration config = - SimpleUniverse.getPreferredConfiguration(); - - Canvas3D c = new Canvas3D(config); - add("Center", c); + // Create a Canvas3D using the preferred configuration + Canvas3D c = new Canvas3D(config); - // Create a simple scene and attach it to the virtual universe - BranchGroup scene = createSceneGraph(); - u = new SimpleUniverse(c); + // Create simple universe with view branch + univ = new SimpleUniverse(c); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. - u.getViewingPlatform().setNominalViewingTransform(); + univ.getViewingPlatform().setNominalViewingTransform(); - u.addBranchGraph(scene); + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); + + return c; } - public void destroy() { - u.cleanup(); + /** + * Creates new form Pyramid2Cube + */ + public Pyramid2Cube() { + // Initialize the GUI components + initComponents(); + + // Create Canvas3D and SimpleUniverse; add canvas to drawing panel + Canvas3D c = createUniverse(); + drawingPanel.add(c, java.awt.BorderLayout.CENTER); + + // Create the content branch and add it to the universe + scene = createSceneGraph(); + univ.addBranchGraph(scene); } - public static void main(String[] args) { - new MainFrame(new Pyramid2Cube(), 700, 700); + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("Pyramid2Cube"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// </editor-fold>//GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new Pyramid2Cube().setVisible(true); + } + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/objload/ObjLoad.java b/src/classes/org/jdesktop/j3d/examples/objload/ObjLoad.java index dd57983..059747e 100644 --- a/src/classes/org/jdesktop/j3d/examples/objload/ObjLoad.java +++ b/src/classes/org/jdesktop/j3d/examples/objload/ObjLoad.java @@ -48,27 +48,30 @@ import com.sun.j3d.loaders.objectfile.ObjectFile; import com.sun.j3d.loaders.ParsingErrorException; import com.sun.j3d.loaders.IncorrectFormatException; import com.sun.j3d.loaders.Scene; -import java.applet.Applet; -import java.awt.*; -import java.awt.event.*; -import com.sun.j3d.utils.applet.MainFrame; + import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; -import java.io.*; -import com.sun.j3d.utils.behaviors.vp.*; -import java.net.URL; +import java.awt.GraphicsConfiguration; import java.net.MalformedURLException; +import java.net.URL; +import com.sun.j3d.utils.behaviors.vp.*; +import java.io.FileNotFoundException; +import org.jdesktop.j3d.examples.Resources; -public class ObjLoad extends Applet { +/** + * Simple Java 3D example program to display an .obj object. + */ +public class ObjLoad extends javax.swing.JFrame { private boolean spin = false; private boolean noTriangulate = false; private boolean noStripify = false; private double creaseAngle = 60.0; private URL filename = null; - private SimpleUniverse u; - private BoundingSphere bounds; + + private SimpleUniverse univ = null; + private BranchGroup scene = null; public BranchGroup createSceneGraph() { // Create the root of the branch graph @@ -115,7 +118,7 @@ public class ObjLoad extends Applet { objTrans.addChild(s.getSceneGroup()); - bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); + BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); if (spin) { Transform3D yAxis = new Transform3D(); @@ -139,49 +142,21 @@ public class ObjLoad extends Applet { return objRoot; } + + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); - private void usage() - { - System.out.println( - "Usage: java ObjLoad [-s] [-n] [-t] [-c degrees] <.obj file>"); - System.out.println(" -s Spin (no user interaction)"); - System.out.println(" -n No triangulation"); - System.out.println(" -t No stripification"); - System.out.println( - " -c Set crease angle for normal generation (default is 60 without"); - System.out.println( - " smoothing group info, otherwise 180 within smoothing groups)"); - System.exit(0); - } // End of usage - - - - public void init() { - if (filename == null) { - // Applet - try { - URL path = getCodeBase(); - filename = new URL(path.toString() + "./galleon.obj"); - } - catch (MalformedURLException e) { - System.err.println(e); - System.exit(1); - } - } - - setLayout(new BorderLayout()); - GraphicsConfiguration config = - SimpleUniverse.getPreferredConfiguration(); + // Create a Canvas3D using the preferred configuration + Canvas3D canvas3d = new Canvas3D(config); - Canvas3D c = new Canvas3D(config); - add("Center", c); + // Create simple universe with view branch + univ = new SimpleUniverse(canvas3d); + BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); - // Create a simple scene and attach it to the virtual universe - BranchGroup scene = createSceneGraph(); - u = new SimpleUniverse(c); - // add mouse behaviors to the ViewingPlatform - ViewingPlatform viewingPlatform = u.getViewingPlatform(); + ViewingPlatform viewingPlatform = univ.getViewingPlatform(); PlatformGeometry pg = new PlatformGeometry(); @@ -214,74 +189,124 @@ public class ObjLoad extends Applet { viewingPlatform.setNominalViewingTransform(); if (!spin) { - OrbitBehavior orbit = new OrbitBehavior(c, + OrbitBehavior orbit = new OrbitBehavior(canvas3d, OrbitBehavior.REVERSE_ALL); - BoundingSphere bounds = - new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); orbit.setSchedulingBounds(bounds); viewingPlatform.setViewPlatformBehavior(orbit); - } + } + + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); - u.addBranchGraph(scene); + return canvas3d; } - // Caled if running as a program - public ObjLoad(String[] args) { - if (args.length != 0) { - for (int i = 0 ; i < args.length ; i++) { - if (args[i].startsWith("-")) { - if (args[i].equals("-s")) { - spin = true; - } else if (args[i].equals("-n")) { - noTriangulate = true; - } else if (args[i].equals("-t")) { - noStripify = true; - } else if (args[i].equals("-c")) { - if (i < args.length - 1) { - creaseAngle = (new Double(args[++i])).doubleValue(); - } else usage(); - } else { - usage(); - } - } else { - try { - if ((args[i].indexOf("file:") == 0) || - (args[i].indexOf("http") == 0)) { - filename = new URL(args[i]); - } - else if (args[i].charAt(0) != '/') { - filename = new URL("file:./" + args[i]); - } - else { - filename = new URL("file:" + args[i]); - } - } - catch (MalformedURLException e) { - System.err.println(e); - System.exit(1); - } - } - } - } - } - - - - // Running as an applet - public ObjLoad() { - } + private void usage() { + System.out.println( + "Usage: java ObjLoad [-s] [-n] [-t] [-c degrees] <.obj file>"); + System.out.println(" -s Spin (no user interaction)"); + System.out.println(" -n No triangulation"); + System.out.println(" -t No stripification"); + System.out.println( + " -c Set crease angle for normal generation (default is 60 without"); + System.out.println( + " smoothing group info, otherwise 180 within smoothing groups)"); + System.exit(0); + } // End of usage - public void destroy() { - u.cleanup(); + /** + * Creates new form ObjLoad + */ + public ObjLoad(String args[]) { + if (args.length != 0) { + for (int i = 0 ; i < args.length ; i++) { + if (args[i].startsWith("-")) { + if (args[i].equals("-s")) { + spin = true; + } else if (args[i].equals("-n")) { + noTriangulate = true; + } else if (args[i].equals("-t")) { + noStripify = true; + } else if (args[i].equals("-c")) { + if (i < args.length - 1) { + creaseAngle = (new Double(args[++i])).doubleValue(); + } else usage(); + } else { + usage(); + } + } else { + try { + if ((args[i].indexOf("file:") == 0) || + (args[i].indexOf("http") == 0)) { + filename = new URL(args[i]); + } else if (args[i].charAt(0) != '/') { + filename = new URL("file:./" + args[i]); + } else { + filename = new URL("file:" + args[i]); + } + } catch (MalformedURLException e) { + System.err.println(e); + System.exit(1); + } + } + } + } + + if (filename == null) { + filename = Resources.getResource("resources/geometry/galleon.obj"); + if (filename == null) { + System.err.println("resources/geometry/galleon.obj not found"); + System.exit(1); + } + } + + // Initialize the GUI components + initComponents(); + + // Create Canvas3D and SimpleUniverse; add canvas to drawing panel + Canvas3D c = createUniverse(); + drawingPanel.add(c, java.awt.BorderLayout.CENTER); + + // Create the content branch and add it to the universe + scene = createSceneGraph(); + univ.addBranchGraph(scene); } - - - // - // The following allows ObjLoad to be run as an application - // as well as an applet - // - public static void main(String[] args) { - new MainFrame(new ObjLoad(args), 700, 700); + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("ObjLoad"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// </editor-fold>//GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(final String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + ObjLoad objLoad = new ObjLoad(args); + objLoad.setVisible(true); + } + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/oriented_shape3d/OrientedPtTest.java b/src/classes/org/jdesktop/j3d/examples/oriented_shape3d/OrientedPtTest.java index 60333bb..919cc6e 100644 --- a/src/classes/org/jdesktop/j3d/examples/oriented_shape3d/OrientedPtTest.java +++ b/src/classes/org/jdesktop/j3d/examples/oriented_shape3d/OrientedPtTest.java @@ -46,7 +46,6 @@ package org.jdesktop.j3d.examples.oriented_shape3d; import java.applet.Applet; import java.awt.BorderLayout; -import java.awt.event.*; import com.sun.j3d.utils.image.TextureLoader; import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.geometry.ColorCube; @@ -56,9 +55,9 @@ import com.sun.j3d.utils.geometry.Sphere; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; -import java.io.*; import java.awt.*; import com.sun.j3d.utils.behaviors.vp.*; +import org.jdesktop.j3d.examples.Resources; public class OrientedPtTest extends Applet { @@ -225,26 +224,17 @@ public class OrientedPtTest extends Applet { public void init() { // the paths to the image files for an applet + earthImage = Resources.getResource("resources/images/earth.jpg"); if (earthImage == null) { - try { - earthImage = new java.net.URL(getCodeBase().toString() + - "../images/earth.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - } - if (stoneImage == null) { - try { - stoneImage = new java.net.URL(getCodeBase().toString() + - "../images/stone.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - } + System.err.println("resources/images/earth.jpg not found"); + System.exit(1); + } + + stoneImage = Resources.getResource("resources/images/stone.jpg"); + if (stoneImage == null) { + System.err.println("resources/images/stone.jpg not found"); + System.exit(1); + } setLayout(new BorderLayout()); Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); @@ -282,15 +272,17 @@ public class OrientedPtTest extends Applet { public static void main(String[] args) { java.net.URL earthURL = null; java.net.URL stoneURL = null; - try { - // the paths to the image files for an application - earthURL = new java.net.URL("file:../images/earth.jpg"); - stoneURL = new java.net.URL("file:../images/stone.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } + earthURL = Resources.getResource("resources/images/earth.jpg"); + if (earthURL == null) { + System.err.println("resources/images/earth.jpg not found"); + System.exit(1); + } + + stoneURL = Resources.getResource("resources/images/stone.jpg"); + if (stoneURL == null) { + System.err.println("resources/images/stone.jpg not found"); + System.exit(1); + } new MainFrame(new OrientedPtTest(earthURL, stoneURL), 400, 400); } diff --git a/src/classes/org/jdesktop/j3d/examples/oriented_shape3d/OrientedTest.java b/src/classes/org/jdesktop/j3d/examples/oriented_shape3d/OrientedTest.java index 191c375..f01baf8 100644 --- a/src/classes/org/jdesktop/j3d/examples/oriented_shape3d/OrientedTest.java +++ b/src/classes/org/jdesktop/j3d/examples/oriented_shape3d/OrientedTest.java @@ -46,7 +46,6 @@ package org.jdesktop.j3d.examples.oriented_shape3d; import java.applet.Applet; import java.awt.*; -import java.awt.event.*; import com.sun.j3d.utils.image.TextureLoader; import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.geometry.*; @@ -54,6 +53,7 @@ import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; import com.sun.j3d.utils.behaviors.mouse.*; +import org.jdesktop.j3d.examples.Resources; public class OrientedTest extends Applet { @@ -208,26 +208,18 @@ public class OrientedTest extends Applet { public void init() { // the paths to the image files for an applet + earthImage = Resources.getResource("resources/images/earth.jpg"); if (earthImage == null) { - try { - earthImage = new java.net.URL(getCodeBase().toString() + - "../images/earth.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - } - if (stoneImage == null) { - try { - stoneImage = new java.net.URL(getCodeBase().toString() + - "../images/stone.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - } + System.err.println("resources/images/earth.jpg not found"); + System.exit(1); + } + + stoneImage = Resources.getResource("resources/images/stone.jpg"); + if (stoneImage == null) { + System.err.println("resources/images/stone.jpg not found"); + System.exit(1); + } + setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); @@ -290,15 +282,18 @@ public class OrientedTest extends Applet { public static void main(String[] args) { java.net.URL earthURL = null; java.net.URL stoneURL = null; - try { - // the paths to the image files for an application - earthURL = new java.net.URL("file:../images/earth.jpg"); - stoneURL = new java.net.URL("file:../images/stone.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } + + earthURL = Resources.getResource("resources/images/earth.jpg"); + if (earthURL == null) { + System.err.println("resources/images/earth.jpg not found"); + System.exit(1); + } + + stoneURL = Resources.getResource("resources/images/stone.jpg"); + if (stoneURL == null) { + System.err.println("resources/images/stone.jpg not found"); + System.exit(1); + } new MainFrame(new OrientedTest(earthURL, stoneURL), 400, 400); } diff --git a/src/classes/org/jdesktop/j3d/examples/package_info/PackageInfo.java b/src/classes/org/jdesktop/j3d/examples/package_info/PackageInfo.java index 2cc6cad..90c6efa 100644 --- a/src/classes/org/jdesktop/j3d/examples/package_info/PackageInfo.java +++ b/src/classes/org/jdesktop/j3d/examples/package_info/PackageInfo.java @@ -44,52 +44,96 @@ package org.jdesktop.j3d.examples.package_info; -public class PackageInfo { - public PackageInfo() { - ClassLoader classLoader = getClass().getClassLoader(); +import javax.swing.JTextArea; - pkgInfo(classLoader, "javax.vecmath", "Point3d"); - pkgInfo(classLoader, "javax.media.j3d", "SceneGraphObject"); - pkgInfo(classLoader, "com.sun.j3d.utils.universe", "SimpleUniverse"); - //pkgInfo(classLoader, "com.sun.j3d.loaders.vrml97", "VrmlLoader"); - } +public class PackageInfo extends javax.swing.JFrame { + + private void pkgInfo(JTextArea textArea, + ClassLoader classLoader, + String pkgName, + String className) { + + try { + classLoader.loadClass(pkgName + "." + className); + + Package p = Package.getPackage(pkgName); + if (p == null) { + textArea.append("WARNING: Package.getPackage(" + + pkgName + + ") is null\n"); + } else { + textArea.append(p.toString() + "\n"); + textArea.append("Specification Title = " + + p.getSpecificationTitle() + "\n"); + textArea.append("Specification Vendor = " + + p.getSpecificationVendor() + "\n"); + textArea.append("Specification Version = " + + p.getSpecificationVersion() + "\n"); - static void pkgInfo(ClassLoader classLoader, - String pkgName, - String className) { + textArea.append("Implementation Vendor = " + + p.getImplementationVendor() + "\n"); + textArea.append("Implementation Version = " + + p.getImplementationVersion() + "\n"); + } + } catch (ClassNotFoundException e) { + textArea.append("Unable to load " + pkgName + "\n"); + } - try { - classLoader.loadClass(pkgName + "." + className); + textArea.append("\n"); + } - Package p = Package.getPackage(pkgName); - if (p == null) { - System.out.println("WARNING: Package.getPackage(" + - pkgName + - ") is null"); - } - else { - System.out.println(p); - System.out.println("Specification Title = " + - p.getSpecificationTitle()); - System.out.println("Specification Vendor = " + - p.getSpecificationVendor()); - System.out.println("Specification Version = " + - p.getSpecificationVersion()); + /** + * Creates new form PackageInfo + */ + public PackageInfo() { + initComponents(); - System.out.println("Implementation Vendor = " + - p.getImplementationVendor()); - System.out.println("Implementation Version = " + - p.getImplementationVersion()); - } - } - catch (ClassNotFoundException e) { - System.out.println("Unable to load " + pkgName); - } + ClassLoader classLoader = getClass().getClassLoader(); - System.out.println(); + pkgInfo(myTextArea, classLoader, "javax.vecmath", "Point3d"); + pkgInfo(myTextArea, classLoader, "javax.media.j3d", "SceneGraphObject"); + pkgInfo(myTextArea, classLoader, "com.sun.j3d.utils.universe", "SimpleUniverse"); } - public static void main(String[] args) { - new PackageInfo(); + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents + private void initComponents() { + jScrollPane1 = new javax.swing.JScrollPane(); + myTextArea = new javax.swing.JTextArea(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("Package Info"); + jScrollPane1.setPreferredSize(new java.awt.Dimension(400, 400)); + myTextArea.setColumns(20); + myTextArea.setEditable(false); + myTextArea.setRows(5); + jScrollPane1.setViewportView(myTextArea); + + getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER); + + pack(); + }// </editor-fold>//GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new PackageInfo().setVisible(true); + } + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTextArea myTextArea; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/package_info/QueryProperties.java b/src/classes/org/jdesktop/j3d/examples/package_info/QueryProperties.java index fb34965..4febcd6 100644 --- a/src/classes/org/jdesktop/j3d/examples/package_info/QueryProperties.java +++ b/src/classes/org/jdesktop/j3d/examples/package_info/QueryProperties.java @@ -44,14 +44,22 @@ package org.jdesktop.j3d.examples.package_info; -import java.util.*; -import javax.media.j3d.*; import java.awt.GraphicsEnvironment; import java.awt.GraphicsConfiguration; -import com.sun.j3d.utils.universe.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import javax.media.j3d.Canvas3D; +import javax.media.j3d.GraphicsConfigTemplate3D; +import javax.media.j3d.VirtualUniverse; +import javax.swing.JTextArea; -public class QueryProperties { - public static void printProps(Map map, String[] propList) { +public class QueryProperties extends javax.swing.JFrame { + + public static void printProps(JTextArea textArea, Map map, String[] propList) { // Create an alphabetical list of keys List keyList = new ArrayList(map.keySet()); Collections.sort(keyList); @@ -69,7 +77,7 @@ public class QueryProperties { if (idxWild < 0) { key = propList[i]; if (!hs.contains(key)) { - System.out.println(key + " = " + map.get(key)); + textArea.append(key + " = " + map.get(key) + "\n"); hs.add(key); } } @@ -79,14 +87,14 @@ public class QueryProperties { while (it.hasNext()) { key = (String)it.next(); if (key.startsWith(pattern) && !hs.contains(key)) { - System.out.println(key + " = " + map.get(key)); + textArea.append(key + " = " + map.get(key) + "\n"); hs.add(key); } } } else { - System.out.println(propList[i] + - " = ERROR: KEY WITH EMBEDDED WILD CARD IGNORED"); + textArea.append(propList[i] + + " = ERROR: KEY WITH EMBEDDED WILD CARD IGNORED\n"); } } @@ -95,13 +103,16 @@ public class QueryProperties { while (it.hasNext()) { key = (String)it.next(); if (!hs.contains(key)) { - System.out.println(key + " = " + map.get(key)); + textArea.append(key + " = " + map.get(key) + "\n"); } } } - public static void main(String[] args) { + /** Creates new form QueryProperties */ + public QueryProperties() { + initComponents(); + VirtualUniverse vu = new VirtualUniverse(); Map vuMap = vu.getProperties(); final String[] vuPropList = { @@ -113,8 +124,8 @@ public class QueryProperties { // Just print all other properties in alphabetical order }; - printProps(vuMap, vuPropList); - System.out.println(); + printProps(myTextArea, vuMap, vuPropList); + myTextArea.append("\n"); GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D(); @@ -143,8 +154,48 @@ public class QueryProperties { // Just print all other properties in alphabetical order }; - printProps(c3dMap, c3dPropList); + printProps(myTextArea, c3dMap, c3dPropList); + } + + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents + private void initComponents() { + jScrollPane1 = new javax.swing.JScrollPane(); + myTextArea = new javax.swing.JTextArea(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("QueryProperties"); + jScrollPane1.setPreferredSize(new java.awt.Dimension(400, 500)); + myTextArea.setColumns(20); + myTextArea.setEditable(false); + myTextArea.setRows(5); + jScrollPane1.setViewportView(myTextArea); + + getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER); - System.exit(0); + pack(); + }// </editor-fold>//GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new QueryProperties().setVisible(true); + } + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTextArea myTextArea; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/picking/TickTockPicking.java b/src/classes/org/jdesktop/j3d/examples/picking/TickTockPicking.java index 29eaec0..6828d6a 100644 --- a/src/classes/org/jdesktop/j3d/examples/picking/TickTockPicking.java +++ b/src/classes/org/jdesktop/j3d/examples/picking/TickTockPicking.java @@ -44,22 +44,20 @@ package org.jdesktop.j3d.examples.picking; -import java.applet.Applet; -import java.awt.*; -import java.awt.event.*; -import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; -import com.sun.j3d.utils.image.TextureLoader; import javax.media.j3d.*; import javax.vecmath.*; +import com.sun.j3d.utils.image.TextureLoader; +import java.awt.GraphicsConfiguration; +import org.jdesktop.j3d.examples.Resources; -public class TickTockPicking extends Applet { +public class TickTockPicking extends javax.swing.JFrame { + private SimpleUniverse univ = null; + private BranchGroup scene = null; // path the the texture map image private java.net.URL texImage = null; - private SimpleUniverse u = null; - public BranchGroup createSceneGraph(Canvas3D c) { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); @@ -384,65 +382,85 @@ public class TickTockPicking extends Applet { return objTrans; } + + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); + // Create a Canvas3D using the preferred configuration + Canvas3D c = new Canvas3D(config); - public TickTockPicking() { - } - - public TickTockPicking(java.net.URL url) { - texImage = url; - } - - public void init() { - if (texImage == null) { - // the path to the image for an applet - try { - texImage = new java.net.URL(getCodeBase().toString() + - "../images/apimage.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - } - - setLayout(new BorderLayout()); - GraphicsConfiguration config = - SimpleUniverse.getPreferredConfiguration(); - - Canvas3D c = new Canvas3D(config); - add("Center", c); - - // Create a simple scene and attach it to the virtual universe - BranchGroup scene = createSceneGraph(c); - u = new SimpleUniverse(c); + // Create simple universe with view branch + univ = new SimpleUniverse(c); - // This will move the ViewPlatform back a bit so the - // objects in the scene can be viewed. - u.getViewingPlatform().setNominalViewingTransform(); + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + univ.getViewingPlatform().setNominalViewingTransform(); - u.addBranchGraph(scene); + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); + return c; } - public void destroy() { - u.cleanup(); + /** + * Creates new form HelloUniverse + */ + public TickTockPicking() { + + // the path to the image for an applet + texImage = Resources.getResource("resources/images/stone.jpg"); + if (texImage == null) { + System.err.println("resources/images/stone.jpg not found"); + System.exit(1); + } + // Initialize the GUI components + initComponents(); + + // Create Canvas3D and SimpleUniverse; add canvas to drawing panel + Canvas3D c = createUniverse(); + drawingPanel.add(c, java.awt.BorderLayout.CENTER); + + // Create the content branch and add it to the universe + scene = createSceneGraph(c); + univ.addBranchGraph(scene); } + + // ---------------------------------------------------------------- - // - // The following allows TickTockPicking to be run as an application - // as well as an applet - // - public static void main(String[] args) { - // the path the the texture map for an application - java.net.URL url = null; - try { - url = new java.net.URL("file:../images/apimage.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - new MainFrame(new TickTockPicking(url), 700, 700); + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("TickTockPicking"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// </editor-fold>//GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new TickTockPicking().setVisible(true); + } + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/print_canvas3d/PrintCanvas3D.java b/src/classes/org/jdesktop/j3d/examples/print_canvas3d/PrintCanvas3D.java index c40993a..884af67 100644 --- a/src/classes/org/jdesktop/j3d/examples/print_canvas3d/PrintCanvas3D.java +++ b/src/classes/org/jdesktop/j3d/examples/print_canvas3d/PrintCanvas3D.java @@ -45,6 +45,7 @@ package org.jdesktop.j3d.examples.print_canvas3d; import com.sun.j3d.utils.universe.*; +import java.net.MalformedURLException; import javax.media.j3d.*; import javax.vecmath.*; import java.awt.*; @@ -56,9 +57,10 @@ import com.sun.j3d.loaders.ParsingErrorException; import com.sun.j3d.loaders.IncorrectFormatException; import com.sun.j3d.loaders.Scene; import java.awt.image.BufferedImage; -import java.awt.event.*; import java.io.*; import com.sun.j3d.utils.behaviors.mouse.*; +import java.net.URL; +import org.jdesktop.j3d.examples.Resources; public class PrintCanvas3D extends javax.swing.JFrame { @@ -67,7 +69,7 @@ public class PrintCanvas3D extends javax.swing.JFrame { private static final double creaseAngle = 60.0; private Canvas3D onScreenCanvas3D; private OffScreenCanvas3D offScreenCanvas3D; - private String filename = null; + private URL filename = null; private static final int OFF_SCREEN_SCALE = 3; private SimpleUniverse univ = null; @@ -230,13 +232,23 @@ public class PrintCanvas3D extends javax.swing.JFrame { public PrintCanvas3D(String args[]) { if (args.length == 0) { - usage(); + filename = Resources.getResource("resources/geometry/beethoven.obj"); + if (filename == null) { + System.err.println("resources/geometry/beethoven.obj not found"); + System.exit(1); + } } else { for (int i = 0 ; i < args.length ; i++) { if (args[i].startsWith("-")) { System.err.println("Argument '" + args[i] + "' ignored."); } else { - filename = args[i]; + try{ + filename = new URL(args[i]); + } + catch (MalformedURLException e) { + System.err.println(e.getMessage()); + System.exit(1); + } } } } diff --git a/src/classes/org/jdesktop/j3d/examples/pure_immediate/PureImmediate.java b/src/classes/org/jdesktop/j3d/examples/pure_immediate/PureImmediate.java index 72e5bdd..726637b 100644 --- a/src/classes/org/jdesktop/j3d/examples/pure_immediate/PureImmediate.java +++ b/src/classes/org/jdesktop/j3d/examples/pure_immediate/PureImmediate.java @@ -44,15 +44,10 @@ package org.jdesktop.j3d.examples.pure_immediate; -import java.applet.Applet; -import java.awt.BorderLayout; -import java.awt.GraphicsConfiguration; -import java.awt.event.*; -import com.sun.j3d.utils.applet.MainFrame; -import com.sun.j3d.utils.geometry.ColorCube; import com.sun.j3d.utils.universe.*; +import com.sun.j3d.utils.geometry.ColorCube; import javax.media.j3d.*; -import javax.vecmath.*; +import java.awt.GraphicsConfiguration; /** * Pure immediate mode example program. In pure immediate mode, the @@ -60,7 +55,11 @@ import javax.vecmath.*; * example, this is done immediately after the canvas is created. A * separate thread is started up to do the immediate mode rendering. */ -public class PureImmediate extends Applet implements Runnable { +public class PureImmediate extends javax.swing.JFrame implements Runnable { + + + private SimpleUniverse univ = null; + private BranchGroup scene = null; private Canvas3D canvas; private GraphicsContext3D gc = null; @@ -70,8 +69,6 @@ public class PureImmediate extends Applet implements Runnable { // One rotation (2*PI radians) every 6 seconds private Alpha rotAlpha = new Alpha(-1, 6000); - private SimpleUniverse u = null; - // // Renders a single frame by clearing the canvas, drawing the // geometry, and swapping the draw and display buffer. @@ -97,7 +94,6 @@ public class PureImmediate extends Applet implements Runnable { canvas.swap(); } - // // Run method for our immediate mode rendering thread. // @@ -110,42 +106,74 @@ public class PureImmediate extends Applet implements Runnable { } - public PureImmediate() { - } + private void createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); - // - // init: create the canvas, stop the renderer, - // create the universe, and start the drawing thread. - // - public void init() { - setLayout(new BorderLayout()); - GraphicsConfiguration config = - SimpleUniverse.getPreferredConfiguration(); - - canvas = new Canvas3D(config); + // Create a Canvas3D using the preferred configuration + canvas = new Canvas3D(config); canvas.stopRenderer(); - add("Center", canvas); + // Create simple universe with view branch + univ = new SimpleUniverse(canvas); - // Create the universe and viewing branch - u = new SimpleUniverse(canvas); + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + univ.getViewingPlatform().setNominalViewingTransform(); - // This will move the ViewPlatform back a bit so the - // objects in the scene can be viewed. - u.getViewingPlatform().setNominalViewingTransform(); - - // Start a new thread that will continuously render - new Thread(this).start(); + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); } - public void destroy() { - u.cleanup(); + /** + * Creates new form PureImmediate + */ + public PureImmediate() { + // Initialize the GUI components + initComponents(); + + // Create Canvas3D and SimpleUniverse; add canvas to drawing panel + createUniverse(); + drawingPanel.add(canvas, java.awt.BorderLayout.CENTER); + + // Start a new thread that will continuously render + new Thread(this).start(); } - // - // The following allows PureImmediate to be run as an application - // as well as an applet - // - public static void main(String[] args) { - new MainFrame(new PureImmediate(), 256, 256); + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("PureImmediate"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(250, 250)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// </editor-fold>//GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new PureImmediate().setVisible(true); + } + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/pure_immediate/PureImmediateStereo.java b/src/classes/org/jdesktop/j3d/examples/pure_immediate/PureImmediateStereo.java index 8c52509..2d030fe 100644 --- a/src/classes/org/jdesktop/j3d/examples/pure_immediate/PureImmediateStereo.java +++ b/src/classes/org/jdesktop/j3d/examples/pure_immediate/PureImmediateStereo.java @@ -44,15 +44,13 @@ package org.jdesktop.j3d.examples.pure_immediate; -import java.applet.Applet; -import java.awt.*; import java.util.*; -import java.awt.event.*; -import com.sun.j3d.utils.applet.MainFrame; -import com.sun.j3d.utils.universe.*; import com.sun.j3d.utils.geometry.*; +import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsEnvironment; /** * Pure immediate mode stereo example program for stereo. In pure @@ -61,7 +59,11 @@ import javax.vecmath.*; * canvas is created. A separate thread is started up to do the * immediate mode rendering. */ -public class PureImmediateStereo extends Applet implements Runnable { + +public class PureImmediateStereo extends javax.swing.JFrame implements Runnable { + + private SimpleUniverse univ = null; + private BranchGroup scene = null; // Set this to true when the graphics card use shared z buffer // in stereo mode. @@ -78,7 +80,6 @@ public class PureImmediateStereo extends Applet implements Runnable { // One rotation (2*PI radians) every 6 seconds private Alpha rotAlpha = new Alpha(-1, 6000); - private SimpleUniverse u = null; private double angle; // Compute data which is common for both @@ -199,16 +200,7 @@ public class PureImmediateStereo extends Applet implements Runnable { } - public PureImmediateStereo() { - } - - // - // init: create the canvas, stop the renderer, - // create the universe, and start the drawing thread. - // - public void init() { - setLayout(new BorderLayout()); - + private void createUniverse() { // Preferred to use Stereo GraphicsConfigTemplate3D gct = new GraphicsConfigTemplate3D(); gct.setStereo(GraphicsConfigTemplate3D.PREFERRED); @@ -238,29 +230,67 @@ public class PureImmediateStereo extends Applet implements Runnable { // we must stop the Renderer in PureImmediate mode canvas.stopRenderer(); - add("Center", canvas); - // Create the universe and viewing branch - u = new SimpleUniverse(canvas); + // Create simple universe with view branch + univ = new SimpleUniverse(canvas); - // This will move the ViewPlatform back a bit so the - // objects in the scene can be viewed. - u.getViewingPlatform().setNominalViewingTransform(); + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + univ.getViewingPlatform().setNominalViewingTransform(); - // Start a new thread that will continuously render + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); + + // Start a new thread that will continuously render (new Thread(this)).start(); } - // Cleanup all Java3D threads and memory when this applet exit - public void destroy() { - u.cleanup(); + /** + * Creates new form PureImmediateStereo + */ + public PureImmediateStereo() { + // Initialize the GUI components + initComponents(); + + // Create Canvas3D and SimpleUniverse; add canvas to drawing panel + createUniverse(); + drawingPanel.add(canvas, java.awt.BorderLayout.CENTER); } - // - // The following allows PureImmediateStereo to be run as an application - // as well as an applet - // - public static void main(String[] args) { - new MainFrame(new PureImmediateStereo(), 512, 256); + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("PureImmediateStereo"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(512, 256)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// </editor-fold>//GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new PureImmediateStereo().setVisible(true); + } + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/sound/AudioBehaviorMoveOne.java b/src/classes/org/jdesktop/j3d/examples/sound/AudioBehaviorMoveOne.java deleted file mode 100644 index e5fc463..0000000 --- a/src/classes/org/jdesktop/j3d/examples/sound/AudioBehaviorMoveOne.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * $RCSfile$ - * - * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any - * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND - * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY - * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL - * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF - * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS - * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR - * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, - * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND - * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR - * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed, licensed or - * intended for use in the design, construction, operation or - * maintenance of any nuclear facility. - * - * $Revision$ - * $Date$ - * $State$ - */ - -package org.jdesktop.j3d.examples.sound; - -import javax.media.j3d.*; -import javax.vecmath.*; -import java.util.Enumeration; - -// User defined audio behavior class -public class AudioBehaviorMoveOne extends Behavior { - WakeupOnElapsedTime wt; - WakeupOnBehaviorPost wp; - PointSound psound = new PointSound(); - static int WAKEUP_SOUND = 0; - long dur; - // long time; - // long lastTime = -1; - boolean first_loop = true; - String fileName; - - // Override Behavior's initialize method to setup wakeup criteria - public void initialize() { - MediaContainer sample = new MediaContainer(); - sample.setCapability(MediaContainer.ALLOW_URL_WRITE); - sample.setCapability(MediaContainer.ALLOW_URL_READ); - sample.setURLString(fileName); - psound.setSoundData(sample); - // exaggerate the sound position now that viewPlatform - // tranform is taken into account - Point3f soundPos = new Point3f(-20.0f, 0.0f, 0.0f); - psound.setPosition(soundPos); - WakeupOnElapsedTime wp = new WakeupOnElapsedTime(5000); - wakeupOn(wp); - } - - // Override Behavior's stimulus method to handle the event - public void processStimulus(Enumeration criteria) { - // time = System.currentTimeMillis(); - if (first_loop) { - first_loop = false; - dur = psound.getDuration(); - if (dur == Sound.DURATION_UNKNOWN) - dur = 2000; // Force iterations every 2 seconds - // System.out.println(" sound duration time " + dur); - wt = new WakeupOnElapsedTime(dur); - } - else { - // System.out.println(" time between setEnables calls "+ - // (time - lastTime)); - psound.setEnable(false) ; - } - psound.setEnable(true); - // lastTime = time; - wakeupOn(wt); - } - - // - // Constructor for rotation behavior. Parameter: front and back Sound nodes - // - public AudioBehaviorMoveOne(PointSound psound, String filename) { - this.psound = psound; - this.fileName = filename; - } -} diff --git a/src/classes/org/jdesktop/j3d/examples/sound/AudioReverberate.java b/src/classes/org/jdesktop/j3d/examples/sound/AudioReverberate.java index 1d83702..d248359 100644 --- a/src/classes/org/jdesktop/j3d/examples/sound/AudioReverberate.java +++ b/src/classes/org/jdesktop/j3d/examples/sound/AudioReverberate.java @@ -44,6 +44,7 @@ package org.jdesktop.j3d.examples.sound; +import java.net.URL; import javax.media.j3d.*; import javax.vecmath.*; import java.util.Enumeration; @@ -86,7 +87,7 @@ public class AudioReverberate extends Behavior { long dur; long time; boolean firstTime = true; - String fileName; + URL url = null; int lCount = 0; int loopCount = 0; @@ -94,7 +95,7 @@ public class AudioReverberate extends Behavior { public void initialize() { MediaContainer sample = new MediaContainer(); sample.setCacheEnable(true); - sample.setURLString(fileName); + sample.setURLObject(url); psound.setSoundData(sample); Point3f soundPos = new Point3f(-23.0f, 0.0f, 0.0f); psound.setPosition(soundPos); @@ -162,10 +163,9 @@ public class AudioReverberate extends Behavior { // // Constructor for rotation behavior. Parameter: front and back Sound nodes // - public AudioReverberate(PointSound psound, String filename, - AuralAttributes sscape) { + public AudioReverberate(PointSound psound, URL url, AuralAttributes sscape) { this.psound = psound; - this.fileName = filename; + this.url = url; this.sScape = sscape; } } diff --git a/src/classes/org/jdesktop/j3d/examples/sound/MoveAppBoundingLeaf.java b/src/classes/org/jdesktop/j3d/examples/sound/MoveAppBoundingLeaf.java deleted file mode 100644 index 7de3b46..0000000 --- a/src/classes/org/jdesktop/j3d/examples/sound/MoveAppBoundingLeaf.java +++ /dev/null @@ -1,389 +0,0 @@ -/* - * $RCSfile$ - * - * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any - * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND - * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY - * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL - * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF - * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS - * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR - * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, - * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND - * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR - * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGES. - * - * You acknowledge that this software is not designed, licensed or - * intended for use in the design, construction, operation or - * maintenance of any nuclear facility. - * - * $Revision$ - * $Date$ - * $State$ - */ - -package org.jdesktop.j3d.examples.sound; - -/* - * This Java3D program: - * Creates an instance of the JavaSoundMixer AudioDevice, initializing it - * and attaching it to the PhysicalEnvironment with a special version - * of UniverseBuilder (UniverseBuildJS). - * Creates one Point sound sources. - * Creates two Soundscapes with their own aural attributes. Each - * of these Soundscapes defines its own bounding leaf region. - * Creates and executes a custom behavior (AudioBehaviorMoveOne) that - * starts sound playing and transforms the AuralAttribute positions - * by modifying the TransformGroup that contains both soundscape - * nodes. - * Usage: java MoveAppBoundingLeaf [ URLpath [ name ]] - * - * The first optional command line parameter is the URL path to directory - * containing: - * (1) the files that will be named on the command line, or - * (2) the javaone/data/sounds directory that contains the default files - * If not given the default path is: - * file:/net/java3d/export/java3d/javaone/data/sounds - * NOTE: This default path is only valid on Solaris Eng Menlo Park network. - * A path must be supplied if sound files to be used are in a different - * directory location. - * NOTE: When running on Java3D Menlo Park Test WinTel platform path should - * be set to - * file:/java3d/export/java3d/javaone/data/sounds - * - * The second thru fourth optional command line parameters are sound file names - * If not given the default file name is: - * unicycle_close.au - */ - -import java.applet.Applet; -import java.net.URL; -import java.awt.*; -import java.awt.event.*; -import com.sun.j3d.utils.applet.MainFrame; -import com.sun.j3d.utils.geometry.ColorCube; -import com.sun.j3d.utils.geometry.Sphere; -import com.sun.j3d.utils.universe.*; -import java.io.File; -import javax.media.j3d.*; -import javax.vecmath.*; - -public class MoveAppBoundingLeaf extends Applet { - - // File name of sound sample - private static int filenamesGiven = 0; - private static URL[] url = new URL[1]; - private static String[] filename = new String[1]; - private static String path = null; - private static boolean filenamesSet = false; - - private SimpleUniverse u = null; - - public BranchGroup createSceneGraph() { - // Create the root of the subgraph - BranchGroup objRoot = new BranchGroup(); - - // 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 objTrans = new TransformGroup(); - objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); - objRoot.addChild(objTrans); - - // Create a simple shape leaf node and add it into the scene graph. - objTrans.addChild(new ColorCube(0.7)); - - // 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 rotation = new Alpha(-1, Alpha.INCREASING_ENABLE, - 0, 0, - 20000, 0, 0, - 0, 0, 0); - RotationInterpolator rotator = - new RotationInterpolator(rotation, - objTrans, yAxis, - 0.0f, (float) Math.PI*2.0f); - BoundingSphere bounds = - new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); - rotator.setSchedulingBounds(bounds); - objTrans.addChild(rotator); - // - // Create a sound node and add it to the scene graph - // - PointSound sound = new PointSound(); - sound.setCapability(PointSound.ALLOW_ENABLE_WRITE); - sound.setCapability(PointSound.ALLOW_INITIAL_GAIN_WRITE); - sound.setCapability(PointSound.ALLOW_SOUND_DATA_WRITE); - sound.setCapability(PointSound.ALLOW_SCHEDULING_BOUNDS_WRITE); - sound.setCapability(PointSound.ALLOW_CONT_PLAY_WRITE); - sound.setCapability(PointSound.ALLOW_RELEASE_WRITE); - sound.setCapability(PointSound.ALLOW_DURATION_READ); - sound.setCapability(PointSound.ALLOW_IS_PLAYING_READ); - sound.setCapability(PointSound.ALLOW_POSITION_WRITE); - sound.setCapability(PointSound.ALLOW_LOOP_WRITE); - - BoundingSphere soundBounds = - new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); - sound.setSchedulingBounds(soundBounds); - objTrans.addChild(sound); - - /* - * Spheres denoting aural attribute regions - */ - TransformGroup objTransChild1 = new TransformGroup(); - TransformGroup objTransChild2 = new TransformGroup(); - objTransChild1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); - objTransChild2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); - Transform3D translate1 = new Transform3D(); - Transform3D translate2 = new Transform3D(); - Vector3f vector1 = new Vector3f( 2.0f, 0.0f, 0.0f); - Vector3f vector2 = new Vector3f(-2.0f, 0.0f, 0.0f); - translate1.setTranslation(vector1); - translate2.setTranslation(vector2); - objTransChild1.setTransform(translate1); - objTransChild2.setTransform(translate2); - Sphere sphere1 = new Sphere(0.42f); - Sphere sphere2 = new Sphere(0.38f); - - Appearance app = new Appearance(); - app.setCapability( Appearance.ALLOW_POLYGON_ATTRIBUTES_WRITE ); - sphere1.setAppearance( app ); - sphere2.setAppearance( app ); - objTransChild1.addChild(sphere1); - objTransChild2.addChild(sphere2); - - objTrans.addChild(objTransChild1); - objTrans.addChild(objTransChild2); - /** - * Define Soundscapes/AuralAttributes - */ - // First Aural Attributes - Point2f[] distanceFilter = new Point2f[2]; - distanceFilter[0] = new Point2f(6.0f, 6000f); - distanceFilter[1] = new Point2f(17.0f, 700f); - AuralAttributes attributes = new AuralAttributes(1.0f, 2.0f, 0.3f, - 4.0f, 5, distanceFilter, 0.8f, 0.0f); - attributes.setReverbDelay(90.0f) ; - attributes.setReflectionCoefficient(0.999f) ; - attributes.setReverbOrder(9) ; - - // SoundScape - BoundingSphere bounds1 = - new BoundingSphere(new Point3d(2.0,0.0,0.0), 3.5); - - BoundingLeaf sScapeBounds1 = new BoundingLeaf(bounds1); - Soundscape soundScape = new Soundscape(null, attributes); - soundScape.setApplicationBoundingLeaf(sScapeBounds1); - /** addChild of BoundingLeaf as well**/ - objTrans.addChild(sScapeBounds1); - - AuralAttributes queryAttribs = new AuralAttributes(); - if (queryAttribs == null) - System.out.println(" new AuralAttributes returned NULL"); - // else - // System.out.println(" new AuralAttributes returned " + queryAttribs); - queryAttribs = soundScape.getAuralAttributes(); - if (queryAttribs == null) - System.out.println("getAuralAttributes returned NULL"); - // else - // System.out.println("AuralAttributes for Soundscape 1:"); - float tmpFloat = queryAttribs.getAttributeGain(); - // System.out.println(" Gain = " + tmpFloat); - tmpFloat = queryAttribs.getRolloff(); - // System.out.println(" Rolloff = " + tmpFloat); - tmpFloat = queryAttribs.getReflectionCoefficient(); - // System.out.println(" Reflection Coeff = " + tmpFloat); - tmpFloat = queryAttribs.getReverbDelay(); - // System.out.println(" Delay = " + tmpFloat); - int tmpInt = queryAttribs.getReverbOrder(); - // System.out.println(" Order = " + tmpInt); - int length = queryAttribs.getDistanceFilterLength(); - // System.out.println(" Filter length = " + length); - Point2f[] tmpPoint = new Point2f[length]; - tmpPoint = new Point2f[length]; - for (int i=0; i< length; i++) - tmpPoint[i] = new Point2f(); - queryAttribs.getDistanceFilter(tmpPoint); - // for (int i=0; i< length; i++) - // System.out.println(" Distance Filter = (" + tmpPoint[i].x + - // ", " + tmpPoint[i].y + ")" ); - tmpFloat = queryAttribs.getFrequencyScaleFactor(); - // System.out.println(" Freq scalefactor = " + tmpFloat); - tmpFloat = queryAttribs.getVelocityScaleFactor(); - // System.out.println(" Velocity scalefactor= " + tmpFloat); - objTrans.addChild(soundScape); - - // System.out.println("SoundScape2**********************************"); - Soundscape soundScape2 = new Soundscape(); - distanceFilter = new Point2f[2]; - distanceFilter[0] = new Point2f(2.0f, 20000.0f); - distanceFilter[1] = new Point2f(20.0f, 2000.0f); - AuralAttributes attributes2 = new AuralAttributes(); - attributes2.setAttributeGain(1.2f); - attributes2.setRolloff(2.2f); - attributes2.setReverbDelay(1313.0f) ; - attributes2.setReflectionCoefficient(1.0f) ; - attributes2.setReverbOrder(15) ; - distanceFilter[0] = new Point2f(5.0f, 15000.0f); - distanceFilter[1] = new Point2f(15.0f, 500.0f); - attributes2.setDistanceFilter(distanceFilter); - attributes2.setFrequencyScaleFactor(0.8f); - attributes2.setVelocityScaleFactor(0.0f); - BoundingSphere bounds2 = - new BoundingSphere(new Point3d(-2.0,0.0,0.0), 0.38); - BoundingLeaf sScapeBounds2 = new BoundingLeaf(bounds2); - soundScape2.setApplicationBoundingLeaf(sScapeBounds2); - // set BoundingLeaf as a child of transform node - objTrans.addChild(sScapeBounds2); - soundScape2.setAuralAttributes(attributes2); - - queryAttribs = soundScape2.getAuralAttributes(); - if (queryAttribs == null) - System.out.println(" new AuralAttributes returned NULL"); - // else - // System.out.println(" new AuralAttributes returned " + queryAttribs); - // System.out.println("AuralAttributes for Soundscape 2:"); - tmpFloat = queryAttribs.getAttributeGain(); - // System.out.println(" Gain = " + tmpFloat); - tmpFloat = queryAttribs.getRolloff(); - // System.out.println(" Rolloff = " + tmpFloat); - tmpFloat = queryAttribs.getReflectionCoefficient(); - // System.out.println(" Reflection Coeff = " + tmpFloat); - tmpFloat = queryAttribs.getReverbDelay(); - // System.out.println(" Delay = " + tmpFloat); - tmpInt = queryAttribs.getReverbOrder(); - // System.out.println(" Order = " + tmpInt); - length = queryAttribs.getDistanceFilterLength(); - // System.out.println(" Filter length = " + length); - tmpPoint = new Point2f[length]; - for (int i=0; i< length; i++) - tmpPoint[i] = new Point2f(); - queryAttribs.getDistanceFilter(tmpPoint); - // for (int i=0; i< length; i++) - // System.out.println(" Distance Filter = (" + tmpPoint[i].x + - // ", " + tmpPoint[i].y + ")" ); - tmpFloat = queryAttribs.getFrequencyScaleFactor(); - // System.out.println(" Freq scalefactor = " + tmpFloat); - tmpFloat = queryAttribs.getVelocityScaleFactor(); - // System.out.println(" Velocity scalefactor= " + tmpFloat); - objTrans.addChild(soundScape2); - - // - // Create a new Behavior object that will play the sound - // - AudioBehaviorMoveOne player = new AudioBehaviorMoveOne(sound, - filename[0]); - player.setSchedulingBounds(soundBounds); - objTrans.addChild(player); - - return objRoot; - } - - public MoveAppBoundingLeaf() { - } - - public void init() { - if (!filenamesSet) { - // path is null if started from applet - if (path == null) { - path = getCodeBase().toString(); - } - - /* - * append given file name to given URL path - */ - if (filenamesGiven > 0) { - filename[0] = new String(path + "/" + filename[0]); - } - else { - // fill in default file names if all three not given - filename[0] = new String(path + "/techno_machine.au"); - } - filenamesSet = true; - } - - setLayout(new BorderLayout()); - GraphicsConfiguration config = - SimpleUniverse.getPreferredConfiguration(); - - Canvas3D c = new Canvas3D(config); - add("Center", c); - - /* - * Change filenames into URLs - */ - String substr = filename[0].substring(0,4); - try { - url[0] = new URL(filename[0]); - } - catch (Exception e) { - return; - } - /* - * Create a simple scene and attach it to the virtual universe - */ - u = new SimpleUniverse(c); - AudioDevice audioDev = u.getViewer().createAudioDevice(); - BranchGroup scene = createSceneGraph(); - - // This will move the ViewPlatform back a bit so the - // objects in the scene can be viewed. - u.getViewingPlatform().setNominalViewingTransform(); - - u.addBranchGraph(scene); - } - - public void destroy() { - u.cleanup(); - } - - // - // The following allows AuralAttributes to be run as an application - // as well as an applet - // - public static void main(String[] args) { - if (args.length > 0) { - if ( (args[0].startsWith("file"+File.pathSeparator)) || - (args[0].startsWith("http"+File.pathSeparator)) ) { - path = args[0]; - } - else { - path = "file:" + args[0]; - } - } - else { - path = "file:."; - } - - if (args.length > 1) { - filename[0] = args[1]; - if (filename[0] != null) { - filenamesGiven++ ; - } - } - - new MainFrame(new MoveAppBoundingLeaf(), 256, 256); - } -} diff --git a/src/classes/org/jdesktop/j3d/examples/sound/ReverberateSound.java b/src/classes/org/jdesktop/j3d/examples/sound/ReverberateSound.java index ad6a2e3..d1981a0 100644 --- a/src/classes/org/jdesktop/j3d/examples/sound/ReverberateSound.java +++ b/src/classes/org/jdesktop/j3d/examples/sound/ReverberateSound.java @@ -56,22 +56,19 @@ package org.jdesktop.j3d.examples.sound; import java.applet.Applet; import java.awt.*; -import java.awt.event.*; import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.geometry.ColorCube; import com.sun.j3d.utils.universe.*; -import java.io.File; +import java.net.URL; import javax.media.j3d.*; +import javax.swing.JOptionPane; import javax.vecmath.*; +import org.jdesktop.j3d.examples.Resources; public class ReverberateSound extends Applet { // File name of sound sample - private static String[] filename = new String[1]; - private static String path = null; - private static int filenamesGiven = 0; - private static boolean filenamesSet = false; - + private static URL url = null; private SimpleUniverse u = null; public BranchGroup createSceneGraph() { @@ -134,12 +131,10 @@ public class ReverberateSound extends Applet { // // Create a new Behavior object that will play the sound // - AudioReverberate player = new AudioReverberate(sound, filename[0], - attributes2); + AudioReverberate player = new AudioReverberate(sound, url, attributes2); player.setSchedulingBounds(bounds); objTrans.addChild(player); - return objRoot; } @@ -147,25 +142,11 @@ public class ReverberateSound extends Applet { } public void init() { - if (!filenamesSet) { - // path is null if started from applet - if (path == null) { - // the path for an applet - path = getCodeBase().toString(); - } - - /* - * append given file name to given URL path - */ - if (filenamesGiven > 0) { - filename[0] = new String(path + "/" + filename[0]); - } - else { - // fill in default file names if all three not given - filename[0] = new String(path + "/hello_universe.au"); + url = Resources.getResource("resources/audio/hello_universe.au"); + if (url == null) { + System.err.println("resources/audio/hello_universe.au not found"); + System.exit(1); } - filenamesSet = true; - } setLayout(new BorderLayout()); GraphicsConfiguration config = @@ -186,6 +167,12 @@ public class ReverberateSound extends Applet { u.getViewingPlatform().setNominalViewingTransform(); u.addBranchGraph(scene); + + JOptionPane.showMessageDialog(this, + ("This program is still a work in progress.\n" + + "Please check back in Java 3D 1.5.\n"), + "Incomplete Work", + JOptionPane.INFORMATION_MESSAGE); } public void destroy() { @@ -197,26 +184,6 @@ public class ReverberateSound extends Applet { // as well as an applet // public static void main(String[] args) { - if (args.length > 0) { - if ( (args[0].startsWith("file"+File.pathSeparator)) || - (args[0].startsWith("http"+File.pathSeparator)) ) { - path = args[0]; - } - else { - path = "file:" + args[0]; - } - } - else { - path = "file:."; - } - - if (args.length > 1) { - filename[0] = args[1]; - if (filename[0] != null) { - filenamesGiven++ ; - } - } - new MainFrame(new ReverberateSound(), 256, 256); } } diff --git a/src/classes/org/jdesktop/j3d/examples/sound/SimpleSounds.java b/src/classes/org/jdesktop/j3d/examples/sound/SimpleSounds.java index d7c8c49..81e103e 100644 --- a/src/classes/org/jdesktop/j3d/examples/sound/SimpleSounds.java +++ b/src/classes/org/jdesktop/j3d/examples/sound/SimpleSounds.java @@ -47,14 +47,13 @@ package org.jdesktop.j3d.examples.sound; import java.applet.Applet; import java.net.URL; import java.awt.*; -import java.awt.event.*; import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.geometry.ColorCube; import com.sun.j3d.utils.universe.*; -import java.io.File; -import java.security.*; import javax.media.j3d.*; +import javax.swing.JOptionPane; import javax.vecmath.*; +import org.jdesktop.j3d.examples.Resources; /* * This Java3D program: @@ -94,13 +93,7 @@ import javax.vecmath.*; public class SimpleSounds extends Applet { - // File name of sound sample - private static int filenamesGiven = 0; private static URL[] url = new URL[3]; - private static String[] filename = new String[3]; - private static String path = null; - private static boolean filenamesSet = false; - private SimpleUniverse u = null; public BranchGroup createSceneGraph() { @@ -197,31 +190,6 @@ public class SimpleSounds extends Applet { } public void init() { - if (!filenamesSet) { - // path is null if started from appletviewer/browser - if (path == null) { - // the path for an applet - path = getCodeBase().toString(); - } - int j; - /* - * append given file name to given URL path - */ - for (j=0; j<filenamesGiven; j++) - filename[j] = new String(path + "/" + filename[j]); - /* - * fill in default file names if all three not given - */ - for (int i=j; i<3; i++) { - if (i == 0) - filename[0] = new String(path + "/techno_machine.au"); - if (i == 1) - filename[1] = new String(path + "/hello_universe.au"); - if (i == 2) - filename[2] = new String(path + "/roar.au"); - } - filenamesSet = true; - } setLayout(new BorderLayout()); GraphicsConfiguration config = @@ -230,19 +198,24 @@ public class SimpleSounds extends Applet { Canvas3D c = new Canvas3D(config); add("Center", c); - /* - * Change filenames into URLs - */ - for (int i=0; i<3; i++) { - try { - url[i] = new URL(filename[i]); - } - catch (Exception e) { - System.out.println(e.getMessage()); - return; - } + url[0] = Resources.getResource("resources/audio/techno_machine.au"); + if (url == null) { + System.err.println("resources/audio/techno_machine.au not found"); + System.exit(1); } - + + url[1] = Resources.getResource("resources/audio/hello_universe.au"); + if (url == null) { + System.err.println("resources/audio/hello_universe.au not found"); + System.exit(1); + } + + url[2] = Resources.getResource("resources/audio/roar.au"); + if (url == null) { + System.err.println("resources/audio/roar.au not found"); + System.exit(1); + } + /* * Create a simple scene and attach it to the virtual universe */ @@ -255,6 +228,12 @@ public class SimpleSounds extends Applet { u.getViewingPlatform().setNominalViewingTransform(); u.addBranchGraph(scene); + + JOptionPane.showMessageDialog(this, + ("This program is still a work in progress.\n" + + "Please check back in Java 3D 1.5.\n"), + "Incomplete Work", + JOptionPane.INFORMATION_MESSAGE); } public void destroy() { @@ -266,29 +245,6 @@ public class SimpleSounds extends Applet { * as well as an applet */ public static void main(String[] args) { - if (args.length > 0) { - if ( (args[0].startsWith("file"+File.pathSeparator)) || - (args[0].startsWith("http"+File.pathSeparator)) ) { - path = args[0]; - } - else { - path = "file:" + args[0]; - } - } - else { - path = "file:."; - } - - for (int i=0; i<3; i++) { - if (args.length > (i+1)) { - filename[i] = args[i+1]; - if (filename[i] != null) { - filenamesGiven++ ; - } - } - else - break; - } new MainFrame(new SimpleSounds(), args, 256, 256); } } diff --git a/src/classes/org/jdesktop/j3d/examples/sphere_motion/SphereMotion.java b/src/classes/org/jdesktop/j3d/examples/sphere_motion/SphereMotion.java index 49b3293..bf30793 100644 --- a/src/classes/org/jdesktop/j3d/examples/sphere_motion/SphereMotion.java +++ b/src/classes/org/jdesktop/j3d/examples/sphere_motion/SphereMotion.java @@ -44,16 +44,16 @@ package org.jdesktop.j3d.examples.sphere_motion; -import java.applet.Applet; -import java.awt.*; -import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.geometry.Sphere; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; -import java.util.Enumeration; +import java.awt.GraphicsConfiguration; -public class SphereMotion extends Applet { +public class SphereMotion extends javax.swing.JFrame { + + private SimpleUniverse univ = null; + private BranchGroup scene = null; // Constants for type of light to use private static final int DIRECTIONAL_LIGHT = 0; @@ -64,9 +64,7 @@ public class SphereMotion extends Applet { // lights. This flag is set based on command line argument private static int lightType = POINT_LIGHT; - private SimpleUniverse u = null; - - public BranchGroup createSceneGraph(SimpleUniverse u) { + public BranchGroup createSceneGraph() { Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f); Color3f sColor = new Color3f(1.0f, 1.0f, 1.0f); Color3f objColor = new Color3f(0.6f, 0.6f, 0.6f); @@ -218,7 +216,7 @@ public class SphereMotion extends Applet { // Create a position interpolator and attach it to the view // platform TransformGroup vpTrans = - u.getViewingPlatform().getViewPlatformTransform(); + univ.getViewingPlatform().getViewPlatformTransform(); Transform3D axisOfTranslation = new Transform3D(); Alpha transAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | @@ -240,37 +238,33 @@ public class SphereMotion extends Applet { return objRoot; } + + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); - public SphereMotion() { - } - - public void init() { - setLayout(new BorderLayout()); - GraphicsConfiguration config = - SimpleUniverse.getPreferredConfiguration(); + // Create a Canvas3D using the preferred configuration + Canvas3D c = new Canvas3D(config); - Canvas3D c = new Canvas3D(config); - add("Center", c); + // Create simple universe with view branch + univ = new SimpleUniverse(c); - u = new SimpleUniverse(c); - BranchGroup scene = createSceneGraph(u); + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + univ.getViewingPlatform().setNominalViewingTransform(); - // This will move the ViewPlatform back a bit so the - // objects in the scene can be viewed. - u.getViewingPlatform().setNominalViewingTransform(); + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); - u.addBranchGraph(scene); + return c; } - public void destroy() { - u.cleanup(); - } - - // - // The following allows SphereMotion to be run as an application - // as well as an applet - // - public static void main(String[] args) { + /** + * Creates new form SphereMotion + */ + public SphereMotion(final String[] args) { + // Parse the Input Arguments String usage = "Usage: java SphereMotion [-point | -spot | -dir]"; for (int i = 0; i < args.length; i++) { @@ -296,8 +290,55 @@ public class SphereMotion extends Applet { System.out.println(usage); System.exit(0); } - } + } + + // Initialize the GUI components + initComponents(); + + // Create Canvas3D and SimpleUniverse; add canvas to drawing panel + Canvas3D c = createUniverse(); + drawingPanel.add(c, java.awt.BorderLayout.CENTER); + + // Create the content branch and add it to the universe + scene = createSceneGraph(); + univ.addBranchGraph(scene); + } - new MainFrame(new SphereMotion(), 700, 700); + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("SphereMotion"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// </editor-fold>//GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(final String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + SphereMotion sphereMotion = new SphereMotion(args); + sphereMotion.setVisible(true); + } + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/texture/MultiTextureTest.java b/src/classes/org/jdesktop/j3d/examples/texture/MultiTextureTest.java index 026cfe9..f1ebf02 100644 --- a/src/classes/org/jdesktop/j3d/examples/texture/MultiTextureTest.java +++ b/src/classes/org/jdesktop/j3d/examples/texture/MultiTextureTest.java @@ -55,6 +55,7 @@ import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; import java.awt.image.BufferedImage; +import org.jdesktop.j3d.examples.Resources; public class MultiTextureTest extends Applet implements ItemListener{ @@ -203,66 +204,60 @@ public class MultiTextureTest extends Applet implements ItemListener{ } public void init() { - if (stoneImage == null) { - // the path to the image for an applet - try { - stoneImage = new java.net.URL(getCodeBase().toString() + - "../images/stone.jpg"); + if (stoneImage == null) { + // the path to the image for an applet + stoneImage = Resources.getResource("resources/images/stone.jpg"); + if (stoneImage == null) { + System.err.println("resources/images/stone.jpg not found"); + System.exit(1); + } + + if (skyImage == null) { + // the path to the image for an applet + skyImage = Resources.getResource("resources/images/bg.jpg"); + if (skyImage == null) { + System.err.println("resources/images/bg.jpg not found"); + System.exit(1); + } + } } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - } - - if (skyImage == null) { - // the path to the image for an applet - try { - skyImage = new java.net.URL(getCodeBase().toString() + - "../images/bg.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - } - - setLayout(new BorderLayout()); - GraphicsConfiguration config = - SimpleUniverse.getPreferredConfiguration(); - - Canvas3D c = new Canvas3D(config); - add("Center", c); - - BranchGroup scene = createSceneGraph(); - u = new SimpleUniverse(c); - - ViewingPlatform viewingPlatform = u.getViewingPlatform(); - // This will move the ViewPlatform back a bit so the - // objects in the scene can be viewed. - viewingPlatform.setNominalViewingTransform(); - - // add orbit behavior but disable translate - OrbitBehavior orbit = - new OrbitBehavior(c, OrbitBehavior.REVERSE_ALL | - OrbitBehavior.DISABLE_TRANSLATE); - BoundingSphere bounds = - new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); - orbit.setSchedulingBounds(bounds); - viewingPlatform.setViewPlatformBehavior(orbit); - - u.addBranchGraph(scene); - - // create the gui - choice = new Choice(); - choice.addItem("stone + light"); - choice.addItem("stone"); - choice.addItem("lightMap"); - choice.addItem("sky"); - choice.addItem("stone + sky"); - choice.addItemListener(this); - add("North", choice); - + + setLayout(new BorderLayout()); + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); + + Canvas3D c = new Canvas3D(config); + add("Center", c); + + BranchGroup scene = createSceneGraph(); + u = new SimpleUniverse(c); + + ViewingPlatform viewingPlatform = u.getViewingPlatform(); + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + viewingPlatform.setNominalViewingTransform(); + + // add orbit behavior but disable translate + OrbitBehavior orbit = + new OrbitBehavior(c, OrbitBehavior.REVERSE_ALL | + OrbitBehavior.DISABLE_TRANSLATE); + BoundingSphere bounds = + new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); + orbit.setSchedulingBounds(bounds); + viewingPlatform.setViewPlatformBehavior(orbit); + + u.addBranchGraph(scene); + + // create the gui + choice = new Choice(); + choice.addItem("stone + light"); + choice.addItem("stone"); + choice.addItem("lightMap"); + choice.addItem("sky"); + choice.addItem("stone + sky"); + choice.addItemListener(this); + add("North", choice); + } public void destroy() { @@ -302,19 +297,24 @@ public class MultiTextureTest extends Applet implements ItemListener{ } public static void main(String argv[]) - { - java.net.URL stoneURL = null; - java.net.URL skyURL = null; - // the path to the image for an application - try { - stoneURL = new java.net.URL("file:../images/stone.jpg"); - skyURL = new java.net.URL("file:../images/bg.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - new MainFrame(new MultiTextureTest(stoneURL, skyURL), 750, 750); +{ + java.net.URL stoneURL = null; + java.net.URL skyURL = null; + // the path to the image for an application + + stoneURL = Resources.getResource("resources/images/stone.jpg"); + if (stoneURL == null) { + System.err.println("resources/images/stone.jpg not found"); + System.exit(1); + } + + skyURL = Resources.getResource("resources/images/bg.jpg"); + if (skyURL == null) { + System.err.println("resources/images/bg.jpg not found"); + System.exit(1); + } + + new MainFrame(new MultiTextureTest(stoneURL, skyURL), 750, 750); } } diff --git a/src/classes/org/jdesktop/j3d/examples/texture/TextureImage.java b/src/classes/org/jdesktop/j3d/examples/texture/TextureImage.java index b6ab08f..5ac421e 100644 --- a/src/classes/org/jdesktop/j3d/examples/texture/TextureImage.java +++ b/src/classes/org/jdesktop/j3d/examples/texture/TextureImage.java @@ -46,13 +46,13 @@ package org.jdesktop.j3d.examples.texture; import java.applet.Applet; import java.awt.*; -import java.awt.event.*; import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; import com.sun.j3d.utils.image.TextureLoader; import com.sun.j3d.utils.geometry.Box; import javax.media.j3d.*; import javax.vecmath.*; +import org.jdesktop.j3d.examples.Resources; public class TextureImage extends Applet { @@ -118,14 +118,11 @@ public class TextureImage extends Applet { public void init() { if (texImage == null) { // the path to the image for an applet - try { - texImage = new java.net.URL(getCodeBase().toString() + - "../images/stone.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } + texImage = Resources.getResource("resources/images/stone.jpg"); + if (texImage == null) { + System.err.println("resources/images/stone.jpg not found"); + System.exit(1); + } } setLayout(new BorderLayout()); GraphicsConfiguration config = @@ -156,25 +153,21 @@ public class TextureImage extends Applet { public static void main(String[] args) { java.net.URL url = null; if (args.length > 0) { - try { - url = new java.net.URL("file:" + args[0]); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - } - else { - // the path to the image for an application - try { - url = new java.net.URL("file:../images/stone.jpg"); - } - catch (java.net.MalformedURLException ex) { - System.out.println(ex.getMessage()); - System.exit(1); - } - } - new MainFrame(new TextureImage(url), 256, 256); + try { + url = new java.net.URL("file:" + args[0]); + } catch (java.net.MalformedURLException ex) { + System.out.println(ex.getMessage()); + System.exit(1); + } + } else { + // the path to the image for an application + url = Resources.getResource("resources/images/stone.jpg"); + if (url == null) { + System.err.println("resources/images/stone.jpg not found"); + System.exit(1); + } + } + new MainFrame(new TextureImage(url), 256, 256); } } diff --git a/src/classes/org/jdesktop/j3d/examples/texture_by_ref/TextureByReference.java b/src/classes/org/jdesktop/j3d/examples/texture_by_ref/TextureByReference.java index 1faad7e..e12204c 100644 --- a/src/classes/org/jdesktop/j3d/examples/texture_by_ref/TextureByReference.java +++ b/src/classes/org/jdesktop/j3d/examples/texture_by_ref/TextureByReference.java @@ -52,10 +52,10 @@ import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; import java.awt.image.*; -import java.awt.color.ColorSpace; import com.sun.j3d.utils.image.TextureLoader; import javax.swing.*; import javax.swing.event.*; +import org.jdesktop.j3d.examples.Resources; public class TextureByReference extends Applet @@ -88,16 +88,16 @@ implements ItemListener, ActionListener, ChangeListener { // image files used for the Texture animation for the applet, // or if no parameters are passed in for the application public static final String[] defaultFiles = { - "../images/animation1.gif", - "../images/animation2.gif", - "../images/animation3.gif", - "../images/animation4.gif", - "../images/animation5.gif", - "../images/animation6.gif", - "../images/animation7.gif", - "../images/animation8.gif", - "../images/animation9.gif", - "../images/animation10.gif"}; + "resources/images/animation1.gif", + "resources/images/animation2.gif", + "resources/images/animation3.gif", + "resources/images/animation4.gif", + "resources/images/animation5.gif", + "resources/images/animation6.gif", + "resources/images/animation7.gif", + "resources/images/animation8.gif", + "resources/images/animation9.gif", + "resources/images/animation10.gif"}; private java.net.URL[] urls = null; @@ -113,7 +113,13 @@ implements ItemListener, ActionListener, ChangeListener { if (urls == null) { urls = new java.net.URL[defaultFiles.length]; for (int i = 0; i < defaultFiles.length; i++) { - try { + urls[i] = Resources.getResource(defaultFiles[i]); + if (urls[i] == null) { + System.err.println(defaultFiles[i] + " not found"); + System.exit(1); + } + /* + try { urls[i] = new java.net.URL(getCodeBase().toString() + defaultFiles[i]); } @@ -121,6 +127,7 @@ implements ItemListener, ActionListener, ChangeListener { System.out.println(ex.getMessage()); System.exit(1); } + */ } } setLayout(new BorderLayout()); @@ -511,7 +518,14 @@ implements ItemListener, ActionListener, ChangeListener { else { fnames = new java.net.URL[TextureByReference.defaultFiles.length]; for (int i = 0; i < TextureByReference.defaultFiles.length; i++) { - try { + fnames[i] = Resources.getResource(defaultFiles[i]); + if (fnames[i] == null) { + System.err.println(TextureByReference.defaultFiles[i] + " not found"); + System.exit(1); + } + +/* + try { fnames[i] = new java.net.URL("file:" + TextureByReference.defaultFiles[i]); } @@ -519,6 +533,7 @@ implements ItemListener, ActionListener, ChangeListener { System.out.println(ex.getMessage()); System.exit(1); } + */ } } new MainFrame((new TextureByReference(fnames)), 650, 750); diff --git a/src/resources/images/apimage.jpg b/src/resources/images/apimage.jpg Binary files differdeleted file mode 100644 index ab80a4a..0000000 --- a/src/resources/images/apimage.jpg +++ /dev/null diff --git a/src/resources/images/bg.jpg b/src/resources/images/bg.jpg Binary files differindex 556babe..9790379 100644 --- a/src/resources/images/bg.jpg +++ b/src/resources/images/bg.jpg diff --git a/src/resources/images/gold.jpg b/src/resources/images/gold.jpg Binary files differindex 40e8786..aec73c5 100644 --- a/src/resources/images/gold.jpg +++ b/src/resources/images/gold.jpg diff --git a/src/resources/images/stone.jpg b/src/resources/images/stone.jpg Binary files differindex ab80a4a..6aa8914 100644 --- a/src/resources/images/stone.jpg +++ b/src/resources/images/stone.jpg |