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 /src/classes/org/jdesktop/j3d/examples/collision | |
parent | 19e30a5771eb1ec413e562c0d99b6263978dfba0 (diff) |
Merged changes between 1.4.0-beta4 and 1.4.0-fcs into dev-1_5 branch
Diffstat (limited to 'src/classes/org/jdesktop/j3d/examples/collision')
-rw-r--r-- | src/classes/org/jdesktop/j3d/examples/collision/TickTockCollision.java | 103 |
1 files changed, 72 insertions, 31 deletions
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 + } |