Axiom.Animating.AnimationTrack.GetKeyFramesAtTime C# (CSharp) Метод

GetKeyFramesAtTime() публичный Метод

Gets the 2 KeyFrame objects which are active at the time given, and the blend value between them.
At any point in time in an animation, there are either 1 or 2 keyframes which are 'active', 1 if the time index is exactly on a keyframe, 2 at all other times i.e. the keyframe before and the keyframe after.
public GetKeyFramesAtTime ( float time, KeyFrame &keyFrame1, KeyFrame &keyFrame2, short &firstKeyIndex ) : float
time float The time index in seconds.
keyFrame1 KeyFrame Receive the keyframe just before or at this time index.
keyFrame2 KeyFrame Receive the keyframe just after this time index.
firstKeyIndex short If supplied, will receive the index of the 'from' keyframe incase the caller needs it.
Результат float
		public float GetKeyFramesAtTime( float time, out KeyFrame keyFrame1, out KeyFrame keyFrame2, out short firstKeyIndex )
		{
			short firstIndex = -1;
			float totalLength = parent.Length;

			// wrap time
			while ( time > totalLength )
				time -= totalLength;

			int i = 0;

			// makes compiler happy so it wont complain about this var being unassigned
			keyFrame1 = null;

			// find the last keyframe before or on current time
			for ( i = 0; i < keyFrameList.Count; i++ )
			{
				KeyFrame keyFrame = keyFrameList[ i ];

				// kick out now if the current frames time is greater than the current time
				if ( keyFrame.Time > time )
					break;

				keyFrame1 = keyFrame;
				++firstIndex;
			}

			// trap case where there is no key before this time
			// use the first key anyway and pretend it's time index 0
			if ( firstIndex == -1 )
			{
				keyFrame1 = keyFrameList[ 0 ];
				++firstIndex;
			}

			// fill index of the first key
			firstKeyIndex = firstIndex;

			// parametric time
			// t1 = time of previous keyframe
			// t2 = time of next keyframe
			float t1, t2;

			// find first keyframe after the time
			// if no next keyframe, wrap back to first
			// TODO: Verify logic
			if ( firstIndex == ( keyFrameList.Count - 1 ) )
			{
				keyFrame2 = keyFrameList[ 0 ];
				t2 = totalLength;
			}
			else
			{
				keyFrame2 = keyFrameList[ firstIndex + 1 ];
				t2 = keyFrame2.Time;
			}

			t1 = keyFrame1.Time;

			if ( t1 == t2 )
			{
				// same keyframe
				return 0.0f;
			}
			else
			{
				return ( time - t1 ) / ( t2 - t1 );
			}
		}