Пример #1
0
            public vec2d_f Backward(float x, float y)
            {
                vec2d_f ret = new vec2d_f(
                    x * _matrix[3, 0, 0] + y * _matrix[3, 1, 0] + _matrix[3, 2, 0],
                    x * _matrix[3, 0, 1] + y * _matrix[3, 1, 1] + _matrix[3, 2, 1]
                    );
                float out_z = x * _matrix[3, 0, 2] + y * _matrix[3, 1, 2] + _matrix[3, 2, 2];

                if (out_z != 0)
                {
                    ret /= out_z;
                }

                return(ret);
            }
Пример #2
0
            public vec2d_f Forward(float x, float y)
            {
                vec2d_f ret = new vec2d_f(
                    x * _matrix[_sourceMatrix, 0, 0] + y * _matrix[_sourceMatrix, 1, 0] + _matrix[_sourceMatrix, 2, 0],
                    x * _matrix[_sourceMatrix, 0, 1] + y * _matrix[_sourceMatrix, 1, 1] + _matrix[_sourceMatrix, 2, 1]
                    );

                float out_z = x * _matrix[_sourceMatrix, 0, 2] + y * _matrix[_sourceMatrix, 1, 2] + _matrix[_sourceMatrix, 2, 2];

                if (out_z != 0)
                {
                    ret /= out_z;
                }

                return(ret);
            }
Пример #3
0
        public void DrawSprite(Sprite sprite, Transform2D transform)
        {
            if (sprite == null)
            {
                return;
            }

            // Work out bounding rectangle of sprite
            float   ex = 0.0f, ey = 0.0f;
            vec2d_f s = transform.Forward(0.0f, 0.0f);
            vec2d_f p = new vec2d_f(s);

            s.x = Math.Min(s.x, p.x);
            s.y = Math.Min(s.y, p.y);
            ex  = Math.Max(ex, p.x);
            ey  = Math.Max(ey, p.y);

            transform.Forward(sprite.Width, sprite.Height);
            s.x = Math.Min(s.x, p.x);
            s.y = Math.Min(s.y, p.y);
            ex  = Math.Max(ex, p.x);
            ey  = Math.Max(ey, p.y);

            p   = transform.Forward(0.0f, sprite.Height);
            s.x = Math.Min(s.x, p.x);
            s.y = Math.Min(s.y, p.y);
            ex  = Math.Max(ex, p.x);
            ey  = Math.Max(ey, p.y);

            p   = transform.Forward(sprite.Width, 0.0f);
            s.x = Math.Min(s.x, p.x);
            s.y = Math.Min(s.y, p.y);
            ex  = Math.Max(ex, p.x);
            ey  = Math.Max(ey, p.y);

            // Perform inversion of transform if required
            transform.Invert();

            float sx = s.x;
            float sy = s.y;

            if (ex < sx)
            {
                PGEMath.Swap(ref ex, ref sx);
            }
            if (ey < sy)
            {
                PGEMath.Swap(ref ey, ref sy);
            }
            s.x = sx;
            s.y = sy;

            // Iterate through render space, and sample Sprite from suitable texel location
            for (float i = s.x; i < ex; i++)
            {
                for (float j = s.y; j < ey; j++)
                {
                    vec2d_f o = transform.Backward(i, j);
                    pge.Draw((uint)i, (uint)j, sprite.GetPixel((uint)(o.x + 0.5f), (uint)(o.y + 0.5f)));
                }
            }
        }