Skip to content

Commit 99f5087

Browse files
committed
feat: Make particles respond to instantaneous wind speed and direction
1 parent 920870a commit 99f5087

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

Source/RunActivity/Viewer3D/ParticleEmitter.cs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,31 @@
1-
// COPYRIGHT 2011, 2012, 2013, 2014 by the Open Rails project.
2-
//
1+
// COPYRIGHT 2009 - 2023 by the Open Rails project.
2+
//
33
// This file is part of Open Rails.
4-
//
4+
//
55
// Open Rails is free software: you can redistribute it and/or modify
66
// it under the terms of the GNU General Public License as published by
77
// the Free Software Foundation, either version 3 of the License, or
88
// (at your option) any later version.
9-
//
9+
//
1010
// Open Rails is distributed in the hope that it will be useful,
1111
// but WITHOUT ANY WARRANTY; without even the implied warranty of
1212
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313
// GNU General Public License for more details.
14-
//
14+
//
1515
// You should have received a copy of the GNU General Public License
1616
// along with Open Rails. If not, see <http://www.gnu.org/licenses/>.
1717

18-
// This file is the responsibility of the 3D & Environment Team.
18+
// This file is the responsibility of the 3D & Environment Team.
1919

2020
// Enable this define to debug the inputs to the particle emitters from other parts of the program.
2121
//#define DEBUG_EMITTER_INPUT
2222

23+
using System;
24+
using System.Collections.Generic;
2325
using Microsoft.Xna.Framework;
2426
using Microsoft.Xna.Framework.Graphics;
25-
using Microsoft.Xna.Framework.Graphics.PackedVector;
26-
using Orts.Simulation.RollingStocks;
2727
using ORTS.Common;
28-
using System;
29-
using System.Collections.Generic;
30-
using System.Runtime.InteropServices;
28+
using Orts.Simulation.RollingStocks;
3129

3230
namespace Orts.Viewer3D
3331
{
@@ -211,9 +209,6 @@ struct ParticleVertex
211209

212210
Viewer viewer;
213211
GraphicsDevice graphicsDevice;
214-
215-
static float windDisplacementX;
216-
static float windDisplacementZ;
217212

218213
public ParticleEmitterPrimitive(Viewer viewer, ParticleEmitterData data, WorldPosition worldPosition)
219214
{
@@ -321,9 +316,6 @@ int GetCountFreeParticles()
321316

322317
public void Update(float currentTime, ElapsedTime elapsedTime)
323318
{
324-
windDisplacementX = viewer.Simulator.Weather.WindInstantaneousDirection.X * 0.25f;
325-
windDisplacementZ = viewer.Simulator.Weather.WindInstantaneousDirection.Y * 0.25f;
326-
327319
var velocity = WorldPosition.Location - LastWorldPosition.Location;
328320
velocity.X += (WorldPosition.TileX - LastWorldPosition.TileX) * 2048;
329321
velocity.Z += (WorldPosition.TileZ - LastWorldPosition.TileZ) * 2048;
@@ -369,15 +361,15 @@ public void Update(float currentTime, ElapsedTime elapsedTime)
369361
initialVelocity.X += (float)(Viewer.Random.NextDouble() - 0.5f) * ParticleEmitterViewer.InitialSpreadRate;
370362
initialVelocity.Z += (float)(Viewer.Random.NextDouble() - 0.5f) * ParticleEmitterViewer.InitialSpreadRate;
371363

372-
// Target/final velocity vaies in X, Y and Z.
364+
// Target/final velocity varies in X, Y and Z.
373365
var targetVelocity = globalTargetVelocity;
374366
targetVelocity.X += Noise.Generate(time + PerlinStart[0]) * ParticleEmitterViewer.SpreadRate;
375367
targetVelocity.Y += Noise.Generate(time + PerlinStart[1]) * ParticleEmitterViewer.SpreadRate;
376368
targetVelocity.Z += Noise.Generate(time + PerlinStart[2]) * ParticleEmitterViewer.SpreadRate;
377369

378370
// Add wind speed
379-
targetVelocity.X += windDisplacementX;
380-
targetVelocity.Z += windDisplacementZ;
371+
targetVelocity.X += viewer.Simulator.Weather.WindInstantaneousSpeedMpS * viewer.Simulator.Weather.WindInstantaneousDirection.X;
372+
targetVelocity.Z += viewer.Simulator.Weather.WindInstantaneousSpeedMpS * viewer.Simulator.Weather.WindInstantaneousDirection.Y;
381373

382374
// ActionDuration is variable too.
383375
var duration = ParticleDuration * (1 + Noise.Generate(time + PerlinStart[3]) * ParticleEmitterViewer.DurationVariation);

0 commit comments

Comments
 (0)