001: /*
002: * $RCSfile: SharedMemoryPushTracker.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:20 $
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.*; // Note the following is necessary only for the sleep calls.
050: import java.lang.Thread;
051:
052: /**
053: * NOTE: this class is very much out of date. It is using deprecated
054: * and unimplemented 1.1 API constants (POLLED and STREAMING) that are
055: * now gone in 1.2. The offending lines have been commented out
056: * and marked with an "OBSOLETE:" comment.
057: *<p>
058: *
059: * The SharedMemoryPushTracker Class defines the code to make a sharedMemoryPush input
060: * device work correclty
061: *
062: * @version 1.5, 99/09/15 13:47:24
063: * @author Henry Sowizral
064: */
065: public class SharedMemoryPushTracker extends Tracker {
066:
067: // This device's slave filename
068: String slaveFilename;
069:
070: // Current Sensor Read (last one we generated)
071: SensorRead currentRead;
072:
073: // Next SensorRead (the one we're now generating)
074: SensorRead nextRead;
075:
076: // The current sensor
077: int currentSensor = 0;
078:
079: // Holds a sensor's Euler Angles
080: Vector3d deviceEulerAngles = new Vector3d();
081:
082: // Holds the sensor's current Position
083: Vector3d deviceTranslateValues = new Vector3d();
084:
085: // The number of sensors associated with this device.
086: static final int SensorCount = 8;
087:
088: // The number of buttons associated with this device.
089: static final int ButtonCount = 5;
090:
091: // The initial position and orientation
092: Transform3D initialPosOrient = new Transform3D();
093:
094: static float PositionOrientation[] = new float[6];
095: static int[] ButtonArray = new int[1];
096:
097: /**
098: * Construct a new SharedMemoryPushTracker
099: * @param view the view object
100: * @paran deviceFilename the SharedMemoryPush's devide name
101: * @param mode the mode of access one of POLLED or STREAMING
102: * @param sensorCount the number of sensors associated with this sharedMemoryPush
103: * @param buttonCount the number of buttons associated with each sensor
104: */
105: public SharedMemoryPushTracker(View view, String deviceFilename,
106: int mode, int sensorCount, int buttonCount) {
107: this .super (view, deviceFilename, mode, sensorCount, buttonCount);
108: }
109:
110: /**
111: * Construct a new SharedMemoryPushTracker with a hand tracker
112: * @param view the view object
113: * @param masterFilename the SharedMemoryPush's master port device name
114: * @paran slaveFilename the SharedMemoryPush's slave port device name
115: * @param mode the mode of access one of POLLED or STREAMING
116: * @param sensorCount the number of sensors associated with this sharedMemoryPush
117: * @param buttonCount the number of buttons associated with each sensor
118: */
119: public SharedMemoryPushTracker(View view, String masterFilename,
120: String slaveFilename, int mode, int sensorCount,
121: int buttonCount) {
122: this .super (view, masterFilename, mode, sensorCount, buttonCount);
123: this .slaveFilename = slaveFilename;
124: }
125:
126: native int StartUp(String filename);
127:
128: native int ProcessStream(int sensorIndex, float PosOrient[],
129: int Buttons[]);
130:
131: /**
132: * Code to initialize the device
133: * @param deviceFilename
134: */
135: public boolean initialize() {
136: return this .initialize(19200);
137: }
138:
139: /**
140: * Initializes the SharedMemoryPush deviceFilename by opening the
141: * device and sending the SharedMemoryPush the initialization information.
142: * @param deviceFilename the SharedMemoryPush's deviceFilename
143: * @param baudRate the speed we want the SharedMemoryPush to run at
144: */
145: public boolean initialize(int baudRate) {
146: /* OBSOLETE:
147: if (processingMode == STREAMING) {
148: return (0 == this.StartUp(""));
149: } else if (processingMode == POLLED) {
150: return (0 == this.StartUp("")); // IEM
151: }
152: */
153: System.out.println("Polling not supported");
154: initialPosOrient.setIdentity();
155: return false;
156: }
157:
158: /**
159: * Code to set the device's current position and orientation as the devices
160: * nominal position and orientation(establish its reference frame relative
161: * to the "Tracker base" reference frame).
162: */
163: public void setNominalPositionAndOrientation() {
164:
165: Transform3D BaseTransform = new Transform3D();
166:
167: (sensors[currentSensor].getCurrentSensorRead())
168: .get(BaseTransform);
169: initialPosOrient.invert(BaseTransform);
170: System.out.println("New PositionOrientation transform");
171: System.out.println(initialPosOrient);
172: ButtonArray[0] = 0;
173: }
174:
175: /**
176: * Code to poll and then process the input from a sharedMemoryPush.
177: */
178: public void pollAndProcessInput() {
179: System.out
180: .println("pollAndProcessInput: entered. not supported");
181: }
182:
183: Matrix3d oldMatrix = new Matrix3d();
184: Matrix3d newMatrix = new Matrix3d();
185: Matrix3d tmpMatrix = new Matrix3d();
186:
187: Transform3D oldTransform = new Transform3D();
188: Vector3d oldLocation = new Vector3d();
189:
190: Transform3D newTransform = new Transform3D();
191: Vector3d newLocation = new Vector3d();
192:
193: Transform3D tmpTransform = new Transform3D();
194:
195: Vector3d tmpVector = new Vector3d();
196:
197: /**
198: * Code to process the device's streaming input.
199: */
200: public void processStreamInput() {
201: long time;
202:
203: this .ProcessStream(0, PositionOrientation, ButtonArray);
204: /*
205: System.out.println("Shared Memory Push PositionOrientation: "
206: + PositionOrientation[0] +
207: " " + PositionOrientation[0] +
208: " " + PositionOrientation[1] +
209: " " + PositionOrientation[2] +
210: " " + PositionOrientation[3] +
211: " " + PositionOrientation[4] +
212: " " + PositionOrientation[5]);
213: */
214: time = System.currentTimeMillis();
215:
216: tmpVector.set(PositionOrientation[0], PositionOrientation[1],
217: PositionOrientation[2]);
218: newTransform.setTranslation(tmpVector);
219:
220: setMatrixFromValues(PositionOrientation, newMatrix);
221: newTransform.setRotationScale(newMatrix);
222:
223: tmpTransform.mul(initialPosOrient, newTransform);
224: sensors[currentSensor].setNextSensorRead(time, tmpTransform,
225: ButtonArray);
226:
227: }
228:
229: /**
230: * Code to construct a delta Matrix from SharedMemoryPush inputs
231: */
232: void setMatrixFromValues(float posOrient[], Matrix3d Delta) {
233: double sina, sinb, sinc, cosa, cosb, cosc;
234:
235: sina = Math.sin(posOrient[3]);
236: sinb = Math.sin(posOrient[4]);
237: sinc = Math.sin(posOrient[5]);
238:
239: cosa = Math.cos(posOrient[3]);
240: cosb = Math.cos(posOrient[4]);
241: cosc = Math.cos(posOrient[5]);
242:
243: Delta.m00 = cosb * cosc;
244: Delta.m01 = cosb * sinc;
245: Delta.m02 = -sinb;
246:
247: Delta.m10 = -(cosa * sinc) + (sina * sinb * sinc);
248: Delta.m11 = (cosa * cosc) + (sina * sinb * sinc);
249: Delta.m12 = sina * cosb;
250:
251: Delta.m20 = (sina * sinc) + (cosa * sinb * cosc);
252: Delta.m21 = -(sina * cosc) + (cosa * sinb * sinc);
253: Delta.m22 = cosa * cosb;
254: }
255:
256: }
|