protected override void SetParticle(int idx, NodeReference reference, ParticleEffectInstance instance, ref Matrix4 transform, float sparam, float globaltime) { float w = Width.GetValue(sparam, 0) / 2; float h = Height.GetValue(sparam, 0) / 2; float d = Depth.GetValue(sparam, 0) / 2; float s_min = MathHelper.DegreesToRadians(MinSpread.GetValue(sparam, 0)); float s_max = MathHelper.DegreesToRadians(MaxSpread.GetValue(sparam, 0)); var pos = new Vector3( FxRandom.NextFloat(-w, w), FxRandom.NextFloat(-h, h), FxRandom.NextFloat(-d, d) ); var n = RandomInCone(s_min, s_max); //var tr = Transform.GetMatrix(sparam, globaltime); //var tr = Matrix4.Identity; //n = (tr * new Vector4(n.Normalized(), 0)).Xyz.Normalized(); Vector3 translate; Quaternion rotate; if (DoTransform(reference, sparam, globaltime, out translate, out rotate)) { pos += translate; n = rotate * n; } var pr = pos; instance.Pool.Particles[idx].Position = pr; instance.Pool.Particles [idx].Normal = n * Pressure.GetValue(sparam, 0); }
protected override void SetParticle(int idx, NodeReference reference, ParticleEffectInstance instance, ref Matrix4x4 transform, float sparam, float globaltime) { var r_min = MinRadius.GetValue(sparam, 0); var r_max = MaxRadius.GetValue(sparam, 0); var radius = FxRandom.NextFloat(r_min, r_max); var p = new Vector3( FxRandom.NextFloat(-1, 1), FxRandom.NextFloat(-1, 1), FxRandom.NextFloat(-1, 1) ); p.Normalize(); var n = p; Vector3 translate; Quaternion rotate; if (DoTransform(reference, sparam, globaltime, out translate, out rotate)) { p += translate; n = Vector3.Transform(n, rotate); } n *= Pressure.GetValue(sparam, 0); var pr = p * radius; instance.Pool.Particles[idx].Position = pr; instance.Pool.Particles[idx].Normal = n; }
protected virtual float GetSpread(float sparam, float time) { var s_min = MathHelper.DegreesToRadians(MinSpread.GetValue(sparam, 0)); var s_max = MathHelper.DegreesToRadians(MaxSpread.GetValue(sparam, 0)); return(FxRandom.NextFloat(s_min, s_max)); }
static Vector3 RandomCube(float minspread, float maxspread) { //(sqrt(1 - z^2) * cosϕ, sqrt(1 - z^2) * sinϕ, z) var halfspread = maxspread / 2; float z = FxRandom.NextFloat((float)Math.Cos(halfspread), 1 - (minspread / 2)); float t = FxRandom.NextFloat(0, (float)(Math.PI * 2)); return(new Vector3( (float)(Math.Sqrt(1 - z * z) * Math.Cos(t)), (float)(Math.Sqrt(1 - z * z) * Math.Sin(t)), z )); }
//Different direction to FxCubeEmitter static Vector3 RandomInCone(float minspread, float maxspread) { var direction = Vector3.UnitY; var axis = Vector3.UnitX; var angle = FxRandom.NextFloat(minspread, maxspread); var rotation = Quaternion.CreateFromAxisAngle(axis, angle); Vector3 output = Vector3.Transform(direction, rotation); var random = FxRandom.NextFloat(-MathHelper.Pi, MathHelper.Pi); rotation = Quaternion.CreateFromAxisAngle(direction, random); output = Vector3.Transform(output, rotation); return(output); }
//Different direction to FxCubeEmitter static Vector3 RandomInCone(float minspread, float maxspread) { return(Vector3.UnitY); var direction = Vector3.UnitY; var axis = Vector3.UnitZ; var angle = FxRandom.NextFloat(minspread, maxspread); var rotation = Quaternion.FromAxisAngle(axis, angle); Vector3 output = rotation * direction; var random = FxRandom.NextFloat(-MathHelper.Pi, MathHelper.Pi); rotation = Quaternion.FromAxisAngle(direction, random); output = rotation * output; return(output); }
protected override void SetParticle(int idx, NodeReference reference, ParticleEffectInstance instance, ref Matrix4x4 transform, float sparam, float globaltime) { var r_min = MinRadius.GetValue(sparam, 0); var r_max = MaxRadius.GetValue(sparam, 0); var radius = FxRandom.NextFloat(r_min, r_max); float s_min = MathHelper.DegreesToRadians(MinSpread.GetValue(sparam, 0)); float s_max = MathHelper.DegreesToRadians(MaxSpread.GetValue(sparam, 0)); var n = RandomInCone(s_min, s_max); Vector3 translate; Quaternion rotate; if (DoTransform(reference, sparam, globaltime, out translate, out rotate)) { n = Vector3.Transform(n, rotate); } var p = n * radius + translate; n *= Pressure.GetValue(sparam, 0); instance.Pool.Particles[idx].Position = p; instance.Pool.Particles[idx].Normal = n; }