@@ -31,8 +31,8 @@ public class AnimatedPart
3131 // Shape that we're animating.
3232 readonly PoseableShape PoseableShape ;
3333
34- // Number of animation key-frames that are used by this part. This is calculated from the matrices provided.
35- public int FrameCount ;
34+ // Maximum animation key-frame value used by this part. This is calculated from the matrices provided.
35+ public int MaxFrame ;
3636
3737 // Current frame of the animation.
3838 float AnimationKey ;
@@ -55,26 +55,26 @@ public void AddMatrix(int matrix)
5555 {
5656 if ( matrix < 0 ) return ;
5757 MatrixIndexes . Add ( matrix ) ;
58- UpdateFrameCount ( matrix ) ;
58+ UpdateMaxFrame ( matrix ) ;
5959 }
6060
61- void UpdateFrameCount ( int matrix )
61+ void UpdateMaxFrame ( int matrix )
6262 {
6363 if ( PoseableShape . SharedShape . Animations != null
6464 && PoseableShape . SharedShape . Animations . Count > 0
6565 && PoseableShape . SharedShape . Animations [ 0 ] . anim_nodes . Count > matrix
6666 && PoseableShape . SharedShape . Animations [ 0 ] . anim_nodes [ matrix ] . controllers . Count > 0
6767 && PoseableShape . SharedShape . Animations [ 0 ] . anim_nodes [ matrix ] . controllers [ 0 ] . Count > 0 )
6868 {
69- FrameCount = Math . Max ( FrameCount , PoseableShape . SharedShape . Animations [ 0 ] . anim_nodes [ matrix ] . controllers [ 0 ] . ToArray ( ) . Cast < KeyPosition > ( ) . Last ( ) . Frame ) ;
69+ MaxFrame = Math . Max ( MaxFrame , PoseableShape . SharedShape . Animations [ 0 ] . anim_nodes [ matrix ] . controllers [ 0 ] . ToArray ( ) . Cast < KeyPosition > ( ) . Last ( ) . Frame ) ;
7070 // Sometimes there are more frames in the second controller than in the first
7171 if ( PoseableShape . SharedShape . Animations [ 0 ] . anim_nodes [ matrix ] . controllers . Count > 1
7272 && PoseableShape . SharedShape . Animations [ 0 ] . anim_nodes [ matrix ] . controllers [ 1 ] . Count > 0 )
73- FrameCount = Math . Max ( FrameCount , PoseableShape . SharedShape . Animations [ 0 ] . anim_nodes [ matrix ] . controllers [ 1 ] . ToArray ( ) . Cast < KeyPosition > ( ) . Last ( ) . Frame ) ;
73+ MaxFrame = Math . Max ( MaxFrame , PoseableShape . SharedShape . Animations [ 0 ] . anim_nodes [ matrix ] . controllers [ 1 ] . ToArray ( ) . Cast < KeyPosition > ( ) . Last ( ) . Frame ) ;
7474 }
7575 for ( var i = 0 ; i < PoseableShape . Hierarchy . Length ; i ++ )
7676 if ( PoseableShape . Hierarchy [ i ] == matrix )
77- UpdateFrameCount ( i ) ;
77+ UpdateMaxFrame ( i ) ;
7878 }
7979
8080 /// <summary>
@@ -98,7 +98,7 @@ void SetFrame(float frame)
9898 /// </summary>
9999 public void SetFrameClamp ( float frame )
100100 {
101- if ( frame > FrameCount ) frame = FrameCount ;
101+ if ( frame > MaxFrame ) frame = MaxFrame ;
102102 if ( frame < 0 ) frame = 0 ;
103103 SetFrame ( frame ) ;
104104 }
@@ -109,8 +109,8 @@ public void SetFrameClamp(float frame)
109109 public void UpdateFrameClamp ( float frame , ElapsedTime elapsedTime )
110110 {
111111 float newState ;
112- if ( Math . Abs ( frame - AnimationKey ) > 1 .0f * elapsedTime . ClockSeconds )
113- newState = AnimationKey + Math . Sign ( frame - AnimationKey ) * elapsedTime . ClockSeconds ;
112+ if ( Math . Abs ( frame - AnimationKey ) > 10 .0f * elapsedTime . ClockSeconds )
113+ newState = AnimationKey + Math . Sign ( frame - AnimationKey ) * 10.0f * elapsedTime . ClockSeconds ;
114114 else
115115 newState = frame ;
116116
@@ -122,19 +122,19 @@ public void UpdateFrameClamp(float frame, ElapsedTime elapsedTime)
122122 /// </summary>
123123 public void SetFrameCycle ( float frame )
124124 {
125- // Animates from 0-FrameCount then FrameCount -0 for values of 0>=frame<=2*FrameCount .
126- SetFrameClamp ( FrameCount - Math . Abs ( frame - FrameCount ) ) ;
125+ // Animates from 0-MaxFrame then MaxFrame -0 for values of 0>=frame<=2*MaxFrame .
126+ SetFrameClamp ( MaxFrame - Math . Abs ( frame - MaxFrame ) ) ;
127127 }
128128
129129 /// <summary>
130130 /// Sets the animation to a particular frame whilst wrapping it around the frame count range.
131131 /// </summary>
132132 public void SetFrameWrap ( float frame )
133133 {
134- // Wrap the frame around 0-FrameCount without hanging when FrameCount =0.
135- while ( FrameCount > 0 && frame < 0 ) frame += FrameCount ;
134+ // Wrap the frame around 0-MaxFrame without hanging when MaxFrame =0.
135+ while ( MaxFrame > 0 && frame < 0 ) frame += MaxFrame ;
136136 if ( frame < 0 ) frame = 0 ;
137- frame %= FrameCount ;
137+ frame %= MaxFrame ;
138138 SetFrame ( frame ) ;
139139 }
140140
@@ -143,7 +143,7 @@ public void SetFrameWrap(float frame)
143143 /// </summary>
144144 public void SetState ( bool state )
145145 {
146- SetFrame ( state ? FrameCount : 0 ) ;
146+ SetFrame ( state ? MaxFrame : 0 ) ;
147147 }
148148
149149 /// <summary>
@@ -161,23 +161,23 @@ public void UpdateState(bool state, ElapsedTime elapsedTime)
161161 public float UpdateAndReturnState ( bool state , ElapsedTime elapsedTime )
162162 {
163163 SetFrameClamp ( AnimationKey + ( state ? 1 : - 1 ) * elapsedTime . ClockSeconds ) ;
164- return AnimationKey / FrameCount ;
164+ return AnimationKey / MaxFrame ;
165165 }
166166
167167 /// <summary>
168168 /// Returns the animation key fraction (between 0 and 1)
169169 /// </summary>
170170 public float AnimationKeyFraction ( )
171171 {
172- return AnimationKey / FrameCount ;
172+ return AnimationKey / MaxFrame ;
173173 }
174174
175175 /// <summary>
176176 /// Updates an animated part that loops (e.g. running gear), changing by the given amount.
177177 /// </summary>
178178 public void UpdateLoop ( float change )
179179 {
180- if ( PoseableShape . SharedShape . Animations == null || PoseableShape . SharedShape . Animations . Count == 0 || FrameCount == 0 )
180+ if ( PoseableShape . SharedShape . Animations == null || PoseableShape . SharedShape . Animations . Count == 0 || MaxFrame == 0 )
181181 return ;
182182
183183 // The speed of rotation is set at 8 frames of animation per rotation at 30 FPS (so 16 frames = 60 FPS, etc.).
@@ -190,12 +190,12 @@ public void UpdateLoop(float change)
190190 /// </summary>
191191 public void UpdateLoop ( bool running , ElapsedTime elapsedTime , float frameRateMultiplier = 1.5f )
192192 {
193- if ( PoseableShape . SharedShape . Animations == null || PoseableShape . SharedShape . Animations . Count == 0 || FrameCount == 0 )
193+ if ( PoseableShape . SharedShape . Animations == null || PoseableShape . SharedShape . Animations . Count == 0 || MaxFrame == 0 )
194194 return ;
195195
196196 // The speed of cycling is as default 1.5 frames of animation per second at 30 FPS.
197197 var frameRate = PoseableShape . SharedShape . Animations [ 0 ] . FrameRate * frameRateMultiplier / 30f ;
198- if ( running || ( AnimationKey > 0 && AnimationKey + elapsedTime . ClockSeconds * frameRate < FrameCount ) )
198+ if ( running || ( AnimationKey > 0 && AnimationKey + elapsedTime . ClockSeconds * frameRate < MaxFrame ) )
199199 SetFrameWrap ( AnimationKey + elapsedTime . ClockSeconds * frameRate ) ;
200200 else
201201 SetFrame ( 0 ) ;
0 commit comments