001: /*
002: * $RCSfile: SensorMovementBehavior.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.behaviors;
046:
047: import javax.media.j3d.*;
048: import java.util.*;
049: import java.awt.Event;
050: import java.awt.Point;
051: import java.awt.AWTEvent;
052: import java.awt.event.KeyEvent;
053: import java.awt.event.MouseEvent;
054: import javax.vecmath.*;
055:
056: /**
057: * SensorMovementBehavior uses the specified sensor to update the
058: * Viewplatform's Transform
059: *
060: *
061: */
062:
063: public class SensorMovementBehavior extends Behavior {
064:
065: TransformGroup tgroup;
066: WakeupCriterion[] conditions;
067:
068: Point3d currentPosn; // Translation
069:
070: View view;
071: PhysicalEnvironment physicalEnv;
072: int sensorIndex;
073:
074: public SensorMovementBehavior(View view, int sensorIndex,
075: TransformGroup tGroup) {
076: super ();
077: this .tgroup = tGroup;
078: this .sensorIndex = sensorIndex;
079: this .view = view;
080: physicalEnv = view.getPhysicalEnvironment();
081: }
082:
083: public void initialize() {
084: initialize(new BoundingSphere(new Point3d(0.0, 0.0, 0.0),
085: 1000.0), new Point3d(0.0, 0.0, 0.0));
086: }
087:
088: WakeupOr w = null;
089:
090: public void initialize(BoundingSphere bounds, Point3d currentPosn) {
091:
092: conditions = new WakeupCriterion[1];
093: //conditions[0] = new WakeupOnAWTEvent( Event.KEY_PRESS );
094: //conditions[1] = new WakeupOnElapsedFrames( 0 );
095: conditions[0] = new WakeupOnElapsedFrames(0);
096:
097: w = new WakeupOr(conditions);
098: wakeupOn(w);
099: setSchedulingBounds(bounds);
100:
101: // (this.currentPosn).set(currentPosn);
102: }
103:
104: public void processStimulus(Enumeration criteria) {
105:
106: Transform3D orig = new Transform3D();
107: WakeupCriterion wakeup;
108: AWTEvent[] evt = null;
109: boolean timer = false;
110:
111: /*
112: while( criteria.hasMoreElements() ) {
113: wakeup = (WakeupCriterion)criteria.nextElement();
114: if (wakeup instanceof WakeupOnAWTEvent)
115: evt=((WakeupOnAWTEvent)wakeup).getAWTEvent();
116: if (wakeup instanceof WakeupOnElapsedFrames) timer=true;
117: }
118:
119:
120: if (evt!=null && evt[0] instanceof KeyEvent)
121: processKeyEvent( (KeyEvent)evt[0] );
122: */
123: /*
124: if (evt!=null && evt[0] instanceof MouseEvent) {
125: processMouseEvent( (MouseEvent)evt[0] );
126: timer = true;
127: }
128: */
129:
130: (physicalEnv.getSensor(sensorIndex)).getRead(orig);
131: /*
132: System.out.println("New matrix");
133: System.out.println(orig);
134: */
135: tgroup.setTransform(orig);
136: wakeupOn(w);
137: }
138:
139: /*
140: public void processMouseEvent( MouseEvent evt ) {
141: double x, y;
142:
143: if (evt.getID()!=MouseEvent.MOUSE_MOVED) return;
144:
145: mousePosn = evt.getPoint();
146:
147: x = mousePosn.x - mouseCenter.x;
148: y = mousePosn.y - mouseCenter.y;
149:
150: yawAngleDelta = -x/MOUSE_MOVEMENT * MAX_ANGLE*Math.abs(x);
151:
152: if (evt.isShiftDown())
153: pitchAngleDelta = -y/MOUSE_MOVEMENT * MAX_ANGLE*Math.abs(y);
154: else
155: velocity = y/MOUSE_MOVEMENT * ACCELERATION_FACTOR*Math.abs(y);
156:
157: }
158: */
159:
160: private void processKeyEvent(KeyEvent evt) {
161:
162: int key;
163:
164: key = evt.getKeyCode();
165:
166: if (key == KeyEvent.VK_UP) {
167: /* */
168: } else if (key == KeyEvent.VK_DOWN) {
169: /* */
170: } else if (key == KeyEvent.VK_LEFT) {
171: /* */
172: } else if (key == KeyEvent.VK_RIGHT) {
173: /* */
174: } else if (key == KeyEvent.VK_S) {
175: /* set to initial */
176: } else if (key == KeyEvent.VK_C) {
177: ((physicalEnv.getSensor(sensorIndex)).getDevice())
178: .setNominalPositionAndOrientation();
179: }
180:
181: }
182:
183: }
|