001: /*
002: * $RCSfile: ConfigPhysicalBody.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 java.awt.event.*;
048: import java.lang.Integer;
049: import java.io.*;
050: import javax.media.j3d.*;
051: import javax.vecmath.*;
052: import java.util.*;
053:
054: class ConfigPhysicalBody extends ConfigObject {
055:
056: Point3d leftEyePosition = new Point3d(-0.033, 0.0, 0.0);
057: Point3d rightEyePosition = new Point3d(0.033, 0.0, 0.0);
058: double stereoEyeSeparation = Double.MAX_VALUE;
059:
060: Point3d leftEarPosition = new Point3d(-0.080, -0.030, 0.09);
061: Point3d rightEarPosition = new Point3d(0.080, -0.030, 0.09);
062:
063: double nominalEyeHeightFromGround = 1.68;
064: double nominalEyeOffsetFromNominalScreen = 0.4572;
065:
066: Matrix4d headToHeadTracker = new Matrix4d(1.0, 0.0, 0.0, 0.0, 0.0,
067: 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0);
068:
069: PhysicalBody j3dPhysicalBody;
070:
071: // Overridden to do nothing.
072: protected void initialize(ConfigCommand command) {
073: }
074:
075: protected void setProperty(ConfigCommand command) {
076: int argc = command.argc;
077: Object[] argv = command.argv;
078: String prop;
079: Object val;
080:
081: // Check that arg[1] and arg[2] are strings
082: if (argc != 4) {
083: syntaxError("Incorrect number of arguments to "
084: + command.commandName);
085: }
086:
087: if (!isName(argv[1])) {
088: syntaxError("The first argument to " + command.commandName
089: + " must be a name");
090: }
091:
092: if (!isName(argv[2])) {
093: syntaxError("The second argument to " + command.commandName
094: + " must be an property/attribute name");
095: }
096:
097: prop = (String) argv[2];
098: val = argv[3];
099:
100: if (prop.equals("StereoEyeSeparation")) {
101: if (!(val instanceof Double)) {
102: syntaxError("StereoEyeSeparation must be a number");
103: }
104: stereoEyeSeparation = ((Double) val).doubleValue();
105: } else if (prop.equals("LeftEyePosition")) {
106: if (!(val instanceof Point3d)) {
107: syntaxError("LeftEyePosition must be a point");
108: }
109: leftEyePosition = (Point3d) val;
110: } else if (prop.equals("RightEyePosition")) {
111: if (!(val instanceof Point3d)) {
112: syntaxError("RightEyePosition must be a point");
113: }
114: rightEyePosition = (Point3d) val;
115: } else if (prop.equals("LeftEarPosition")) {
116: if (!(val instanceof Point3d)) {
117: syntaxError("LeftEarPosition must be a point");
118: }
119: leftEarPosition = (Point3d) val;
120: } else if (prop.equals("RightEarPosition")) {
121: if (!(val instanceof Point3d)) {
122: syntaxError("RightEarPosition must be a point");
123: }
124: leftEarPosition = (Point3d) val;
125: } else if (prop.equals("NominalEyeHeightFromGround")) {
126: if (!(val instanceof Double)) {
127: syntaxError("NominalEyeHeightFromGround must be a number");
128: }
129: nominalEyeHeightFromGround = ((Double) val).doubleValue();
130: } else if (prop.equals("NominalEyeOffsetFromNominalScreen")) {
131: if (!(val instanceof Double)) {
132: syntaxError("NominalEyeOffsetFromNominalScreen "
133: + "must be a number");
134: }
135: nominalEyeOffsetFromNominalScreen = ((Double) val)
136: .doubleValue();
137: } else if (prop.equals("HeadToHeadTracker")) {
138: if (!(val instanceof Matrix4d)) {
139: syntaxError("HeadToHeadTracker must be a matrix");
140: }
141: headToHeadTracker = (Matrix4d) val;
142: } else {
143: syntaxError("Unknown " + command.commandName + " \"" + prop
144: + "\"");
145: }
146: }
147:
148: PhysicalBody createJ3dPhysicalBody() {
149: // Transfer all the information from the config version
150: if (stereoEyeSeparation < Double.MAX_VALUE) {
151: leftEyePosition.set(-stereoEyeSeparation / 2.0, 0.0, 0.0);
152: rightEyePosition.set(stereoEyeSeparation / 2.0, 0.0, 0.0);
153: }
154:
155: j3dPhysicalBody = new PhysicalBody(leftEyePosition,
156: rightEyePosition, leftEarPosition, rightEarPosition);
157:
158: j3dPhysicalBody.setHeadToHeadTracker(new Transform3D(
159: headToHeadTracker));
160:
161: j3dPhysicalBody
162: .setNominalEyeHeightFromGround(nominalEyeHeightFromGround);
163: j3dPhysicalBody
164: .setNominalEyeOffsetFromNominalScreen(nominalEyeOffsetFromNominalScreen);
165:
166: return j3dPhysicalBody;
167: }
168: }
|