001: /*
002: * $RCSfile: TouchSensor.java,v $
003: *
004: * @(#)TouchSensor.java 1.28 99/03/10 18:02:52
005: *
006: * Copyright (c) 1996-1998 Sun Microsystems, Inc. All Rights Reserved.
007: *
008: * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
009: * modify and redistribute this software in source and binary code form,
010: * provided that i) this copyright notice and license appear on all copies of
011: * the software; and ii) Licensee does not utilize the software in a manner
012: * which is disparaging to Sun.
013: *
014: * This software is provided "AS IS," without a warranty of any kind. ALL
015: * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
016: * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
017: * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
018: * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
019: * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
020: * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
021: * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
022: * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
023: * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
024: * POSSIBILITY OF SUCH DAMAGES.
025: *
026: * This software is not designed or intended for use in on-line control of
027: * aircraft, air traffic, aircraft navigation or aircraft communications; or in
028: * the design, construction, operation or maintenance of any nuclear
029: * facility. Licensee represents and warrants that it will not use or
030: * redistribute the Software for such purposes.
031: *
032: * $Revision: 1.2 $
033: * $Date: 2005/02/03 23:07:03 $
034: * $State: Exp $
035: */
036: /*
037: * @Author: Rick Goldberg
038: *
039: */
040: package org.jdesktop.j3d.loaders.vrml97.impl;
041:
042: import java.util.Vector;
043:
044: /** Description of the Class */
045: public class TouchSensor extends Node implements VrmlSensor {
046:
047: // exposedField
048: SFBool enabled;
049:
050: // Event outs
051: SFVec3f hitNormal;
052: SFVec3f hitPoint;
053: SFVec2f hitTexCoord;
054: SFBool isActive;
055: SFBool isOver;
056: SFTime touchTime;
057:
058: // Scene graph reference
059: javax.media.j3d.Node parentImpl;
060:
061: /**
062: *Constructor for the TouchSensor object
063: *
064: *@param loader Description of the Parameter
065: */
066: public TouchSensor(Loader loader) {
067: super (loader);
068: enabled = new SFBool(true);
069: hitNormal = new SFVec3f();
070: hitPoint = new SFVec3f();
071: hitTexCoord = new SFVec2f();
072: isActive = new SFBool(true);
073: isOver = new SFBool(false);
074: touchTime = new SFTime(0.0);
075: loader.addTouchSensor(this );
076: initFields();
077: }
078:
079: /**
080: *Constructor for the TouchSensor object
081: *
082: *@param loader Description of the Parameter
083: *@param enabled Description of the Parameter
084: */
085: TouchSensor(Loader loader, SFBool enabled) {
086: super (loader);
087: this .enabled = enabled;
088: hitNormal = new SFVec3f();
089: hitPoint = new SFVec3f();
090: hitTexCoord = new SFVec2f();
091: isActive = new SFBool(true);
092: isOver = new SFBool(false);
093: touchTime = new SFTime(0.0);
094: loader.addTouchSensor(this );
095: initFields();
096: }
097:
098: /** Description of the Method */
099: public void initImpl() {
100: loader.addTouchSensor(this );
101: }
102:
103: /**
104: * Description of the Method
105: *
106: *@param parentImpl Description of the Parameter
107: */
108: void updateParent(javax.media.j3d.Node parentImpl) {
109: if (loader.debug) {
110: System.out.println("TouchSensor.updateParent()");
111: }
112: if (loader.loaderMode > Loader.LOAD_STATIC) {
113: if (loader.debug) {
114: System.out
115: .println("Touch Sensor enabling PICK_REPORTING on "
116: + " parent " + parentImpl);
117: }
118: Vector v = (Vector) (parentImpl.getUserData());
119: if (v == null) {
120: v = new Vector();
121: parentImpl.setUserData(v);
122: if (loader.debug) {
123: System.out.println("Touch Sensor parent: "
124: + parentImpl
125: + " had no user data, added vector:" + v);
126: }
127: }
128: v.addElement(this );
129: parentImpl
130: .setCapability(javax.media.j3d.Node.ENABLE_PICK_REPORTING);
131: parentImpl
132: .setCapability(javax.media.j3d.Node.ALLOW_BOUNDS_READ);
133: parentImpl
134: .setCapability(javax.media.j3d.Node.ALLOW_LOCAL_TO_VWORLD_READ);
135: parentImpl.setPickable(true);
136: }
137: }
138:
139: /**
140: * Description of the Method
141: *
142: *@param eventInName Description of the Parameter
143: *@param time Description of the Parameter
144: */
145: public void notifyMethod(String eventInName, double time) {
146: if (eventInName.equals("enabled")) {
147: } else if (eventInName.equals("route_enabled")) {
148: // No-op
149: } else {
150: System.err.println("TouchSensor: unknown eventInName "
151: + eventInName);
152: }
153: }
154:
155: /**
156: * Description of the Method
157: *
158: *@return Description of the Return Value
159: */
160: public Object clone() {
161: TouchSensor t = new TouchSensor(loader, (SFBool) enabled
162: .clone());
163: return t;
164: }
165:
166: /**
167: * Gets the type attribute of the TouchSensor object
168: *
169: *@return The type value
170: */
171: public String getType() {
172: return "TouchSensor";
173: }
174:
175: /** Description of the Method */
176: void initFields() {
177: enabled.init(this , FieldSpec, Field.EXPOSED_FIELD, "enabled");
178: hitNormal.init(this , FieldSpec, Field.EVENT_OUT, "hitNormal");
179: hitPoint.init(this , FieldSpec, Field.EVENT_OUT, "hitPoint");
180: hitTexCoord.init(this , FieldSpec, Field.EVENT_OUT,
181: "hitTexCoord");
182: isActive.init(this , FieldSpec, Field.EVENT_OUT, "isActive");
183: isOver.init(this , FieldSpec, Field.EVENT_OUT, "isOver");
184: touchTime.init(this , FieldSpec, Field.EVENT_OUT, "touchTime");
185: }
186:
187: }
|