001: /*
002: * $RCSfile: Interpolator.java,v $
003: *
004: * Copyright 1996-2008 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
006: *
007: * This code is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License version 2 only, as
009: * published by the Free Software Foundation. Sun designates this
010: * particular file as subject to the "Classpath" exception as provided
011: * by Sun in the LICENSE file that accompanied this code.
012: *
013: * This code is distributed in the hope that it will be useful, but WITHOUT
014: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: * version 2 for more details (a copy is included in the LICENSE file that
017: * accompanied this code).
018: *
019: * You should have received a copy of the GNU General Public License version
020: * 2 along with this work; if not, write to the Free Software Foundation,
021: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
022: *
023: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
024: * CA 95054 USA or visit www.sun.com if you need additional information or
025: * have any questions.
026: *
027: * $Revision: 1.6 $
028: * $Date: 2008/02/28 20:17:25 $
029: * $State: Exp $
030: */
031:
032: package javax.media.j3d;
033:
034: import java.util.Vector;
035:
036: /**
037: * Interpolator is an abstract class that extends Behavior to provide
038: * common methods used by various interpolation subclasses. These
039: * include methods to convert a time value into an alpha value (A
040: * value in the range 0 to 1) and a method to initialize the behavior.
041: * Subclasses provide the methods that convert alpha values into
042: * values within that subclass' output range.
043: */
044:
045: public abstract class Interpolator extends Behavior {
046:
047: // This interpolator's alpha generator
048: Alpha alpha;
049:
050: /**
051: * Default WakeupCondition for all interpolators. The
052: * wakeupOn method of Behavior, which takes a WakeupCondition as
053: * the method parameter, will need to be called at the end
054: * of the processStimulus method of any class that subclasses
055: * Interpolator; this can be done with the following method call:
056: * wakeupOn(defaultWakeupCriterion).
057: */
058: protected WakeupCriterion defaultWakeupCriterion = (WakeupCriterion) new WakeupOnElapsedFrames(
059: 0);
060:
061: /**
062: * Constructs an Interpolator node with a null alpha value.
063: */
064: public Interpolator() {
065: }
066:
067: /**
068: * Constructs an Interpolator node with the specified alpha value.
069: * @param alpha the alpha object used by this interpolator.
070: * If it is null, then this interpolator will not run.
071: */
072: public Interpolator(Alpha alpha) {
073: this .alpha = alpha;
074: }
075:
076: /**
077: * Retrieves this interpolator's alpha object.
078: * @return this interpolator's alpha object
079: */
080: public Alpha getAlpha() {
081: return this .alpha;
082: }
083:
084: /**
085: * Set this interpolator's alpha to the specified alpha object.
086: * @param alpha the new alpha object. If set to null,
087: * then this interpolator will stop running.
088: */
089: public void setAlpha(Alpha alpha) {
090: this .alpha = alpha;
091: VirtualUniverse.mc.sendRunMessage(J3dThread.RENDER_THREAD);
092: }
093:
094: /**
095: * This is the default Interpolator behavior initialization routine.
096: * It schedules the behavior to awaken at the next frame.
097: */
098: public void initialize() {
099: // Reset alpha
100: //alpha.setStartTime(J3dClock.currentTimeMillis());
101:
102: // Insert wakeup condition into queue
103: wakeupOn(defaultWakeupCriterion);
104: }
105:
106: /**
107: * Copies all Interpolator information from
108: * <code>originalNode</code> into
109: * the current node. This method is called from the
110: * <code>cloneNode</code> method which is, in turn, called by the
111: * <code>cloneTree</code> method.<P>
112: *
113: * @param originalNode the original node to duplicate.
114: * @param forceDuplicate when set to <code>true</code>, causes the
115: * <code>duplicateOnCloneTree</code> flag to be ignored. When
116: * <code>false</code>, the value of each node's
117: * <code>duplicateOnCloneTree</code> variable determines whether
118: * NodeComponent data is duplicated or copied.
119: *
120: * @exception RestrictedAccessException if this object is part of a live
121: * or compiled scenegraph.
122: *
123: * @see Node#duplicateNode
124: * @see Node#cloneTree
125: * @see NodeComponent#setDuplicateOnCloneTree
126: */
127: void duplicateAttributes(Node originalNode, boolean forceDuplicate) {
128: super .duplicateAttributes(originalNode, forceDuplicate);
129:
130: Interpolator it = (Interpolator) originalNode;
131:
132: Alpha a = it.getAlpha();
133: if (a != null) {
134: setAlpha(a.cloneAlpha());
135: }
136: }
137: }
|