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