Visual Studio 2019でDxLibを使って地図画像を回転表示させてみた。
Visual Studio 2019でDxLibを使ってみた、という話の続き。
地図画像のデータは、Google Maps Static APIを使って取得する。
→ Google Maps Static API v2を使ってみた
そして、取得した画像をDxLibのDrawRotaGraph2という機能を使って、回転表示させてみた。

ソースコードは、以下のような感じだ。
#include "dxlib/DxLib.h"
extern int Get_GoogleMaps_Pict(double lat,double lng,int maptype);
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow )
{
int GrHandle;
char fname[1024];
double map_direction=0;
double lat,lng;
ChangeWindowMode( TRUE ) ; // Window MODE
if ( DxLib_Init() == -1 ) { // init
return -1; // Error
}
SetDrawScreen( DX_SCREEN_BACK ) ;
SetWindowSizeChangeEnableFlag( TRUE );
ScreenFlip();
lat = 35.1704; lng = 136.882; // 名古屋駅の緯度,経度
if (Get_GoogleMaps_Pict(lat,lng,3)== -1) { // Googleから地図画像を取ってくる
MessageBox(0,"Map picture download error (Cannot access google.com)",0,0);
}
strcpy(fname,"map_pict.png");
GrHandle=LoadGraph(fname);
map_direction=0;
while (1) {
map_direction--;
if (map_direction<0) { map_direction+=360; }
SetDrawArea( 0 , 0 , 640 , 480) ;
ClearDrawScreen();
SetDrawArea( 120 , 30 , 120+401 , 401 ) ;
DrawRotaGraph2( 200+120,200+30 /* 表示位置-中心 */ , 300, 300 /* 画像データの回転中心 */
, 1.00 /* 拡大 */ , map_direction /180.0 * 3.14159265 /* 回転角 */
, GrHandle, FALSE, FALSE);
ScreenFlip();
if (ProcessMessage() == -1) { break; }
if( CheckHitKey( KEY_INPUT_ESCAPE ) != 0 ) { break; }// ESC key to quit
Sleep(100);
}
DxLib_End(); // finish
return 0;
}
このソースコードだと、画像を一定速度で回転させるだけだが、電子コンパスとかと連動させると地図をPCの向きにあわせて動かすことができる。
昔、そんなのを作ってみたのだった。
→ ネットブックにGPSと電子コンパスを接続してみる