public static SortedList ParseAnimations(XmlNode node) { SortedList animations = new SortedList(); foreach (XmlNode animNode in node.ChildNodes) { //<Stand_Angry>10 0-10,13,15,9</Stand_Angry> string sAnim = Serialization.XmlHelper.GetValueOrInnerText(animNode).Trim(); ArrayList anim = ParseAnimationString(sAnim); SortedList aKeys = new SortedList(); animations.Add(animNode.Name, aKeys); int nTime = 0; foreach (int val in anim) { AnimationKey key = new AnimationKey(nTime, val); //+nFirstFrame); aKeys.Add(key.Time, key); nTime++; } } return animations; }
public static SortedList ParseAnimations(XmlNode node) { SortedList animations = new SortedList(); foreach (XmlNode animNode in node.ChildNodes) { //<Stand_Angry>10 0-10,13,15,9</Stand_Angry> string sAnim = Serialization.XmlHelper.GetValueOrInnerText(animNode).Trim(); ArrayList anim = ParseAnimationString(sAnim); SortedList aKeys = new SortedList(); animations.Add(animNode.Name, aKeys); int nTime = 0; foreach (int val in anim) { AnimationKey key = new AnimationKey(nTime, val); //+nFirstFrame); aKeys.Add(key.Time, key); nTime++; } } return(animations); }
public void Step() { if (!m_bActive) { return; } if (this.m_fStep == 0) { return; } this.m_fTime += this.m_fStep; if (this._slKeys.Count >= 1) { //TODO: optimize - should cache last key's time. AnimationKey finalKey = this._slKeys.Values[this._slKeys.Count - 1]; if (this.m_fTime > finalKey.Time) { if (m_mode == Modes.Once) { m_bActive = false; return; } else if (m_mode == Modes.Loop) { m_fTime = 0; } } } //TODO: optimize - should cache next key's time and only proceed if it's been passed. float fVal = this.GetValueAtTime(m_fTime); if (m_pi != null) { if (m_pi.PropertyType == typeof(int)) { m_pi.SetValue(m_obj, (int)fVal, null); } else if (m_pi.PropertyType == typeof(float)) { m_pi.SetValue(m_obj, fVal, null); } else if (m_pi.PropertyType == typeof(double)) { m_pi.SetValue(m_obj, (double)fVal, null); } } }
public float GetValueAtTime(float a_fTime) { if (_slKeys.Count > 1) { //TODO: use interpolation strategies. Right now it's linear. //http://www.tinaja.com/cubic01.asp AnimationKey key1 = this.GetKeyNearTime(a_fTime, 0, true); AnimationKey key2 = this.GetKeyNearTime(a_fTime, 1, true); if (key1.Time == key2.Time) //TODO: shouldn't really happen? key2 should be null instead? { return(key1.Value); } float fWhereInbetween = (a_fTime - key1.Time) / (key2.Time - key1.Time); float fVal = (key2.Value - key1.Value) * fWhereInbetween + key1.Value; return(fVal); } else { return(a_fTime); } }
/// <summary> /// Get an animation key near the specified time /// </summary> /// <param name="a_fTime"></param> /// <param name="a_nOffset">0=last key (or, if a_fTime coincides with a key, the current key), 1=next key. Other values are also allowed</param> /// <param name="a_bIfOutsideReturnExtreme">If the specified key doesn't exist, should it return the nearest</param> /// <returns>The requested key</returns> public AnimationKey GetKeyNearTime(float a_fTime, int a_nOffset, bool a_bIfOutsideReturnExtreme) { int nIndex = this._slKeys.IndexOfKey(a_fTime); if (nIndex < 0) { AnimationKey keyTemp = new AnimationKey(0, 0); this._slKeys.Add(a_fTime, keyTemp); nIndex = this._slKeys.IndexOfKey(a_fTime); this._slKeys.RemoveAt(nIndex); nIndex--; } nIndex += a_nOffset; if (nIndex < 0) { if (a_bIfOutsideReturnExtreme) { nIndex = 0; } else { return(null); } } if (nIndex >= this._slKeys.Count) { if (a_bIfOutsideReturnExtreme) { nIndex = this._slKeys.Count - 1; } else { return(null); } } return(this._slKeys.Values[nIndex]); }
public void RemoveKey(AnimationKey key) { this._slKeys.Remove(key.Time); }
/// <summary> /// Get an animation key near the specified time /// </summary> /// <param name="a_fTime"></param> /// <param name="a_nOffset">0=last key (or, if a_fTime coincides with a key, the current key), 1=next key. Other values are also allowed</param> /// <param name="a_bIfOutsideReturnExtreme">If the specified key doesn't exist, should it return the nearest</param> /// <returns>The requested key</returns> public AnimationKey GetKeyNearTime(float a_fTime, int a_nOffset, bool a_bIfOutsideReturnExtreme) { int nIndex = this._slKeys.IndexOfKey(a_fTime); if (nIndex < 0) { AnimationKey keyTemp = new AnimationKey(0,0); this._slKeys.Add(a_fTime, keyTemp); nIndex = this._slKeys.IndexOfKey(a_fTime); this._slKeys.RemoveAt(nIndex); nIndex--; } nIndex+=a_nOffset; if (nIndex < 0) { if (a_bIfOutsideReturnExtreme) nIndex = 0; else return null; } if (nIndex >= this._slKeys.Count) { if (a_bIfOutsideReturnExtreme) nIndex = this._slKeys.Count-1; else return null; } return this._slKeys.Values[nIndex]; }
public void AddKey(AnimationKey key) { this._slKeys.Add(key.Time, key); }