@@ -1468,7 +1468,7 @@ public CABViewControlTypes GetControlType()
1468
1468
/// Gets the requested Locomotive data and returns it as a fraction (from 0 to 1) of the range between Min and Max values.
1469
1469
/// </summary>
1470
1470
/// <returns>Data value as fraction (from 0 to 1) of the range between Min and Max values</returns>
1471
- public float GetRangeFraction ( )
1471
+ public float GetRangeFraction ( bool offsetFromZero = false )
1472
1472
{
1473
1473
var data = Locomotive . GetDataOf ( Control ) ;
1474
1474
if ( data < Control . MinValue )
@@ -1479,7 +1479,7 @@ public float GetRangeFraction()
1479
1479
if ( Control . MaxValue == Control . MinValue )
1480
1480
return 0 ;
1481
1481
1482
- return ( float ) ( ( data - Control . MinValue ) / ( Control . MaxValue - Control . MinValue ) ) ;
1482
+ return ( float ) ( ( data - ( offsetFromZero && Control . MinValue < 0 ? 0 : Control . MinValue ) ) / ( Control . MaxValue - Control . MinValue ) ) ;
1483
1483
}
1484
1484
1485
1485
public CABViewControlStyles GetStyle ( )
@@ -1630,7 +1630,8 @@ public CabViewGaugeRenderer(Viewer viewer, MSTSLocomotive locomotive, CVCFirebox
1630
1630
1631
1631
public color GetColor ( out bool positive )
1632
1632
{
1633
- if ( Locomotive . GetDataOf ( Control ) < 0 ) { positive = false ; return Gauge . NegativeColor ; }
1633
+ if ( Locomotive . GetDataOf ( Control ) < 0 )
1634
+ { positive = false ; return Gauge . NegativeColor ; }
1634
1635
else { positive = true ; return Gauge . PositiveColor ; }
1635
1636
}
1636
1637
@@ -2986,7 +2987,7 @@ public ThreeDimCabDigit(Viewer viewer, int iMatrix, string size, string aceFile,
2986
2987
2987
2988
//create the shape primitive
2988
2989
shapePrimitive = new MutableShapePrimitive ( Material , NumVertices , NumIndices , new [ ] { - 1 } , 0 ) ;
2989
- UpdateShapePrimitive ( ) ;
2990
+ UpdateShapePrimitive ( Material ) ;
2990
2991
2991
2992
}
2992
2993
@@ -2997,11 +2998,11 @@ Material FindMaterial(bool Alert)
2997
2998
CABViewControlTypes controltype = CVFR . GetControlType ( ) ;
2998
2999
Material material = null ;
2999
3000
3000
- if ( AceFile != "" )
3001
+ if ( Alert ) { imageName = "alert.ace" ; }
3002
+ else if ( AceFile != "" )
3001
3003
{
3002
3004
imageName = AceFile ;
3003
3005
}
3004
- else if ( Alert ) { imageName = "alert.ace" ; }
3005
3006
else
3006
3007
{
3007
3008
switch ( controltype )
@@ -3085,11 +3086,11 @@ public void UpdateDigit()
3085
3086
}
3086
3087
3087
3088
//update the shape primitive
3088
- UpdateShapePrimitive ( ) ;
3089
+ UpdateShapePrimitive ( UsedMaterial ) ;
3089
3090
3090
3091
}
3091
3092
3092
- private void UpdateShapePrimitive ( )
3093
+ private void UpdateShapePrimitive ( Material material )
3093
3094
{
3094
3095
var indexData = new short [ NumIndices ] ;
3095
3096
Array . Copy ( TriangleListIndices , indexData , NumIndices ) ;
@@ -3098,6 +3099,8 @@ private void UpdateShapePrimitive()
3098
3099
var vertexData = new VertexPositionNormalTexture [ NumVertices ] ;
3099
3100
Array . Copy ( VertexList , vertexData , NumVertices ) ;
3100
3101
shapePrimitive . SetVertexData ( vertexData , 0 , NumVertices , NumIndices / 3 ) ;
3102
+
3103
+ shapePrimitive . SetMaterial ( material ) ;
3101
3104
}
3102
3105
3103
3106
//ACE MAP:
@@ -3216,8 +3219,9 @@ public ThreeDimCabGaugeNative(Viewer viewer, int iMatrix, string size, string le
3216
3219
3217
3220
3218
3221
//create the shape primitive
3219
- shapePrimitive = new MutableShapePrimitive ( FindMaterial ( ) , NumVertices , NumIndices , new [ ] { - 1 } , 0 ) ;
3220
- UpdateShapePrimitive ( ) ;
3222
+ var material = FindMaterial ( ) ;
3223
+ shapePrimitive = new MutableShapePrimitive ( material , NumVertices , NumIndices , new [ ] { - 1 } , 0 ) ;
3224
+ UpdateShapePrimitive ( material ) ;
3221
3225
3222
3226
}
3223
3227
@@ -3229,13 +3233,14 @@ Material FindMaterial()
3229
3233
{
3230
3234
if ( PositiveMaterial == null )
3231
3235
{
3232
- PositiveMaterial = new SolidColorMaterial ( this . Viewer , 0f , c . R , c . G , c . B ) ;
3236
+ PositiveMaterial = new SolidColorMaterial ( this . Viewer , c . A , c . R , c . G , c . B ) ;
3233
3237
}
3234
3238
return PositiveMaterial ;
3235
3239
}
3236
3240
else
3237
3241
{
3238
- if ( NegativeMaterial == null ) NegativeMaterial = new SolidColorMaterial ( this . Viewer , c . A , c . R , c . G , c . B ) ;
3242
+ if ( NegativeMaterial == null )
3243
+ NegativeMaterial = new SolidColorMaterial ( this . Viewer , c . A , c . R , c . G , c . B ) ;
3239
3244
return NegativeMaterial ;
3240
3245
}
3241
3246
}
@@ -3247,45 +3252,46 @@ public void UpdateDigit()
3247
3252
3248
3253
Material UsedMaterial = FindMaterial ( ) ;
3249
3254
3250
- float length = CVFR . GetRangeFraction ( ) ;
3255
+ float length = CVFR . GetRangeFraction ( true ) ;
3251
3256
3252
3257
CVCGauge gauge = CVFR . GetGauge ( ) ;
3253
3258
3254
3259
var len = maxLen * length ;
3260
+ var absLen = Math . Abs ( len ) ;
3255
3261
Vertex v1 , v2 , v3 , v4 ;
3256
3262
3257
3263
//the left-bottom vertex if ori=0;dir=0, right-bottom if ori=0,dir=1; left-top if ori=1,dir=0; left-bottom if ori=1,dir=1;
3258
3264
v1 = new Vertex ( 0f , 0f , 0.002f , 0 , 0 , - 1 , 0f , 0f ) ;
3259
3265
3260
3266
if ( Orientation == 0 )
3261
3267
{
3262
- if ( Direction == 0 ) //moving right
3268
+ if ( Direction == 0 ^ len < 0 ) //moving right
3263
3269
{
3264
3270
//other vertices
3265
3271
v2 = new Vertex ( 0f , width , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3266
- v3 = new Vertex ( len , width , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3267
- v4 = new Vertex ( len , 0f , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3272
+ v3 = new Vertex ( absLen , width , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3273
+ v4 = new Vertex ( absLen , 0f , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3268
3274
}
3269
3275
else //moving left
3270
3276
{
3271
3277
v4 = new Vertex ( 0f , width , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3272
- v3 = new Vertex ( - len , width , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3273
- v2 = new Vertex ( - len , 0f , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3278
+ v3 = new Vertex ( - absLen , width , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3279
+ v2 = new Vertex ( - absLen , 0f , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3274
3280
}
3275
3281
}
3276
3282
else
3277
3283
{
3278
- if ( Direction == 1 ) //up
3284
+ if ( Direction == 1 ^ len < 0 ) //up
3279
3285
{
3280
3286
//other vertices
3281
- v2 = new Vertex ( 0f , len , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3282
- v3 = new Vertex ( width , len , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3287
+ v2 = new Vertex ( 0f , absLen , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3288
+ v3 = new Vertex ( width , absLen , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3283
3289
v4 = new Vertex ( width , 0f , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3284
3290
}
3285
3291
else //moving down
3286
3292
{
3287
- v4 = new Vertex ( 0f , - len , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3288
- v3 = new Vertex ( width , - len , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3293
+ v4 = new Vertex ( 0f , - absLen , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3294
+ v3 = new Vertex ( width , - absLen , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3289
3295
v2 = new Vertex ( width , 0 , 0.002f , 0 , 0 , 1 , 0f , 0f ) ;
3290
3296
}
3291
3297
}
@@ -3298,7 +3304,7 @@ public void UpdateDigit()
3298
3304
NumVertices += 4 ;
3299
3305
3300
3306
//update the shape primitive
3301
- UpdateShapePrimitive ( ) ;
3307
+ UpdateShapePrimitive ( UsedMaterial ) ;
3302
3308
3303
3309
}
3304
3310
@@ -3330,7 +3336,7 @@ static float GetTextureCoordY(char c)
3330
3336
return 1.0f ;
3331
3337
}
3332
3338
3333
- private void UpdateShapePrimitive ( )
3339
+ private void UpdateShapePrimitive ( Material material )
3334
3340
{
3335
3341
var indexData = new short [ NumIndices ] ;
3336
3342
Array . Copy ( TriangleListIndices , indexData , NumIndices ) ;
@@ -3339,6 +3345,8 @@ private void UpdateShapePrimitive()
3339
3345
var vertexData = new VertexPositionNormalTexture [ NumVertices ] ;
3340
3346
Array . Copy ( VertexList , vertexData , NumVertices ) ;
3341
3347
shapePrimitive . SetVertexData ( vertexData , 0 , NumVertices , NumIndices / 3 ) ;
3348
+
3349
+ shapePrimitive . SetMaterial ( material ) ;
3342
3350
}
3343
3351
3344
3352
public void PrepareFrame ( RenderFrame frame , ElapsedTime elapsedTime )
0 commit comments