public override void Draw(ref Particle particle, float lasttime, float globaltime, NodeReference reference, ResourceManager res, Billboards billboards, ref Matrix4 transform, float sparam) { var time = particle.TimeAlive / particle.LifeSpan; var node_tr = GetTranslation(reference, transform, sparam, time); var p = node_tr.Transform(particle.Position); Texture2D tex; Vector2 tl, tr, bl, br; HandleTexture(res, sparam, globaltime, ref particle, out tex, out tl, out tr, out bl, out br); var c = Color.GetValue(sparam, time); var a = Alpha.GetValue(sparam, time); billboards.Draw( tex, p, new Vector2(Size.GetValue(sparam, time)) * 2, new Color4(c, a), tl, tr, bl, br, Rotate == null ? 0f : MathHelper.DegreesToRadians(Rotate.GetValue(sparam, time)), SortLayers.OBJECT, BlendInfo ); }
public override void Draw(ref Particle particle, float globaltime, NodeReference reference, ResourceManager res, Billboards billboards, ref Matrix4 transform, float sparam) { var time = particle.TimeAlive / particle.LifeSpan; var node_tr = GetTranslation(reference, transform, sparam, time); var p = node_tr.Transform(particle.Position); Texture2D tex; Vector2 tl, tr, bl, br; HandleTexture(res, globaltime, sparam, ref particle, out tex, out tl, out tr, out bl, out br); var c = Color.GetValue(sparam, time); var a = Alpha.GetValue(sparam, time); var p2 = node_tr.Transform(particle.Position + particle.Normal); //var n = (p - p2).Normalized(); var n = Vector3.UnitZ; billboards.DrawPerspective( tex, p, new Vector2(Width.GetValue(sparam, time), Height.GetValue(sparam, time)), new Color4(c, a), tl, tr, bl, br, n, Rotate == null ? 0f : Rotate.GetValue(sparam, time), SortLayers.OBJECT, BlendInfo ); }
public override void Draw(ref Particle particle, int pidx, float lasttime, float globaltime, NodeReference reference, ResourceManager res, ParticleEffectInstance instance, ref Matrix4 transform, float sparam) { var time = particle.TimeAlive / particle.LifeSpan; var node_tr = GetAttachment(reference, transform); Vector3 deltap; Quaternion deltaq; if (DoTransform(reference, sparam, lasttime, globaltime, out deltap, out deltaq)) { particle.Position += deltap; particle.Orientation *= deltaq; } var p = node_tr.Transform(particle.Orientation * particle.Position); Texture2D tex; Vector2 tl, tr, bl, br; HandleTexture(res, sparam, globaltime, ref particle, out tex, out tl, out tr, out bl, out br); var c = Color.GetValue(sparam, time); var a = Alpha.GetValue(sparam, time); instance.Pool.DrawBasic( particle.Instance, this, p, new Vector2(Size.GetValue(sparam, time)) * 2, new Color4(c, a), tl, tr, bl, br, Rotate == null ? 0f : MathHelper.DegreesToRadians(Rotate.GetValue(sparam, time)) ); }
protected float GetFrame(float globaltime, float sparam, ref Particle particle) { float frame = 0; if (UseCommonAnimation) { frame = CommonAnimation.GetValue(sparam, globaltime); } else { frame = Animation.GetValue(sparam, particle.TimeAlive / particle.LifeSpan); } return(MathHelper.Clamp(frame, 0, 1)); }
public override void Draw(ref Particle particle, float lasttime, float globaltime, NodeReference reference, ResourceManager res, Billboards billboards, ref Matrix4 transform, float sparam) { var time = particle.TimeAlive / particle.LifeSpan; var node_tr = GetAttachment(reference, transform); var src_pos = particle.Position; var l = Length.GetValue(sparam, time); var w = Width.GetValue(sparam, time); var sc = Scale.GetValue(sparam, time); if (!CenterOnPos) { var nd = particle.Normal.Normalized(); src_pos += nd * (l * sc * 0.25f); } var p = node_tr.Transform(src_pos); Texture2D tex; Vector2 tl, tr, bl, br; HandleTexture(res, globaltime, sparam, ref particle, out tex, out tl, out tr, out bl, out br); var c = Color.GetValue(sparam, time); var a = Alpha.GetValue(sparam, time); var p2 = node_tr.Transform(src_pos + (particle.Normal * 20)); //var n = (p2 - p).Normalized(); var n = (transform * new Vector4(particle.Normal.Normalized(), 0)).Xyz.Normalized(); billboards.DrawRectAppearance( tex, p, new Vector2(l, w) * sc * 0.5f, new Color4(c, a), tl, tr, bl, br, n, Rotate == null ? 0f : MathHelper.DegreesToRadians(Rotate.GetValue(sparam, time)), SortLayers.OBJECT, BlendInfo ); if (DrawNormals) { Debug.DrawLine(p - (n * 12), p + (n * 12)); } }
public override void Draw(ref Particle particle, int pidx, float lasttime, float globaltime, NodeReference reference, ResourceManager res, ParticleEffectInstance instance, ref Matrix4x4 transform, float sparam) { var time = particle.TimeAlive / particle.LifeSpan; var node_tr = GetAttachment(reference, transform); var src_pos = particle.Position; var l = Length.GetValue(sparam, time); var w = Width.GetValue(sparam, time); var sc = Scale.GetValue(sparam, time); if (!CenterOnPos) { var nd = particle.Normal.Normalized(); src_pos += nd * (l * sc * 0.25f); } var p = Vector3.Transform(src_pos, node_tr); Texture2D tex; Vector2 tl, tr, bl, br; HandleTexture(res, globaltime, sparam, ref particle, out tex, out tl, out tr, out bl, out br); var c = Color.GetValue(sparam, time); var a = Alpha.GetValue(sparam, time); var p2 = Vector3.Transform(src_pos + (particle.Normal * 20), node_tr); //var n = (p2 - p).Normalized(); var n = Vector3.TransformNormal(particle.Normal, transform).Normalized(); instance.Pool.DrawRect( particle.Instance, this, tex, p, new Vector2(l, w) * sc * 0.5f, new Color4(c, a), tl, tr, bl, br, n, Rotate == null ? 0f : MathHelper.DegreesToRadians(Rotate.GetValue(sparam, time)) ); if (DrawNormals) { Debug.DrawLine(p - (n * 12), p + (n * 12)); } }
protected void HandleTexture( ResourceManager res, float globaltime, float sparam, ref Particle particle, out Texture2D tex2d, out Vector2 tl, out Vector2 tr, out Vector2 bl, out Vector2 br ) { //Initial texcoords tl = new Vector2(0, 0); tr = new Vector2(1, 0); bl = new Vector2(0, 1); br = new Vector2(1, 1); if (Texture == null) { tex2d = res.NullTexture; return; } //Get the Texture2D if (_tex == null && _frame == null && _tex2D != null) { if (_tex2D == null || _tex2D.IsDisposed) { _tex2D = res.FindTexture(Texture) as Texture2D; } tex2d = _tex2D; } else if (_tex == null) { if (res.TryGetShape(Texture, out _tex)) { _tex2D = (Texture2D)res.FindTexture(_tex.Texture); } else if (res.TryGetFrameAnimation(Texture, out _frame)) { _tex2D = res.FindTexture(Texture + "_0") as Texture2D; } else { _tex2D = res.FindTexture(Texture) as Texture2D; } } if (_tex2D == null || _tex2D.IsDisposed) { if (_frame == null) { _tex2D = res.FindTexture(_tex == null ? Texture : _tex.Texture) as Texture2D; } else { _tex2D = res.FindTexture(Texture + "_0") as Texture2D; } } tex2d = _tex2D; if (tex2d == null) { tex2d = (Texture2D)res.FindTexture(ResourceManager.WhiteTextureName); } //Shape? if (_tex != null) { tl = new Vector2(_tex.Dimensions.X, _tex.Dimensions.Y); tr = new Vector2(_tex.Dimensions.X + _tex.Dimensions.Width, _tex.Dimensions.Y); bl = new Vector2(_tex.Dimensions.X, _tex.Dimensions.Y + _tex.Dimensions.Height); br = new Vector2(_tex.Dimensions.X + _tex.Dimensions.Width, _tex.Dimensions.Y + _tex.Dimensions.Height); } else if (_frame != null) { float frame = 0; if (UseCommonAnimation) { frame = CommonAnimation.GetValue(sparam, globaltime); } else { frame = Animation.GetValue(sparam, particle.TimeAlive / particle.LifeSpan); } frame = MathHelper.Clamp(frame, 0, 1); var frameNo = (int)Math.Floor(frame / _frame.FrameCount); var rect = _frame.Frames[frameNo]; tl = new Vector2(rect.X, rect.Y); tr = new Vector2(rect.X + rect.Width, rect.Y); bl = new Vector2(rect.X, rect.Y + rect.Height); br = new Vector2(rect.X + rect.Width, rect.Y + rect.Height); } //Flip if (FlipHorizontal) { tl.X = 1 - tl.X; tr.X = 1 - tl.X; bl.X = 1 - bl.X; br.X = 1 - br.X; } if (FlipVertical) { tl.Y = 1 - tl.Y; tr.Y = 1 - tr.Y; bl.Y = 1 - bl.Y; br.Y = 1 - br.Y; } }
public override void Draw(ref Particle particle, float globaltime, NodeReference reference, ResourceManager res, Billboards billboards, ref Matrix4 transform, float sparam) { var time = particle.TimeAlive / particle.LifeSpan; var node_tr = GetTranslation(reference, transform, sparam, time); var src_pos = particle.Position; var l = Length.GetValue(sparam, time); var w = Width.GetValue(sparam, time); var sc = Scale.GetValue(sparam, time); if (!CenterOnPos) { var nd = particle.Normal.Normalized(); src_pos += nd * (l * sc * 0.25f); } var p = node_tr.Transform(src_pos); Texture2D tex; Vector2 tl, tr, bl, br; HandleTexture(res, globaltime, sparam, ref particle, out tex, out tl, out tr, out bl, out br); var c = Color.GetValue(sparam, time); var a = Alpha.GetValue(sparam, time); var p2 = node_tr.Transform(src_pos + (particle.Normal * 20)); var n = (p2 - p).Normalized(); billboards.DrawRectAppearance( tex, p, new Vector2(l, w) * sc * 0.5f, new Color4(c, a), tl, tr, bl, br, n, Rotate == null ? 0f : Rotate.GetValue(sparam, time), SortLayers.OBJECT, BlendInfo ); /*var p1_proj = Project(billboards, p); * var p2_proj = Project(billboards, p2); * * var px1 = new Vector2( * (p1_proj.X + 1) / 2 * 1024, * (1 - p1_proj.Y) / 2 * 768); * var px2 = new Vector2( * (p2_proj.X + 1) / 2 * 1024, * (1 - p2_proj.Y) / 2 * 1024 * ); * * var angle = (float)Math.Atan2(px2.Y - px1.Y, px2.X - px1.X);*/ /*var src_pos2 = src_pos + (particle.Normal * 20); * var angle = (float)Math.Atan2(src_pos2.Y - src_pos.Y, src_pos2.Z - src_pos.Z); * var angle_deg = MathHelper.RadiansToDegrees(angle); * billboards.Draw( * tex, * p, * new Vector2(l, w) * sc * 0.5f, * new Color4(c, a), * tl, * tr, * bl, * br, * angle, //Rotate == null ? 0f : Rotate.GetValue(sparam, time), * SortLayers.OBJECT, * BlendInfo * );*/ if (DrawNormals) { Debug.DrawLine(p - (n * 8), p + (n * 8)); } }
protected void HandleTexture( ResourceManager res, float globaltime, float sparam, ref Particle particle, out Texture2D tex2d, out Vector2 tl, out Vector2 tr, out Vector2 bl, out Vector2 br ) { //Initial texcoords tl = new Vector2(0, 0); tr = new Vector2(1, 0); bl = new Vector2(0, 1); br = new Vector2(1, 1); //Get texture GetTexture2D(res, out tex2d); //Shape? if (_tex != null) { tl = new Vector2(_tex.Dimensions.X, _tex.Dimensions.Y); tr = new Vector2(_tex.Dimensions.X + _tex.Dimensions.Width, _tex.Dimensions.Y); bl = new Vector2(_tex.Dimensions.X, _tex.Dimensions.Y + _tex.Dimensions.Height); br = new Vector2(_tex.Dimensions.X + _tex.Dimensions.Width, _tex.Dimensions.Y + _tex.Dimensions.Height); } else if (_frame != null) { float frame = 0; if (UseCommonAnimation) { frame = CommonAnimation.GetValue(sparam, globaltime); } else { frame = Animation.GetValue(sparam, particle.TimeAlive / particle.LifeSpan); } frame = MathHelper.Clamp(frame, 0, 1); var frameNo = (int)Math.Floor(frame / _frame.FrameCount); var rect = _frame.Frames[frameNo]; tl = new Vector2(rect.X, rect.Y); tr = new Vector2(rect.X + rect.Width, rect.Y); bl = new Vector2(rect.X, rect.Y + rect.Height); br = new Vector2(rect.X + rect.Width, rect.Y + rect.Height); } //Flip if (FlipHorizontal) { tl.X = 1 - tl.X; tr.X = 1 - tl.X; bl.X = 1 - bl.X; br.X = 1 - br.X; } if (FlipVertical) { tl.Y = 1 - tl.Y; tr.Y = 1 - tr.Y; bl.Y = 1 - bl.Y; br.Y = 1 - br.Y; } }