001: /*
002: * $RCSfile: ConfigPhysicalEnvironment.java,v $
003: *
004: * Copyright (c) 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.4 $
041: * $Date: 2007/02/09 17:20:43 $
042: * $State: Exp $
043: */
044:
045: package com.sun.j3d.utils.universe;
046:
047: import javax.media.j3d.*;
048: import javax.vecmath.*;
049: import java.util.*;
050:
051: class ConfigPhysicalEnvironment extends ConfigObject {
052:
053: /**
054: * The corresponding J3D core PhysicalEnvironment instance.
055: */
056: PhysicalEnvironment j3dPhysicalEnvironment = null;
057:
058: /**
059: * The coexistence to tracker base matrix.
060: */
061: Matrix4d coexistenceToTrackerBase = null;
062:
063: // All other configurable attributes.
064: private ConfigSensor headTracker = null;
065: private ArrayList inputDevices = new ArrayList();
066: private int coexistenceCenterInPworldPolicy = View.NOMINAL_SCREEN;
067:
068: /**
069: * Overrides initialize() to do nothing.
070: */
071: protected void initialize(ConfigCommand command) {
072: }
073:
074: /**
075: * Handles the commands
076: * (PhysicalEnvironmentAttribute {instance} {attrName} {attrValue}) and
077: * (PhysicalEnvironmentProperty {instance} {attrName} {attrValue}).
078: *
079: * @param command the command that invoked this method
080: */
081: protected void setProperty(ConfigCommand command) {
082: Object val;
083: Object[] argv = command.argv;
084: int argc = command.argc;
085: String sval, prop;
086:
087: if (argc != 4) {
088: syntaxError("Incorrect number of arguments to "
089: + command.commandName);
090: }
091:
092: if (!isName(argv[1])) {
093: syntaxError("The first argument to " + command.commandName
094: + " must be a name");
095: }
096:
097: if (!isName(argv[2])) {
098: syntaxError("The second argument to " + command.commandName
099: + " must be a property name");
100: }
101:
102: prop = (String) argv[2];
103: val = argv[3];
104:
105: if (prop.equals("CoexistenceCenterInPworldPolicy")) {
106: if (!(val instanceof String))
107: syntaxError("CoexistenceCenterInPworldPolicy must be string");
108:
109: sval = (String) val;
110: if (sval.equals("NOMINAL_HEAD"))
111: coexistenceCenterInPworldPolicy = View.NOMINAL_HEAD;
112: else if (sval.equals("NOMINAL_SCREEN"))
113: coexistenceCenterInPworldPolicy = View.NOMINAL_SCREEN;
114: else if (sval.equals("NOMINAL_FEET"))
115: coexistenceCenterInPworldPolicy = View.NOMINAL_FEET;
116: else
117: syntaxError("Illegal value " + sval
118: + " for CoexistenceCenterInPworldPolicy");
119: } else if (prop.equals("CoexistenceToTrackerBase")) {
120: if (val instanceof Matrix4d)
121: coexistenceToTrackerBase = (Matrix4d) val;
122: else
123: syntaxError("CoexistenceToTrackerBase must be a Matrix4d");
124: } else if (prop.equals("InputDevice")) {
125: if (!(val instanceof String))
126: syntaxError("InputDevice must be a name");
127:
128: sval = (String) val;
129: inputDevices.add(configContainer.findConfigObject("Device",
130: sval));
131: } else if (prop.equals("HeadTracker")) {
132: if (!(val instanceof String))
133: syntaxError("HeadTracker must be a Sensor name");
134:
135: sval = (String) val;
136: headTracker = (ConfigSensor) configContainer
137: .findConfigObject("Sensor", sval);
138: } else {
139: syntaxError("Unknown " + command.commandName + " \"" + prop
140: + "\"");
141: }
142: }
143:
144: /**
145: * Create a core Java 3D PhysicalEnvironment instance using the attributes
146: * gathered by this object.
147: */
148: PhysicalEnvironment createJ3dPhysicalEnvironment() {
149: j3dPhysicalEnvironment = new PhysicalEnvironment();
150:
151: j3dPhysicalEnvironment
152: .setCoexistenceCenterInPworldPolicy(coexistenceCenterInPworldPolicy);
153:
154: if (coexistenceToTrackerBase != null)
155: j3dPhysicalEnvironment
156: .setCoexistenceToTrackerBase(new Transform3D(
157: coexistenceToTrackerBase));
158:
159: return j3dPhysicalEnvironment;
160: }
161:
162: /**
163: * Process the devices associated with the PhysicalEnvironment.
164: */
165: void processDevices() {
166: for (int j = 0; j < inputDevices.size(); j++) {
167: ConfigDevice configDevice = (ConfigDevice) inputDevices
168: .get(j);
169: InputDevice device = configDevice.j3dInputDevice;
170: j3dPhysicalEnvironment.addInputDevice(device);
171: }
172:
173: if (headTracker != null) {
174: j3dPhysicalEnvironment.setHeadIndex(0);
175: j3dPhysicalEnvironment.setSensor(0, headTracker.j3dSensor);
176: }
177: }
178: }
|