画像を回転し表示したいのですがうまくいきません。
DrawRotaGraphと同じような回転画像を表示するアルゴリズムを教えていただきませんでしょうか
実行時の画面
一番左:オリジナルの画像
真ん中:DrawRotaGraphで回転し表示
一番右:自分で回転画像を表示
#include "DxLib.h"
#include "Math.h"
#define PI 3.1415926535897932384626433832795f
#define RAD(X) ((PI / 180.0f) * X)
// プログラムは WinMain から始まります
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow )
{
SetOutApplicationLogValidFlag(FALSE);
if(ChangeWindowMode(TRUE) != DX_CHANGESCREEN_OK)
{
return -1;
}
if( DxLib_Init() == -1 ) // DXライブラリ初期化処理
{
return -1 ; // エラーが起きたら直ちに終了
}
int GHandle = LoadGraph( "test.bmp" ) ;
float rad = 45;
float c = cos(RAD(-rad));
float s = sin(RAD(-rad));
int w;
int h;
GetGraphSize(GHandle, &w, &h);
int x1, y1, x2, y2;
int int_cos, int_sin;
int DstW, DstH;
int DstCx, DstCy;
int SrcCx, SrcCy;
SrcCx = (int)(w / 2.0f);
SrcCy = (int)(h / 2.0f);
////出力画像の幅高さを計算
DstW = (int)( fabs(w * c) + fabs(h * s) + 0.5 );
DstH = (int)( fabs(w * s) + fabs(h * c) + 0.5 );
DstCx = DstW / 2;
DstCy = DstH / 2;
int_cos = (int)(c * 1024);
int_sin = (int)(s * 1024);
// 描画先画面を裏にする
SetDrawScreen( DX_SCREEN_BACK ) ;
while( ProcessMessage() == 0 && CheckHitKey( KEY_INPUT_ESCAPE ) == 0 )
{
// 画面を消去
ClearDrawScreen() ;
DrawGraph( 0 , 0 , GHandle , TRUE ) ;
for(y2 = 0; y2 < DstH; y2++)
{
for(x2 = 0; x2 < DstW; x2++)
{
// 出力画像の座標(nx, ny)から入力画像の座標(x, y)を逆算する
x1 = (int)(((x2-DstCx) * int_cos - (y2-DstCy) * int_sin) >> 10) + SrcCx;
y1 = (int)(((x2-DstCx) * int_sin + (y2-DstCy) * int_cos) >> 10) + SrcCy;
if (x1 >= 0 && x1 < w && y1 >= 0 && y1 < h)
{
int col = GetPixel(x1, y1);
DrawPixel(30 + x2, 0 + y2, col);
}
else
{
DrawPixel(30 + x2, 0 + y2, 0x0F0F0F);
}
}
}
// 読みこんだグラフィックを回転描画
DrawRotaGraph( 20 , 3 , 1.0f , RAD(45) , GHandle , TRUE ) ;
// 裏画面の内容を表画面に反映させる
ScreenFlip() ;
}
DxLib_End() ; // DXライブラリ使用の終了処理
return 0 ; // ソフトの終了
}