diff options
author | jada <jada@28c7f869-5b4e-e670-f602-82bfaf57f300> | 2006-03-03 03:23:40 +0000 |
---|---|---|
committer | jada <jada@28c7f869-5b4e-e670-f602-82bfaf57f300> | 2006-03-03 03:23:40 +0000 |
commit | cd09b499eb9069dc5f7a83d229c318ccf144b56c (patch) | |
tree | 5ce1e7a88b7bb19f3fba5ab831aa7ca88688ee91 /src/classes/org/jdesktop/j3d/examples/gears | |
parent | 374714fa97f3aeacee236e3a019b7c252cb671c0 (diff) |
1) Added VertexAttrTestCg and converted more programs to use JFrame instead of MainFrame
2) Cleanup and rename.
Diffstat (limited to 'src/classes/org/jdesktop/j3d/examples/gears')
4 files changed, 269 insertions, 124 deletions
diff --git a/src/classes/org/jdesktop/j3d/examples/gears/GearBox.form b/src/classes/org/jdesktop/j3d/examples/gears/GearBox.form new file mode 100644 index 0000000..840732c --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/gears/GearBox.form @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<Form version="1.0" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"> + <Properties> + <Property name="defaultCloseOperation" type="int" value="3"/> + <Property name="title" type="java.lang.String" value="GearBox"/> + </Properties> + <SyntheticProperties> + <SyntheticProperty name="formSizePolicy" type="int" value="1"/> + </SyntheticProperties> + <AuxValues> + <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> + <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> + <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/> + </AuxValues> + + <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/> + <SubComponents> + <Container class="javax.swing.JPanel" name="drawingPanel"> + <Properties> + <Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor"> + <Dimension value="[700, 700]"/> + </Property> + </Properties> + <Constraints> + <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription"> + <BorderConstraints direction="Center"/> + </Constraint> + </Constraints> + + <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/> + </Container> + </SubComponents> +</Form> 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.form b/src/classes/org/jdesktop/j3d/examples/gears/GearTest.form new file mode 100644 index 0000000..0ba2e64 --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/gears/GearTest.form @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<Form version="1.0" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"> + <Properties> + <Property name="defaultCloseOperation" type="int" value="3"/> + <Property name="title" type="java.lang.String" value="GearTest"/> + </Properties> + <SyntheticProperties> + <SyntheticProperty name="formSizePolicy" type="int" value="1"/> + </SyntheticProperties> + <AuxValues> + <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> + <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> + <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/> + </AuxValues> + + <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/> + <SubComponents> + <Container class="javax.swing.JPanel" name="drawingPanel"> + <Properties> + <Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor"> + <Dimension value="[700, 700]"/> + </Property> + </Properties> + <Constraints> + <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription"> + <BorderConstraints direction="Center"/> + </Constraint> + </Constraints> + + <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/> + </Container> + </SubComponents> +</Form> 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 + } |