public ParticleSpring(Particle particle, Particle other, float springConstant, float restLength) : base(particle) { _other = other; _springConstant = springConstant; _restLength = restLength; }
public IPacket ReadPacket(IMinecraftDataReader reader) { ParticleID = (Particle) reader.ReadInt(); LongDistance = reader.ReadBoolean(); X = reader.ReadFloat(); Y = reader.ReadFloat(); Z = reader.ReadFloat(); OffsetX = reader.ReadFloat(); OffsetY = reader.ReadFloat(); OffsetZ = reader.ReadFloat(); ParticleData = reader.ReadFloat(); NumberOfParticles = reader.ReadInt(); switch (ParticleID) { case Particle.ITEM_CRACK: case Particle.BLOCK_CRACK: //case Particle.BLOCK_DUST: Data = reader.ReadVarIntArray(2); break; default: Data = reader.ReadVarIntArray(0); break; } return this; }
public int Fade(Particle particle, float ParticleLifeTime) { int fade = particle.Fade; if (ParticleFadeIn && ParticleFadeOut) { FadeDelay = (int)ParticleLifeTime / 2; } // Fade in if (ParticleFadeIn) { if (particle.TotalLifetime <= ParticleLifeTime - FadeDelay) { fade = (int)(((particle.TotalLifetime) / (ParticleLifeTime - FadeDelay)) * particle.InitialOpacity); } } // Fade out if (ParticleFadeOut) { if (particle.TotalLifetime > FadeDelay) { fade = particle.InitialOpacity - (int)(((particle.TotalLifetime - FadeDelay) / (ParticleLifeTime - FadeDelay)) * particle.InitialOpacity); } } return fade; }
public AddParticleDlg(Particle copy) { InitializeComponent(); /* Add relevant info to fields.. */ txtName.Text = copy.Name; txtAlphaStart.Text = copy.StartAlpha.ToString(); txtEndAlpha.Text = copy.EndAlpha.ToString(); txtRot.Text = copy.Rotation.ToString(); txtDeltaRot.Text = copy.RotationSpeed.ToString(); txtScale.Text = copy.ScaleStart.ToString(); txtScaleEnd.Text = copy.ScaleEnd.ToString(); txtMinLife.Text = copy.MinLife.ToString(); txtMaxLife.Text = copy.MaxLife.ToString(); txtTexturePath.Text = copy.TextureName; System.Drawing.Color color; color = System.Drawing.Color.FromArgb(copy.StartColor.R, copy.StartColor.G, copy.StartColor.B); pctStartColor.BackColor = color; pctEndColor.BackColor = System.Drawing.Color.FromArgb(copy.EndColor.R, copy.EndColor.G, copy.EndColor.B); StartColor = copy.StartColor; EndColor = copy.EndColor; EditedParticle = true; }
/// <summary> /// Processes the particles. /// </summary> /// <param name="dt">Elapsed time in whole and fractional seconds.</param> /// <param name="particleArray">A pointer to an array of particles.</param> /// <param name="count">The number of particles which need to be processed.</param> protected internal override unsafe void Process(float dt, Particle* particleArray, int count) { this.TotalSeconds += dt; float deltaAmp = this.Amplitude * dt; for (int i = 0; i < count; i++) { Particle* particle = (particleArray + i); float secondsAlive = this.TotalSeconds - particle->Inception; float sin = Calculator.Cos(secondsAlive * this.Frequency); Vector2 force = new Vector2(sin, 0f); force.X = ((force.X * this.AngleCos) + (force.Y * -this.AngleSin)); force.Y = ((force.X * this.AngleSin) + (force.Y * this.AngleCos)); force.X *= deltaAmp; force.Y *= deltaAmp; particle->Velocity.X += force.X; particle->Velocity.Y += force.Y; } }
protected override void ProcessConstant(float constant, float deltaTime, Particle[] particles, int begin, int end) { for (int i = begin; i < end; ++i) { particles[i].m_rotation = constant; } }
protected override void ProcessLinear(float bias, float scale, float deltaTime, Particle[] particles, int begin, int end) { for (int i = begin; i < end; ++i) { particles[i].m_rotation = bias + scale * particles[i].m_age / particles[i].m_life; } }
public void WhenParticleLifeIsPointFive_SetsColourBetweenInitialAndFinal() { var particle = new Particle { Age = new []{ 0.5f }, R = new float[1], G = new float[1], B = new float[1] }; var subject = new ColourInterpolator2 { InitialColour = new Colour(1f, 0f, 0f), FinalColour = new Colour(0f, 0f, 1f) }; unsafe { subject.Update(0.01666f, ref particle, 1); particle.R[0].Should().BeApproximately(0.5f, 0.000001f); particle.G[0].Should().BeApproximately(0f, 0.000001f); particle.B[0].Should().BeApproximately(0.5f, 0.000001f); } }
protected internal override void Update(float elapsedSeconds, ref Particle particle, int count) { fixed (float* agePtr = particle.Age) fixed (float* rPtr = particle.R) fixed (float* gPtr = particle.G) fixed (float* bPtr = particle.B) fixed (float* aPtr = particle.Opacity) { var ageDataPtr = agePtr; var rDataPtr = rPtr; var gDataPtr = gPtr; var bDataPtr = bPtr; var aDataPtr = aPtr; for (var j = 0; j < count; j++) { var age = *(ageDataPtr + j); var inverseAge = 1.0f - age; var alpha = InitialColour.A * age; *(aDataPtr + j) = alpha; *(rDataPtr + j) = InitialColour.H * inverseAge; *(gDataPtr + j) = InitialColour.S * inverseAge; *(bDataPtr + j) = InitialColour.L * inverseAge; } } }
public ParticleText(GraphicsDevice graphicsDevice, SpriteFont font, string text, Texture2D particleTexture, float scale,Vector2 screenSize ) { this.scale = scale; this.particleTexture = particleTexture; var viewport = graphicsDevice.Viewport; //screenSize = new Vector2(viewport.Width , viewport.Height-300);//this is in constructor now. this.screenSize = screenSize; textSize = font.MeasureString(text); Vector2 offset = (screenSize / scale - textSize) / 2f ; var textPoints = GetParticlePositions(graphicsDevice, font, text); foreach (var point in textPoints) { var particle = new Particle() { Position = GetRandomParticlePosition(), Destination = point + offset }; textParticles.Add(particle); } }
public void IteratesOverEachParticle() { var buffer = new Particle { Age = new float[100], R = new float[100], G = new float[100], B = new float[100] }; for (var i = 0; i < buffer.Age.Length; i++) buffer.Age[i] = 1.0f; var subject = new ColourInterpolator2 { InitialColour = new Colour(1f, 0f, 0f), FinalColour = new Colour(0f, 0f, 1f) }; subject.Update(0.1666666f, ref buffer, buffer.Age.Length); for (int i = 0; i < buffer.Age.Length; i++) { buffer.B[0].Should().BeApproximately(1f, 0.000001f); } }
public override void Update(Particle part) { //phaseTarget = phaseTarget % 1f; phase += phaseSpeed * Global.Speed * mult; phase = MathHelper.Clamp(phase, 0, 1); double pow = 1.5; float value = phase; value = (float)(Math.Pow(value, pow)); value = 1 - (float)Math.Pow(1 - value, pow); if (phase >= 1) { mult = -1; } else if (phase <= 0) { mult = 1; } Vector2 val = MyMath.Between(startScale, endScale, value); part.Scale = val; base.Update(part); }
/// <summary> /// Processes the particles. /// </summary> /// <param name="dt">Elapsed time in whole and fractional seconds.</param> /// <param name="particle">A pointer to an array of particles.</param> /// <param name="count">The number of particles which need to be processed.</param> protected internal override unsafe void Process(float dt, Particle* particle, int count) { for (int i = 0; i < count; i++) { Particle* previousParticle = particle - 1; if (particle->Momentum == previousParticle->Momentum) { particle->Rotation = previousParticle->Rotation; continue; } float rads = Calculator.Atan2(particle->Momentum.Y, particle->Momentum.X); particle->Rotation = (rads + this.RotationOffset); if (particle->Rotation > Calculator.Pi) particle->Rotation -= Calculator.TwoPi; else if (particle->Rotation < -Calculator.Pi) particle->Rotation += Calculator.TwoPi; particle++; } }
public ParticleSystem(int maxParticles) { MAX_PARTICLES = maxParticles; random = new Random(); _textures = new Texture2D[MAX_TEXTURES]; _particles = new Particle[MAX_PARTICLES]; for (int i = 0; i < MAX_PARTICLES; ++i) { _particles[i] = new Particle(null, _ttl, 0, 0, 0, 0, 0, 0); _particles[i]._exists = false; } _spawnBox.X = 0; _spawnBox.Y = 0; _minRotSpeed = 0; _maxRotSpeed = 0; _minRotInit = 0; _maxRotInit = 0; Angle = 0; _spawnCone = (float)Math.PI * 2f; _minSpeed = 10; _maxSpeed = 10; _alphaDecrement = 0.2f; _decrementTick = 5; _alphaIncrement = 0.2f; _incrementTick = 5; _isOn = true; }
public ParticleAnchoredSpring(Particle particle, Point3D anchor, float springConstant, float restLength) : base(particle) { Anchor = anchor; SpringConstant = springConstant; RestLength = restLength; }
public void Construction_CanCreateAParticleWithAnInitialPositionAndVelocity_AndItsPositionAndVelocityAreInitialised() { var particle = new Particle(TestPosition, TestVelocity); Assert.IsTrue(particle.Position.Equals(TestPosition)); Assert.IsTrue(particle.Velocity.Equals(TestVelocity)); }
public override void UpdateParticle(GameTime time, Particle spawn) { _momentum.X = (float)Math.Cos(spawn.Orientation) * spawn.Speed; _momentum.Y = (float)Math.Sin(spawn.Orientation) * spawn.Speed; if (spawn.Position.X < (float)_rect.X) { spawn.Position.X = (float)_rect.X; _momentum.X *= -1f; _momentum.X *= _bounce; } else if (spawn.Position.X > (float)_rect.Width) { spawn.Position.X = (float)_rect.Width; _momentum.X *= -1f; _momentum.X *= _bounce; } if (spawn.Position.Y < (float)_rect.Y) { spawn.Position.Y = (float)_rect.Y; _momentum.Y *= -1f; _momentum.Y *= _bounce; } else if (spawn.Position.Y > (float)_rect.Height) { spawn.Position.Y = (float)_rect.Height; _momentum.Y *= -1f; _momentum.Y *= _bounce; } spawn.Orientation = (float)Math.Atan2(_momentum.Y, _momentum.X); spawn.Speed = _momentum.Length(); }
public void Construction_CanCreateAParticleWithAnInitialPosition_AndItsPositionIsInitialised() { var particle = new Particle(TestPosition); Assert.IsTrue(particle.Position.Equals(TestPosition)); Assert.IsTrue(particle.Velocity.Equals(Vector3.ZeroVector)); }
/// <summary> /// Processes the specified Particle. /// </summary> /// <param name="dt">Elapsed time in whole and fractional seconds.</param> /// <param name="particle">The particle to be processed.</param> /// <param name="tag">The tag which has been attached to the Particle (or null).</param> public override unsafe void Process(float dt, Particle* particle, object tag) { float a = particle->Age * 0.07f, aInv = 1f - a; particle->Scale = (particle->Scale * aInv) + (this.MergeScale * a); }
public override void Initialize(Emitter emitter, Particle particle) { if (double.IsNaN(m_max)) particle.Lifetime = m_min; else particle.Lifetime = Utils.RandomDouble(m_min, m_max); }
/// <summary> /// Processes the particles. /// </summary> /// <param name="elapsedSeconds">Elapsed time in whole and fractional seconds.</param> /// <param name="particle">A pointer to the first item in an array of particles.</param> /// <param name="count">The number of particles which need to be processed.</param> protected internal override unsafe void Process(float elapsedSeconds, Particle* particle, int count) { particle->Colour.X = (this.InitialColour.X + ((this.UltimateColour.X - this.InitialColour.X) * particle->Age)); particle->Colour.Y = (this.InitialColour.Y + ((this.UltimateColour.Y - this.InitialColour.Y) * particle->Age)); particle->Colour.Z = (this.InitialColour.Z + ((this.UltimateColour.Z - this.InitialColour.Z) * particle->Age)); Particle* previousParticle = particle; particle++; for (int i = 1; i < count; i++) { if (particle->Age < previousParticle->Age) { particle->Colour.X = (this.InitialColour.X + ((this.UltimateColour.X - this.InitialColour.X) * particle->Age)); particle->Colour.Y = (this.InitialColour.Y + ((this.UltimateColour.Y - this.InitialColour.Y) * particle->Age)); particle->Colour.Z = (this.InitialColour.Z + ((this.UltimateColour.Z - this.InitialColour.Z) * particle->Age)); } else { particle->Colour.X = previousParticle->Colour.X; particle->Colour.Y = previousParticle->Colour.Y; particle->Colour.Z = previousParticle->Colour.Z; } previousParticle++; particle++; } }
void Start() { // Calculate the number of warp needed to handle all the particles if (particleCount <= 0) particleCount = 1; mWarpCount = Mathf.CeilToInt((float)particleCount / WARP_SIZE); // Initialize the Particle at the start Particle[] particleArray = new Particle[particleCount]; for (int i = 0; i < particleCount; ++i) { particleArray[i].position.x = Random.value * 2 - 1.0f; particleArray[i].position.y = Random.value * 2 - 1.0f; particleArray[i].position.z = 0; particleArray[i].velocity.x = 0; particleArray[i].velocity.y = 0; particleArray[i].velocity.z = 0; } // Create the ComputeBuffer holding the Particles particleBuffer = new ComputeBuffer(particleCount, SIZE_PARTICLE); particleBuffer.SetData(particleArray); // Find the id of the kernel mComputeShaderKernelID = computeShader.FindKernel("CSMain"); // Bind the ComputeBuffer to the shader and the compute shader computeShader.SetBuffer(mComputeShaderKernelID, "particleBuffer", particleBuffer); material.SetBuffer("particleBuffer", particleBuffer); }
/// <summary> /// Processes the particles. /// </summary> /// <param name="dt">Elapsed time in whole and fractional seconds.</param> /// <param name="particleArray">A pointer to an array of particles.</param> /// <param name="count">The number of particles which need to be processed.</param> protected internal override unsafe void Process(float dt, Particle* particleArray, int count) { Vector2 distance; float strengthDelta = this.Strength * dt; float deltaForceX = this.Force.X * strengthDelta; float deltaForceY = this.Force.Y * strengthDelta; for (int i = 0; i < count; i++) { Particle* particle = (particleArray + i); // Calculate the distance between the Particle and the center of the force... distance.X = this.Position.X - particle->Position.X; distance.Y = this.Position.Y - particle->Position.Y; float squareDistance = ((distance.X * distance.X) + (distance.Y * distance.Y)); // Check to see if the Particle is within range of the force... if (squareDistance < this.SquareRadius) { // Adjust the force vector based on the strength of the force and the time delta... particle->Velocity.X += deltaForceX; particle->Velocity.Y += deltaForceY; } } }
protected internal unsafe override void Update(float elapsedSeconds, ref Particle particle, int count) { _totalSeconds += elapsedSeconds; fixed (float* agePtr = particle.Age) fixed (float* inceptionPtr = particle.Inception) { var ageDataPtr = agePtr; var inceptionDataPtr = inceptionPtr; var term = _term; var totalSeconds = _totalSeconds; for (var j = 0; j < count; j++) { var age = (totalSeconds - *(inceptionDataPtr + j)) / term; // TODO: There is a fairly systemic bug in the emitter code right now that means that the inception time // of a particle can be later than the total elapsed time in here. It happens because the modifiers are // not necessarily updated every frame, while the emitter is. if (age < 0) age = 0; if (age > 1) age = 1; *(ageDataPtr + j) = age; } } }
/// <summary> /// Processes the particles. /// </summary> /// <param name="dt">Elapsed time in whole and fractional seconds.</param> /// <param name="particleArray">A pointer to an array of particles.</param> /// <param name="count">The number of particles which need to be processed.</param> protected internal override unsafe void Process(float dt, Particle* particleArray, int count) { // Create the transformation matrix... float h = ((this.HueShift * dt) * Calculator.Pi) / 180f; float u = Calculator.Cos(h); float w = Calculator.Sin(h); Matrix hueTransform = new Matrix(1f, 0f, 0f, 0f, 0f, u, -w, 0f, 0f, w, u, 0f, 0f, 0f, 0f, 1f); for (int i = 0; i < count; i++) { Particle* particle = (particleArray + i); Vector4 colour; // Convert the current colour of the particle to YIQ colour space... Vector4.Transform(ref particle->Colour, ref HueShiftModifier.YIQTransformMatrix, out colour); // Transform the colour in YIQ space... Vector4.Transform(ref colour, ref hueTransform, out colour); // Convert the colour back to RGB... Vector4.Transform(ref colour, ref HueShiftModifier.RGBTransformMatrix, out colour); // And apply back to the particle... particle->Colour.X = colour.X; particle->Colour.Y = colour.Y; particle->Colour.Z = colour.Z; } }
public void updateSmokeParticles(NoiseGenerator noise, float newX, float newY) { for (int i = 0; i < smoke.Length; i++) { if (smoke[i] != null) { if (smoke[i].currentAlpha > smoke[i].minAlpha) { smoke[i].currentAlpha -= 0.01f; smoke[i].x += smoke[i].moveX; smoke[i].y += smoke[i].moveY; smoke[i].angle += smoke[i].rotation; if (smoke[i].expanding) { if (smoke[i].currentSize < smoke[i].maxSize) { smoke[i].currentSize ++; } } else if (smoke[i].currentSize > smoke[i].minSize) { smoke[i].currentSize --; } } else if (smoke[i].looping) { float alpha = maxAlpha - (float)noise.random.NextDouble(); smoke[i] = new Particle(newX + noise.random.Next(-2, 3), newY + noise.random.Next(-2, 3), 0, 0, (float)(maxSize - i), 1f, maxSize, (alpha / ((float)i + 1)), 0f, 0f, (float)(noise.random.Next(-1, 2) * 0.1f), true, false, true); } } } }
public Emitter(Color a_Tint, Vector2 a_Position) { m_Position = a_Position; m_RotationMin = MathHelper.ToRadians(0); m_RotationMax = MathHelper.ToRadians(360); m_Amount = 16; m_LifeMin = 20.8f; m_LifeMax = 30.6f; m_Tint = a_Tint; m_Speed = 0.9f; for (int loop = 0; loop < m_Amount; loop++) { float tempRotation = (float)(new Random(EmitterManager.List.Count + loop + randSeed++).NextDouble() * (m_RotationMax - m_RotationMin)); tempRotation += m_RotationMin; float tempLife = (float)(new Random(EmitterManager.List.Count + loop + randSeed++).NextDouble() * (m_LifeMax - m_LifeMin)); tempLife += m_LifeMin; Particle tempParticle = new Particle(this); tempParticle.LifeTotal = tempLife; tempParticle.Rotation = tempRotation; tempParticle.Speed = m_Speed; tempParticle.Tint = m_Tint; tempParticle.Position = a_Position; m_List.Add(tempParticle); } EmitterManager.List.Add(this); }
protected internal unsafe override void Update(float elapsedSeconds, ref Particle particle, int count) { var velocityThreshold2 = VelocityThreshold * VelocityThreshold; var i = 0; unchecked { while (count-- > 0) { var velocity2 = ((particle.VX[i] * particle.VX[i]) + (particle.VY[i] * particle.VY[i])); if (velocity2 >= velocityThreshold2) { particle.R[i] = VelocityColour.H; particle.G[i] = VelocityColour.S; particle.B[i] = VelocityColour.L; } else { var t = (float)Math.Sqrt(velocity2) / VelocityThreshold; particle.R[i] = ((VelocityColour.H - StationaryColour.H) * t) + StationaryColour.H; particle.G[i] = ((VelocityColour.S - StationaryColour.S) * t) + StationaryColour.S; particle.B[i] = ((VelocityColour.L - StationaryColour.L) * t) + StationaryColour.L; } i++; } } }
public XnaRect ResolveUVBounds(string uvBoundsName, Particle.ParticleSystem system) { uvBoundsName = uvBoundsName ?? "{Whole}"; if (uvBoundsName == "{Whole}") { return system != null && system.TextureObject != null ? new XnaRect(0, 0, system.TextureObject.Width, system.TextureObject.Height) : XnaRect.Empty; } else if (uvBoundsName.StartsWith("{") && uvBoundsName.EndsWith("}")) { string[][] tokens = uvBoundsName.Substring(1, uvBoundsName.Length - 2) .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(t => t.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries)).ToArray(); int x, y, w, h; if (tokens.Length != 4 || tokens.Any(t => t.Length != 2) || tokens[0][0] != "x" || !int.TryParse(tokens[0][1], out x) || tokens[1][0] != "y" || !int.TryParse(tokens[1][1], out y) || (tokens[2][0] != "width" && tokens[2][0] != "w") || !int.TryParse(tokens[2][1], out w) || (tokens[3][0] != "height" && tokens[3][0] != "h") || !int.TryParse(tokens[3][1], out h)) { throw new FormatException(String.Format("Cannot convert '{0}' to a rectangle.", uvBoundsName)); } return new XnaRect(x, y, w, h); } else { return XnaRect.Empty; } }
/// <summary> /// Modifies a single Particle. /// </summary> /// <param name="time">Game timing information.</param> /// <param name="particle">Particle to modify.</param> public override void ProcessActiveParticle(GameTime time, Particle particle) { //particle.Momentum += (_gravity * (float)time.ElapsedGameTime.TotalSeconds); Vector2 dtGrav; Vector2.Multiply(ref _gravity, (float)time.ElapsedGameTime.TotalSeconds, out dtGrav); Vector2.Add(ref particle.Momentum, ref dtGrav, out particle.Momentum); }
void UpdateParticles2() { Plane movePlane = new Plane(); for (int i = 1; i < m_Particles.Count; ++i) { Particle p = m_Particles[i]; Particle p0 = m_Particles[p.m_ParentIndex]; float restLen; if (p.m_Transform != null) { restLen = (p0.m_Transform.position - p.m_Transform.position).magnitude; } else { restLen = p0.m_Transform.localToWorldMatrix.MultiplyVector(p.m_EndOffset).magnitude; } // keep shape float stiffness = Mathf.Lerp(1.0f, p.m_Stiffness, m_Weight); if (stiffness > 0 || p.m_Elasticity > 0) { Matrix4x4 m0 = p0.m_Transform.localToWorldMatrix; m0.SetColumn(3, p0.m_Position); Vector3 restPos; if (p.m_Transform != null) { restPos = m0.MultiplyPoint3x4(p.m_Transform.localPosition); } else { restPos = m0.MultiplyPoint3x4(p.m_EndOffset); } Vector3 d = restPos - p.m_Position; p.m_Position += d * p.m_Elasticity; if (stiffness > 0) { d = restPos - p.m_Position; float len = d.magnitude; float maxlen = restLen * (1 - stiffness) * 2; if (len > maxlen) { p.m_Position += d * ((len - maxlen) / len); } } } // collide if (m_Colliders != null) { float particleRadius = p.m_Radius * m_ObjectScale; for (int j = 0; j < m_Colliders.Count; ++j) { DynamicBoneCollider c = m_Colliders[j]; if (c != null && c.enabled) { c.Collide(ref p.m_Position, particleRadius); } } } // freeze axis, project to plane if (m_FreezeAxis != FreezeAxis.None) { switch (m_FreezeAxis) { case FreezeAxis.X: movePlane.SetNormalAndPosition(p0.m_Transform.right, p0.m_Position); break; case FreezeAxis.Y: movePlane.SetNormalAndPosition(p0.m_Transform.up, p0.m_Position); break; case FreezeAxis.Z: movePlane.SetNormalAndPosition(p0.m_Transform.forward, p0.m_Position); break; } p.m_Position -= movePlane.normal * movePlane.GetDistanceToPoint(p.m_Position); } // keep length Vector3 dd = p0.m_Position - p.m_Position; float leng = dd.magnitude; if (leng > 0) { p.m_Position += dd * ((leng - restLen) / leng); } } }
void ApplyParticlesToTransforms() { #if !UNITY_5_4_OR_NEWER // detect negative scale Vector3 ax = Vector3.right; Vector3 ay = Vector3.up; Vector3 az = Vector3.forward; bool nx = false, ny = false, nz = false; Vector3 loosyScale = transform.lossyScale; if (loosyScale.x < 0 || loosyScale.y < 0 || loosyScale.z < 0) { Transform mirrorObject = transform; do { Vector3 ls = mirrorObject.localScale; nx = ls.x < 0; if (nx) { ax = mirrorObject.right; } ny = ls.y < 0; if (ny) { ay = mirrorObject.up; } nz = ls.z < 0; if (nz) { az = mirrorObject.forward; } if (nx || ny || nz) { break; } mirrorObject = mirrorObject.parent; }while (mirrorObject != null); } #endif for (int i = 1; i < m_Particles.Count; ++i) { Particle p = m_Particles[i]; Particle p0 = m_Particles[p.m_ParentIndex]; if (p0.m_Transform.childCount <= 1) // do not modify bone orientation if has more then one child { Vector3 v; if (p.m_Transform != null) { v = p.m_Transform.localPosition; } else { v = p.m_EndOffset; } Vector3 v2 = p.m_Position - p0.m_Position; #if !UNITY_5_4_OR_NEWER if (nx) { v2 = MirrorVector(v2, ax); } if (ny) { v2 = MirrorVector(v2, ay); } if (nz) { v2 = MirrorVector(v2, az); } #endif Quaternion rot = Quaternion.FromToRotation(p0.m_Transform.TransformDirection(v), v2); p0.m_Transform.rotation = rot * p0.m_Transform.rotation; } if (p.m_Transform != null) { p.m_Transform.position = p.m_Position; } } }
public static IParticle AddParticleTarget(IObjAiBase unit, string particle, ITarget target, float size = 1.0f, string bone = "", Vector3 direction = new Vector3(), float lifetime = 0, bool reqVision = true) { var p = new Particle(_game, unit, target, particle, size, bone, 0, direction, lifetime, reqVision); return(p); }
// only update stiffness and keep bone length void SkipUpdateParticles() { for (int i = 0; i < m_Particles.Count; ++i) { Particle p = m_Particles[i]; if (p.m_ParentIndex >= 0) { p.m_PrevPosition += m_ObjectMove; p.m_Position += m_ObjectMove; Particle p0 = m_Particles[p.m_ParentIndex]; float restLen; if (p.m_Transform != null) { restLen = (p0.m_Transform.position - p.m_Transform.position).magnitude; } else { restLen = p0.m_Transform.localToWorldMatrix.MultiplyVector(p.m_EndOffset).magnitude; } // keep shape float stiffness = Mathf.Lerp(1.0f, p.m_Stiffness, m_Weight); if (stiffness > 0) { Matrix4x4 m0 = p0.m_Transform.localToWorldMatrix; m0.SetColumn(3, p0.m_Position); Vector3 restPos; if (p.m_Transform != null) { restPos = m0.MultiplyPoint3x4(p.m_Transform.localPosition); } else { restPos = m0.MultiplyPoint3x4(p.m_EndOffset); } Vector3 d = restPos - p.m_Position; float len = d.magnitude; float maxlen = restLen * (1 - stiffness) * 2; if (len > maxlen) { p.m_Position += d * ((len - maxlen) / len); } } // keep length Vector3 dd = p0.m_Position - p.m_Position; float leng = dd.magnitude; if (leng > 0) { p.m_Position += dd * ((leng - restLen) / leng); } } else { p.m_PrevPosition = p.m_Position; p.m_Position = p.m_Transform.position; } } }
public void Initialize(Particle particle) => particle.TransformationMatrix = Transform;
void AppendParticles(Transform b, int parentIndex, float boneLength) { Particle p = new Particle(); p.m_Transform = b; p.m_ParentIndex = parentIndex; if (b != null) { p.m_Position = p.m_PrevPosition = b.position; p.m_InitLocalPosition = b.localPosition; p.m_InitLocalRotation = b.localRotation; } else // end bone { Transform pb = m_Particles[parentIndex].m_Transform; if (m_EndLength > 0) { Transform ppb = pb.parent; if (ppb != null) { p.m_EndOffset = pb.InverseTransformPoint((pb.position * 2 - ppb.position)) * m_EndLength; } else { p.m_EndOffset = new Vector3(m_EndLength, 0, 0); } } else { p.m_EndOffset = pb.InverseTransformPoint(transform.TransformDirection(m_EndOffset) + pb.position); } p.m_Position = p.m_PrevPosition = pb.TransformPoint(p.m_EndOffset); } if (parentIndex >= 0) { boneLength += (m_Particles[parentIndex].m_Transform.position - p.m_Position).magnitude; p.m_BoneLength = boneLength; m_BoneTotalLength = Mathf.Max(m_BoneTotalLength, boneLength); } int index = m_Particles.Count; m_Particles.Add(p); if (b != null) { for (int i = 0; i < b.childCount; ++i) { bool exclude = false; if (m_Exclusions != null) { for (int j = 0; j < m_Exclusions.Count; ++j) { Transform e = m_Exclusions[j]; if (e == b.GetChild(i)) { exclude = true; break; } } } if (!exclude) { AppendParticles(b.GetChild(i), index, boneLength); } } if (b.childCount == 0 && (m_EndLength > 0 || m_EndOffset != Vector3.zero)) { AppendParticles(null, index, boneLength); } } }
/// <summary> /// クロスシミュレーション計算開始 /// </summary> /// <param name="update"></param> public void UpdateStartSimulation(UpdateTimeManager update) { // 時間 float deltaTime = update.DeltaTime; float physicsDeltaTime = update.PhysicsDeltaTime; float updatePower = update.UpdatePower; float updateDeltaTime = update.UpdateIntervalTime; int ups = update.UpdatePerSecond; // 活動チームが1つ以上ある場合のみ更新 if (Team.ActiveTeamCount > 0) { // 今回フレームの更新回数 int updateCount = Team.CalcMaxUpdateCount(ups, deltaTime, physicsDeltaTime, updateDeltaTime); //Debug.Log($"updateCount:{updateCount} dtime:{deltaTime} pdtime:{physicsDeltaTime} fixedCount:{update.FixedUpdateCount}"); // 風更新 Wind.UpdateWind(); // チームデータ更新、更新回数確定、ワールド移動影響、テレポート Team.PreUpdateTeamData(deltaTime, physicsDeltaTime, updateDeltaTime, ups, updateCount); // ワーカー処理 WarmupWorker(); // ボーン姿勢をパーティクルにコピーする Particle.UpdateBoneToParticle(); // 物理更新前ワーカー処理 //MasterJob = RenderMeshWorker.PreUpdate(MasterJob); // 何もなし MasterJob = VirtualMeshWorker.PreUpdate(MasterJob); // 仮想メッシュをスキニングしワールド姿勢を求める MasterJob = MeshParticleWorker.PreUpdate(MasterJob); // 仮想メッシュ頂点姿勢を連動パーティクルにコピーする //MasterJob = SpringMeshWorker.PreUpdate(MasterJob); // 何もなし //MasterJob = AdjustRotationWorker.PreUpdate(MasterJob); // 何もなし //MasterJob = LineWorker.PreUpdate(MasterJob); // 何もなし //MasterJob = BaseSkinningWorker.PreUpdate(MasterJob); // ベーススキニングによりbasePos/baseRotをスキニング // パーティクルのリセット判定 Particle.UpdateResetParticle(); // 物理更新 for (int i = 0, cnt = updateCount; i < cnt; i++) { UpdatePhysics(updateCount, i, updatePower, updateDeltaTime); } // 物理演算後処理 PostUpdatePhysics(updateDeltaTime); // 物理更新後ワーカー処理 MasterJob = TriangleWorker.PostUpdate(MasterJob); // トライアングル回転調整 MasterJob = LineWorker.PostUpdate(MasterJob); // ラインの回転調整 MasterJob = AdjustRotationWorker.PostUpdate(MasterJob); // パーティクル回転調整(Adjust Rotation) Particle.UpdateParticleToBone(); // パーティクル姿勢をボーン姿勢に書き戻す(ここに挟まないと駄目) MasterJob = SpringMeshWorker.PostUpdate(MasterJob); // メッシュスプリング MasterJob = MeshParticleWorker.PostUpdate(MasterJob); // パーティクル姿勢を仮想メッシュに書き出す MasterJob = VirtualMeshWorker.PostUpdate(MasterJob); // 仮想メッシュ座標書き込み(仮想メッシュトライアングル法線計算) MasterJob = RenderMeshWorker.PostUpdate(MasterJob); // レンダーメッシュ座標書き込み(仮想メッシュからレンダーメッシュ座標計算) // 書き込みボーン姿勢をローカル姿勢に変換する Bone.ConvertWorldToLocal(); // チームデータ後処理 Team.PostUpdateTeamData(); } }
public void Update(Particle particle) { }
public override bool Update(float deltaTime) { base.Update(deltaTime); float endTime = (BUILDUP_LENGTH + PAUSE_TIME + BURST_LENGTH); // update shader parameters _ripContrastData.Shader.Parameters["Time"].SetValue(_currentTime); _ripContrastData.Shader.Parameters["NoiseTexture"].SetValue(SpiritMod.Instance.GetTexture("Textures/Events/BigNoise")); _ripContrastData.Shader.Parameters["FieldCenter"].SetValue(_center); _ripContrastData.Shader.Parameters["ScreenRipStrength"].SetValue(_screenRipStrength.Ease(_currentTime)); _ripContrastData.Shader.Parameters["ContrastBubbleStrength"].SetValue(_contrastBubbleStrength.Ease(_currentTime)); _ripContrastData.Shader.Parameters["ScreenRipOffsetMultiplier"].SetValue((_currentTime < BUILDUP_LENGTH + PAUSE_TIME * 0.5f) ? 1f : -1f); _burstData.Shader.Parameters["FieldTexture"].SetValue(SpiritMod.Instance.GetTexture("Textures/Events/BeaconBurstTexture")); _burstData.Shader.Parameters["BurstRadius"].SetValue(_burstRadius.Ease(_currentTime)); _burstData.Shader.Parameters["BurstStrength"].SetValue(_burstStrength.Ease(_currentTime)); // glitch effect Main.LocalPlayer.GetSpiritPlayer().starplateGlitchEffect = true; // giltch effect paramaters float glitchMultiplier = _screenRipStrength.Ease(_currentTime); if (_currentTime >= BUILDUP_LENGTH) { glitchMultiplier *= Math.Max(1.0f - (_currentTime - BUILDUP_LENGTH) * 8f, 0f); } SpiritMod.glitchEffect.Parameters["Speed"].SetValue(glitchMultiplier * 0.3f); //0.4f is default SpiritMod.glitchScreenShader.UseIntensity(glitchMultiplier * 0.03f); // spawn new particles _gravEquationTop = G * _particleMass.Ease(_currentTime); int count = (int)_particleSpawnCount.Ease(_currentTime); if (_currentTime > BUILDUP_LENGTH) { count = 0; } for (int i = 0; i < count; i++) { float angle = Main.rand.NextFloat(-MathHelper.Pi, MathHelper.Pi); float distance = Main.rand.NextFloat(128f, 1024f); _particles.Add(new Particle(_center + angle.ToRotationVector2() * distance, (angle + MathHelper.PiOver2).ToRotationVector2() * Main.rand.NextFloat(1f, 3f))); } // update existing particles (using gravitational equation, mass of 1 so F=V) for (int i = 0; i < _particles.Count; i++) { Particle particle = _particles[i]; Vector2 newPos = particle.Position + particle.Velocity; particle.Position = newPos; Vector2 dir = _center - particle.Position; float r = dir.Length(); float f = _gravEquationTop / (r * r); particle.Velocity += Vector2.Normalize(dir) * f; particle.Opacity = Math.Min(particle.Opacity, MathHelper.Clamp(EaseFunction.EaseQuadOut.Ease(r / 1024f), 0f, 1f)); if (particle.Opacity <= 0f) { _particles.RemoveAt(i--); continue; } particle.Lifetime += deltaTime * 1.2f; if (particle.Lifetime > 1f) { particle.Lifetime = 1f; } _particles[i] = particle; } return(_currentTime >= endTime); }
public void GetParticle([FromUri] Particle particle) { }
private void ResetParticle(ref Particle p) { if (this.disposed) { throw new ObjectDisposedException("ParticleSystemRenderer"); } this.emitedParticle = true; p.Alive = true; if (this.settings.MinLife != this.settings.MaxLife) { float pLife = MathHelper.Lerp( this.settings.MinLife, this.settings.MaxLife, (float)this.random.NextDouble()); p.TimeLife = pLife; } else { p.TimeLife = this.settings.MinLife; } p.Life = p.TimeLife; // Velocity if (this.settings.RandomVelocity != Vector2.Zero) { p.Velocity.X = this.settings.LocalVelocity.X + (this.settings.RandomVelocity.X * (((float)this.random.NextDouble() * 2) - 1)); p.Velocity.Y = this.settings.LocalVelocity.Y + (this.settings.RandomVelocity.Y * (((float)this.random.NextDouble() * 2) - 1)); } else { p.Velocity.X = this.settings.LocalVelocity.X; p.Velocity.Y = this.settings.LocalVelocity.Y; } p.Position = (this.Transform as Transform3D).Position; p.StartTime = DateTime.Now.Ticks; if (this.settings.EmitterSize != Vector3.Zero) { switch (this.settings.EmitterShape) { case ParticleSystem2D.Shape.Circle: { float radius = this.settings.EmitterSize.X > this.settings.EmitterSize.Y ? (this.settings.EmitterSize.X / 2) : (this.settings.EmitterSize.Y / 2); double angle = this.random.NextDouble() * MathHelper.TwoPi; float x = (float)Math.Cos(angle); float y = (float)Math.Sin(angle); p.Position.X = p.Position.X + (x * radius); p.Position.Y = p.Position.Y + (y * radius); break; } case ParticleSystem2D.Shape.FillCircle: { float rnd0 = ((float)this.random.NextDouble() * 2) - 1; float rnd1 = ((float)this.random.NextDouble() * 2) - 1; float radius = this.settings.EmitterSize.X > this.settings.EmitterSize.Y ? (this.settings.EmitterSize.X / 2) : (this.settings.EmitterSize.Y / 2); double angle = this.random.NextDouble() * MathHelper.TwoPi; float x = (float)Math.Cos(angle); float y = (float)Math.Sin(angle); p.Position.X = p.Position.X + (x * radius * rnd0); p.Position.Y = p.Position.Y + (y * radius * rnd1); break; } case ParticleSystem2D.Shape.Rectangle: { int c = this.random.Next(4); float rnd0 = ((float)this.random.NextDouble() * 2) - 1; float xside = this.settings.EmitterSize.X / 2; float yside = this.settings.EmitterSize.Y / 2; switch (c) { case 0: p.Position.X = p.Position.X + xside; p.Position.Y = p.Position.Y + (yside * rnd0); break; case 1: p.Position.X = p.Position.X - xside; p.Position.Y = p.Position.Y + (yside * rnd0); break; case 2: p.Position.X = p.Position.X + (xside * rnd0); p.Position.Y = p.Position.Y + yside; break; case 3: default: p.Position.X = p.Position.X + (xside * rnd0); p.Position.Y = p.Position.Y - yside; break; } break; } case ParticleSystem2D.Shape.FillRectangle: { float rnd0 = ((float)this.random.NextDouble() * 2) - 1; float rnd1 = ((float)this.random.NextDouble() * 2) - 1; p.Position.X = p.Position.X + ((this.settings.EmitterSize.X / 2) * rnd0); p.Position.Y = p.Position.Y + ((this.settings.EmitterSize.Y / 2) * rnd1); break; } case ParticleSystem2D.Shape.FillBox: { float rnd0 = ((float)this.random.NextDouble() * 2) - 1; float rnd1 = ((float)this.random.NextDouble() * 2) - 1; float rnd2 = ((float)this.random.NextDouble() * 2) - 1; p.Position.X = p.Position.X + ((this.settings.EmitterSize.X / 2) * rnd0); p.Position.Y = p.Position.Y + ((this.settings.EmitterSize.Y / 2) * rnd1); p.Position.Z = p.Position.Z + ((this.settings.EmitterSize.Z / 2) * rnd1); break; } default: { throw new ArgumentException("Invalid particleSystem shape"); } } } // Initial Angle if (this.settings.InitialAngle.Distinct(0) || this.settings.InitialAngleVariation.Distinct(0)) { float randomAngle = this.settings.InitialAngleVariation * (((float)this.random.NextDouble() * 2) - 1); p.Angle = this.settings.InitialAngle + randomAngle; } // Velocity Rotation if (this.settings.MinRotateSpeed.Distinct(this.settings.MaxRotateSpeed)) { p.VelocityRotation = MathHelper.Lerp(this.settings.MinRotateSpeed, this.settings.MaxRotateSpeed, (float)this.random.NextDouble()); } else { p.VelocityRotation = this.settings.MinRotateSpeed; } // Size if (this.settings.MinSize.Distinct(this.settings.MaxSize)) { p.Size = MathHelper.Lerp(this.settings.MinSize, this.settings.MaxSize, (float)this.random.NextDouble()); } else { p.Size = this.settings.MinSize; } // Color if (this.settings.MinColor != this.settings.MaxColor) { p.CurrentColor = Color.Lerp(this.settings.MinColor, this.settings.MaxColor, 1 - (float)this.random.NextDouble()); } else { p.CurrentColor = this.settings.MinColor; } p.Color = p.CurrentColor; p.CurrentIndex = -1; Matrix.CreateFromYawPitchRoll(0, 0, this.Transform.Rotation, out this.rotationMatrix); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Particle obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
/// <summary> /// Draws the particle system. /// </summary> /// <param name="gameTime">The elapsed game time.</param> public override void Draw(TimeSpan gameTime) { // Optimización del estado inactivo if (this.System.NumParticles == 0 || (!this.internalEnabled && !this.settings.Emit)) { return; } if (this.numParticles != this.System.NumParticles) { this.LoadParticleSystem(); } if (!this.Owner.Scene.IsPaused) { // Sets the timeFactor for updating velocities. float timeFactor = VELOCITYFACTOR * (float)gameTime.TotalSeconds; this.aliveParticles = 0; // Sorts the array according age. if (this.settings.SortEnabled && this.emitedParticle) { Array.Sort( this.particles, delegate(Particle p1, Particle p2) { if (p1.StartTime != p2.StartTime) { return(p1.StartTime.CompareTo(p2.StartTime)); } else { return(p1.Life.CompareTo(p2.Life)); } }); } this.emitedParticle = false; bool infiniteCreation = this.settings.EmitRate == 0; // Sets the time passed between 2 particles creation. this.emitLapse = (this.settings.EmitRate > 0) ? 1 / this.settings.EmitRate : 0; int particlesToCreate = 0; if (!infiniteCreation) { float particlesToCreateF = ((float)gameTime.TotalSeconds / this.emitLapse) + this.emitRemainder; particlesToCreate = (int)particlesToCreateF; this.emitRemainder = particlesToCreateF - particlesToCreate; } int nVertices = 0; // Recorremos todas las partículas for (int i = 0; i < this.numParticles; i++) { Particle p = this.particles[i]; // Update particle // Si la partícula está viva seguimos consumiendo su vida if (p.Alive) { p.Life = p.Life - gameTime.TotalSeconds; } // Si la partícula ha llegado al final de su vida if (p.Life < 0) { // Si permitimos la emisión de nuevas partículas y debe resetear sus valores if (this.settings.Emit && (infiniteCreation || (particlesToCreate > 0))) { this.ResetParticle(ref p); particlesToCreate--; } else { // Si la particula no está viva p.Alive = false; p.Size = 0; } } else { // Si la particula está viva y visible // p.Position p.Velocity.X = p.Velocity.X + (timeFactor * this.settings.Gravity.X); p.Velocity.Y = p.Velocity.Y + (timeFactor * this.settings.Gravity.Y); // Calculate the rotation with the transform Vector3.TransformNormal(ref p.Velocity, ref this.rotationMatrix, out this.rotationVector); p.Position.X = p.Position.X + (timeFactor * this.rotationVector.X); p.Position.Y = p.Position.Y + (timeFactor * this.rotationVector.Y); if (this.settings.CollisionType != ParticleSystem2D.ParticleCollisionFlags.None) { // Checks vertical collisions if (this.settings.CollisionType.HasFlag(ParticleSystem2D.ParticleCollisionFlags.Bottom) && (p.Position.Y > this.settings.CollisionBottom)) { switch (this.settings.CollisionBehavior) { case ParticleSystem2D.ParticleCollisionBehavior.Die: // Kills the particle p.Alive = false; p.Size = 0; p.Life = -1; break; case ParticleSystem2D.ParticleCollisionBehavior.Bounce: // Mirrors the position and velocity with the bounciness factor. float bounciness = this.settings.Bounciness; p.Position.Y = this.settings.CollisionBottom - (bounciness * (p.Position.Y - this.settings.CollisionBottom)); // Applies the collision spread to the velocity if (this.settings.CollisionSpread != Vector2.Zero) { p.Velocity.X = bounciness * (p.Velocity.X + (this.settings.CollisionSpread.X * (((float)this.random.NextDouble() * 2) - 1))); p.Velocity.Y = -bounciness * (p.Velocity.Y + (this.settings.CollisionSpread.Y * (((float)this.random.NextDouble() * 2) - 1))); } else { p.Velocity.X = bounciness * p.Velocity.X; p.Velocity.Y = -bounciness * p.Velocity.Y; } break; default: // Do nothing break; } } else if (this.settings.CollisionType.HasFlag(ParticleSystem2D.ParticleCollisionFlags.Top) && (p.Position.Y < this.settings.CollisionTop)) { switch (this.settings.CollisionBehavior) { case ParticleSystem2D.ParticleCollisionBehavior.Die: // Kills the particle p.Alive = false; p.Size = 0; p.Life = -1; break; case ParticleSystem2D.ParticleCollisionBehavior.Bounce: // Mirrors the position and velocity with the bounciness factor. float bounciness = this.settings.Bounciness; p.Position.Y = this.settings.CollisionTop + (bounciness * (this.settings.CollisionTop - p.Position.Y)); // Applies the collision spread to the velocity if (this.settings.CollisionSpread != Vector2.Zero) { p.Velocity.X = bounciness * (p.Velocity.X + (this.settings.CollisionSpread.X * (((float)this.random.NextDouble() * 2) - 1))); p.Velocity.Y = -bounciness * (p.Velocity.Y + (this.settings.CollisionSpread.Y * (((float)this.random.NextDouble() * 2) - 1))); } else { p.Velocity.X = bounciness * p.Velocity.X; p.Velocity.Y = -bounciness * p.Velocity.Y; } break; default: // Do nothing break; } } // Checks horizontal collisions if (this.settings.CollisionType.HasFlag(ParticleSystem2D.ParticleCollisionFlags.Right) && (p.Position.X > this.settings.CollisionRight)) { switch (this.settings.CollisionBehavior) { case ParticleSystem2D.ParticleCollisionBehavior.Die: // Kills the particle p.Alive = false; p.Size = 0; p.Life = -1; break; case ParticleSystem2D.ParticleCollisionBehavior.Bounce: // Mirrors the position and velocity with the bounciness factor. float bounciness = this.settings.Bounciness; p.Position.X = this.settings.CollisionRight - (bounciness * (p.Position.X - this.settings.CollisionRight)); // Applies the collision spread to the velocity if (this.settings.CollisionSpread != Vector2.Zero) { p.Velocity.X = -bounciness * (p.Velocity.X + (this.settings.CollisionSpread.X * (((float)this.random.NextDouble() * 2) - 1))); p.Velocity.Y = bounciness * (p.Velocity.Y + (this.settings.CollisionSpread.Y * (((float)this.random.NextDouble() * 2) - 1))); } else { p.Velocity.X = -bounciness * p.Velocity.X; p.Velocity.Y = bounciness * p.Velocity.Y; } break; default: // Do nothing break; } } else if (this.settings.CollisionType.HasFlag(ParticleSystem2D.ParticleCollisionFlags.Left) && (p.Position.X < this.settings.CollisionLeft)) { switch (this.settings.CollisionBehavior) { case ParticleSystem2D.ParticleCollisionBehavior.Die: // Kills the particle p.Alive = false; p.Size = 0; p.Life = -1; break; case ParticleSystem2D.ParticleCollisionBehavior.Bounce: // Mirrors the position and velocity with the bounciness factor. float bounciness = this.settings.Bounciness; p.Position.X = this.settings.CollisionLeft + (bounciness * (this.settings.CollisionLeft - p.Position.X)); // Applies the collision spread to the velocity if (this.settings.CollisionSpread != Vector2.Zero) { p.Velocity.X = -bounciness * (p.Velocity.X + (this.settings.CollisionSpread.X * (((float)this.random.NextDouble() * 2) - 1))); p.Velocity.Y = bounciness * (p.Velocity.Y + (this.settings.CollisionSpread.Y * (((float)this.random.NextDouble() * 2) - 1))); } else { p.Velocity.X = -bounciness * p.Velocity.X; p.Velocity.Y = bounciness * p.Velocity.Y; } break; default: // Do nothing break; } } } // Rotate p.Angle = p.Angle + (timeFactor * p.VelocityRotation); // Color if (this.settings.LinearColorEnabled && p.TimeLife != 0 && this.settings.InterpolationColors != null && this.settings.InterpolationColors.Count > 1) { // Num destiny colors int count = this.settings.InterpolationColors.Count; // Current lerp double lerp = 1 - (p.Life / p.TimeLife); // Life time of one color double colorPeriod = 1 / (count - 1.0); // destiny Color int sourceIndex = (int)(lerp / colorPeriod); sourceIndex = Math.Max(0, Math.Min(count - 2, sourceIndex)); double currentLerp = (lerp - (sourceIndex * colorPeriod)) / colorPeriod; Color sourceColor = this.settings.InterpolationColors[sourceIndex]; Color destinyColor = this.settings.InterpolationColors[sourceIndex + 1]; p.Color = Color.Lerp(ref sourceColor, ref destinyColor, (float)currentLerp); } else { p.Color = p.CurrentColor; } if (this.settings.AlphaEnabled && p.TimeLife.Distinct(0)) { double age = p.Life / p.TimeLife; p.Color *= (float)age; } p.Color *= this.Transform.GlobalOpacity; // Update Vertex Buffer Matrix world = this.CalculateLocalWorld(ref p); Vector3.Transform(ref vertex1, ref world, out this.vertices[nVertices].Position); this.vertices[nVertices++].Color = p.Color; Vector3.Transform(ref vertex2, ref world, out this.vertices[nVertices].Position); this.vertices[nVertices++].Color = p.Color; Vector3.Transform(ref vertex3, ref world, out this.vertices[nVertices].Position); this.vertices[nVertices++].Color = p.Color; Vector3.Transform(ref vertex4, ref world, out this.vertices[nVertices].Position); this.vertices[nVertices++].Color = p.Color; // Si la partícula está viva la contamos if (p.Alive) { this.aliveParticles++; } } } this.internalEnabled = this.aliveParticles > 0; if (this.internalEnabled) { this.mesh.NumVertices = nVertices; this.mesh.NumPrimitives = nVertices / 2; this.mesh.ZOrder = this.Transform.DrawOrder; this.mesh.VertexBuffer.SetData(this.vertices, this.numVertices); this.GraphicsDevice.BindVertexBuffer(this.mesh.VertexBuffer); this.RenderManager.DrawMesh(this.mesh, this.MaterialsMap.DefaultMaterial, ref localWorld, false); } } else { // if the scene is paused, draw the previous mesh this.RenderManager.DrawMesh(this.mesh, this.MaterialsMap.DefaultMaterial, ref localWorld, false); } }
private static void Detect(Detector detector, Particle particle, out bool r) { r = detector.InDirectionOfDetector(particle); }