001: /*
002: * $RCSfile: InvertedSensorMovementBehavior.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: * InvertSensorMovementBehavior uses the specified sensor to update the
058: * Viewplatform's Transform
059: *
060: *
061: */
062:
063: public class InvertedSensorMovementBehavior 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 InvertedSensorMovementBehavior(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(
085: new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 700.0),
086: new Point3d(600, 20, 600));
087: }
088:
089: public void initialize(BoundingSphere bounds, Point3d currentPosn) {
090:
091: conditions = new WakeupCriterion[2];
092: conditions[0] = new WakeupOnAWTEvent(Event.KEY_PRESS);
093: conditions[1] = new WakeupOnElapsedFrames(0);
094:
095: wakeupOn(new WakeupOr(conditions));
096: setSchedulingBounds(bounds);
097:
098: // (this.currentPosn).set(currentPosn);
099: }
100:
101: public void processStimulus(Enumeration criteria) {
102:
103: Transform3D orig = new Transform3D();
104: WakeupCriterion wakeup;
105: AWTEvent[] evt = null;
106: boolean timer = false;
107:
108: while (criteria.hasMoreElements()) {
109: wakeup = (WakeupCriterion) criteria.nextElement();
110: if (wakeup instanceof WakeupOnAWTEvent)
111: evt = ((WakeupOnAWTEvent) wakeup).getAWTEvent();
112: if (wakeup instanceof WakeupOnElapsedFrames)
113: timer = true;
114: }
115:
116: if (evt != null && evt[0] instanceof KeyEvent)
117: processKeyEvent((KeyEvent) evt[0]);
118: /*
119: if (evt!=null && evt[0] instanceof MouseEvent) {
120: processMouseEvent( (MouseEvent)evt[0] );
121: timer = true;
122: }
123: */
124:
125: (physicalEnv.getSensor(sensorIndex)).getRead(orig);
126: /*
127: System.out.println("New matrix");
128: System.out.println(orig);
129: */
130: tgroup.setTransform(orig);
131:
132: wakeupOn(new WakeupOr(conditions));
133: }
134:
135: /*
136: public void processMouseEvent( MouseEvent evt ) {
137: double x, y;
138:
139: if (evt.getID()!=MouseEvent.MOUSE_MOVED) return;
140:
141: mousePosn = evt.getPoint();
142:
143: x = mousePosn.x - mouseCenter.x;
144: y = mousePosn.y - mouseCenter.y;
145:
146: yawAngleDelta = -x/MOUSE_MOVEMENT * MAX_ANGLE*Math.abs(x);
147:
148: if (evt.isShiftDown())
149: pitchAngleDelta = -y/MOUSE_MOVEMENT * MAX_ANGLE*Math.abs(y);
150: else
151: velocity = y/MOUSE_MOVEMENT * ACCELERATION_FACTOR*Math.abs(y);
152:
153: }
154: */
155:
156: private void processKeyEvent(KeyEvent evt) {
157:
158: int key;
159:
160: key = evt.getKeyCode();
161:
162: if (key == KeyEvent.VK_UP) {
163: /* */
164: } else if (key == KeyEvent.VK_DOWN) {
165: /* */
166: } else if (key == KeyEvent.VK_LEFT) {
167: /* */
168: } else if (key == KeyEvent.VK_RIGHT) {
169: /* */
170: } else if (key == KeyEvent.VK_S) {
171: /* set to initial */
172: } else if (key == KeyEvent.VK_C) {
173: ((physicalEnv.getSensor(sensorIndex)).getDevice())
174: .setNominalPositionAndOrientation();
175: }
176:
177: }
178:
179: }
|