コード例 #1
0
ファイル: LGraphics.cs プロジェクト: keppelcao/LGame
 public void Transform(Transform2i t)
 {
     UpdatePixels();
     Color[] processedPixels = new Color[size];
     for (int y = 0; y < height; ++y)
     {
         int yOffset = y * width;
         int fpY = MathUtils.FromInt(y);
         int constX = MathUtils.Mul(fpY, t.matrixs[0][1])
                 + t.matrixs[0][2];
         int constY = MathUtils.Mul(fpY, t.matrixs[1][1])
                 + t.matrixs[1][2];
         for (int x = 0; x < width; ++x)
         {
             int fpX = MathUtils.FromInt(x);
             int tx = MathUtils.ToInt(MathUtils.Mul(fpX,
                     t.matrixs[0][0]) + constX);
             if (tx < 0 || width <= tx)
             {
                 processedPixels[x + yOffset].PackedValue = transparent;
             }
             else
             {
                 int ty = MathUtils.ToInt(MathUtils.Mul(fpX,
                         t.matrixs[1][0]) + constY);
                 if (ty < 0 || height <= ty)
                 {
                     processedPixels[x + yOffset].PackedValue = transparent;
                 }
                 else
                 {
                     processedPixels[x + yOffset] = pixels[tx + ty
                             * width];
                 }
             }
         }
     }
     this.pixels = processedPixels;
     this.isDitry = true;
 }
コード例 #2
0
ファイル: LGraphics.cs プロジェクト: keppelcao/LGame
 public void Rotate(float angle, float x, float y)
 {
     UpdatePixels();
     Transform2i transform = new Transform2i();
     transform.Rotate(angle, x, y);
     Color[] processedPixels = new Color[size];
     for (int j = 0; j < height; ++j)
     {
         int yOffset = j * width;
         int fpY = MathUtils.FromInt(j);
         int constX = MathUtils.Mul(fpY, transform.matrixs[0][1])
                 + transform.matrixs[0][2];
         int constY = MathUtils.Mul(fpY, transform.matrixs[1][1])
                 + transform.matrixs[1][2];
         for (int i = 0; i < width; ++i)
         {
             int fpX = MathUtils.FromInt(i);
             int tx = MathUtils.ToInt(MathUtils.Mul(fpX,
                     transform.matrixs[0][0]) + constX);
             if (tx < 0 || width <= tx)
             {
                 processedPixels[i + yOffset].PackedValue = transparent;
             }
             else
             {
                 int ty = MathUtils.ToInt(MathUtils.Mul(fpX,
                         transform.matrixs[1][0]) + constY);
                 if (ty < 0 || height <= ty)
                 {
                     processedPixels[i + yOffset].PackedValue = transparent;
                 }
                 else
                 {
                     processedPixels[i + yOffset] = pixels[tx + ty
                             * width];
                 }
             }
         }
     }
     this.pixels = processedPixels;
     this.isDitry = true;
 }