File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed
Source/RunActivity/Viewer3D Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -226,8 +226,29 @@ public void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
226
226
227
227
// Calculate XNA matrix for shape file objects by offsetting from car's location
228
228
// The new List<int> is intentional, this allows the dictionary to be changed while iterating
229
+ int maxDepth = trainCarShape . Hierarchy . Max ( ) ;
229
230
foreach ( int index in new List < int > ( ShapeXNATranslations . Keys ) )
230
- ShapeXNATranslations [ index ] = trainCarShape . XNAMatrices [ index ] * xnaDTileTranslation ;
231
+ {
232
+ Matrix res = trainCarShape . XNAMatrices [ index ] ;
233
+ int hIndex = trainCarShape . Hierarchy [ index ] ;
234
+
235
+ int i = 0 ;
236
+
237
+ // Transform the matrix repeatedly for all of its parents
238
+ while ( hIndex > - 1 && hIndex < trainCarShape . Hierarchy . Length && i < maxDepth )
239
+ {
240
+ res = res * trainCarShape . XNAMatrices [ hIndex ] ;
241
+ // Prevent potential infinite loop due to faulty hierarchy definition
242
+ if ( hIndex != trainCarShape . Hierarchy [ hIndex ] )
243
+ hIndex = trainCarShape . Hierarchy [ hIndex ] ;
244
+ else
245
+ break ;
246
+
247
+ i ++ ;
248
+ }
249
+
250
+ ShapeXNATranslations [ index ] = res * xnaDTileTranslation ;
251
+ }
231
252
232
253
float objectRadius = 20 ; // Even more arbitrary.
233
254
float objectViewingDistance = Viewer . Settings . ViewingDistance ; // Arbitrary.
You can’t perform that action at this time.
0 commit comments