// This method will start sun wind. Or if there is one coming, this will reset it so it will start again. public static void Start() { IsActive = true; //m_burningCue = MyAudio.AddCue3D(MySoundCuesEnum.SfxSolarWind, m_initialSunWindPosition, m_directionFromSunNormalized, Vector3.Up, Vector3.Zero); const int meteorsCount = 5; //const int frontDistance = 1000; //const int sideDistance = 3000; const int minSpeed = 1000; const int maxSpeed = 4000; //Vector3 sphereCenter = MyCamera.Position + MyCamera.ForwardVector * frontDistance - MyCamera.LeftVector * sideDistance; Vector3 sphereCenter = MyCamera.Position + MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized() * 10000; //Vector3 windForwardDirection = MyCamera.LeftVector ; int i = 0; while (i < meteorsCount) { //float distance = MyMwcUtils.GetRandomFloat(0, sphereRadius); //Vector3 position = sphereCenter + MyMwcUtils.GetRandomVector3Normalized() * new Vector3(distance, distance, distance); //Vector3 meteorDirection = (windForwardDirection + (MyMwcUtils.GetRandomVector3Normalized() * 0.05f)) * MyMwcUtils.GetRandomInt(minSpeed, maxSpeed); //Vector3 meteorDirection = -MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized();// MyMwcUtils.GetRandomVector3HemisphereNormalized(-MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized()); Vector3 meteorDirection = MyMwcUtils.GetRandomVector3HemisphereNormalized(-MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized()); Vector3 position = sphereCenter + meteorDirection * MyMwcUtils.GetRandomInt(100, 5000); //float normalizedDistance = distance / sphereRadius; float size = MyMwcUtils.GetRandomInt(minSize, maxSize); MyLine line = new MyLine(position, position + meteorDirection * 100); MyIntersectionResultLineBoundingSphere?result = MyEntities.GetIntersectionWithLineAndBoundingSphere(ref line, null, null, 1, null, true); if (result != null) { //Do not create meteors colliding with base if (!(result.Value.PhysObject is MyMeteor)) { continue; } } Matrix worldMatrix = Matrix.CreateFromAxisAngle(MyMwcUtils.GetRandomVector3Normalized(), MyMwcUtils.GetRandomFloat(0, MathHelper.Pi)); worldMatrix.Translation = position; MyMeteor meteor = MyMeteor.GenerateMeteor(size, worldMatrix, position, m_fireMeteorMaterials[MyMwcUtils.GetRandomInt(0, m_fireMeteorMaterials.Count)]); float speed = MyMwcUtils.GetRandomInt(minSpeed, maxSpeed); meteor.Start(meteorDirection * speed, MyMwcUtils.GetRandomFloat(0, 1) > 0.92f ? 101 : 100); i++; } }
public static void Update() { // Update only if sun wind is active if (IsActive == false) { return; } float darkeningPhase; float dt; int relTime = GetDarkeningPhase(out darkeningPhase, out dt); if (relTime > MaxTimeMs) { Clear(); return; } MyAudio.UpdateCuePosition(ambientSound, MyCamera.Position + MyCamera.ForwardVector * -MaxSoundDistance * (1 - darkeningPhase), MyCamera.ForwardVector, MyCamera.UpVector, Vector3.Zero); MyAudio.UpdateCueVolume(ambientSound, darkeningPhase * MaxAmbientVolume); // update smoke foreach (SmokeParticle part in smokeParticles) { Vector3 toCamera = (MyCamera.Position - part.Pos); toCamera.Normalize(); float alpha = darkeningPhase * MaxSmokeAlpha; part.Color = new Vector4(alpha, alpha, alpha, alpha); //part.Color.W = darkeningPhase; part.Pos += part.Velocity * dt + toCamera * CenterBias * dt; part.Angle += part.AngularVelocity * dt; } // remove old ice and sparks m_iceList.Clear(); foreach (IceParticle particle in iceParticles) { if (particle.StartTime + 4000 < relTime) { m_iceList.Add(particle); } } foreach (IceParticle ice in m_iceList) { ice.AsteroidEntity.MarkForClose(); Debug.Assert(ice.TrailEffect != null, "ice.TrailEffect != null"); ice.TrailEffect.Stop(); ice.TrailEffect = null; StopCue(ice.Sound); iceParticles.Remove(ice); } int c = 0; while (c < storms.Count) { ElectricStorm storm = storms[c]; if (storm.StartTime + 1500 < relTime) { storms.RemoveAt(c); continue; } c++; } // if its dark add new sparks and ice balls if (darkeningPhase >= 1) { if (storms.Count < MaxSparkCount && MyMwcUtils.GetRandomInt(SparkEveryMs) < dt * 1000.0f) { var storm = new ElectricStorm { Position = MyCamera.Position + MyCamera.ForwardVector * 250 + MyMwcUtils.GetRandomVector3HemisphereNormalized(MyCamera.ForwardVector) * MyMwcUtils.GetRandomFloat(0, 300), StartTime = relTime, Effect = MyParticlesManager.CreateParticleEffect( (int)MyParticleEffectsIDEnum.Damage_Sparks), }; storm.Effect.WorldMatrix = Matrix.CreateTranslation(storm.Position); storm.Effect.AutoDelete = true; storm.Effect.UserScale = 2; storm.Sound = MyAudio.AddCue2D(MySoundCuesEnum.SfxSpark); storms.Add(storm); } if (iceParticles.Count < MaxIceCount && MyMwcUtils.GetRandomInt(IceEveryMs) < dt * 1000.0f) { Vector3 dir = MyMwcUtils.GetRandomVector3HemisphereNormalized(MyCamera.ForwardVector); Vector3 pos = MyCamera.Position + MyCamera.ForwardVector * 250 + MyMwcUtils.GetRandomVector3Normalized() * MyMwcUtils.GetRandomFloat(0, 200) + dir * MyMwcUtils.GetRandomFloat(0, 500); MyMwcObjectBuilder_StaticAsteroid rockModel = MySectorGenerator.GenerateStaticAsteroid(MyMwcUtils.GetRandomFloat(0.1f, 2f), MyStaticAsteroidTypeSetEnum.A, MyMwcVoxelMaterialsEnum.Ice_01, pos, random, asteroidTypes); Matrix matrix = Matrix.CreateFromAxisAngle(MyMwcUtils.GetRandomVector3Normalized(), MyMwcUtils.GetRandomFloat(0, MathHelper.Pi)); matrix.Translation = pos; MyEntity asteroid = MyEntities.CreateFromObjectBuilderAndAdd(null, rockModel, matrix); asteroid.Physics.Enabled = false; asteroid.CastShadows = false; MyParticleEffect effect = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_CannonShot); Vector3 velocity = -dir *MyMwcUtils.GetRandomInt(150, 400); iceParticles.Add(new IceParticle { StartTime = relTime, Position = pos, Direction = -dir, AsteroidEntity = asteroid, TrailEffect = effect, RotAxis = MyMwcUtils.GetRandomVector3Normalized(), RotAngle = MyMwcUtils.GetRandomRadian(), AngularVelocity = MyMwcUtils.GetRandomFloat(0.2f, 10f), Velocity = velocity, Sound = MyAudio.AddCue3D(MySoundCuesEnum.WepSniperHighFire2d, pos, dir, dir * -dir, velocity) }); } } // update ice parts foreach (IceParticle particle in iceParticles) { particle.RotAngle += particle.AngularVelocity * dt; particle.Position += particle.Velocity * dt; Matrix matrix = Matrix.CreateFromAxisAngle(particle.RotAxis, particle.RotAngle); matrix.Translation = particle.Position; particle.AsteroidEntity.SetWorldMatrix(matrix); Matrix trans = Matrix.CreateTranslation(-particle.Direction * 10); particle.TrailEffect.WorldMatrix = matrix * trans; MyAudio.UpdateCuePosition(particle.Sound, particle.Position, particle.Direction, particle.Direction * -particle.Direction, particle.Velocity); } lastUpdateMs = MyMinerGame.TotalGamePlayTimeInMilliseconds; }
public void CalculateStartPosition(float elapsedTime, Matrix worldMatrix, float userScale, out Vector3 startOffset, out Vector3 startPosition) { Vector3 currentOffsetUntransformed; Offset.GetInterpolatedValue <Vector3>(elapsedTime, out currentOffsetUntransformed); float currentSize; Size.GetInterpolatedValue <float>(elapsedTime, out currentSize); currentSize *= MyMwcUtils.GetRandomFloat(RadiusMin, RadiusMax) * userScale; Vector3 localPos = Vector3.Zero; Vector3 worldOffset; Vector3.Transform(ref currentOffsetUntransformed, ref worldMatrix, out worldOffset); switch (Type) { case MyParticleEmitterType.Point: localPos = Vector3.Zero; break; case MyParticleEmitterType.Line: localPos = Vector3.Forward * MyMwcUtils.GetRandomFloat(0.0f, currentSize); break; case MyParticleEmitterType.Sphere: localPos = MyMwcUtils.GetRandomVector3Normalized() * currentSize; break; case MyParticleEmitterType.Box: float currentSizeHalf = currentSize * 0.5f; localPos = new Vector3( MinerWars.CommonLIB.AppCode.Utils.MyMwcUtils.GetRandomFloat(-currentSizeHalf, currentSizeHalf), MinerWars.CommonLIB.AppCode.Utils.MyMwcUtils.GetRandomFloat(-currentSizeHalf, currentSizeHalf), MinerWars.CommonLIB.AppCode.Utils.MyMwcUtils.GetRandomFloat(-currentSizeHalf, currentSizeHalf) ); break; case MyParticleEmitterType.Hemisphere: localPos = MyMwcUtils.GetRandomVector3HemisphereNormalized(Vector3.Forward) * currentSize; break; case MyParticleEmitterType.Circle: localPos = MyMwcUtils.GetRandomVector3CircleNormalized() * currentSize; break; default: System.Diagnostics.Debug.Assert(false); break; } Vector3 worldPos; if (DirToCamera) { Matrix WorldView = worldMatrix * MyCamera.ViewMatrix; WorldView.Translation += currentOffsetUntransformed; Matrix newWorld = WorldView * Matrix.Invert(MyCamera.ViewMatrix); Vector3 dir = MyCamera.Position - newWorld.Translation; dir.Normalize(); Matrix matrix = MyMath.MatrixFromDir(dir); matrix.Translation = newWorld.Translation; Vector3.Transform(ref localPos, ref matrix, out worldPos); startOffset = newWorld.Translation; startPosition = worldPos; } else { Vector3.TransformNormal(ref localPos, ref worldMatrix, out worldPos); startOffset = worldOffset; startPosition = worldOffset + worldPos; } }