coding Shift_JIS; import GUI; import Graphics; import Graphics2D; import Graphics3D; //ウィンドウのX,Y,幅,高さ const int WINDOW_X = 0; const int WINDOW_Y = 0; const int WINDOW_WIDTH = 820; const int WINDOW_HEIGHT = 640; const string WINDOW_TITLE = "Graphics Window"; //画面のX,Y,幅,高さ const int SCREEN_X = 0; const int SCREEN_Y = 0; const int SCREEN_WIDTH = 800; const int SCREEN_HEIGHT = 600; //背景色 const int SCREEN_COLOR_RED = 0; const int SCREEN_COLOR_GREEN = 0; const int SCREEN_COLOR_BLUE = 0; const int SCREEN_COLOR_ALPHA = 255; //3Dライトのパラメータ const float LIGHT_X = 1.2; //ライトXベクトル const float LIGHT_Y = 1.5; //ライトYベクトル const float LIGHT_Z = 1.0; //ライトZベクトル const float LIGHT_BRIGHTNESS = 0.5; //ライト輝度 const float AMBIENT_BRIGHTNESS = 0.5; //環境光の輝度 //アニメーション関連 int loopWait = 30; //1フレーム当たりの待機時間(ミリ秒) boolean mainLoopState = true; //継続判定 //GUIコンポーネント int window; //ウィンドウ int screenLabel; //画面表示ラベル //以下、描画関連のリソース類 int graphics2D; //2D描画用グラフィックスリソース int renderer2D; //2D描画用レンダラー int graphics3D; //3D描画用グラフィックスリソース int renderer3D; //3D描画用レンダラー /** * main関数、最初にここから実行されます。 */ void main(){ //GUIの構築や初期化 initializeComponent(); //ユーザー定義の初期化処理 initialize(); //アニメーションのメインループ while(mainLoopState){ //ユーザー定義の描画処理 paint(); //ユーザー定義の更新処理 update(); //GUIコンポーネントの再描画 paintComponent(screenLabel); paintComponent(window); //指定時間待機(アニメーションウェイト) sleep(loopWait); } //アニメーションループを抜けたら終了 finalize(); exit(); } /** * ウィンドウを閉じた際に呼び出されるイベントハンドラです。 */ void onWindowClose(int id){ if(id == window){ //メインループを脱出させて終了させる mainLoopState = false; } } /** * ユーザー定義の初期化処理、 * ここは起動時に一度だけ呼び出されます。 */ void initialize(){ // 3Dモデルなどを適当に配置 int axis = newAxisModel(3.0, 3.0, 3.0); mountModel(axis, renderer3D); int sphere = newSphereModel(1.4, 1.4, 1.4, 30, 20); mountModel(sphere, renderer3D); } /** * ユーザー定義の描画処理、 * ここはアニメーションの毎時刻呼び出されます。 */ void paint(){ //まず2DCGを背景色でクリア(画面には2DCGが表示される) clearGraphics2D(renderer2D); //2DCGに図形を適当に描き込み setDrawColor(renderer2D, 0, 0, 255, 255); drawRect(renderer2D, 50, 280, 300, 300, true); //3DCGレンダラーを動かして描画(内容はgraphics3Dに) paintGraphics3D(renderer3D); //2DCG上に、3DCG(renderer3Dの出力 = graphics3D)を描画 drawImage( renderer2D, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, graphics3D ); //2DCGに図形を適当に描き込み setDrawColor(renderer2D, 0, 255, 0, 180); drawOval(renderer2D, 400, 100, 200, 200, true); } /** * ユーザー定義の更新処理、 * ここはアニメーションの毎時刻呼び出されます。 */ void update(){ //立体モデルの位置などを毎時刻動かす場合に、 //ここに記述します。 } /** * ユーザー定義の終了時処理、 * ここは終了時に一度だけ呼び出されます。 */ void finalize(){ //毎時刻のファイル書き込み処理などを行っている場合に、 //ここでファイルを閉じます。 } /** * GUIの構築やレンダラーの生成など、初期化処理を行います。 */ void initializeComponent(){ //2D描画用レンダラーの生成 graphics2D = newGraphics(); renderer2D = newGraphics2DRenderer( SCREEN_WIDTH, SCREEN_HEIGHT, graphics2D ); //3D描画用レンダラーの生成 graphics3D = newGraphics(); renderer3D = newGraphics3DRenderer( SCREEN_WIDTH, SCREEN_HEIGHT, graphics3D ); //ウィンドウの生成 window = newWindow( WINDOW_X, WINDOW_Y, WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE ); //画面表示ラベルの生成(画面には2D描画結果を表示させる) screenLabel = newGraphicsLabel( SCREEN_X, SCREEN_Y, SCREEN_WIDTH, SCREEN_HEIGHT, graphics2D ); //画面表示ラベルをウィンドウ上に配置 mountComponent(screenLabel, window); //2D背景色の設定 setGraphics2DColor( renderer2D, SCREEN_COLOR_RED, SCREEN_COLOR_GREEN, SCREEN_COLOR_BLUE, SCREEN_COLOR_ALPHA ); //3D背景色は透明に設定 setGraphics3DColor(renderer3D, 0, 0, 0, 0); //3DCGの視点操作を、screenLabel上のマウス操作と結びつける setGraphics3DDefaultEventHandler(renderer3D, screenLabel); //3DCGライトの配置 mountLight( newLight(LIGHT_X,LIGHT_Y,LIGHT_Z,LIGHT_BRIGHTNESS), renderer3D ) ; mountLight( newAmbientLight(0.0,0.0,0.0,AMBIENT_BRIGHTNESS), renderer3D ) ; }