aboutsummaryrefslogtreecommitdiffstats
path: root/src/classes/org/jdesktop/j3d/examples/background
diff options
context:
space:
mode:
Diffstat (limited to 'src/classes/org/jdesktop/j3d/examples/background')
-rw-r--r--src/classes/org/jdesktop/j3d/examples/background/BackgroundGeometry.java147
1 files changed, 86 insertions, 61 deletions
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
+
}
-