001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.perseus.model;
028:
029: /**
030: * @version $Id: TransformRefValues.java,v 1.3 2006/06/29 10:47:36 ln156897 Exp $
031: */
032: public class TransformRefValues implements RefValues {
033: /**
034: * This RefValues TransformSegments.
035: */
036: TransformSegment[] segments;
037:
038: /**
039: * A working array to return a value from the compute method.
040: */
041: float[][] w;
042:
043: /**
044: * Used to store the length of this RefValues
045: */
046: float length;
047:
048: /**
049: * Used to store the length of each segment
050: */
051: float[] segLength;
052:
053: /**
054: * @param i requested segment index.
055: * @return Segment at index i
056: */
057: public Segment getSegment(int i) {
058: return segments[i];
059: }
060:
061: /**
062: * @return the number of segments in refValues
063: */
064: public int getSegments() {
065: return segments.length;
066: }
067:
068: /**
069: * FloatRefValues only have one component. This returns the number of
070: * components in the start value of the first segment.
071: *
072: * @return the number of components. There is an array of float for each
073: * component.
074: */
075: public int getComponents() {
076: return 6;
077: }
078:
079: /**
080: * Computes the value for the input interpolated values.
081: * There should be as many entries in the return array as there
082: * are components in the RefValues.
083: *
084: * @param si the current segment index
085: * @param p the current penetration
086: */
087: public Object[] compute(int si, float p) {
088: segments[si].compute(p, w);
089: return w;
090: }
091:
092: /**
093: * Adds a new time segment so accomodate for discreet behavior.
094: * If there is only one segment for discreet animations, the
095: * last value is never shown. To accomodate for that, this
096: * method should add a segment to the RefValues so that the
097: * last animation value is shown during the last value interval
098: * of a discreet animation.
099: */
100: public void makeDiscrete() {
101: TransformSegment[] tmpSegments = new TransformSegment[segments.length + 1];
102: System.arraycopy(segments, 0, tmpSegments, 0, segments.length);
103: TransformSegment lastSeg = segments[segments.length - 1];
104: TransformSegment newSeg = new TransformSegment();
105: newSeg.start = lastSeg.end;
106: newSeg.end = lastSeg.end;
107: newSeg.type = lastSeg.type;
108: tmpSegments[tmpSegments.length - 1] = newSeg;
109: segments = tmpSegments;
110: }
111:
112: /**
113: * Computes the length of the RefValues.
114: *
115: * @return the total length of refValues.
116: */
117: public float getLength() {
118: return length;
119: }
120:
121: /**
122: * Computes the length of segment at index si
123: *
124: * @param si the segment index.
125: */
126: public float getLength(final int si) {
127: return segLength[si];
128: }
129:
130: /**
131: * Should be called after the RefValue's configuration is complete
132: * to give the implementation a chance to initialize
133: * internal data and cache values.
134: */
135: public void initialize() {
136: // Initialize the working buffer
137: final int nc = 6;
138:
139: w = new float[nc][];
140:
141: final int ns = segments.length;
142:
143: // Initialize the segments.
144: for (int si = 0; si < ns; si++) {
145: segments[si].initialize();
146: }
147:
148: length = 0;
149: segLength = new float[ns];
150:
151: // The length of a TransformSegment, along each component, is the
152: // sum of the length of each segment along that component.
153: for (int ci = 0; ci < nc; ci++) {
154: w[ci] = new float[1];
155: }
156:
157: for (int si = 0; si < ns; si++) {
158: segLength[si] = segments[si].getLength();
159: length += segLength[si];
160: }
161: }
162:
163: /**
164: * Debug helper.
165: */
166: /*
167: public String toString() {
168: StringBuffer sb = new StringBuffer();
169: sb.append("TransformRefValues[" + getSegments() + "]\n");
170: for (int si = 0; si < getSegments(); si++) {
171: Segment seg = getSegment(si);
172: sb.append("seg[" + si + "] : " + seg.toString() + "\n");
173: }
174: return sb.toString();
175: }
176: */
177: }
|