2013年12月7日土曜日

earth.idlコンパイル方法

(1) Microsoft Visual C++ 2008 Express EditionからVisual Studio 2008 コマンド プロンプトを起動
(2) コマンドラインは以下の通り
  midl /cpp_cmd cl.exe /cpp_opt "/E" /out "出力先ディレクトリ" "earth.idlのあるディレクトリ"
*スペースに注意


参考:IDLコンパイル成功!
http://futr.cocolog-nifty.com/blog/2008/04/idl_f4f5.html

Google Earth COM API を C++ で使う
http://oshiro.bpe.es.osaka-u.ac.jp/people/staff/imura/computer/misc/google_earth_com_api/disp_content


------以下サンプルプログラムを空のプロジェクトから記述(追加のインクルードファイルにearth.hを追加)------
// main.cpp
#include     <windows.h>
#include     <iostream>

#include     "earth.h"

using namespace std;



int
main( int argc, char **argv )
{
     IApplicationGE     *app;
     ICameraInfoGE     *camera;
     HRESULT     hr;

     // COMの初期化

     CoInitialize( 0 );

     // IApplicationGE を得る
    
     hr = CoCreateInstance(
          CLSID_ApplicationGE,
          0,
          CLSCTX_LOCAL_SERVER,
          IID_IApplicationGE,
          reinterpret_cast<LPVOID *>( &app ));
     if ( FAILED( hr )) {
          cerr << "cannot create IApplicationGE" << endl;
          return -1;
     }

     // Google Earth の情報を得る

     AppTypeGE     app_type;
     int     major, minor, build;
     app->get_VersionAppType( &app_type );
     app->get_VersionMajor( &major );
     app->get_VersionMinor( &minor );
     app->get_VersionBuild( &build );
     cout << "You are using ";
     switch ( app_type ) {
     case EnterpriseClientGE:
          cout << "Google Earth Enterprise Client" << endl;
          break;
     case ProGE:
          cout << "Google Earth Pro" << endl;
          break;
     case PlusGE:
          cout << "Google Earth Plus" << endl;
          break;
     case FreeGE:
          cout << "Google Earth Free" << endl;
          break;
     default:
          cout << "Unknown" << endl;
          break;
     }
     cout << "version: " << major << "." << minor << "." << build << endl;

     // 初期化が終了するまで待つ

     BOOL     is_initialized;
     do {
          hr = app->IsInitialized( &is_initialized );
     } while ( is_initialized == false );

     // 現在のカメラ位置に関する情報を得る

     // まずカメラのインスタンスを取得する

     hr = app->GetCamera( true, &camera );
     if ( FAILED( hr )) {
          cerr << "IApplicationGE::GetCamera() failed" << endl;
          return -1;
     }

     // 各種パラメータの値を得る

     double     lat, lon, alt;
     AltitudeModeGE     alt_mode;
     double     range, tilt, azimuth;
     camera->get_FocusPointLatitude( &lat );          // 緯度
     camera->get_FocusPointLongitude( &lon );     // 経度
     camera->get_FocusPointAltitude( &alt );          // 高度
     camera->get_FocusPointAltitudeMode( &alt_mode );     // 高度の計測方法
     camera->get_Range( &range );
     camera->get_Tilt( &tilt );
     camera->get_Azimuth( &azimuth );
     cout << "現在の視点情報" << endl;
     cout << "注視点の緯度: " << lat << endl;
     cout << "注視点の経度: " << lon << endl;
     cout << "注視点の高度: " << alt << endl;
     cout << "高度の原点は地表: " << alt_mode << endl;
     cout << "注視点からの距離: " << range << endl;
     cout << "天頂角: " << tilt << endl;     // 水平だと90度
     cout << "方位角: " << azimuth << endl; // 注視点に対して視点が真南にあると
     // 0度。そこから時計まわりに角度が増える。

     // カメラを設定する

     app->SetCameraParams( 34.7316,     // 緯度
                                135.734,     // 経度
                                0.0,          // 高度
                                RelativeToGroundAltitudeGE,     // 高度の計測方法
                                300.0,     // 距離
                                0.0,          // 天頂角
                                0.0,          // 方位角
                                0.1 );     // 移動速度 (5.0より大きいと瞬時に移動)

     // 終了

     CoUninitialize();

     return 0;
}

0 件のコメント:

コメントを投稿