public override void Draw() { base.Draw(); if (!ShouldDrawParticles) { return; } var direction = -Vector3.Normalize(ControlledVelocity); float thickness = 0.025f; float speed = ControlledVelocity.Length(); float length = (float)MathHelper.Clamp(speed / 50.0f, 0.0, 1.0); foreach (var particle in m_activeParticles) { if (!particle.Active) { continue; } MyTransparentGeometry.AddLineBillboard(particle.Material, particle.Color, particle.Position, direction, length, thickness); } }
public override void UpdateBeforeSimulation() { base.UpdateBeforeSimulation(); ProfilerShort.Begin("SpaceParticles.UpdateBeforeSimulation"); try { if (!ShouldDrawParticles) { return; } if (ControlledVelocity.Length() < 10.0f) { return; } var distance = ParticleSpawnDistance; var angle = Math.PI / 2.0f; var tanFovSq = 1.0f; // Math.Tan(angle / 2.0f); var velocityVector = ControlledVelocity - 8.5f * Vector3.Normalize(ControlledVelocity); var sweepArea = 4 * distance * distance * tanFovSq; m_particlesLeftToSpawn += (float)((0.25f + MyRandom.Instance.NextFloat() * 1.25f) * velocityVector.Length() * sweepArea * ParticleDensity * VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_MILLISECONDS); // particles/update if (m_particlesLeftToSpawn < 1.0f) { return; } var minAngle = angle / 2.0f; var maxAngle = minAngle + angle; var phi = minAngle + MyRandom.Instance.NextFloat() * (maxAngle - minAngle); var theta = minAngle + MyRandom.Instance.NextFloat() * (maxAngle - minAngle); var restrictedAngleAmount = 6.0f; while (m_particlesLeftToSpawn-- >= 1.0f) { float degree = (float)Math.PI / 180.0f; if (Math.Abs(phi - Math.PI / 2.0) < restrictedAngleAmount * degree && Math.Abs(theta - Math.PI / 2.0) < restrictedAngleAmount * degree) { phi += (Math.Sign(MyRandom.Instance.NextFloat()) * restrictedAngleAmount * degree); theta += (Math.Sign(MyRandom.Instance.NextFloat()) * restrictedAngleAmount * degree); } var sinTheta = (float)Math.Sin(theta); var cosTheta = (float)Math.Cos(theta); var sinPhi = (float)Math.Sin(phi); var cosPhi = (float)Math.Cos(phi); var upVector = MySector.MainCamera.UpVector; var forwardVector = Vector3.Normalize(velocityVector); var leftVector = Vector3.Cross(forwardVector, -upVector); Vector3 particlePosition = MySector.MainCamera.Position + distance * (upVector * cosTheta + leftVector * sinTheta * cosPhi + forwardVector * sinTheta * sinPhi); Spawn(particlePosition); m_lastParticleSpawn = MySandboxGame.TotalGamePlayTimeInMilliseconds; } } finally { ProfilerShort.End(); } }