/* * Moonlight|3D * Copyright (C) 2005 The Moonlight|3D team * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * Created on Nov 16, 2005 */ package ml.backend.anim; import java.util.ArrayList; import ml.backend.selection.PathElement; import ml.core.helper.Property; import ml.core.helper.Value; public class KeyframeAnimationTrack implements AnimationTrack { public class KeyValuePair { public double time; public Value value; } private String nodeName; private String propertyName; private Value defaultValue; private ArrayList keys; private KeyframeInterpolator startExtrapolator; private KeyframeInterpolator endExtrapolator; private ArrayList interpolators; public KeyframeAnimationTrack() { keys=new ArrayList(); interpolators=new ArrayList(); } public String getNodeName() { return nodeName; } public String getPropertyName() { return propertyName; } public Value getDefaultValue() { return defaultValue; } public void insertKey(double time, Property value, KeyframeInterpolator interpolator) { KeyValuePair key=new KeyValuePair(); key.time=time; key.value=value; for(int i=0;itime) { keys.add(i,key); interpolators.add(i,interpolator); return; } } keys.add(key); interpolators.add(interpolator); } public Value getValue(double time) { if(keys.size()==0) { return defaultValue; } if(keys.get(0).time>time) { return startExtrapolator.interpolate(this,time); } if(time>keys.get(keys.size()-1).time) { return endExtrapolator.interpolate(this,time); } for(int i=0;ikeys.get(i).time) { return keys.get(i).value; } } return null; // this line should never actually be reached } public ArrayList getKeyList() { return keys; } /** * Set the start extrapolator for this animation track. The start * extrapolator is applied to extrapolate from the first keyframe * in the track backwards in time to the desired point in time. * Despite the name, normal interpolators are used for that operation. * It is up to the interpolator implementation to calculate meaningful * values. * * @param extrapolator the start extrapolator */ public void setStartExtrapolator(KeyframeInterpolator extrapolator) { startExtrapolator=extrapolator; } /** * Return the start extrapolator that is used to interpolate from the * first keyframe backwards in time. * * @return the start extrapolator */ public KeyframeInterpolator getStartExtrapolator() { return startExtrapolator; } /** * Set the end extrapolator for this animation track. The end * extrapolator is applied to extrapolate from the last keyframe * in the track forward in time to the desired point in time. * Despite the name, normal interpolators are used for that operation. * It is up to the interpolator implementation to calculate meaningful * values. * * @param extrapolator the end extrapolator */ public void setEndExtrapolator(KeyframeInterpolator extrapolator) { endExtrapolator=extrapolator; } /** * Return the end extrapolator that is used to interpolate from the * last keyframe forward in time. * * @return the end extrapolator */ public KeyframeInterpolator getEndExtrapolator() { return endExtrapolator; } public PathElement findChildElement(String childName) { return null; } public boolean isValidAppendixName(String appendix) { return false; } public Object getFromAppendix(String appendix) { return null; } }