encode Shift_JIS ; import Graphics ; import Graphics3D ; import GUI ; import Math ; // 各種設定値 const int X = 200; // 画面左上のX座標 const int Y = 100; // 画面左上のY座標 const int WIDTH = 700; // 画面の幅 const int HEIGHT = 600; // 画面の高さ const string TITLE = "Hello 3DCG !"; // 画面タイトル const int BG_RED = 0; //背景色の赤成分( 0〜255 ) const int BG_GREEN = 0; //背景色の緑成分( 0〜255 ) const int BG_BLUE = 0; //背景色の青成分( 0〜255 ) const float LIGHT_X = 1.2; // ライトのX方向成分 const float LIGHT_Y = 1.5; // ライトのY方向成分 const float LIGHT_Z = 1.0; // ライトのZ方向成分 const float LIGHT_POWER = 0.5; // ライトの輝度 const float AMBIENT_POWER = 0.5; // ライトの輝度 // アニメーションのメインループを制御する変数(OFFでプログラム終了時) bool mainLoopState = true; // 描画関連リソース int mainRenderer; // 3DCGレンダラー(描画エンジン) int mainGraphics; // グラフィックスリソース // GUI関連リソース int mainWindow; // ウィンドウ int mainDisplayLabel; // 表示ラベル /* * ウィンドウの構築などの初期化処理 */ void init( ){ // グラフィックスデータや表示画面の生成 mainGraphics = newGraphics( ); mainRenderer = newGraphics3DRenderer( WIDTH, HEIGHT, mainGraphics ); mainWindow = newWindow( X, Y, WIDTH, HEIGHT, TITLE ); mainDisplayLabel = newImageLabel( 0, 0, WIDTH, HEIGHT, mainGraphics ); mountComponent( mainDisplayLabel, mainWindow ); // マウス操作や背景色の設定 setGraphics3DDefaultEventHandler( mainRenderer, mainDisplayLabel ); setGraphics3DColor( mainRenderer, BG_RED, BG_GREEN, BG_BLUE, 255 ); // (LIGHT_X, LIGHT_Y, LIGHT_Z)の方向から原点に向かって照射する、輝度LIGHT_POWERの平行光源を配置 int light = newLight( LIGHT_X, LIGHT_Y, LIGHT_Z, LIGHT_POWER ); mountLight( light, mainRenderer ); // 輝度AMBIENT_POWERのアンビエント光源を配置 int ambientLight = newAmbientLight( 0.0, 0.0, 0.0, AMBIENT_POWER ); mountLight( ambientLight, mainRenderer ); } /* * ウィンドウサイズが変更された際に呼び出されるイベントハンドラ */ void onWindowResize( int id, int width, int height ){ if( id == mainWindow ){ setGraphics3DSize( mainRenderer, width, height ); setComponentSize( mainDisplayLabel, width, height ); } } /* * ウィンドウが閉じられた時に呼び出されるイベントハンドラ */ void onWindowClose( int id ){ mainLoopState = false; // メインループを脱出 } /* * main関数 */ void main( string args[] ){ init(); //初期化処理 // 波面の幅 double lx = 3.8; double ly = 3.8; // 基盤となる座標系を宣言(配置の調整用) int coord = newCoordinate(); moveCoordinate( coord, -lx*0.5, -ly*0.5, 0.3 ); mountCoordinate( coord, mainRenderer ); int nx = 80; // X方向メッシュ数 int ny = 80; // Y方向メッシュ数 // 格子点のZ値配列(nx×nyメッシュ)を生成 double x; double y; double x_; double y_; double z[ nx ][ ny ]; double dx = lx / nx; double dy = ly / ny; for( int i=0; i