1 / 17

ギニュー特戦隊

ギニュー特戦隊.           安達 一哲           安藤 和真           高原 樹           西川 玉恵. 課題  3. 四角い 3 次元の箱を斜めに見た状態を画面に描け。頂点の位置は数値として適時入力し、もっとも見栄えのする値を採用せよ(=座標回転などの操作はあえてしなくても良い)。.   プログラムの仕方. 1 ・二次元の平面に、箱を斜めに見た状態を描く。 2 ・三次元に箱を描き、回転させる。.    方法 1.    方法 2.                           Y

diata
Download Presentation

ギニュー特戦隊

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ギニュー特戦隊           安達 一哲           安藤 和真           高原 樹           西川 玉恵

  2. 課題 3 • 四角い3次元の箱を斜めに見た状態を画面に描け。頂点の位置は数値として適時入力し、もっとも見栄えのする値を採用せよ(=座標回転などの操作はあえてしなくても良い)。

  3.   プログラムの仕方 1・二次元の平面に、箱を斜めに見た状態を描く。 2・三次元に箱を描き、回転させる。

  4.    方法1

  5.    方法2                           Y       X                   0

  6.    方法2 Y X 0

  7.    方法2                          Y Z          X         0

  8.    方法2                                   Y  X0 Z

  9.    1のソ-ス #include <windows.h> // 描画のためのヘッダファイル struct point { // 構造体の定義 int x; int y; }; void acp_plots ( const HDC hdc, const RECT rc, const int xc, const int yc, const HPEN hpen[] ) { struct point position[8]; // 構造体の変数の定義 position[0].x= 0; position[0].y= 0; // 長方形の頂点の座標を設定 position[1].x= -100; position[1].y= 100; position[2].x= -150; position[2].y= 0; position[3].x= -50; position[3].y= -100; position[4].x= 250; position[4].y= 100; position[5].x= 150; position[5].y= 200; position[6].x= 100; position[6].y= 100; position[7].x= 200; position[7].y= 0;

  10. SelectObject( hdc, hpen[1] ); // 赤のペンで長方形を描く MoveToEx( hdc , position[0].x+xc , // X軸は原点の座標を足し、Y軸 yc-position[0].y , NULL ); // は原点から引く LineTo( hdc , position[1].x+xc , yc-position[1].y );//手前の四角形を描く LineTo( hdc , position[2].x+xc , yc-position[2].y); LineTo( hdc , position[3].x+xc , yc-position[3].y ); LineTo( hdc , position[0].x+xc , yc-position[0].y ); SelectObject( hdc, hpen[1] ); //手前の四角形の頂点から奥の四角形の頂点に MoveToEx( hdc , position[0].x+xc , //線を引く yc-position[0].y , NULL ); LineTo( hdc , position[4].x+xc , yc-position[4].y ); SelectObject( hdc, hpen[1] ); MoveToEx( hdc , position[1].x+xc , yc-position[1].y , NULL ); LineTo( hdc , position[5].x+xc , yc-position[5].y); SelectObject( hdc, hpen[1] ); MoveToEx( hdc , position[2].x+xc , yc-position[2].y , NULL ); LineTo( hdc , position[6].x+xc , yc-position[6].y );

  11. SelectObject( hdc, hpen[1] ); MoveToEx( hdc , position[3].x+xc , yc-position[3].y , NULL ); LineTo( hdc , position[7].x+xc , yc-position[7].y ); SelectObject( hdc, hpen[1] ); //奥の四角形を描く MoveToEx( hdc , position[4].x+xc , yc-position[4].y , NULL ); LineTo( hdc , position[5].x+xc , yc-position[5].y ); LineTo( hdc , position[6].x+xc , yc-position[6].y); LineTo( hdc , position[7].x+xc , yc-position[7].y ); LineTo( hdc , position[4].x+xc , yc-position[4].y ); }

  12. 1の実行結果

  13. 2のソース #include <stdio.h> #include <math.h> #include <windows.h> int i; //for 用のカウンタ double rad = 3.14/6; //回転角 struct point { double x; double y; double z; }; struct point rotpoint_y( struct point p0,double rad) //y軸回りに回転させる { struct point p1; p1.x = p0.x*cos(rad) + p0.z*sin(rad); p1.y = p0.y; p1.z = -p0.x*sin(rad) + p0.z*cos(rad); p0.x = p1.x; p0.y = p1.y; p0.z = p1.z; return p0; }

  14. struct point rotpoint_x( struct point p0,double rad) //x軸回りに回転させる { struct point p1; p1.z = p0.z*cos(rad) + p0.y*sin(rad); p1.x = p0.x; p1.y = -p0.z*sin(rad) + p0.y*cos(rad); p0.x = p1.x; p0.y = p1.y; p0.z = p1.z; return p0; } void myPaint ( const HDC myWindow, const int height, const int width ) { struct point p[8],px[2],py[2],pz[2]; p[0].x = 200; p[0].y = 100; p[0].z = 50; //各頂点の座標 p[1].x = -200; p[1].y = 100; p[1].z = 50; p[2].x = -200; p[2].y = -100; p[2].z = 50; p[3].x = 200; p[3].y = -100; p[3].z = 50; p[4].x = 200; p[4].y = 100; p[4].z = -50; p[5].x = -200; p[5].y = 100; p[5].z = -50; p[6].x = -200; p[6].y = -100; p[6].z = -50; p[7].x = 200; p[7].y = -100; p[7].z = -50; px[0].x = -300; px[0].y = 0; px[0].z = 0; //x軸の両端 px[1].x = 300; px[1].y = 0; px[1].z = 0; py[0].x = 0; py[0].y = -300; py[0].z = 0; //y軸の両端 py[1].x = 0; py[1].y = 300; py[1].z = 0; pz[0].x = 0; pz[0].y = 0; pz[0].z = -300; //z軸の両端 pz[1].x = 0; pz[1].y = 0; pz[1].z = 300;

  15. for(i=0;i<=1;++i) //x軸、y軸回りに回転 { px[i] = rotpoint_y(px[i],rad); px[i] = rotpoint_x(px[i],rad); py[i] = rotpoint_y(py[i],rad); py[i] = rotpoint_x(py[i],rad); pz[i] = rotpoint_y(pz[i],rad); pz[i] = rotpoint_x(pz[i],rad); for(i=0;i<8;++i) //x軸、y軸回りに回転 { p[i] = rotpoint_y(p[i],rad); p[i] = rotpoint_x(p[i],rad); } for(i=0;i<8;++i) //相対座標に変換 { p[i].x += 300; p[i].y = 300 - p[i].y; } for(i=0;i<2;++i) //相対座標に変換 { px[i].x += 300; px[i].y = 300 - px[i].y; py[i].x += 300; py[i].y = 300 - py[i].y; pz[i].x += 300; pz[i].y = 300 - pz[i].y; }

  16. MoveToEx(myWindow,(int)px[0].x,(int)px[0].y,NULL); //座標軸を描くMoveToEx(myWindow,(int)px[0].x,(int)px[0].y,NULL); //座標軸を描く LineTo(myWindow,(int)px[1].x,(int)px[1].y); MoveToEx(myWindow,(int)py[0].x,(int)py[0].y,NULL); LineTo(myWindow,(int)py[1].x,(int)py[1].y); MoveToEx(myWindow,(int)pz[0].x,(int)pz[0].y,NULL); LineTo(myWindow,(int)pz[1].x,(int)pz[1].y); MoveToEx(myWindow,(int)p[0].x,(int)p[0].y,NULL); //箱を描く LineTo(myWindow,(int)p[1].x,(int)p[1].y); for(i=1;i<=3;++i) LineTo(myWindow,(int)p[i].x,(int)p[i].y); LineTo(myWindow,(int)p[0].x,(int)p[0].y); MoveToEx(myWindow,(int)p[4].x,(int)p[4].y,NULL); for(i=5;i<=7;++i) LineTo(myWindow,(int)p[i].x,(int)p[i].y); LineTo(myWindow,(int)p[4].x,(int)p[4].y); for(i=0;i<=3;++i) { MoveToEx(myWindow,(int)p[i].x,(int)p[i].y,NULL); LineTo(myWindow,(int)p[i+4].x,(int)p[i+4].y); } }

  17. 2の実行結果

More Related