private void DisposeEffects() { nearEffects.ForEach((a) => MyParticlesManager.RemoveParticleEffect(a)); nearEffects.Clear(); farEffects.ForEach((a) => MyParticlesManager.RemoveParticleEffect(a)); farEffects.Clear(); }
private void UpdateEmitters() { var toRemove = new HashSet <IMySlimBlock>(); foreach (KeyValuePair <IMySlimBlock, MyParticleEffect> e in _emitters) { Vector3D pos = e.Key.GetPosition(); bool closed = e.Key.Closed(); bool zero = Vector3D.IsZero(pos); if (closed || zero) { //if(zero) //MyAPIGateway.Utilities.ShowMessage("Emitter", $"{closed}:{zero}"); toRemove.Add(e.Key); e.Value.Stop(); MyParticlesManager.RemoveParticleEffect(e.Value); continue; } MatrixD mat = e.Value.WorldMatrix; mat.Translation = pos; e.Value.WorldMatrix = mat; } foreach (IMySlimBlock r in toRemove) { _emitters.Remove(r); } }
public static void CheckAndRemoveEmitters(Dictionary <IMySlimBlock, int> newEmitters) { var toRemove = new HashSet <IMySlimBlock>(); foreach (KeyValuePair <IMySlimBlock, MyParticleEffect> e in _emitters) { if (MyAPIGateway.Session.Camera != null) { if (Vector3D.DistanceSquared(MyAPIGateway.Session.Camera.Position, e.Value.WorldMatrix.Translation) > 200 * 200) { toRemove.Add(e.Key); MyParticlesManager.RemoveParticleEffect(e.Value); continue; } } if (!newEmitters.ContainsKey(e.Key)) { toRemove.Add(e.Key); MyParticlesManager.RemoveParticleEffect(e.Value); } } foreach (IMySlimBlock r in toRemove) { _emitters.Remove(r); } }
private void UpdateParticleEffect() { if (_effectCachedModel != _reactor.Model) { _effectCachedModel = _reactor.Model; var tmp = new Dictionary <string, IMyModelDummy>(); _effectCachedModel?.GetDummies(tmp); _effectMatrix = tmp.GetValueOrDefault("subpart_PlasmaParticle")?.Matrix; // empty for particle } if (_reactor.IsWorking && _effectMatrix.HasValue) { var fractionalOutput = _reactor.CurrentOutput / _reactor.MaxOutput; var dTheta = MAX_RATE * fractionalOutput * MyEngineConstants.PHYSICS_STEP_SIZE_IN_SECONDS; _effectMatrix = _effectMatrix.Value * MatrixD.CreateRotationY(dTheta); if (_effect == null) { MyParticlesManager.TryCreateParticleEffect("PlasmaSparks", out _effect); // particle subtype } _effect.WorldMatrix = _effectMatrix.Value * _reactor.WorldMatrix; _effect.Velocity = _reactor.CubeGrid.Physics?.GetVelocityAtPoint(_effect.WorldMatrix.Translation) ?? Vector3.Right; // rotation } else { _effect?.Stop(); if (_effect != null) { MyParticlesManager.RemoveParticleEffect(_effect); } _effect = null; } }
void m_entity_OnClose(MyEntity obj) { if (m_shotSmoke != null) { MyParticlesManager.RemoveParticleEffect(m_shotSmoke); m_shotSmoke = null; } }
private void DestroyFxObjects() { if (_fxImpactParticles != null) { MyParticlesManager.RemoveParticleEffect(_fxImpactParticles); _fxImpactParticles = null; } }
public override void OnBeforeRemovedFromContainer() { base.OnBeforeRemovedFromContainer(); if (this.m_atmosphericEffect != null) { MyParticlesManager.RemoveParticleEffect(this.m_atmosphericEffect, false); this.m_atmosphericEffect = null; } }
public override void Close() { base.Close(); if (m_shotSmoke2 != null) { MyParticlesManager.RemoveParticleEffect(m_shotSmoke2); m_shotSmoke2 = null; } }
public override void Close() { base.Close(); if (m_particleEffect != null) { MyParticlesManager.RemoveParticleEffect(m_particleEffect); m_particleEffect = null; } }
public void StopEffect() { if (ParticleEffect != null) { MyParticlesManager.RemoveParticleEffect(ParticleEffect); ParticleEffect = null; } RefreshParticleSound(); }
public override void OnBeforeRemovedFromContainer() { if (MyAPIGateway.Utilities.IsDedicated) { return; } _reactor.IsWorkingChanged -= Reactor_IsWorkingChanged; _reactor = null; _effect?.Stop(); if (_effect != null) { MyParticlesManager.RemoveParticleEffect(_effect); } }
private void UpdateParticleEffect() { if (_effectCachedModel != _reactor.Model) { _effectCachedModel = _reactor.Model; var tmp = new Dictionary <string, IMyModelDummy>(); _effectCachedModel?.GetDummies(tmp); _effectMatrix = tmp.GetValueOrDefault("subpart_PlasmaParticle")?.Matrix; // empty for particle } if (_reactor.IsWorking && _effectMatrix.HasValue) { var fractionalOutput = _reactor.CurrentOutput / _reactor.MaxOutput; var dTheta = 1 * MyEngineConstants.PHYSICS_STEP_SIZE_IN_SECONDS; _effectMatrix = _effectMatrix.Value * MatrixD.CreateRotationY(-dTheta); if (_effect == null) { MyParticlesManager.TryCreateParticleEffect("EMPdamageEffect", out _effect); // particle subtype } _effect.WorldMatrix = _effectMatrix.Value * _reactor.WorldMatrix; _effect.Velocity = _reactor.CubeGrid.Physics?.GetVelocityAtPoint(_effect.WorldMatrix.Translation) ?? Vector3.Right; // rotation if (_effect == null) { return; } // if (Vector3D.DistanceSquared(MyAPIGateway.Session.Camera.WorldMatrix.Translation, _reactor.Position) >= ParticleMaxDistance * ParticleMaxDistance) // return; } else { _effect?.Stop(); if (_effect != null) { MyParticlesManager.RemoveParticleEffect(_effect); } _effect = null; if (_effect == null) { return; } } }
private static void Clear() { IsActive = false; foreach (IceParticle icePart in iceParticles) { icePart.AsteroidEntity.MarkForClose(); MyParticlesManager.RemoveParticleEffect(icePart.TrailEffect); StopCue(icePart.Sound); } iceParticles.Clear(); smokeParticles.Clear(); foreach (ElectricStorm storm in storms) { // MyParticlesManager.RemoveParticleEffect(storm.Effect); autoclear StopCue(storm.Sound); } storms.Clear(); StopCue(ambientSound); }
public void Draw() { var fire = IsShooting; var result = _raycastResult; var matrix = _dummy.Dummy.WorldMatrix; var origin = matrix.Translation; var dir = matrix.Forward; if (fire) { var from = origin; var to = from + dir * Definition.MaxLazeDistance; if (result.HasValue) { // if hitting a grid go an extra quarter block. Otherwise go an extra fourth of the bounding box var extraDist = (float)Math.Abs((result.Value.Root as IMyCubeGrid)?.GridSize ?? result.Value.Root?.PositionComp?.WorldAABB.HalfExtents .Dot(dir) ?? 0f) / 4f; if (result.Value.Root is IMyVoxelBase) { extraDist = 0.1f; } to = result.Value.HitPosition + extraDist * dir; } var thickness = BeamController.BeamWidth(_energyThroughput); var color = BeamController.BeamColor(_beamColor, _energyThroughput); MySimpleObjectDraw.DrawLine(from, to, BeamController.LaserMaterial, ref color, thickness); } if (!string.IsNullOrEmpty(Definition?.FxImpactName)) { _fxImpactCount = Math.Max(_fxImpactCount - 1, 0); if (fire) { _fxImpactCount = Math.Min(_fxImpactCount + Definition.FxImpactBirthRate, Definition.FxImpactMaxCount); } if (_fxImpactCount > 0 && result.HasValue) { if (_fxImpactParticles == null) { var up = (Vector3)dir; var fwd = Vector3.Normalize(Vector3.Cross(up, new Vector3(up.Y, up.Z, up.X))); var world = MatrixD.CreateWorld(result.Value.HitPosition, fwd, up); // MyParticlesManager.TryCreateParticleEffect(Definition?.FxImpactName, world, out _fxImpactParticles); MyParticlesManager.TryCreateParticleEffect(Definition.FxImpactName, out _fxImpactParticles); } if (_fxImpactParticles != null) { { var up = (Vector3)dir; var fwd = Vector3.Normalize(Vector3.Cross(up, new Vector3(up.Y, up.Z, up.X))); _fxImpactParticles.WorldMatrix = MatrixD.CreateWorld(result.Value.HitPosition, fwd, up); _fxImpactParticles.UserScale = Definition.FxImpactScale; _fxImpactParticles.Velocity = result.Value.Root?.Physics?.GetVelocityAtPoint(result.Value.HitPosition) ?? Vector3.Zero; } _fxImpactParticles.UserBirthMultiplier = _fxImpactCount; } } else { _fxImpactParticles?.StopEmitting(); if (_fxImpactParticles != null) { MyParticlesManager.RemoveParticleEffect(_fxImpactParticles); } _fxImpactParticles = null; } } }
private void DrawAtmosphericEntryEffect() { var naturalGravity = MyGravityProviderSystem.CalculateNaturalGravityInPoint(m_grid.PositionComp.GetPosition()); var naturalGravityMagnitude = naturalGravity.Length(); bool noPhysics = m_grid.Physics == null; bool recentlyHitVoxel = MySandboxGame.TotalGamePlayTimeInMilliseconds - m_lastVoxelContactTime < m_atmosphericEffectVoxelContactDelay; bool notNearPlanet = naturalGravityMagnitude <= 0; bool tooLowSpeed = !noPhysics && (m_grid.Physics.LinearVelocity.Length() < m_atmosphericEffectMinSpeed); if (noPhysics || recentlyHitVoxel || notNearPlanet || tooLowSpeed) { if (m_atmosphericEffect != null) { MyParticlesManager.RemoveParticleEffect(m_atmosphericEffect); m_atmosphericEffect = null; } return; } var currentVelocity = m_grid.Physics.LinearVelocity; var currentVelocityDirection = Vector3.Normalize(currentVelocity); var currentSpeed = currentVelocity.Length(); if (m_atmosphericEffect == null) { if (!MyParticlesManager.TryCreateParticleEffect(52, out m_atmosphericEffect)) { return; } } BoundingBox worldAABB = (BoundingBox)m_grid.PositionComp.WorldAABB; var aabbCenter = worldAABB.Center; var directionFaceCenter = new Vector3(); Debug.Assert(m_tmpCornerList.Count == 0); foreach (var corner in worldAABB.GetCorners()) { var centerToCorner = corner - aabbCenter; if (centerToCorner.Dot(currentVelocityDirection) > 0.01f) { m_tmpCornerList.Add(corner); directionFaceCenter += corner; if (m_tmpCornerList.Count == 4) { break; } } } if (m_tmpCornerList.Count > 0) { directionFaceCenter /= m_tmpCornerList.Count; } Plane plane = new Plane(directionFaceCenter, -currentVelocityDirection); m_tmpCornerList.Clear(); var startPosition = m_grid.Physics.CenterOfMassWorld; float?intersectDistance = new Ray(startPosition, currentVelocityDirection).Intersects(plane); m_lastWorkingIntersectDistance = intersectDistance ?? m_lastWorkingIntersectDistance; var intersectPoint = startPosition + 0.875f * currentVelocityDirection * m_lastWorkingIntersectDistance; Matrix worldMatrix = Matrix.Identity; worldMatrix.Translation = intersectPoint; worldMatrix.Forward = currentVelocityDirection; var forwardPerpendicular = Vector3.Transform(currentVelocityDirection, Quaternion.CreateFromAxisAngle(m_grid.PositionComp.WorldMatrix.Left, (float)Math.PI / 2.0f)); worldMatrix.Up = Vector3.Normalize(Vector3.Reject(m_grid.PositionComp.WorldMatrix.Left, forwardPerpendicular)); worldMatrix.Left = worldMatrix.Up.Cross(worldMatrix.Forward); var atmosphericDensityMultiplier = MyGravityProviderSystem.CalculateHighestNaturalGravityMultiplierInPoint(m_grid.PositionComp.GetPosition()); m_atmosphericEffect.UserScale = (float)worldAABB.ProjectedArea(currentVelocityDirection) / (float)Math.Pow(38.0 * m_grid.GridSize, 2.0); m_atmosphericEffect.UserAxisScale = Vector3.Normalize(new Vector3(1.0f, 1.0f, 1.0f + 1.5f * (m_grid.Physics.LinearVelocity.Length() - m_atmosphericEffectMinSpeed) / (MyGridPhysics.ShipMaxLinearVelocity() - m_atmosphericEffectMinSpeed))); m_atmosphericEffect.WorldMatrix = worldMatrix; m_atmosphericEffect.UserColorMultiplier = new Vector4(MathHelper.Clamp((currentSpeed - m_atmosphericEffectMinSpeed) / (m_atmosphericEffectMinSpeed * 0.5f) * (float)Math.Pow(atmosphericDensityMultiplier, 1.5), 0.0f, m_atmosphericEffectMinFade)); }
private unsafe void DrawAtmosphericEntryEffect() { int num1; bool flag = (MySandboxGame.TotalGamePlayTimeInMilliseconds - this.m_lastVoxelContactTime) < 0x1388; bool flag2 = !(MyGravityProviderSystem.CalculateNaturalGravityInPoint(this.m_grid.PositionComp.GetPosition()).Length() != 0f); bool flag1 = ReferenceEquals(this.m_grid.Physics, null); if (!flag1) { num1 = (int)(this.m_grid.Physics.LinearVelocity.Length() < 75f); } else { num1 = 0; } bool flag3 = (bool)num1; if (((flag1 | flag) | flag2) | flag3) { if (this.m_atmosphericEffect != null) { MyParticlesManager.RemoveParticleEffect(this.m_atmosphericEffect, false); this.m_atmosphericEffect = null; } } else { Vector3 linearVelocity = this.m_grid.Physics.LinearVelocity; Vector3 v = Vector3.Normalize(linearVelocity); float num2 = linearVelocity.Length(); BoundingBox worldAABB = (BoundingBox)this.m_grid.PositionComp.WorldAABB; Vector3 center = worldAABB.Center; Vector3 position = new Vector3(); foreach (Vector3 vector8 in worldAABB.GetCorners()) { Vector3 vector9 = vector8 - center; if (vector9.Dot(v) > 0.01f) { m_tmpCornerList.Add(vector8); position += vector8; if (m_tmpCornerList.Count == 4) { break; } } } if (m_tmpCornerList.Count > 0) { position /= (float)m_tmpCornerList.Count; } Plane plane = new Plane(position, -v); m_tmpCornerList.Clear(); Vector3D centerOfMassWorld = this.m_grid.Physics.CenterOfMassWorld; float? nullable2 = new Ray((Vector3)centerOfMassWorld, v).Intersects(plane); this.m_lastWorkingIntersectDistance = (nullable2 != null) ? nullable2.GetValueOrDefault() : this.m_lastWorkingIntersectDistance; Matrix identity = Matrix.Identity; identity.Translation = (Vector3)(centerOfMassWorld + ((0.875f * v) * this.m_lastWorkingIntersectDistance)); identity.Forward = v; Vector3 direction = Vector3.Transform(v, Quaternion.CreateFromAxisAngle((Vector3)this.m_grid.PositionComp.WorldMatrix.Left, 1.570796f)); identity.Up = Vector3.Normalize(Vector3.Reject((Vector3)this.m_grid.PositionComp.WorldMatrix.Left, direction)); Matrix *matrixPtr1 = (Matrix *)ref identity; matrixPtr1.Left = identity.Up.Cross(identity.Forward); float num3 = MyGravityProviderSystem.CalculateHighestNaturalGravityMultiplierInPoint(this.m_grid.PositionComp.GetPosition()); if ((this.m_atmosphericEffect != null) || MyParticlesManager.TryCreateParticleEffect("Dummy", identity, out this.m_atmosphericEffect)) { this.m_atmosphericEffect.UserScale = worldAABB.ProjectedArea(v) / ((float)Math.Pow(38.0 * this.m_grid.GridSize, 2.0)); this.m_atmosphericEffect.UserAxisScale = Vector3.Normalize(new Vector3(1f, 1f, 1f + ((1.5f * (this.m_grid.Physics.LinearVelocity.Length() - 75f)) / (MyGridPhysics.ShipMaxLinearVelocity() - 75f)))); this.m_atmosphericEffect.UserColorMultiplier = new Vector4(MathHelper.Clamp((float)(((num2 - 75f) / 37.5f) * ((float)Math.Pow((double)num3, 1.5))), (float)0f, (float)0.85f)); } } }