001: /*
002: * $RCSfile: Interpolator.java,v $
003: *
004: * @(#)Interpolator.java 1.11 98/11/05 20:34:36
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: * $Revision: 1.2 $
032: * $Date: 2005/02/03 23:06:57 $
033: * $State: Exp $
034: */
035: /*
036: * @Author: Rick Goldberg
037: * @Author: Doug Gehringer
038: *
039: */
040: package org.jdesktop.j3d.loaders.vrml97.impl;
041:
042: /** Description of the Class */
043: public abstract class Interpolator extends Node {
044:
045: // exposedField
046: MFFloat key;// defined here but initialized by subclass
047:
048: private int lastIndex = 0;
049:
050: int iL;
051: float f, af;
052:
053: /**
054: *Constructor for the Interpolator object
055: *
056: *@param loader Description of the Parameter
057: */
058: Interpolator(Loader loader) {
059: super (loader);
060: }
061:
062: /**
063: * Sets the indexFract attribute of the Interpolator object
064: *
065: *@param value The new indexFract value
066: */
067: void setIndexFract(float value) {
068: int j;
069: if (key.mfloat[lastIndex] < value) {
070: j = lastIndex;
071: } else {
072: j = 0;
073: }
074: for (; (j < key.mfloat.length) && (key.mfloat[j] < value); j++) {
075: ;
076: }
077:
078: iL = j - 1;
079:
080: if (iL >= (key.mfloat.length - 1)) {
081: iL = key.mfloat.length - 2;
082: f = 1.0f;
083: } else if (iL < 0) {
084: iL = 0;
085: f = 0.0f;
086: } else {
087: try {
088: f = value - key.mfloat[iL];
089: f /= key.mfloat[iL + 1] - key.mfloat[iL];
090: } catch (ArrayIndexOutOfBoundsException e) {
091: System.out.println("Interpolator madness!");
092: iL = 0;
093: f = value - key.mfloat[iL];
094: f /= key.mfloat[iL + 1] - key.mfloat[iL];
095: }
096: }
097: lastIndex = iL;
098: af = 1.0f - f;
099: }
100: }
|