001: /*
002: * $RCSfile: ColorInterpolator.java,v $
003: *
004: * @(#)ColorInterpolator.java 1.20 98/11/05 20:34:08
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:52 $
034: * $State: Exp $
035: */
036: /*
037: *@Author: Rick Goldberg
038: *@Author: Doug Gehringer
039: */
040: package org.jdesktop.j3d.loaders.vrml97.impl;
041:
042: /** Description of the Class */
043: public class ColorInterpolator extends Interpolator {
044: // eventIn
045: SFFloat fraction;
046:
047: // exposedField
048: // MFFloat key; // From Interpolator
049: MFColor keyValue;
050:
051: // eventOut
052:
053: // spec goes its value_changed, but we need to have a value first
054: SFColor value;
055:
056: /**
057: *Constructor for the ColorInterpolator object
058: *
059: *@param loader Description of the Parameter
060: */
061: public ColorInterpolator(Loader loader) {
062: super (loader);
063: fraction = new SFFloat(0.0f);
064: key = new MFFloat();
065: keyValue = new MFColor();
066: value = new SFColor(1.0f, 1.0f, 1.0f);
067: initFields();
068: }
069:
070: /**
071: *Constructor for the ColorInterpolator object
072: *
073: *@param loader Description of the Parameter
074: *@param key Description of the Parameter
075: *@param keyValue Description of the Parameter
076: */
077: ColorInterpolator(Loader loader, MFFloat key, MFColor keyValue) {
078: super (loader);
079: // initialize the interpolator to the right
080: // value. otherwise do it manually;
081: this .fraction = new SFFloat(0.0f);
082: this .key = key;
083: this .keyValue = keyValue;
084: this .value = new SFColor(1.0f, 1.0f, 1.0f);// may need to cycle
085: // through one interp
086: initFields();
087: }
088:
089: /**
090: * Description of the Method
091: *
092: *@return Description of the Return Value
093: */
094: public Object clone() {
095: return new ColorInterpolator(loader, (MFFloat) key.clone(),
096: (MFColor) keyValue.clone());
097: }
098:
099: /**
100: * Description of the Method
101: *
102: *@param eventInName Description of the Parameter
103: *@param time Description of the Parameter
104: */
105: public void notifyMethod(String eventInName, double time) {
106: if (eventInName.equals("fraction")) {
107: if (key.mfloat.length > 0) {
108: setIndexFract(fraction.value);
109: float v1r = keyValue.vals[iL * 3 + 0];
110: float v1g = keyValue.vals[iL * 3 + 1];
111: float v1b = keyValue.vals[iL * 3 + 2];
112: float v2r = keyValue.vals[(iL + 1) * 3 + 0];
113: float v2g = keyValue.vals[(iL + 1) * 3 + 1];
114: float v2b = keyValue.vals[(iL + 1) * 3 + 2];
115: value.color[0] = (v1r * af) + (v2r * f);
116: value.color[1] = (v1g * af) + (v2g * f);
117: value.color[2] = (v1b * af) + (v2b * f);
118: }
119: value.route();
120: }
121: }
122:
123: /**
124: * Gets the type attribute of the ColorInterpolator object
125: *
126: *@return The type value
127: */
128: public String getType() {
129: return "ColorInterpolator";
130: }
131:
132: /** Description of the Method */
133: void initFields() {
134: fraction.init(this , FieldSpec, Field.EVENT_IN, "fraction");
135: key.init(this , FieldSpec, Field.EXPOSED_FIELD, "key");
136: keyValue.init(this , FieldSpec, Field.EXPOSED_FIELD, "keyValue");
137: value.init(this , FieldSpec, Field.EVENT_OUT, "value");
138: }
139:
140: }
|