/// <summary> /// 設定された各変換に基づいて /// SrcRectが変換される先を求める。 /// 詳しくは、このクラス自体の説明を読むべし。 /// </summary> /// <returns>転送先矩形が空集合の場合は /// YanesdkResult.InvalidParameterが返る。 /// </returns> public YanesdkResult Calc() { // 転送元矩形の確定 if (SrcWidth <= 0 || SrcHeight <= 0) return YanesdkResult.PreconditionError; Rect r = SrcRect != null ? SrcRect.Clone() : new Rect(0, 0, SrcWidth, SrcHeight); // 右下の点は含まないのでそのための補正も行なう。 // とは言ってもあえてその点を除外する必要はない。 // (理由はsubpixelを考えるとわかる。詳しくは割愛。) BltLayoutHelper bltLayout = new BltLayoutHelper(); bltLayout.Rect1 = r; bltLayout.Layout = Layout; bltLayout.Update(); Point layoutPoint = bltLayout.LayoutPoint; // 合成変換を求める。 Affine2D a; if ((Trans0 == Trans0_ && Trans == Trans_)) { // 前回計算した結果と同じなので計算する必要なし a = A_; } else { // 計算すると同時に計算結果をcacheしておく。 a = A_ = Trans * Trans0; Trans0_ = Trans0; Trans_ = Trans; } // 転送先でのサイズが指定されているのか? if (DstSize != null) { // このサイズに合わせて拡大縮小する変換が必要である。 a = new Affine2D(DstSize.Cx/SrcWidth,DstSize.Cy/SrcHeight)*a; } // 合成変換 = DstPoint平行移動変換×DstSize変換×Trans×Trans0× -LayoutPoint平行移動変換 // A = { DstSize変換×Trans×Trans0 } a = Affine2D.Compose(DstPoint, Affine2D.Compose(a,-layoutPoint)); // 正常に計算できたのでこの変換を保存しておく。 TransAll = a; /* // 転送元でのclipping処理 SrcPoints = new Point[4]; SrcPoints[0] = new Point(left, top); SrcPoints[1] = new Point(right, top); SrcPoints[2] = new Point(right, bottom); SrcPoints[3] = new Point(left, bottom); DstPoints = new Point[4]; // これらの点がはみ出ていれば押し戻して転送先の点を求める for (int i = 0; i < 4; ++i) { // affine変換を用いているので転送先のclippingが容易である Point p = SrcPoints[i]; if (p.X < 0) p.X = 0; if (SrcWidth < p.X) p.X = SrcWidth; if (p.Y < 0) p.Y = 0; if (SrcHeight < p.Y) p.Y = SrcHeight; // これだけで転送先が求まる! DstPoints[i] = a * p; // テクスチャ座標に変換しておく必要がある。 SrcPoints[i] = p * TextureRate; } */ return YanesdkResult.NoError; }
/// <summary> /// 設定された各変換に基づいて /// SrcRectが変換される先を求める。 /// 詳しくは、このクラス自体の説明を読むべし。 /// </summary> /// <returns>転送先矩形が空集合の場合は /// YanesdkResult.InvalidParameterが返る。 /// </returns> public YanesdkResult Calc() { // 転送元矩形の確定 if (SrcWidth <= 0 || SrcHeight <= 0) { return(YanesdkResult.PreconditionError); } Rect r = SrcRect != null ? SrcRect.Clone() : new Rect(0, 0, SrcWidth, SrcHeight); // 右下の点は含まないのでそのための補正も行なう。 // とは言ってもあえてその点を除外する必要はない。 // (理由はsubpixelを考えるとわかる。詳しくは割愛。) BltLayoutHelper bltLayout = new BltLayoutHelper(); bltLayout.Rect1 = r; bltLayout.Layout = Layout; bltLayout.Update(); Point layoutPoint = bltLayout.LayoutPoint; // 合成変換を求める。 Affine2D a; if ((Trans0 == Trans0_ && Trans == Trans_)) { // 前回計算した結果と同じなので計算する必要なし a = A_; } else { // 計算すると同時に計算結果をcacheしておく。 a = A_ = Trans * Trans0; Trans0_ = Trans0; Trans_ = Trans; } // 転送先でのサイズが指定されているのか? if (DstSize != null) { // このサイズに合わせて拡大縮小する変換が必要である。 a = new Affine2D(DstSize.Cx / SrcWidth, DstSize.Cy / SrcHeight) * a; } // 合成変換 = DstPoint平行移動変換×DstSize変換×Trans×Trans0× -LayoutPoint平行移動変換 // A = { DstSize変換×Trans×Trans0 } a = Affine2D.Compose(DstPoint, Affine2D.Compose(a, -layoutPoint)); // 正常に計算できたのでこの変換を保存しておく。 TransAll = a; /* * // 転送元でのclipping処理 * SrcPoints = new Point[4]; * SrcPoints[0] = new Point(left, top); * SrcPoints[1] = new Point(right, top); * SrcPoints[2] = new Point(right, bottom); * SrcPoints[3] = new Point(left, bottom); * * DstPoints = new Point[4]; * * // これらの点がはみ出ていれば押し戻して転送先の点を求める * for (int i = 0; i < 4; ++i) * { * // affine変換を用いているので転送先のclippingが容易である * Point p = SrcPoints[i]; * if (p.X < 0) * p.X = 0; * * if (SrcWidth < p.X) * p.X = SrcWidth; * * if (p.Y < 0) * p.Y = 0; * * if (SrcHeight < p.Y) * p.Y = SrcHeight; * * // これだけで転送先が求まる! * DstPoints[i] = a * p; * * // テクスチャ座標に変換しておく必要がある。 * SrcPoints[i] = p * TextureRate; * } */ return(YanesdkResult.NoError); }