Modified lines:  7
Added line:  None
Removed line:  8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224
Generated by diff2html.pl
© Yves Bailly, MandrakeSoft S.A. 2001, Ryohei Morita 2007
diff2html.pl is licensed under the GNU GPL.

  ../07-01/07-01-Planning.c     07-02-EmbededObjects.c
  224 lines
8716 bytes
Last modified : Mon Nov 5 08:00:38 2012

    98 lines
4035 bytes
Last modified : Mon Nov 5 07:57:30 2012

1 // Keisanki Joron 2 (Introduction to Computing II)   1 // Keisanki Joron 2 (Introduction to Computing II)
2 // Dept. of Engineering Systems, University of Tsukuba   2 // Dept. of Engineering Systems, University of Tsukuba
3 // [UTF-8 / Unix]   3 // [UTF-8 / Unix]
4 // 計算機序論2・実習 (筑波大学工学システム学類)   4 // 計算機序論2・実習 (筑波大学工学システム学類)
5   5
6 // 2012/11/05a kameda[at]iit.tsukuba.ac.jp   6 // 2012/11/05a kameda[at]iit.tsukuba.ac.jp
7 // 07.01. プログラムの構造設計   7 // 07.02. ファイル分割
8      
9 // ***********************************************************************       
10 // CommonHeaders.h : common header files *********************************      
11      
12 // +++--------------------------------------------------      
13 // どの部分ソースでも利用する可能性が高いライブラリ(関数)に      
14 // 相当するヘッダファイル      
15 // +++--------------------------------------------------      
16      
17 #include <stdio.h> // printf()      
18 #include <GL/glut.h> // gl*(), glut*()      
19   8
20 // ***********************************************************************    9 // *********************************************************************** 
21 // EmbededObjects ********************************************************   10 // EmbededObjects ********************************************************
22   11
23 // +++--------------------------------------------------   12 // +++--------------------------------------------------
24 // ソース内部でのCG物体の直接描画   13 // ソース内部でのCG物体の直接描画
25 // +++--------------------------------------------------   14 // +++--------------------------------------------------
26   15
27 // +----------------------------------------------------   16 // +----------------------------------------------------
28 // OpenGL Logoを描く   17 // OpenGL Logoを描く
29 // +----------------------------------------------------   18 // +----------------------------------------------------
30 // s はスケーリングファクタ(s=1.0 で 概ね -1.0 〜 1.0 の大きさ)   19 // s はスケーリングファクタ(s=1.0 で 概ね -1.0 〜 1.0 の大きさ)
31 void ic2_OpenGLLogo (float s) {   20 void ic2_OpenGLLogo (float s) {
32 // 光源によるシェーディング効果を切る(と色の指定が直接色になる)   21 // 光源によるシェーディング効果を切る(と色の指定が直接色になる)
33   glDisable(GL_LIGHTING);      22   glDisable(GL_LIGHTING);   
34   23
35   // 線の幅(画素単位)   24   // 線の幅(画素単位)
36   glLineWidth(1.0);   25   glLineWidth(1.0);
37   26
38   // (R, G, B) 値域は 0.0 - 1.0   27   // (R, G, B) 値域は 0.0 - 1.0
39   glColor3f(1.0, 1.0, 1.0);   28   glColor3f(1.0, 1.0, 1.0);
40   29
41   // glBegin(GL_LINES); から glEnd(); までの間は、   30   // glBegin(GL_LINES); から glEnd(); までの間は、
42   // 「始点・終点」ごとに線分が描画される   31   // 「始点・終点」ごとに線分が描画される
43   glBegin(GL_LINES);    32   glBegin(GL_LINES); 
44   glVertex3f(s * -0.8, s *  0.8, 0.0); glVertex3f(s * -0.8, s *  0.2, 0.0); // O   33   glVertex3f(s * -0.8, s *  0.8, 0.0); glVertex3f(s * -0.8, s *  0.2, 0.0); // O
45   glVertex3f(s * -0.8, s *  0.2, 0.0); glVertex3f(s * -0.4, s *  0.2, 0.0); // O   34   glVertex3f(s * -0.8, s *  0.2, 0.0); glVertex3f(s * -0.4, s *  0.2, 0.0); // O
46   glVertex3f(s * -0.4, s *  0.2, 0.0); glVertex3f(s * -0.4, s *  0.8, 0.0); // O   35   glVertex3f(s * -0.4, s *  0.2, 0.0); glVertex3f(s * -0.4, s *  0.8, 0.0); // O
47   glVertex3f(s * -0.4, s *  0.8, 0.0); glVertex3f(s * -0.8, s *  0.8, 0.0); // O   36   glVertex3f(s * -0.4, s *  0.8, 0.0); glVertex3f(s * -0.8, s *  0.8, 0.0); // O
48   37
49   glVertex3f(s * -0.2, s *  0.6, 0.0); glVertex3f(s * -0.2, s *  0.0, 0.0); // p   38   glVertex3f(s * -0.2, s *  0.6, 0.0); glVertex3f(s * -0.2, s *  0.0, 0.0); // p
50   glVertex3f(s * -0.2, s *  0.6, 0.0); glVertex3f(s *  0.0, s *  0.6, 0.0); // p   39   glVertex3f(s * -0.2, s *  0.6, 0.0); glVertex3f(s *  0.0, s *  0.6, 0.0); // p
51   glVertex3f(s *  0.0, s *  0.6, 0.0); glVertex3f(s *  0.0, s *  0.2, 0.0); // p   40   glVertex3f(s *  0.0, s *  0.6, 0.0); glVertex3f(s *  0.0, s *  0.2, 0.0); // p
52   glVertex3f(s *  0.0, s *  0.2, 0.0); glVertex3f(s * -0.2, s *  0.2, 0.0); // p   41   glVertex3f(s *  0.0, s *  0.2, 0.0); glVertex3f(s * -0.2, s *  0.2, 0.0); // p
53   42
54   glVertex3f(s *  0.2, s *  0.4, 0.0); glVertex3f(s *  0.4, s *  0.4, 0.0); // e   43   glVertex3f(s *  0.2, s *  0.4, 0.0); glVertex3f(s *  0.4, s *  0.4, 0.0); // e
55   glVertex3f(s *  0.4, s *  0.4, 0.0); glVertex3f(s *  0.4, s *  0.6, 0.0); // e   44   glVertex3f(s *  0.4, s *  0.4, 0.0); glVertex3f(s *  0.4, s *  0.6, 0.0); // e
56   glVertex3f(s *  0.4, s *  0.6, 0.0); glVertex3f(s *  0.2, s *  0.6, 0.0); // e   45   glVertex3f(s *  0.4, s *  0.6, 0.0); glVertex3f(s *  0.2, s *  0.6, 0.0); // e
57   glVertex3f(s *  0.2, s *  0.6, 0.0); glVertex3f(s *  0.2, s *  0.2, 0.0); // e   46   glVertex3f(s *  0.2, s *  0.6, 0.0); glVertex3f(s *  0.2, s *  0.2, 0.0); // e
58   glVertex3f(s *  0.2, s *  0.2, 0.0); glVertex3f(s *  0.4, s *  0.2, 0.0); // e   47   glVertex3f(s *  0.2, s *  0.2, 0.0); glVertex3f(s *  0.4, s *  0.2, 0.0); // e
59   48
60   glVertex3f(s *  0.6, s *  0.6, 0.0); glVertex3f(s *  0.6, s *  0.2, 0.0); // n   49   glVertex3f(s *  0.6, s *  0.6, 0.0); glVertex3f(s *  0.6, s *  0.2, 0.0); // n
61   glVertex3f(s *  0.6, s *  0.6, 0.0); glVertex3f(s *  0.8, s *  0.6, 0.0); // n   50   glVertex3f(s *  0.6, s *  0.6, 0.0); glVertex3f(s *  0.8, s *  0.6, 0.0); // n
62   glVertex3f(s *  0.8, s *  0.6, 0.0); glVertex3f(s *  0.8, s *  0.2, 0.0); // n   51   glVertex3f(s *  0.8, s *  0.6, 0.0); glVertex3f(s *  0.8, s *  0.2, 0.0); // n
63   52
64   glVertex3f(s *  0.0, s * -0.2, 0.0); glVertex3f(s * -0.6, s * - 0.2, 0.0); // G   53   glVertex3f(s *  0.0, s * -0.2, 0.0); glVertex3f(s * -0.6, s * - 0.2, 0.0); // G
65   glVertex3f(s * -0.6, s * -0.2, 0.0); glVertex3f(s * -0.6, s * - 0.8, 0.0); // G   54   glVertex3f(s * -0.6, s * -0.2, 0.0); glVertex3f(s * -0.6, s * - 0.8, 0.0); // G
66   glVertex3f(s * -0.6, s * -0.8, 0.0); glVertex3f(s *  0.0, s * - 0.8, 0.0); // G   55   glVertex3f(s * -0.6, s * -0.8, 0.0); glVertex3f(s *  0.0, s * - 0.8, 0.0); // G
67   glVertex3f(s *  0.0, s * -0.8, 0.0); glVertex3f(s *  0.0, s * - 0.5, 0.0); // G   56   glVertex3f(s *  0.0, s * -0.8, 0.0); glVertex3f(s *  0.0, s * - 0.5, 0.0); // G
68   glVertex3f(s *  0.0, s * -0.5, 0.0); glVertex3f(s * -0.3, s * - 0.5, 0.0); // G   57   glVertex3f(s *  0.0, s * -0.5, 0.0); glVertex3f(s * -0.3, s * - 0.5, 0.0); // G
69   58
70   glVertex3f(s *  0.2, s * -0.2, 0.0); glVertex3f(s *  0.2, s * - 0.8, 0.0); // L   59   glVertex3f(s *  0.2, s * -0.2, 0.0); glVertex3f(s *  0.2, s * - 0.8, 0.0); // L
71   glVertex3f(s *  0.2, s * -0.8, 0.0); glVertex3f(s *  0.8, s * - 0.8, 0.0); // L   60   glVertex3f(s *  0.2, s * -0.8, 0.0); glVertex3f(s *  0.8, s * - 0.8, 0.0); // L
72   glEnd();   61   glEnd();
73   62
74   // glBegin(GL_LINE_LOOP); から glEnd(); までの間は、   63   // glBegin(GL_LINE_LOOP); から glEnd(); までの間は、
75   // 全ての頂点を使った閉じた線分が描画される   64   // 全ての頂点を使った閉じた線分が描画される
76   65
77   // 左上隅   66   // 左上隅
78   glColor3f(1.0, 1.0, 1.0);   67   glColor3f(1.0, 1.0, 1.0);
79   glBegin(GL_LINE_LOOP);   68   glBegin(GL_LINE_LOOP);
80   glVertex3f(s * -1.0, s *  1.0, 0.0);   69   glVertex3f(s * -1.0, s *  1.0, 0.0);
81   glVertex3f(s * -0.8, s *  1.0, 0.0);   70   glVertex3f(s * -0.8, s *  1.0, 0.0);
82   glVertex3f(s * -1.0, s *  0.8, 0.0);   71   glVertex3f(s * -1.0, s *  0.8, 0.0);
83   glEnd();   72   glEnd();
84      73   
85   // 右上隅   74   // 右上隅
86   glColor3f(0.1, 1.0, 1.0);   75   glColor3f(0.1, 1.0, 1.0);
87   glBegin(GL_LINE_LOOP);   76   glBegin(GL_LINE_LOOP);
88   glVertex3f(s *  0.8, s *  1.0, 0.0);   77   glVertex3f(s *  0.8, s *  1.0, 0.0);
89   glVertex3f(s *  1.0, s *  1.0, 0.0);   78   glVertex3f(s *  1.0, s *  1.0, 0.0);
90   glVertex3f(s *  1.0, s *  0.8, 0.0);   79   glVertex3f(s *  1.0, s *  0.8, 0.0);
91   glEnd();   80   glEnd();
92   81
93   // 左下隅   82   // 左下隅
94   glColor3f(1.0, 0.1, 1.0);   83   glColor3f(1.0, 0.1, 1.0);
95   glBegin(GL_LINE_LOOP);   84   glBegin(GL_LINE_LOOP);
96   glVertex3f(s * -1.0, s * -0.8, 0.0);   85   glVertex3f(s * -1.0, s * -0.8, 0.0);
97   glVertex3f(s * -0.8, s * -1.0, 0.0);   86   glVertex3f(s * -0.8, s * -1.0, 0.0);
98   glVertex3f(s * -1.0, s * -1.0, 0.0);   87   glVertex3f(s * -1.0, s * -1.0, 0.0);
99   glEnd();   88   glEnd();
100   89
101   // 右下隅   90   // 右下隅
102   glColor3f(1.0, 1.0, 0.1);   91   glColor3f(1.0, 1.0, 0.1);
103   glBegin(GL_LINE_LOOP);   92   glBegin(GL_LINE_LOOP);
104   glVertex3f(s *  0.8, s * -1.0, 0.0);   93   glVertex3f(s *  0.8, s * -1.0, 0.0);
105   glVertex3f(s *  1.0, s * -0.8, 0.0);   94   glVertex3f(s *  1.0, s * -0.8, 0.0);
106   glVertex3f(s *  1.0, s * -1.0, 0.0);   95   glVertex3f(s *  1.0, s * -1.0, 0.0);
107   glEnd();   96   glEnd();
108 }   97 }
109   98
110 // ***********************************************************************       
111 // Projection ************************************************************      
112      
113 // +++--------------------------------------------------      
114 // カメラの投影行列を設定      
115 // +++--------------------------------------------------      
116      
117 // +----------------------------------------------------      
118 // 直交投影      
119 // +----------------------------------------------------      
120 void ic2_SetUpCamera_Ortho (void) {      
121   // OpenGLのPROJECTION行列スタックにアクセス      
122   glMatrixMode(GL_PROJECTION);      
123      
124   // PROJECTION行列スタックトップを単位行列で初期化      
125   glLoadIdentity();       
126      
127   // 直交投影行列を生成するサポート関数 glOrtho を呼び出す      
128   // glOrtho(左端, 右端, 下端, 上端, 近接側クリッピング面,  遠方側クリッピング面)      
129   glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); //       
130 }      
131      
132 // ***********************************************************************       
133 // Rendering *************************************************************      
134      
135 // +++--------------------------------------------------      
136 // スクリーンに描画する      
137 // +++--------------------------------------------------      
138      
139 // +----------------------------------------------------      
140 // 1フレーム分の描画      
141 // +----------------------------------------------------      
142 void ic2_DrawFrame (void) {      
143   // (1) 描画バッファの初期化      
144   // 以前にglClearColor()で指定した色で塗り潰す      
145   glClear(GL_COLOR_BUFFER_BIT);      
146      
147   // (2) カメラの設定      
148   ic2_SetUpCamera_Ortho();      
149      
150   // (3) 光源の設置      
151      
152   // (4) 物体の描画      
153   ic2_OpenGLLogo(0.95);      
154      
155   // (5) 描画バッファの切替      
156   glutSwapBuffers();      
157 }      
158      
159 // ***********************************************************************       
160 // Callback **************************************************************       
161      
162 // +++--------------------------------------------------      
163 // GLUTでのイベント駆動型プログラミング      
164 // +++--------------------------------------------------      
165      
166 // +----------------------------------------------------      
167 // 「タイマー」で呼出し(繰り返すことで「一定間隔呼出し」化)      
168 // +----------------------------------------------------      
169 void ic2_timerhandler(int keynumber){      
170   glutPostRedisplay(); // OpenGLのmainloopに戻ったら再描画を頼む      
171   glutTimerFunc(250, ic2_timerhandler, 0); // 250[ms]後にまた呼び出す      
172 }      
173      
174 // ***********************************************************************       
175 // Initialization ********************************************************       
176      
177 // +++--------------------------------------------------      
178 // 初期化(主にGLUT)      
179 // +++--------------------------------------------------      
180      
181 // +----------------------------------------------------      
182 // OpenGLとしてのWindowの初期化      
183 // +----------------------------------------------------      
184 void ic2_BootWindow (char winname[]) {      
185      
186   // DisplayModeの設定(それぞれを|で繋ぐ)      
187   //   GLUT_DOUBLE ... ダブルバッファ      
188   //   GLUT_RGB    ... RGB表色モード      
189   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);       
190      
191   // 準備(Initialization)が済んだらウィンドウを開く      
192   glutCreateWindow(winname);      
193      
194   // Callback関数を設定 (イベント処理)      
195   glutDisplayFunc(ic2_DrawFrame); // フレームを(再)描画するために呼び出す関数      
196   glutTimerFunc(250, ic2_timerhandler, 0); // 250[ms]後に呼び出す関数      
197      
198   // ウィンドウ全体を書き直すときの色(R,G,B,0) ここでは黒      
199   glClearColor(0.0, 0.0, 0.0, 0.0);      
200 }      
201      
202 // ***********************************************************************       
203 // MainFunction **********************************************************       
204      
205 // +----------------------------------------------------      
206 // メイン関数など      
207 // +----------------------------------------------------      
208      
209 // +----------------------------------------------------      
210 // Main Function      
211 // +----------------------------------------------------      
212 int main (int argc, char *argv[]) {      
213      
214   // glutライブラリによる引数の解釈      
215   glutInit(&argc, argv);      
216      
217   // OpenGL Window の初期化      
218   ic2_BootWindow(argv[0]);      
219      
220   // 無限ループの開始      
221   glutMainLoop();      
222         
223   return 0;      
224 }      

Generated by diff2html.pl on Mon Nov 5 13:34:39 2012
Command-line:
/home/ubuntu/scripts/diff2html_utf.pl ../07-01/07-01-Planning.c 07-02-EmbededObjects.c