Source Code Cross Referenced for JavaOneLogitechTracker.java in  » 6.0-JDK-Modules » java-3d » com » sun » j3d » utils » trackers » 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 » com.sun.j3d.utils.trackers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $RCSfile: JavaOneLogitechTracker.java,v $
003:         *
004:         * Copyright 1996-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.1 $
041:         * $Date: 2007/09/25 20:01:19 $
042:         * $State: Exp $
043:         */
044:
045:        package com.sun.j3d.utils.trackers;
046:
047:        import java.lang.String;
048:        import javax.vecmath.*;
049:        import javax.media.j3d.*;
050:
051:        /**
052:         * NOTE: this class is very much out of date.  It is using deprecated
053:         * 1.1 API method View.addInputDevice.  This method is
054:         * now gone in 1.2.  The offending lines have been commented out
055:         * and marked with an "OBSOLETE:" comment.
056:         *<p>
057:         *
058:         * The SharedMemoryLogitechTracker Class defines the code to make a 
059:         * sharedMemoryLogitech input device work correctly.
060:         *
061:         * @version 	1.10, 98/03/16 21:15:21
062:         * @author 	Henry Sowizral
063:         */
064:        public class JavaOneLogitechTracker extends Tracker {
065:
066:            boolean headTrackingEnabled = false;
067:            View view;
068:
069:            // This device's slave filename
070:            String slaveFilename;
071:
072:            // Current Sensor Read (last one we generated)
073:            SensorRead currentRead;
074:
075:            // Next SensorRead (the one we're now generating)
076:            SensorRead nextRead;
077:
078:            // The current sensor
079:            int currentSensor = 0;
080:
081:            //  Holds a sensor's Euler Angles
082:            Vector3d deviceEulerAngles;
083:
084:            //  Holds the sensor's current Position
085:            Vector3d deviceTranslateValues;
086:
087:            // The number of sensors associated with this device.
088:            static final int SensorCount = 8;
089:
090:            // The number of buttons associated with this device.
091:            static final int ButtonCount = 5;
092:
093:            // The initial position and orientation
094:            Transform3D initialPosOrient;
095:
096:            static float[] PositionOrientation;
097:            static int[] ButtonArray;
098:
099:            Matrix3d oldMatrix;
100:            Matrix3d newMatrix;
101:            Matrix3d tmpMatrix;
102:
103:            Matrix3d yawMat;
104:            Matrix3d pitchMat;
105:            Matrix3d rollMat;
106:
107:            Transform3D oldTransform;
108:            Vector3d oldLocation;
109:
110:            Transform3D newTransform;
111:            Vector3d newLocation;
112:
113:            Transform3D tmpTransform;
114:
115:            Vector3d tmpVector;
116:
117:            boolean useGlasses = false;
118:
119:            /**
120:             * Construct a new SharedMemoryLogitechTracker
121:             * @param view the view object
122:             * @paran deviceFilename the SharedMemoryLogitech's devide name
123:             * @param mode the mode of access one of POLLED or STREAMING
124:             * @param sensorCount the number of sensors associated with this sharedMemoryLogitech
125:             * @param buttonCount the number of buttons associated with each sensor
126:             */
127:            public JavaOneLogitechTracker(View view, String deviceFilename,
128:                    int mode, int sensorCount, int buttonCount,
129:                    boolean useGlasses) {
130:                this .super (view, deviceFilename, mode, sensorCount, buttonCount);
131:                this .useGlasses = useGlasses;
132:                this .view = view;
133:                // OBSOLETE: view.addInputDevice(this);
134:            }
135:
136:            /**
137:             * Construct a new SharedMemoryLogitechTracker
138:             * @param sensorCount the number of sensors associated with this 
139:             * sharedMemoryLogitech
140:             * @param buttonCount the number of buttons associated with each sensor
141:             */
142:            public JavaOneLogitechTracker(View view, int sensorCount,
143:                    int buttonCount, boolean useGlasses) {
144:                this .super (sensorCount, buttonCount);
145:                this .useGlasses = useGlasses;
146:                this .view = view;
147:
148:                deviceEulerAngles = new Vector3d();
149:                deviceTranslateValues = new Vector3d();
150:                initialPosOrient = new Transform3D();
151:                PositionOrientation = new float[6];
152:                ButtonArray = new int[1];
153:                oldMatrix = new Matrix3d();
154:                newMatrix = new Matrix3d();
155:                tmpMatrix = new Matrix3d();
156:                yawMat = new Matrix3d();
157:                pitchMat = new Matrix3d();
158:                rollMat = new Matrix3d();
159:                oldTransform = new Transform3D();
160:                oldLocation = new Vector3d();
161:                newTransform = new Transform3D();
162:                newLocation = new Vector3d();
163:                tmpTransform = new Transform3D();
164:                tmpVector = new Vector3d();
165:
166:                //view.addInputDevice(this);
167:            }
168:
169:            /**
170:             * Construct a new SharedMemoryLogitechTracker with a hand tracker
171:             * @param view the view object
172:             * @param masterFilename the SharedMemoryLogitech's master port device name
173:             * @paran slaveFilename the SharedMemoryLogitech's slave port device name
174:             * @param mode the mode of access one of POLLED or STREAMING
175:             * @param sensorCount the number of sensors associated with this sharedMemoryLogitech
176:             * @param buttonCount the number of buttons associated with each sensor
177:             */
178:            public JavaOneLogitechTracker(View view, String masterFilename,
179:                    String slaveFilename, int mode, int sensorCount,
180:                    int buttonCount, boolean useGlasses) {
181:                this .super (view, masterFilename, mode, sensorCount, buttonCount);
182:                this .useGlasses = useGlasses;
183:                this .slaveFilename = slaveFilename;
184:                this .view = view;
185:                // OBSOLETE: view.addInputDevice(this);
186:            }
187:
188:            native int StartUp(String filename, boolean glasses);
189:
190:            native int ProcessStream(float PosOrient[], int Buttons[]);
191:
192:            /**
193:             * Code to initialize the device
194:             * @param deviceFilename
195:             */
196:            public boolean initialize() {
197:                return this .initialize(19200);
198:            }
199:
200:            /**
201:             * Initializes the SharedMemoryLogitech deviceFilename by opening the
202:             * device and sending the SharedMemoryLogitech the initialization information.
203:             * @param deviceFilename the SharedMemoryLogitech's deviceFilename
204:             * @param baudRate the speed we want the SharedMemoryLogitech to run at
205:             */
206:            public boolean initialize(int baudRate) {
207:                //	if (processingMode == STREAMING) {
208:                return (0 == this .StartUp("", useGlasses));
209:                //	}
210:                //System.out.println("Polling not supported");
211:                //initialPosOrient.setIdentity();
212:                //return false;
213:            }
214:
215:            /**
216:             * Code to set the device's current position and orientation as the devices
217:             * nominal position and orientation(establish its reference frame relative
218:             * to the "Tracker base" reference frame).
219:             */
220:            public void setNominalPositionAndOrientation() {
221:
222:                Transform3D BaseTransform = new Transform3D();
223:                //(sensors[currentSensor].getCurrentSensorRead()).get(BaseTransform);
224:                //System.out.println("Here it is\n" + BaseTransform);
225:                /*
226:                 Transform3D translation = new Transform3D();
227:                 translation.setZero();
228:                 //double eyeDist = 1.0 / Math.tan(view.getFieldOfView() / 2.0);
229:                 //eyeDist += 3.0;
230:                 double eyeDist = 5.4;
231:                 translation.setTranslation(new Vector3d(0.0,0.0,eyeDist));
232:                 BaseTransform.add(translation);
233:                 */
234:                //initialPosOrient.invert(BaseTransform);
235:                //Buttons = 0;
236:                // actually, we should get the last reading to do this or it
237:                // might mess up prediction
238:                this .ProcessStream(PositionOrientation, ButtonArray);
239:                tmpVector.set(PositionOrientation[0], PositionOrientation[1],
240:                        PositionOrientation[2]);
241:                newTransform.setTranslation(tmpVector);
242:                setMatrixFromValues(PositionOrientation, newMatrix);
243:                newTransform.setRotationScale(newMatrix);
244:                initialPosOrient.invert(newTransform);
245:                if (headTrackingEnabled == false) {
246:                    view.setTrackingEnable(true);
247:                    headTrackingEnabled = true;
248:                }
249:            }
250:
251:            /**
252:             * Code to poll and then process the input from a sharedMemoryLogitech.
253:             */
254:            public void pollAndProcessInput() {
255:                processStreamInput();
256:                //System.out.println("pollAndProcessInput: entered. not supported");
257:            }
258:
259:            /**
260:             * Code to process the device's streaming input.
261:             */
262:            public void processStreamInput() {
263:                long time;
264:                this .ProcessStream(PositionOrientation, ButtonArray);
265:                time = System.currentTimeMillis();
266:                tmpVector.set(PositionOrientation[0], PositionOrientation[1],
267:                        PositionOrientation[2]);
268:                newTransform.setTranslation(tmpVector);
269:                setMatrixFromValues(PositionOrientation, newMatrix);
270:                newTransform.setRotationScale(newMatrix);
271:                tmpTransform.mul(initialPosOrient, newTransform);
272:                sensors[currentSensor].setNextSensorRead(time, tmpTransform,
273:                        ButtonArray);
274:            }
275:
276:            /**
277:             * Code to construct a delta Matrix from SharedMemoryLogitech inputs
278:             */
279:            void setMatrixFromValues(float posOrient[], Matrix3d Delta) {
280:
281:                // Note that pitch, yaw, and roll are cumulative    
282:                pitchMat.rotX(-posOrient[3]);
283:                yawMat.rotY(-posOrient[4]);
284:                rollMat.rotZ(-posOrient[5]);
285:
286:                Delta.mul(yawMat, pitchMat);
287:                Delta.mul(rollMat);
288:
289:            }
290:
291:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.