001: /*
002: * $RCSfile: ScaleInterpolator.java,v $
003: *
004: * Copyright 1997-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.5 $
028: * $Date: 2008/02/28 20:17:29 $
029: * $State: Exp $
030: */
031:
032: package javax.media.j3d;
033:
034: /**
035: * Scale interpolation behavior. This class defines a behavior
036: * that modifies the uniform scale component of its target
037: * TransformGroup by linearly interpolating between a pair of
038: * specified scale values (using the value generated by the
039: * specified Alpha object). The interpolated scale value is
040: * used to generate a scale transform in the local coordinate
041: * system of this interpolator.
042: */
043:
044: public class ScaleInterpolator extends TransformInterpolator {
045:
046: float minimumScale;
047: float maximumScale;
048: private Transform3D scale = new Transform3D();
049:
050: // We can't use a boolean flag since it is possible
051: // that after alpha change, this procedure only run
052: // once at alpha.finish(). So the best way is to
053: // detect alpha value change.
054: private float prevAlphaValue = Float.NaN;
055: private WakeupCriterion passiveWakeupCriterion = (WakeupCriterion) new WakeupOnElapsedFrames(
056: 0, true);
057:
058: // non-public, default constructor used by cloneNode
059: ScaleInterpolator() {
060: }
061:
062: /**
063: * Constructs a trivial scale interpolator that varies its target
064: * TransformGroup node between the two specified alpha values
065: * using the specified alpha, an identity matrix,
066: * a minimum scale = 0.1f, and a maximum scale = 1.0f.
067: * @param alpha the alpha object for this interpolator
068: * @param target the TransformGroup node affected by this interpolator
069: */
070: public ScaleInterpolator(Alpha alpha, TransformGroup target) {
071:
072: super (alpha, target);
073: this .minimumScale = 0.1f;
074: this .maximumScale = 1.0f;
075: }
076:
077: /**
078: * Constructs a new scaleInterpolator object that varies its target
079: * TransformGroup node's scale component between two scale values
080: * (minimumScale and maximumScale).
081: * @param alpha the alpha object for this interpolator
082: * @param target the TransformGroup node affected by this interpolator
083: * @param axisOfTransform the transform that defines the local coordinate
084: * system in which this interpolator operates; the scale is done
085: * about the origin of this local coordinate system.
086: * @param minimumScale the starting scale
087: * @param maximumScale the ending scale
088: */
089: public ScaleInterpolator(Alpha alpha, TransformGroup target,
090: Transform3D axisOfTransform, float minimumScale,
091: float maximumScale) {
092:
093: super (alpha, target, axisOfTransform);
094:
095: this .minimumScale = minimumScale;
096: this .maximumScale = maximumScale;
097: }
098:
099: /**
100: * This method sets the minimumScale for this interpolator.
101: * @param scale The new minimal scale
102: */
103: public void setMinimumScale(float scale) {
104: this .minimumScale = scale;
105: }
106:
107: /**
108: * This method retrieves this interpolator's minimumScale.
109: * @return the interpolator's minimal scale value
110: */
111: public float getMinimumScale() {
112: return this .minimumScale;
113: }
114:
115: /**
116: * This method sets the maximumScale for this interpolator.
117: * @param scale the new maximum scale
118: */
119: public void setMaximumScale(float scale) {
120: this .maximumScale = scale;
121: }
122:
123: /**
124: * This method retrieves this interpolator's maximumScale.
125: * @return the interpolator's maximum scale vslue
126: */
127: public float getMaximumScale() {
128: return this .maximumScale;
129: }
130:
131: /**
132: * @deprecated As of Java 3D version 1.3, replaced by
133: * <code>TransformInterpolator.setTransformAxis(Transform3D)</code>
134: */
135: public void setAxisOfScale(Transform3D axisOfScale) {
136: setTransformAxis(axisOfScale);
137: }
138:
139: /**
140: * @deprecated As of Java 3D version 1.3, replaced by
141: * <code>TransformInterpolator.getTransformAxis()</code>
142: */
143: public Transform3D getAxisOfScale() {
144: return getTransformAxis();
145: }
146:
147: /**
148: * Computes the new transform for this interpolator for a given
149: * alpha value.
150: *
151: * @param alphaValue alpha value between 0.0 and 1.0
152: * @param transform object that receives the computed transform for
153: * the specified alpha value
154: *
155: * @since Java 3D 1.3
156: */
157: public void computeTransform(float alphaValue, Transform3D transform) {
158:
159: double val = (1.0 - alphaValue) * minimumScale + alphaValue
160: * maximumScale;
161:
162: // construct a Transform3D from: axis * scale * axisInverse
163: scale.set(val);
164: transform.mul(axis, scale);
165: transform.mul(transform, axisInverse);
166: }
167:
168: /**
169: * Used to create a new instance of the node. This routine is called
170: * by <code>cloneTree</code> to duplicate the current node.
171: * @param forceDuplicate when set to <code>true</code>, causes the
172: * <code>duplicateOnCloneTree</code> flag to be ignored. When
173: * <code>false</code>, the value of each node's
174: * <code>duplicateOnCloneTree</code> variable determines whether
175: * NodeComponent data is duplicated or copied.
176: *
177: * @see Node#cloneTree
178: * @see Node#cloneNode
179: * @see Node#duplicateNode
180: * @see NodeComponent#setDuplicateOnCloneTree
181: */
182: public Node cloneNode(boolean forceDuplicate) {
183: ScaleInterpolator si = new ScaleInterpolator();
184: si.duplicateNode(this , forceDuplicate);
185: return si;
186: }
187:
188: /**
189: * Copies all ScaleInterpolator information from
190: * <code>originalNode</code> into
191: * the current node. This method is called from the
192: * <code>cloneNode</code> method which is, in turn, called by the
193: * <code>cloneTree</code> method.<P>
194: *
195: * @param originalNode the original node to duplicate.
196: * @param forceDuplicate when set to <code>true</code>, causes the
197: * <code>duplicateOnCloneTree</code> flag to be ignored. When
198: * <code>false</code>, the value of each node's
199: * <code>duplicateOnCloneTree</code> variable determines whether
200: * NodeComponent data is duplicated or copied.
201: *
202: * @exception RestrictedAccessException if this object is part of a live
203: * or compiled scenegraph.
204: *
205: * @see Node#duplicateNode
206: * @see Node#cloneTree
207: * @see NodeComponent#setDuplicateOnCloneTree
208: */
209: void duplicateAttributes(Node originalNode, boolean forceDuplicate) {
210:
211: super .duplicateAttributes(originalNode, forceDuplicate);
212:
213: ScaleInterpolator si = (ScaleInterpolator) originalNode;
214:
215: setMinimumScale(si.getMinimumScale());
216: setMaximumScale(si.getMaximumScale());
217:
218: }
219: }
|