1- // COPYRIGHT 2009 - 2023 by the Open Rails project.
1+ // COPYRIGHT 2009 - 2023 by the Open Rails project.
22//
33// This file is part of Open Rails.
44//
@@ -41,8 +41,6 @@ public class PrecipitationViewer
4141 readonly Material Material ;
4242 readonly PrecipitationPrimitive Precipitation ;
4343
44- Vector3 Wind ;
45-
4644 public PrecipitationViewer ( Viewer viewer )
4745 {
4846 Viewer = viewer ;
@@ -51,14 +49,13 @@ public PrecipitationViewer(Viewer viewer)
5149 Material = viewer . MaterialManager . Load ( "Precipitation" ) ;
5250 Precipitation = new PrecipitationPrimitive ( Viewer . GraphicsDevice ) ;
5351
54- Wind = new Vector3 ( 0 , 0 , 0 ) ;
5552 Reset ( ) ;
5653 }
5754
5855 public void PrepareFrame ( RenderFrame frame , ElapsedTime elapsedTime )
5956 {
6057 var gameTime = ( float ) Viewer . Simulator . GameTime ;
61- Precipitation . DynamicUpdate ( Weather , ref Wind ) ;
58+ Precipitation . DynamicUpdate ( Weather ) ;
6259 Precipitation . Update ( gameTime , elapsedTime , Weather . PrecipitationIntensityPPSPM2 , Viewer ) ;
6360
6461 // 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)
7269
7370 public void Reset ( )
7471 {
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-
8072 var gameTime = ( float ) Viewer . Simulator . GameTime ;
81- Precipitation . Initialize ( Viewer . Simulator . WeatherType , Wind ) ;
73+ Precipitation . Initialize ( Viewer . Simulator . WeatherType ) ;
8274
8375 // Camera is null during first initialisation.
8476 if ( Viewer . Camera != null )
@@ -138,7 +130,6 @@ struct ParticleVertex
138130 }
139131
140132 float ParticleDuration ;
141- Vector3 ParticleDirection ;
142133 HeightCache Heights ;
143134
144135 // Particle buffer goes like this:
@@ -247,32 +238,31 @@ int GetCountFreeParticles()
247238 return ( MaxParticles - nextFree ) + FirstRetiredParticle ;
248239 }
249240
250- public void Initialize ( Orts . Formats . Msts . WeatherType weather , Vector3 wind )
241+ public void Initialize ( Orts . Formats . Msts . WeatherType weather )
251242 {
252243 ParticleDuration = ParticleBoxHeightM / ( weather == Orts . Formats . Msts . WeatherType . Snow ? SnowVelocityMpS : RainVelocityMpS ) / ParticleVelocityFactor ;
253- ParticleDirection = wind ;
254244 FirstActiveParticle = FirstNewParticle = FirstFreeParticle = FirstRetiredParticle = 0 ;
255245 ParticlesToEmit = TimeParticlesLastEmitted = 0 ;
256246 DrawCounter = 0 ;
257247 }
258248
259- public void DynamicUpdate ( Weather weather , ref Vector3 wind )
249+ public void DynamicUpdate ( Weather weather )
260250 {
261251 if ( weather . PrecipitationLiquidity == 0 || weather . PrecipitationLiquidity == 1 )
262252 {
263253 return ;
264254 }
265255
266256 ParticleDuration = ParticleBoxHeightM / ( ( ( RainVelocityMpS - SnowVelocityMpS ) * weather . PrecipitationLiquidity ) + SnowVelocityMpS ) / ParticleVelocityFactor ;
267- wind . X = ( 18 * weather . PrecipitationLiquidity ) + 2 ;
268- ParticleDirection = wind ;
269257 }
270258
271259 public void Update ( float currentTime , ElapsedTime elapsedTime , float particlesPerSecondPerM2 , Viewer viewer )
272260 {
273261 var tiles = viewer . Tiles ;
274262 var scenery = viewer . World . Scenery ;
275263 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 ) ;
276266
277267 if ( TimeParticlesLastEmitted == 0 )
278268 {
@@ -304,7 +294,7 @@ public void Update(float currentTime, ElapsedTime elapsedTime, float particlesPe
304294
305295 for ( var j = 0 ; j < VerticiesPerParticle ; j ++ )
306296 {
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 ) ;
308298 Vertices [ vertex + j ] . StartPosition_StartTime . Y += ParticleBoxHeightM ;
309299 Vertices [ vertex + j ] . EndPosition_EndTime = new Vector4 ( position . XNAMatrix . Translation , time + ParticleDuration ) ;
310300 Vertices [ vertex + j ] . TileXZ_Vertex = new Vector4 ( position . TileX , position . TileZ , j , 0 ) ;
0 commit comments