001: /*
002: * $RCSfile: SharedMemoryLogitechTracker.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: * and unimplemented 1.1 API constants (POLLED and STREAMING) that are
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.13, 99/09/15 13:47:21
062: * @author Henry Sowizral
063: */
064: public class SharedMemoryLogitechTracker extends Tracker {
065:
066: // This device's slave filename
067: String slaveFilename;
068:
069: // Current Sensor Read (last one we generated)
070: SensorRead currentRead;
071:
072: // Next SensorRead (the one we're now generating)
073: SensorRead nextRead;
074:
075: // The current sensor
076: int currentSensor = 0;
077:
078: // Holds a sensor's Euler Angles
079: Vector3d deviceEulerAngles = new Vector3d();
080:
081: // Holds the sensor's current Position
082: Vector3d deviceTranslateValues = new Vector3d();
083:
084: // The number of sensors associated with this device.
085: static final int SensorCount = 8;
086:
087: // The number of buttons associated with this device.
088: static final int ButtonCount = 5;
089:
090: // The initial position and orientation
091: Transform3D initialPosOrient = new Transform3D();
092:
093: static float PositionOrientation[] = new float[6];
094: static int[] ButtonArray = new int[1];
095:
096: Matrix3d oldMatrix = new Matrix3d();
097: Matrix3d newMatrix = new Matrix3d();
098: Matrix3d tmpMatrix = new Matrix3d();
099:
100: Matrix3d yawMat = new Matrix3d();
101: Matrix3d pitchMat = new Matrix3d();
102: Matrix3d rollMat = new Matrix3d();
103:
104: Transform3D oldTransform = new Transform3D();
105: Vector3d oldLocation = new Vector3d();
106:
107: Transform3D newTransform = new Transform3D();
108: Vector3d newLocation = new Vector3d();
109:
110: Transform3D tmpTransform = new Transform3D();
111:
112: Vector3d tmpVector = new Vector3d();
113:
114: boolean useGlasses = false;
115:
116: /**
117: * Construct a new SharedMemoryLogitechTracker
118: * @param view the view object
119: * @paran deviceFilename the SharedMemoryLogitech's devide name
120: * @param mode the mode of access one of POLLED or STREAMING
121: * @param sensorCount the number of sensors associated with this sharedMemoryLogitech
122: * @param buttonCount the number of buttons associated with each sensor
123: */
124: public SharedMemoryLogitechTracker(View view,
125: String deviceFilename, int mode, int sensorCount,
126: int buttonCount, boolean useGlasses) {
127: this .super (view, deviceFilename, mode, sensorCount, buttonCount);
128: this .useGlasses = useGlasses;
129: }
130:
131: /**
132: * Construct a new SharedMemoryLogitechTracker
133: * @param sensorCount the number of sensors associated with this
134: * sharedMemoryLogitech
135: * @param buttonCount the number of buttons associated with each sensor
136: */
137: public SharedMemoryLogitechTracker(int sensorCount,
138: int buttonCount, boolean useGlasses) {
139: this .super (sensorCount, buttonCount);
140: this .useGlasses = useGlasses;
141: }
142:
143: /**
144: * Construct a new SharedMemoryLogitechTracker with a hand tracker
145: * @param view the view object
146: * @param masterFilename the SharedMemoryLogitech's master port device name
147: * @paran slaveFilename the SharedMemoryLogitech's slave port device name
148: * @param mode the mode of access one of POLLED or STREAMING
149: * @param sensorCount the number of sensors associated with this sharedMemoryLogitech
150: * @param buttonCount the number of buttons associated with each sensor
151: */
152: public SharedMemoryLogitechTracker(View view,
153: String masterFilename, String slaveFilename, int mode,
154: int sensorCount, int buttonCount, boolean useGlasses) {
155: this .super (view, masterFilename, mode, sensorCount, buttonCount);
156: this .useGlasses = useGlasses;
157: this .slaveFilename = slaveFilename;
158: }
159:
160: native int StartUp(String filename, boolean glasses);
161:
162: native int ProcessStream(float PosOrient[], int Buttons[]);
163:
164: /**
165: * Code to initialize the device
166: * @param deviceFilename
167: */
168: public boolean initialize() {
169: return this .initialize(19200);
170: }
171:
172: /**
173: * Initializes the SharedMemoryLogitech deviceFilename by opening the
174: * device and sending the SharedMemoryLogitech the initialization information.
175: * @param deviceFilename the SharedMemoryLogitech's deviceFilename
176: * @param baudRate the speed we want the SharedMemoryLogitech to run at
177: */
178: public boolean initialize(int baudRate) {
179: /* OBSOLETE:
180: if (processingMode == STREAMING) {
181: return (0 == this.StartUp("", useGlasses));
182: }
183: */
184: System.out.println("Polling not supported");
185: initialPosOrient.setIdentity();
186: return false;
187: }
188:
189: /**
190: * Code to set the device's current position and orientation as the devices
191: * nominal position and orientation(establish its reference frame relative
192: * to the "Tracker base" reference frame).
193: */
194: public void setNominalPositionAndOrientation() {
195:
196: Transform3D BaseTransform = new Transform3D();
197: //(sensors[currentSensor].getCurrentSensorRead()).get(BaseTransform);
198: //System.out.println("Here it is\n" + BaseTransform);
199: /*
200: Transform3D translation = new Transform3D();
201: translation.setZero();
202: //double eyeDist = 1.0 / Math.tan(view.getFieldOfView() / 2.0);
203: //eyeDist += 3.0;
204: double eyeDist = 5.4;
205: translation.setTranslation(new Vector3d(0.0,0.0,eyeDist));
206: BaseTransform.add(translation);
207: */
208: //initialPosOrient.invert(BaseTransform);
209: //Buttons = 0;
210: // actually, we should get the last reading to do this or it
211: // might mess up prediction
212: this .ProcessStream(PositionOrientation, ButtonArray);
213: tmpVector.set(PositionOrientation[0], PositionOrientation[1],
214: PositionOrientation[2]);
215: newTransform.setTranslation(tmpVector);
216: setMatrixFromValues(PositionOrientation, newMatrix);
217: newTransform.setRotationScale(newMatrix);
218: initialPosOrient.invert(newTransform);
219: }
220:
221: /**
222: * Code to poll and then process the input from a sharedMemoryLogitech.
223: */
224: public void pollAndProcessInput() {
225: System.out
226: .println("pollAndProcessInput: entered. not supported");
227: }
228:
229: /**
230: * Code to process the device's streaming input.
231: */
232: public void processStreamInput() {
233: long time;
234:
235: this .ProcessStream(PositionOrientation, ButtonArray);
236: time = System.currentTimeMillis();
237: tmpVector.set(PositionOrientation[0], PositionOrientation[1],
238: PositionOrientation[2]);
239: newTransform.setTranslation(tmpVector);
240: setMatrixFromValues(PositionOrientation, newMatrix);
241: newTransform.setRotationScale(newMatrix);
242: tmpTransform.mul(initialPosOrient, newTransform);
243: sensors[currentSensor].setNextSensorRead(time, tmpTransform,
244: ButtonArray);
245: }
246:
247: /**
248: * Code to construct a delta Matrix from SharedMemoryLogitech inputs
249: */
250: void setMatrixFromValues(float posOrient[], Matrix3d Delta) {
251:
252: // Note that pitch, yaw, and roll are cumulative
253: pitchMat.rotX(-posOrient[3]);
254: yawMat.rotY(-posOrient[4]);
255: rollMat.rotZ(-posOrient[5]);
256:
257: Delta.mul(yawMat, pitchMat);
258: Delta.mul(rollMat);
259:
260: }
261:
262: }
|