001: /*
002: * $RCSfile: NormalInterpolator.java,v $
003: *
004: * @(#)NormalInterpolator.java 1.16 98/11/05 20:34:48
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:06:59 $
034: * $State: Exp $
035: */
036: /*
037: * @Author: Rick Goldberg
038: * @Author: Doug Gehringer
039: *
040: */
041: // TODO: interp the normals on the unit sphere
042: package org.jdesktop.j3d.loaders.vrml97.impl;
043:
044: /** Description of the Class */
045: public class NormalInterpolator extends Interpolator {
046:
047: // eventIn
048: SFFloat fraction;
049: // exposedField
050: // MFFloat key; // From Interpolator
051: MFVec3f keyValue;
052: // eventOut
053: MFVec3f value;
054:
055: /**
056: *Constructor for the NormalInterpolator object
057: *
058: *@param loader Description of the Parameter
059: */
060: public NormalInterpolator(Loader loader) {
061: super (loader);
062: fraction = new SFFloat(0.0f);
063:
064: //there should be empty constructors for all fields.
065: key = new MFFloat();
066: keyValue = new MFVec3f();
067:
068: initFields();
069:
070: }
071:
072: /**
073: *Constructor for the NormalInterpolator object
074: *
075: *@param loader Description of the Parameter
076: *@param fraction Description of the Parameter
077: *@param key Description of the Parameter
078: *@param keyValue Description of the Parameter
079: */
080: public NormalInterpolator(Loader loader, SFFloat fraction,
081: MFFloat key, MFVec3f keyValue) {
082:
083: super (loader);
084: this .fraction = new SFFloat(0.0f);
085:
086: //there should be empty constructors for all fields.
087: this .key = key;
088: this .keyValue = keyValue;
089:
090: initFields();
091: }
092:
093: /**
094: * Description of the Method
095: *
096: *@param eventInName Description of the Parameter
097: *@param time Description of the Parameter
098: */
099: public void notifyMethod(String eventInName, double time) {
100: if (eventInName.equals("fraction")) {
101: if (key.mfloat.length > 0) {
102: setIndexFract(fraction.value);
103: int valsPerKey = keyValue.size / key.mfloat.length;
104: if (value.size != (valsPerKey * 3)) {
105: value.checkSize(valsPerKey * 3, false);
106: value.size = valsPerKey * 3;
107: }
108:
109: for (int j = 0; j < valsPerKey; j++) {
110: int val1 = iL * valsPerKey * 3;
111: int val2 = (iL + 1) * valsPerKey * 3;
112: float v1x = keyValue.value[(val1 + j) * 3 + 0];
113: float v1y = keyValue.value[(val1 + j) * 3 + 1];
114: float v1z = keyValue.value[(val1 + j) * 3 + 2];
115: float v2x = keyValue.value[(val2 + j) * 3 + 0];
116: float v2y = keyValue.value[(val2 + j) * 3 + 1];
117: float v2z = keyValue.value[(val2 + j) * 3 + 2];
118: value.value[j * 3 + 0] = (v1x * af) + (v2x * f);
119: value.value[j * 3 + 1] = (v1y * af) + (v2y * f);
120: value.value[j * 3 + 2] = (v1z * af) + (v2z * f);
121: }
122: }
123: value.route();
124: }
125:
126: }
127:
128: /**
129: * Gets the type attribute of the NormalInterpolator object
130: *
131: *@return The type value
132: */
133: public String getType() {
134: return "NormalInterpolator";
135: }
136:
137: /**
138: * Description of the Method
139: *
140: *@return Description of the Return Value
141: */
142: public Object clone() {
143: return new NormalInterpolator(loader, (SFFloat) fraction
144: .clone(), (MFFloat) key, (MFVec3f) keyValue);
145: }
146:
147: /** Description of the Method */
148: void initFields() {
149: fraction.init(this , FieldSpec, Field.EVENT_IN, "fraction");
150: key.init(this , FieldSpec, Field.EXPOSED_FIELD, "key");
151: keyValue.init(this , FieldSpec, Field.EXPOSED_FIELD, "keyValue");
152: value.init(this , FieldSpec, Field.EVENT_OUT, "value");
153: }
154:
155: }
|