Ejemplo n.º 1
0
 public void Draw(EntityRenderer renderer, CanvasSpriteBatch sb, CanvasTimingInformation timing)
 {
     sb.Draw(renderer.Sprites[player.Shape], Matrix3x2.CreateTranslation(-player.Shape.Origin *
                                                                         SpriteBuilder.SCALE_FACTOR) *
             Matrix3x2.CreateRotation(player.Direction) *
             Matrix3x2.CreateScale(1f / SpriteBuilder.SCALE_FACTOR) *
             Matrix3x2.CreateTranslation(player.Position), player.Color);
     sb.Draw(renderer.Sprites[Shape.Turret], Matrix3x2.CreateTranslation(-player.Shape.Origin *
                                                                         SpriteBuilder.SCALE_FACTOR) *
             Matrix3x2.CreateRotation(player.TurretDirection) *
             Matrix3x2.CreateScale(1f / SpriteBuilder.SCALE_FACTOR) *
             Matrix3x2.CreateTranslation(player.Position), player.Color);
 }
Ejemplo n.º 2
0
        public void Draw(CanvasDrawingSession ds, CanvasSpriteBatch SBatch, TextureLoader Textures)
        {
            lock ( PFSim )
            {
                var Snapshot = PFSim.Snapshot();
                while (Snapshot.MoveNext())
                {
                    Particle P = Snapshot.Current;

                    float A = Vector2.Transform(new Vector2(0, 1), Matrix3x2.CreateRotation(P.ttl * 0.01f)).X;

                    Vector4 Tint = new Vector4(
                        P.Tint.M11 + P.Tint.M21 + P.Tint.M31 + P.Tint.M41 + P.Tint.M51,
                        P.Tint.M12 + P.Tint.M22 + P.Tint.M32 + P.Tint.M42 + P.Tint.M52,
                        P.Tint.M13 + P.Tint.M23 + P.Tint.M33 + P.Tint.M43 + P.Tint.M53,
                        P.Tint.M14 + P.Tint.M24 + P.Tint.M34 + P.Tint.M44 + P.Tint.M54
                        );

                    Tint.W *= A;
                    ScrollWind.Strength *= 0.5f;

                    SBatch.Draw(
                        Textures[P.TextureId]
                        , P.Pos, Tint
                        , Textures.Center[P.TextureId], 0, P.Scale
                        , CanvasSpriteFlip.None);
                }

                DrawWireFrames(ds);
            }
        }
Ejemplo n.º 3
0
        public void Draw( CanvasDrawingSession ds, CanvasSpriteBatch SBatch, TextureLoader Textures )
        {
            lock ( PFSim )
            {
                var Snapshot = PFSim.Snapshot();
                while ( Snapshot.MoveNext() )
                {
                    Particle P = Snapshot.Current;

                    float A = ( P.Trait & PFTrait.IMMORTAL ) == 0 ? P.ttl * 0.033f : 1;

                    P.Tint.M12 = 4 * ( 1 - A );
                    P.Tint.M21 = 3 * A;

                    Vector4 Tint = new Vector4(
                        P.Tint.M11 + P.Tint.M21 + P.Tint.M31 + P.Tint.M41 + P.Tint.M51,
                        P.Tint.M12 + P.Tint.M22 + P.Tint.M32 + P.Tint.M42 + P.Tint.M52,
                        P.Tint.M13 + P.Tint.M23 + P.Tint.M33 + P.Tint.M43 + P.Tint.M53,
                        P.Tint.M14 + P.Tint.M24 + P.Tint.M34 + P.Tint.M44 + P.Tint.M54
                    ) * 2;

                    Tint.W *= A * 0.125f;

                    SBatch.Draw( Textures[ P.TextureId ], P.Pos, Tint, Textures.Center[ P.TextureId ], 0, P.Scale * A, CanvasSpriteFlip.None );
                }

                DrawWireFrames( ds );
            }
        }
Ejemplo n.º 4
0
        public void Draw(CanvasDrawingSession ds, CanvasSpriteBatch SBatch, TextureLoader Textures)
        {
            lock ( PFSim )
            {
                var Snapshot = PFSim.Snapshot();
                while (Snapshot.MoveNext())
                {
                    Particle P = Snapshot.Current;

                    float A = (P.Trait & PFTrait.IMMORTAL) == 0 ? P.ttl * 0.033f : 1;

                    P.Tint.M12 = 4 * (1 - A);
                    P.Tint.M21 = 3 * A;

                    Vector4 Tint = new Vector4(
                        P.Tint.M11 + P.Tint.M21 + P.Tint.M31 + P.Tint.M41 + P.Tint.M51,
                        P.Tint.M12 + P.Tint.M22 + P.Tint.M32 + P.Tint.M42 + P.Tint.M52,
                        P.Tint.M13 + P.Tint.M23 + P.Tint.M33 + P.Tint.M43 + P.Tint.M53,
                        P.Tint.M14 + P.Tint.M24 + P.Tint.M34 + P.Tint.M44 + P.Tint.M54
                        ) * 2;

                    Tint.W *= A * 0.125f;

                    SBatch.Draw(Textures[P.TextureId], P.Pos, Tint, Textures.Center[P.TextureId], 0, P.Scale * A, CanvasSpriteFlip.None);
                }

                DrawWireFrames(ds);
            }
        }
Ejemplo n.º 5
0
        protected override void Draw(CanvasDrawingSession drawingSession
#if WINDOWS_UWP
                                     , CanvasSpriteBatch spriteBatch
#endif
                                     )
        {
            // 逆向遍历队列,可以让新粒子绘制在旧粒子下方,这样当很多粒子在同一个位置生成时,效果较好
            for (int i = ActiveParticles.Count - 1; i >= 0; i--)
            {
                Particle particle = ActiveParticles[i];

                // NormalizedLifeTime 是一个0到1之间的值,用来表示粒子在生命周期中的进度,这个值接近0或接近1时,
                // 粒子将会渐隐/渐显,使用它来计算粒子的透明度和缩放
                float normalizedLifetime = particle.TimeSinceStart / 4;
                if (normalizedLifetime > 1)
                {
                    normalizedLifetime = 1;
                }

                // We want particles to fade in and fade out, so we'll calculate alpha to be
                // (normalizedLifetime) * (1 - normalizedLifetime). This way, when normalizedLifetime
                // is 0 or 1, alpha is 0. The maximum value is at normalizedLifetime = .5, and is:
                //
                //      (normalizedLifetime) * (1-normalizedLifetime)
                //      (.5)                 * (1-.5)
                //      .25
                //
                // Since we want the maximum alpha to be 1, not .25, we'll scale the entire equation by 4.
                float alpha = (float)EasingHelper.QuinticEase(Windows.UI.Xaml.Media.Animation.EasingMode.EaseOut, normalizedLifetime);
                var   x     = particle.ScaleX;
                var   y     = particle.ScaleY;
                // Make particles grow as they age.
                // They'll start at 75% of their size, and increase to 100% once they're finished.
                if (isImmersive)
                {
                    alpha *= 0.8f;
                    x     *= 1.2f;
                    y     *= 1.2f;
                }
#if WINDOWS_UWP
                if (spriteBatch != null)
                {
                    spriteBatch.Draw(smokeSurfaces[particle.Key], particle.Position, new Vector4(1, 1, 1, alpha), bitmapCenter,
                                     particle.Rotation, new Vector2(x, y), CanvasSpriteFlip.None);
                }
                else
#endif
                {
                    // Compute a transform matrix for this particle.
                    var transform = Matrix3x2.CreateRotation(particle.Rotation, bitmapCenter) *
                                    Matrix3x2.CreateScale(x, y, bitmapCenter) *
                                    Matrix3x2.CreateTranslation(particle.Position - bitmapCenter);

                    // Draw the particle.
                    drawingSession.DrawImage(smokeSurfaces[particle.Key], 0, 0, bitmapBounds, alpha, CanvasImageInterpolation.Linear, new Matrix4x4(transform));
                }
            }
        }
Ejemplo n.º 6
0
        void Draw(CanvasDrawingSession drawingSession
#if WINDOWS_UWP
                  , CanvasSpriteBatch spriteBatch
#endif
                  )
        {
            // Go through the particles in reverse order, so new ones are drawn underneath
            // older ones. This improves visual appearance of effects like smoke plume
            // where many particles are created at the same position over a period of time.
            for (int i = activeParticles.Count - 1; i >= 0; i--)
            {
                Particle particle = activeParticles[i];

                // Normalized lifetime is a value from 0 to 1 and represents how far a particle
                // is through its life. 0 means it just started, .5 is half way through, and
                // 1.0 means it's just about to be finished. This value will be used to calculate
                // alpha and scale, to avoid  having particles suddenly appear or disappear.
                float normalizedLifetime = particle.TimeSinceStart / particle.Lifetime;

                // We want particles to fade in and fade out, so we'll calculate alpha to be
                // (normalizedLifetime) * (1 - normalizedLifetime). This way, when normalizedLifetime
                // is 0 or 1, alpha is 0. The maximum value is at normalizedLifetime = .5, and is:
                //
                //      (normalizedLifetime) * (1-normalizedLifetime)
                //      (.5)                 * (1-.5)
                //      .25
                //
                // Since we want the maximum alpha to be 1, not .25, we'll scale the entire equation by 4.
                float alpha = 4 * normalizedLifetime * (1 - normalizedLifetime);

                // Make particles grow as they age.
                // They'll start at 75% of their size, and increase to 100% once they're finished.
                float scale = particle.Scale * (.75f + .25f * normalizedLifetime);

#if WINDOWS_UWP
                if (spriteBatch != null)
                {
                    spriteBatch.Draw(bitmap, particle.Position, new Vector4(1, 1, 1, alpha), bitmapCenter, particle.Rotation, new Vector2(scale), CanvasSpriteFlip.None);
                }
                else
#endif
                {
                    // Compute a transform matrix for this particle.
                    var transform = Matrix3x2.CreateRotation(particle.Rotation, bitmapCenter) *
                                    Matrix3x2.CreateScale(scale, bitmapCenter) *
                                    Matrix3x2.CreateTranslation(particle.Position - bitmapCenter);

                    // Draw the particle.
                    drawingSession.DrawImage(bitmap, 0, 0, bitmapBounds, alpha, CanvasImageInterpolation.Linear, new Matrix4x4(transform));
                }
            }
        }
Ejemplo n.º 7
0
        public void Draw(ITexture texture, Matrix3x2 transform, Vector4 tint)
        {
            CanvasBlend previousBlend = this.canvasDrawingSession.Blend;

            using (CanvasSpriteBatch spriteBatch = this.canvasDrawingSession.CreateSpriteBatch())
            {
                this.canvasDrawingSession.Blend = CanvasBlend.Add;

                CanvasBitmap bitmap = ((Texture)texture).Bitmap;
                spriteBatch.Draw(bitmap, transform, tint, CanvasSpriteFlip.None);

                this.canvasDrawingSession.Blend = previousBlend;
            }
        }
Ejemplo n.º 8
0
        protected virtual void Draw(CanvasDrawingSession drawingSession
#if WINDOWS_UWP
                                    , CanvasSpriteBatch spriteBatch
#endif
                                    )
        {
            // 逆向遍历队列,可以让新粒子绘制在旧粒子下方,这样当很多粒子在同一个位置生成时,效果较好
            for (int i = activeParticles.Count - 1; i >= 0; i--)
            {
                Particle particle = activeParticles[i];

                // NormalizedLifeTime 是一个0到1之间的值,用来表示粒子在生命周期中的进度,这个值接近0或接近1时,
                // 粒子将会渐隐/渐显,使用它来计算粒子的透明度和缩放
                //float normalizedLifetime = particle.TimeSinceStart / particle.Lifetime;

                // We want particles to fade in and fade out, so we'll calculate alpha to be
                // (normalizedLifetime) * (1 - normalizedLifetime). This way, when normalizedLifetime
                // is 0 or 1, alpha is 0. The maximum value is at normalizedLifetime = .5, and is:
                //
                //      (normalizedLifetime) * (1-normalizedLifetime)
                //      (.5)                 * (1-.5)
                //      .25
                //
                // Since we want the maximum alpha to be 1, not .25, we'll scale the entire equation by 4.
                //float alpha = 4 * normalizedLifetime * (1 - normalizedLifetime);

                // Make particles grow as they age.
                // They'll start at 75% of their size, and increase to 100% once they're finished.
                //float scale = particle.Scale * (.75f + .25f * normalizedLifetime);

#if WINDOWS_UWP
                if (spriteBatch != null)
                {
                    spriteBatch.Draw(bitmap, particle.Position, new Vector4(1, 1, 1, 1 /*alpha*/), bitmapCenter,
                                     particle.Rotation - 1.5708f, new Vector2(particle.ScaleX, particle.ScaleY /*scale*/), CanvasSpriteFlip.None);
                }
                else
#endif
                {
                    // Compute a transform matrix for this particle.
                    var transform = Matrix3x2.CreateRotation(particle.Rotation - 1.5708f, bitmapCenter) *
                                    Matrix3x2.CreateScale(/*scale*/ particle.ScaleX, particle.ScaleY, bitmapCenter) *
                                    Matrix3x2.CreateTranslation(particle.Position - bitmapCenter);

                    // Draw the particle.
                    drawingSession.DrawImage(bitmap, 0, 0, bitmapBounds, 1 /*alpha*/, CanvasImageInterpolation.Linear, new Matrix4x4(transform));
                }
            }
        }
Ejemplo n.º 9
0
        protected void Draw(CanvasDrawingSession drawingSession
#if WINDOWS_UWP
                            , CanvasSpriteBatch spriteBatch
#endif
                            )
        {
#if WINDOWS_UWP
            if (spriteBatch != null)
            {
                spriteBatch.Draw(sunSurfaces[(uint)(nowFrame * slowFactor) % surfaceCount], position, new Vector4(1, 1, 1, opcity), center, rotation, new Vector2(1, 1), CanvasSpriteFlip.None);
            }
            else
#endif
            {
                // Compute a transform matrix for this particle.
                var transform = Matrix3x2.CreateRotation(rotation, center) *
                                Matrix3x2.CreateScale(1, 1, center) *
                                Matrix3x2.CreateTranslation(position - center);

                // Draw the particle.
                drawingSession.DrawImage(sunSurfaces[(uint)(nowFrame * slowFactor) % surfaceCount], 0, 0, bound, opcity, CanvasImageInterpolation.Linear, new Matrix4x4(transform));
            }
        }
Ejemplo n.º 10
0
        public void Draw( CanvasDrawingSession ds, CanvasSpriteBatch SBatch, TextureLoader Textures )
        {
            lock ( PFSim )
            {
                var Snapshot = PFSim.Snapshot();
                while ( Snapshot.MoveNext() )
                {
                    Particle P = Snapshot.Current;

                    float A = -Vector2.Transform( new Vector2( 0, 1 ), Matrix3x2.CreateRotation( 3.1415f * P.ttl * 0.002f ) ).X;

                    Vector4 Tint = new Vector4(
                        P.Tint.M11 + P.Tint.M21 + P.Tint.M31 + P.Tint.M41 + P.Tint.M51,
                        P.Tint.M12 + P.Tint.M22 + P.Tint.M32 + P.Tint.M42 + P.Tint.M52,
                        P.Tint.M13 + P.Tint.M23 + P.Tint.M33 + P.Tint.M43 + P.Tint.M53,
                        P.Tint.M14 + P.Tint.M24 + P.Tint.M34 + P.Tint.M44 + P.Tint.M54
                    );

                    Tint.W *= A;
                    ScrollWind.Strength *= 0.5f;

                    SBatch.Draw(
                        Textures[ P.TextureId ]
                        , P.Pos, Tint
                        , Textures.Center[ P.TextureId ], 0, P.Scale
                        , CanvasSpriteFlip.None );
                }

                DrawWireFrames( ds );
            }
        }
Ejemplo n.º 11
0
        protected virtual void Draw(CanvasDrawingSession drawingSession
#if WINDOWS_UWP
            , CanvasSpriteBatch spriteBatch
#endif
            )
        {
            // 逆向遍历队列,可以让新粒子绘制在旧粒子下方,这样当很多粒子在同一个位置生成时,效果较好
            for (int i = activeParticles.Count - 1; i >= 0; i--)
            {
                Particle particle = activeParticles[i];

                // NormalizedLifeTime 是一个0到1之间的值,用来表示粒子在生命周期中的进度,这个值接近0或接近1时,
                // 粒子将会渐隐/渐显,使用它来计算粒子的透明度和缩放
                //float normalizedLifetime = particle.TimeSinceStart / particle.Lifetime;

                // We want particles to fade in and fade out, so we'll calculate alpha to be
                // (normalizedLifetime) * (1 - normalizedLifetime). This way, when normalizedLifetime
                // is 0 or 1, alpha is 0. The maximum value is at normalizedLifetime = .5, and is:
                //
                //      (normalizedLifetime) * (1-normalizedLifetime)
                //      (.5)                 * (1-.5)
                //      .25
                //
                // Since we want the maximum alpha to be 1, not .25, we'll scale the entire equation by 4.
                //float alpha = 4 * normalizedLifetime * (1 - normalizedLifetime);

                // Make particles grow as they age.
                // They'll start at 75% of their size, and increase to 100% once they're finished.
                //float scale = particle.Scale * (.75f + .25f * normalizedLifetime);

#if WINDOWS_UWP
                if (spriteBatch != null)
                {
                    spriteBatch.Draw(bitmap, particle.Position, new Vector4(1, 1, 1, 1/*alpha*/), bitmapCenter,
                        particle.Rotation - 1.5708f, new Vector2(particle.ScaleX, particle.ScaleY/*scale*/), CanvasSpriteFlip.None);
                }
                else
#endif
                {
                    // Compute a transform matrix for this particle.
                    var transform = Matrix3x2.CreateRotation(particle.Rotation - 1.5708f, bitmapCenter) *
                                    Matrix3x2.CreateScale(/*scale*/particle.ScaleX, particle.ScaleY, bitmapCenter) *
                                    Matrix3x2.CreateTranslation(particle.Position - bitmapCenter);

                    // Draw the particle.
                    drawingSession.DrawImage(bitmap, 0, 0, bitmapBounds, 1/*alpha*/, CanvasImageInterpolation.Linear, new Matrix4x4(transform));
                }
            }
        }
        protected override void Draw(CanvasDrawingSession drawingSession
#if WINDOWS_UWP
            , CanvasSpriteBatch spriteBatch
#endif
            )
        {
            // 逆向遍历队列,可以让新粒子绘制在旧粒子下方,这样当很多粒子在同一个位置生成时,效果较好
            for (int i = ActiveParticles.Count - 1; i >= 0; i--)
            {
                Particle particle = ActiveParticles[i];

                // NormalizedLifeTime 是一个0到1之间的值,用来表示粒子在生命周期中的进度,这个值接近0或接近1时,
                // 粒子将会渐隐/渐显,使用它来计算粒子的透明度和缩放
                float normalizedLifetime = particle.TimeSinceStart / 4;
                if (normalizedLifetime > 1)
                {
                    normalizedLifetime = 1;
                }

                // We want particles to fade in and fade out, so we'll calculate alpha to be
                // (normalizedLifetime) * (1 - normalizedLifetime). This way, when normalizedLifetime
                // is 0 or 1, alpha is 0. The maximum value is at normalizedLifetime = .5, and is:
                //
                //      (normalizedLifetime) * (1-normalizedLifetime)
                //      (.5)                 * (1-.5)
                //      .25
                //
                // Since we want the maximum alpha to be 1, not .25, we'll scale the entire equation by 4.
                float alpha = (float)EasingHelper.QuinticEase(Windows.UI.Xaml.Media.Animation.EasingMode.EaseOut, normalizedLifetime);
                var x = particle.ScaleX;
                var y = particle.ScaleY;
                // Make particles grow as they age.
                // They'll start at 75% of their size, and increase to 100% once they're finished.
                if (isImmersive)
                {
                    alpha *= 0.8f;
                    x *= 1.2f;
                    y *= 1.2f;
                }
#if WINDOWS_UWP
                if (spriteBatch != null)
                {
                    spriteBatch.Draw(smokeSurfaces[particle.Key], particle.Position, new Vector4(1, 1, 1, alpha), bitmapCenter,
                        particle.Rotation, new Vector2(x, y), CanvasSpriteFlip.None);
                }
                else
#endif
                {
                    // Compute a transform matrix for this particle.
                    var transform = Matrix3x2.CreateRotation(particle.Rotation, bitmapCenter) *
                                    Matrix3x2.CreateScale(x, y, bitmapCenter) *
                                    Matrix3x2.CreateTranslation(particle.Position - bitmapCenter);

                    // Draw the particle.
                    drawingSession.DrawImage(smokeSurfaces[particle.Key], 0, 0, bitmapBounds, alpha, CanvasImageInterpolation.Linear, new Matrix4x4(transform));
                }
            }
        }
Ejemplo n.º 13
0
        void Draw(CanvasDrawingSession drawingSession
#if WINDOWS_UWP
            , CanvasSpriteBatch spriteBatch
#endif
            )
        { 
            // Go through the particles in reverse order, so new ones are drawn underneath
            // older ones. This improves visual appearance of effects like smoke plume
            // where many particles are created at the same position over a period of time.
            for (int i = activeParticles.Count - 1; i >= 0; i--)
            {
                Particle particle = activeParticles[i];

                // Normalized lifetime is a value from 0 to 1 and represents how far a particle
                // is through its life. 0 means it just started, .5 is half way through, and
                // 1.0 means it's just about to be finished. This value will be used to calculate
                // alpha and scale, to avoid  having particles suddenly appear or disappear.
                float normalizedLifetime = particle.TimeSinceStart / particle.Lifetime;

                // We want particles to fade in and fade out, so we'll calculate alpha to be
                // (normalizedLifetime) * (1 - normalizedLifetime). This way, when normalizedLifetime
                // is 0 or 1, alpha is 0. The maximum value is at normalizedLifetime = .5, and is:
                //
                //      (normalizedLifetime) * (1-normalizedLifetime)
                //      (.5)                 * (1-.5)
                //      .25
                //
                // Since we want the maximum alpha to be 1, not .25, we'll scale the entire equation by 4.
                float alpha = 4 * normalizedLifetime * (1 - normalizedLifetime);

                // Make particles grow as they age.
                // They'll start at 75% of their size, and increase to 100% once they're finished.
                float scale = particle.Scale * (.75f + .25f * normalizedLifetime);

#if WINDOWS_UWP
                if (spriteBatch != null)
                {
                    spriteBatch.Draw(bitmap, particle.Position, new Vector4(1, 1, 1, alpha), bitmapCenter, particle.Rotation, new Vector2(scale), CanvasSpriteFlip.None);
                }
                else
#endif
                {
                    // Compute a transform matrix for this particle.
                    var transform = Matrix3x2.CreateRotation(particle.Rotation, bitmapCenter) *
                                    Matrix3x2.CreateScale(scale, bitmapCenter) *
                                    Matrix3x2.CreateTranslation(particle.Position - bitmapCenter);

                    // Draw the particle.
                    drawingSession.DrawImage(bitmap, 0, 0, bitmapBounds, alpha, CanvasImageInterpolation.Linear, new Matrix4x4(transform));
                }
            }
        }
Ejemplo n.º 14
0
 public override void Draw(CanvasBitmap canvasBitmap, Rect destRect)
 {
     _spriteBatch.Draw(canvasBitmap, destRect);
 }
Ejemplo n.º 15
0
        protected void Draw(CanvasDrawingSession drawingSession
#if WINDOWS_UWP
            , CanvasSpriteBatch spriteBatch
#endif
            )
        {

#if WINDOWS_UWP
            if (spriteBatch != null)
            {
                spriteBatch.Draw(sunSurfaces[(uint)(nowFrame * slowFactor) % surfaceCount], position, new Vector4(1, 1, 1, opcity), center, rotation, new Vector2(1, 1), CanvasSpriteFlip.None);
            }
            else
#endif
            {
                // Compute a transform matrix for this particle.
                var transform = Matrix3x2.CreateRotation(rotation, center) *
                                Matrix3x2.CreateScale(1, 1, center) *
                                Matrix3x2.CreateTranslation(position - center);

                // Draw the particle.
                drawingSession.DrawImage(sunSurfaces[(uint)(nowFrame * slowFactor) % surfaceCount], 0, 0, bound, opcity, CanvasImageInterpolation.Linear, new Matrix4x4(transform));
            }
        }