Source Code Cross Referenced for VirtualInputDevice.java in  » 6.0-JDK-Modules » java-3d » org » jdesktop » j3d » examples » virtual_input_device » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » java 3d » org.jdesktop.j3d.examples.virtual_input_device 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $RCSfile: VirtualInputDevice.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 javax.media.j3d.*;
048:        import javax.vecmath.*;
049:        import java.awt.*;
050:        import java.awt.event.*;
051:
052:        public class VirtualInputDevice implements  InputDevice {
053:
054:            private Vector3f position = new Vector3f();
055:            private Transform3D newTransform = new Transform3D();
056:            Sensor sensors[] = new Sensor[1];
057:
058:            // The wheel controls control the view platform orientation
059:            private RotationControls rotControls;
060:
061:            // The button position controls control the view platform position
062:            private PositionControls positionControls;
063:
064:            private Transform3D rotTransX = new Transform3D();
065:            private Transform3D rotTransY = new Transform3D();
066:            private Transform3D rotTransZ = new Transform3D();
067:
068:            private Vector3f initPos = new Vector3f();
069:
070:            private int processingMode;
071:            private SensorRead sensorRead = new SensorRead();
072:
073:            // These are the settable parameters.
074:            private boolean printvalues;
075:            private int xscreeninitloc;
076:            private int yscreeninitloc;
077:            private int xscreensize;
078:            private int yscreensize;
079:            private float xobjinitloc;
080:            private float yobjinitloc;
081:            private float zobjinitloc;
082:            private float xaxisrotinit;
083:            private float yaxisrotinit;
084:            private float zaxisrotinit;
085:
086:            /* 
087:             * Create a device, and use the string arguments in args to construct
088:             * the device with user preferences.
089:             */
090:            public VirtualInputDevice(String[] args) {
091:
092:                // default user-definable values
093:                printvalues = false;
094:                xscreeninitloc = 400;
095:                yscreeninitloc = 0;
096:                xscreensize = 400;
097:                yscreensize = 200;
098:                xobjinitloc = 0.0f;
099:                yobjinitloc = 0.0f;
100:                zobjinitloc = 2.2f;
101:                xaxisrotinit = 0.0f;
102:                yaxisrotinit = 0.0f;
103:                zaxisrotinit = 0.0f;
104:
105:                for (int i = 0; i < args.length; i += 2) {
106:                    if (args[i] == null)
107:                        break;
108:                    else if (args[i] == "printvalues")
109:                        printvalues = (Boolean.valueOf(args[i + 1]))
110:                                .booleanValue();
111:                    else if (args[i] == "xscreeninitloc")
112:                        xscreeninitloc = (Integer.valueOf(args[i + 1]))
113:                                .intValue();
114:                    else if (args[i] == "yscreeninitloc")
115:                        yscreeninitloc = (Integer.valueOf(args[i + 1]))
116:                                .intValue();
117:                    else if (args[i] == "xscreensize")
118:                        xscreensize = (Integer.valueOf(args[i + 1])).intValue();
119:                    else if (args[i] == "yscreensize")
120:                        yscreensize = (Integer.valueOf(args[i + 1])).intValue();
121:                    else if (args[i] == "xobjinitloc")
122:                        xobjinitloc = (Float.valueOf(args[i + 1])).floatValue();
123:                    else if (args[i] == "yobjinitloc")
124:                        yobjinitloc = (Float.valueOf(args[i + 1])).floatValue();
125:                    else if (args[i] == "zobjinitloc")
126:                        zobjinitloc = (Integer.valueOf(args[i + 1]))
127:                                .floatValue();
128:                }
129:
130:                if (printvalues == true) {
131:                    System.out
132:                            .println("Initial values for VirtualInputDevice:");
133:                    System.out.println("xscreeninitloc = " + xscreeninitloc);
134:                    System.out.println("yscreeninitloc = " + yscreeninitloc);
135:                    System.out.println("xscreeninitsize = " + xscreensize);
136:                    System.out.println("yscreeninitsize = " + yscreensize);
137:                    System.out.println("xobjinitloc = " + xobjinitloc);
138:                    System.out.println("yobjinitloc = " + yobjinitloc);
139:                    System.out.println("zobjinitloc = " + zobjinitloc);
140:                    System.out.println("xaxisrotinit = " + xaxisrotinit);
141:                    System.out.println("yaxisrotinit = " + yaxisrotinit);
142:                    System.out.println("zaxisrotinit = " + zaxisrotinit);
143:                }
144:
145:                // initialize the InputDevice GUI
146:                Frame deviceFrame = new Frame();
147:                deviceFrame.setSize(xscreensize, yscreensize);
148:                deviceFrame.setLocation(xscreeninitloc, yscreeninitloc);
149:                deviceFrame.setTitle("Virtual Input Device");
150:                ButtonPositionControls positionControls;
151:                // initialize position with initial x, y, and z position
152:                positionControls = new ButtonPositionControls(xobjinitloc,
153:                        yobjinitloc, zobjinitloc);
154:                WheelControls rotControls;
155:                // initialize rotations with initial angles in radians)
156:                rotControls = new WheelControls(xaxisrotinit, yaxisrotinit,
157:                        zaxisrotinit);
158:                positionControls.setDevice(this );
159:                Panel devicePanel = new Panel();
160:                devicePanel.setLayout(new BorderLayout());
161:                devicePanel.add("East", positionControls);
162:                devicePanel.add("West", rotControls);
163:                deviceFrame.add(devicePanel);
164:                deviceFrame.pack();
165:                deviceFrame.setVisible(true);
166:
167:                initPos.set(xobjinitloc, yobjinitloc, zobjinitloc);
168:
169:                this .positionControls = positionControls;
170:                this .rotControls = rotControls;
171:
172:                // default processing mode
173:                processingMode = InputDevice.DEMAND_DRIVEN;
174:
175:                sensors[0] = new Sensor(this );
176:            }
177:
178:            public void close() {
179:            }
180:
181:            public int getProcessingMode() {
182:                return processingMode;
183:            }
184:
185:            public int getSensorCount() {
186:                return sensors.length;
187:            }
188:
189:            public Sensor getSensor(int sensorIndex) {
190:                return sensors[sensorIndex];
191:            }
192:
193:            public boolean initialize() {
194:                return true;
195:            }
196:
197:            public void pollAndProcessInput() {
198:
199:                sensorRead.setTime(System.currentTimeMillis());
200:
201:                rotTransX.rotX(-rotControls.getXAngle());
202:                rotTransY.rotY(-rotControls.getYAngle());
203:                rotTransZ.rotZ(-rotControls.getZAngle());
204:
205:                positionControls.getPosition(position);
206:                newTransform.set(position);
207:                newTransform.mul(rotTransX);
208:
209:                newTransform.mul(rotTransY);
210:                newTransform.mul(rotTransZ);
211:
212:                sensorRead.set(newTransform);
213:                sensors[0].setNextSensorRead(sensorRead);
214:            }
215:
216:            public void processStreamInput() {
217:            }
218:
219:            public void setNominalPositionAndOrientation() {
220:
221:                sensorRead.setTime(System.currentTimeMillis());
222:
223:                rotTransX.rotX(xaxisrotinit);
224:                rotTransY.rotY(yaxisrotinit);
225:                rotTransZ.rotZ(zaxisrotinit);
226:
227:                position.set(initPos);
228:
229:                newTransform.set(position);
230:
231:                newTransform.mul(rotTransX);
232:                newTransform.mul(rotTransY);
233:                newTransform.mul(rotTransZ);
234:
235:                sensorRead.set(newTransform);
236:                sensors[0].setNextSensorRead(sensorRead);
237:                rotControls.reset();
238:                positionControls.setPosition(initPos);
239:            }
240:
241:            public void setProcessingMode(int mode) {
242:
243:                // A typical driver might implement only one of these modes, and
244:                // throw an exception when there is an attempt to switch modes.
245:                // However, this example allows one to use any processing mode.
246:
247:                switch (mode) {
248:                case InputDevice.DEMAND_DRIVEN:
249:                case InputDevice.NON_BLOCKING:
250:                case InputDevice.BLOCKING:
251:                    processingMode = mode;
252:                    break;
253:                default:
254:                    throw new IllegalArgumentException(
255:                            "Processing mode must "
256:                                    + "be one of DEMAND_DRIVEN, NON_BLOCKING, or BLOCKING");
257:                }
258:            }
259:
260:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.