001: /*
002: * $RCSfile: VirtualInputDeviceTest.java,v $
003: *
004: * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * - Redistribution of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * - Redistribution in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * Neither the name of Sun Microsystems, Inc. or the names of
019: * contributors may be used to endorse or promote products derived
020: * from this software without specific prior written permission.
021: *
022: * This software is provided "AS IS," without a warranty of any
023: * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
024: * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
025: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
026: * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
027: * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
028: * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
029: * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
030: * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
031: * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
032: * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
033: * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
034: * POSSIBILITY OF SUCH DAMAGES.
035: *
036: * You acknowledge that this software is not designed, licensed or
037: * intended for use in the design, construction, operation or
038: * maintenance of any nuclear facility.
039: *
040: * $Revision: 1.2 $
041: * $Date: 2007/02/09 17:21:55 $
042: * $State: Exp $
043: */
044:
045: package org.jdesktop.j3d.examples.virtual_input_device;
046:
047: import java.applet.Applet;
048: import java.awt.*;
049: import java.awt.event.*;
050: import com.sun.j3d.utils.applet.MainFrame;
051: import com.sun.j3d.utils.geometry.ColorCube;
052: import com.sun.j3d.utils.universe.*;
053: import javax.media.j3d.*;
054: import javax.vecmath.*;
055:
056: public class VirtualInputDeviceTest extends Applet {
057:
058: private SimpleUniverse u = null;
059:
060: public BranchGroup createSceneGraph() {
061:
062: BranchGroup objRoot = new BranchGroup();
063: TransformGroup objTrans = new TransformGroup();
064: objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
065: objRoot.addChild(objTrans);
066: objTrans.addChild(new ColorCube(0.2));
067: Transform3D yAxis = new Transform3D();
068: Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0,
069: 0, 4000, 0, 0, 0, 0, 0);
070: RotationInterpolator rotator = new RotationInterpolator(
071: rotationAlpha, objTrans, yAxis, 0.0f,
072: (float) Math.PI * 2.0f);
073: BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,
074: 0.0, 0.0), 100.0);
075: rotator.setSchedulingBounds(bounds);
076: objTrans.addChild(rotator);
077: return objRoot;
078: }
079:
080: public VirtualInputDeviceTest() {
081:
082: }
083:
084: public void init() {
085: // These are the string arguments given to the VirtualInputDevice
086: // constructor. These are settable parameters. Look in the
087: // VirtualInputDevice constructor for a complete list.
088: String[] args = new String[10];
089: args[0] = "printvalues";
090: args[1] = "true";
091: args[2] = "yscreeninitloc";
092: args[3] = "50";
093: args[4] = null;
094:
095: InputDevice device = new VirtualInputDevice(args);
096:
097: // now create the VirtualInputDeviceTest Canvas
098: setLayout(new BorderLayout());
099: GraphicsConfiguration config = SimpleUniverse
100: .getPreferredConfiguration();
101:
102: Canvas3D c = new Canvas3D(config);
103: add("Center", c);
104:
105: // Create a simple scene and attach it to the virtual universe
106: BranchGroup scene = createSceneGraph();
107: u = new SimpleUniverse(c);
108:
109: // The InputDevice must be initialized before registering it
110: // with the PhysicalEnvironment object.
111: device.initialize();
112:
113: // Register the VirtualInputDevice with Java 3D
114: u.getViewer().getPhysicalEnvironment().addInputDevice(device);
115:
116: TransformGroup viewTrans = u.getViewingPlatform()
117: .getViewPlatformTransform();
118: SensorBehavior s = new SensorBehavior(viewTrans, device
119: .getSensor(0));
120: s.setSchedulingBounds(new BoundingSphere(new Point3d(0.0, 0.0,
121: 0.0), Float.MAX_VALUE));
122: scene.addChild(s);
123: u.addBranchGraph(scene);
124: }
125:
126: public void destroy() {
127: u.cleanup();
128: }
129:
130: public static void main(String[] args) {
131: new MainFrame(new VirtualInputDeviceTest(), 350, 350);
132: }
133: }
|