1
- // COPYRIGHT 2009 - 2023 by the Open Rails project.
1
+ // COPYRIGHT 2009 - 2023 by the Open Rails project.
2
2
//
3
3
// This file is part of Open Rails.
4
4
//
@@ -41,8 +41,6 @@ public class PrecipitationViewer
41
41
readonly Material Material ;
42
42
readonly PrecipitationPrimitive Precipitation ;
43
43
44
- Vector3 Wind ;
45
-
46
44
public PrecipitationViewer ( Viewer viewer )
47
45
{
48
46
Viewer = viewer ;
@@ -51,14 +49,13 @@ public PrecipitationViewer(Viewer viewer)
51
49
Material = viewer . MaterialManager . Load ( "Precipitation" ) ;
52
50
Precipitation = new PrecipitationPrimitive ( Viewer . GraphicsDevice ) ;
53
51
54
- Wind = new Vector3 ( 0 , 0 , 0 ) ;
55
52
Reset ( ) ;
56
53
}
57
54
58
55
public void PrepareFrame ( RenderFrame frame , ElapsedTime elapsedTime )
59
56
{
60
57
var gameTime = ( float ) Viewer . Simulator . GameTime ;
61
- Precipitation . DynamicUpdate ( Weather , ref Wind ) ;
58
+ Precipitation . DynamicUpdate ( Weather ) ;
62
59
Precipitation . Update ( gameTime , elapsedTime , Weather . PrecipitationIntensityPPSPM2 , Viewer ) ;
63
60
64
61
// Note: This is quite a hack. We ideally should be able to pass this through RenderItem somehow.
@@ -72,13 +69,8 @@ public void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
72
69
73
70
public void Reset ( )
74
71
{
75
- // This procedure is only called once at the start of an activity.
76
- // Added random Wind.X value for rain and snow.
77
- // Max value used by randWind.Next is max value - 1.
78
- Wind . X = Viewer . Simulator . WeatherType == Orts . Formats . Msts . WeatherType . Snow ? Viewer . Random . Next ( 2 , 6 ) : Viewer . Random . Next ( 15 , 21 ) ;
79
-
80
72
var gameTime = ( float ) Viewer . Simulator . GameTime ;
81
- Precipitation . Initialize ( Viewer . Simulator . WeatherType , Wind ) ;
73
+ Precipitation . Initialize ( Viewer . Simulator . WeatherType ) ;
82
74
83
75
// Camera is null during first initialisation.
84
76
if ( Viewer . Camera != null )
@@ -138,7 +130,6 @@ struct ParticleVertex
138
130
}
139
131
140
132
float ParticleDuration ;
141
- Vector3 ParticleDirection ;
142
133
HeightCache Heights ;
143
134
144
135
// Particle buffer goes like this:
@@ -247,32 +238,31 @@ int GetCountFreeParticles()
247
238
return ( MaxParticles - nextFree ) + FirstRetiredParticle ;
248
239
}
249
240
250
- public void Initialize ( Orts . Formats . Msts . WeatherType weather , Vector3 wind )
241
+ public void Initialize ( Orts . Formats . Msts . WeatherType weather )
251
242
{
252
243
ParticleDuration = ParticleBoxHeightM / ( weather == Orts . Formats . Msts . WeatherType . Snow ? SnowVelocityMpS : RainVelocityMpS ) / ParticleVelocityFactor ;
253
- ParticleDirection = wind ;
254
244
FirstActiveParticle = FirstNewParticle = FirstFreeParticle = FirstRetiredParticle = 0 ;
255
245
ParticlesToEmit = TimeParticlesLastEmitted = 0 ;
256
246
DrawCounter = 0 ;
257
247
}
258
248
259
- public void DynamicUpdate ( Weather weather , ref Vector3 wind )
249
+ public void DynamicUpdate ( Weather weather )
260
250
{
261
251
if ( weather . PrecipitationLiquidity == 0 || weather . PrecipitationLiquidity == 1 )
262
252
{
263
253
return ;
264
254
}
265
255
266
256
ParticleDuration = ParticleBoxHeightM / ( ( ( RainVelocityMpS - SnowVelocityMpS ) * weather . PrecipitationLiquidity ) + SnowVelocityMpS ) / ParticleVelocityFactor ;
267
- wind . X = ( 18 * weather . PrecipitationLiquidity ) + 2 ;
268
- ParticleDirection = wind ;
269
257
}
270
258
271
259
public void Update ( float currentTime , ElapsedTime elapsedTime , float particlesPerSecondPerM2 , Viewer viewer )
272
260
{
273
261
var tiles = viewer . Tiles ;
274
262
var scenery = viewer . World . Scenery ;
275
263
var worldLocation = viewer . Camera . CameraWorldLocation ;
264
+ var particleDirection2D = viewer . Simulator . Weather . WindInstantaneousDirection * viewer . Simulator . Weather . WindInstantaneousSpeedMpS ;
265
+ var particleDirection3D = new Vector3 ( particleDirection2D . X , 0 , particleDirection2D . Y ) ;
276
266
277
267
if ( TimeParticlesLastEmitted == 0 )
278
268
{
@@ -304,7 +294,7 @@ public void Update(float currentTime, ElapsedTime elapsedTime, float particlesPe
304
294
305
295
for ( var j = 0 ; j < VerticiesPerParticle ; j ++ )
306
296
{
307
- Vertices [ vertex + j ] . StartPosition_StartTime = new Vector4 ( position . XNAMatrix . Translation - ( ParticleDirection * ParticleDuration ) , time ) ;
297
+ Vertices [ vertex + j ] . StartPosition_StartTime = new Vector4 ( position . XNAMatrix . Translation - ( particleDirection3D * ParticleDuration ) , time ) ;
308
298
Vertices [ vertex + j ] . StartPosition_StartTime . Y += ParticleBoxHeightM ;
309
299
Vertices [ vertex + j ] . EndPosition_EndTime = new Vector4 ( position . XNAMatrix . Translation , time + ParticleDuration ) ;
310
300
Vertices [ vertex + j ] . TileXZ_Vertex = new Vector4 ( position . TileX , position . TileZ , j , 0 ) ;
0 commit comments