|
Generated by diff2html.pl © Yves Bailly, MandrakeSoft S.A. 2001, Ryohei Morita 2007 diff2html.pl is licensed under the GNU GPL. |
../110-5/110-5-ShowNormal.c | 110-6-MoveLight.c | |||
---|---|---|---|---|
588 lines 21550 bytes Last modified : Sun Nov 13 18:00:13 2011 |
613 lines 22499 bytes Last modified : Sun Nov 13 17:59:49 2011 |
|||
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 | 4 | |||
5 | // 2011/11/14 kameda[at]iit.tsukuba.ac.jp | 5 | // 2011/11/14 kameda[at]iit.tsukuba.ac.jp | |
6 | // 10.5 法線ã®è¡¨ç¤º (ã‚ー 'N') | 6 | // 10.6 å…‰æºã®ä¸€æ™‚移動 (ã‚ー 'L') | |
7 | 7 | |||
8 | #include <stdio.h> | 8 | #include <stdio.h> | |
9 | #include <stdlib.h> // exit(), calloc() | 9 | #include <stdlib.h> // exit(), calloc() | |
10 | #include <math.h> // sqrt() | 10 | #include <math.h> // sqrt() | |
11 | #include <GL/glut.h> | 11 | #include <GL/glut.h> | |
12 | 12 | |||
13 | // *********************************************************************** | 13 | // *********************************************************************** | |
14 | // global variables ****************************************************** | 14 | // global variables ****************************************************** | |
15 | 15 | |||
16 | // +---------------------------------------------------- | 16 | // +---------------------------------------------------- | |
17 | // Global Variables | 17 | // Global Variables | |
18 | // +---------------------------------------------------- | 18 | // +---------------------------------------------------- | |
19 | 19 | |||
20 | // Windowサイズ | 20 | // Windowサイズ | |
21 | int window_w = 400; | 21 | int window_w = 400; | |
22 | int window_h = 400; | 22 | int window_h = 400; | |
23 | 23 | |||
24 | // 直交投影時ã®ã‚¹ã‚±ãƒ¼ãƒ«ãƒ•ã‚¡ã‚¯ã‚¿ [pixel / unit_of_imager] | 24 | // 直交投影時ã®ã‚¹ã‚±ãƒ¼ãƒ«ãƒ•ã‚¡ã‚¯ã‚¿ [pixel / unit_of_imager] | |
25 | // ã“ã“ã§ã¯æ£è¦åŒ–カメラã®æ’®åƒé¢ã§ã® 1.0 å˜ä½ã‚’ 200ç”»ç´ ã«ç›¸å½“ã•ã›ã‚‹ | 25 | // ã“ã“ã§ã¯æ£è¦åŒ–カメラã®æ’®åƒé¢ã§ã® 1.0 å˜ä½ã‚’ 200ç”»ç´ ã«ç›¸å½“ã•ã›ã‚‹ | |
26 | float ortho_unit = 200.0; | 26 | float ortho_unit = 200.0; | |
27 | 27 | |||
28 | // Windowã®ID(æ画管ç†ç”¨ï¼‰ | 28 | // Windowã®ID(æ画管ç†ç”¨ï¼‰ | |
29 | int window_id = -1; | 29 | int window_id = -1; | |
30 | 30 | |||
31 | // トグルスイッム(1 ... On, -1 ... Off) | 31 | // トグルスイッム(1 ... On, -1 ... Off) | |
32 | int tgl_showpredefined = -1; // プãƒã‚°ãƒ©ãƒ 内定義物体ã®è¡¨ç¤º | 32 | int tgl_showpredefined = -1; // プãƒã‚°ãƒ©ãƒ 内定義物体ã®è¡¨ç¤º | |
33 | int tgl_shownormal = +1; // 法線表示 | 33 | int tgl_shownormal = -1; // 法線表示 | |
34 | int tgl_movelightonly = -1; // 一時的ãªå…‰æºæ“作 (å¿…ãš-1ã§åˆæœŸåŒ–) | |||
35 | GLfloat mvmlocked[16]; // å…‰æºæ“作時ã«ãƒãƒƒã‚¯ã•ã‚ŒãŸMODELVIEW行列ã®å†…容 | |||
34 | 36 | |||
35 | // オブジェクトモデル | 37 | // オブジェクトモデル | |
36 | struct ic2PATCH *firstpatchptr = NULL; | 38 | struct ic2PATCH *firstpatchptr = NULL; | |
37 | 39 | |||
38 | // *********************************************************************** | 40 | // *********************************************************************** | |
39 | // read model ************************************************************ | 41 | // read model ************************************************************ | |
40 | 42 | |||
41 | // +---------------------------------------------------- | 43 | // +---------------------------------------------------- | |
42 | // 1ã¤ã®ç‚¹ã®ãŸã‚ã®æ§‹é€ 体 | 44 | // 1ã¤ã®ç‚¹ã®ãŸã‚ã®æ§‹é€ 体 | |
43 | // +---------------------------------------------------- | 45 | // +---------------------------------------------------- | |
44 | struct ic2POINT { | 46 | struct ic2POINT { | |
45 | float x; | 47 | float x; | |
46 | float y; | 48 | float y; | |
47 | float z; | 49 | float z; | |
48 | }; | 50 | }; | |
49 | 51 | |||
50 | // +---------------------------------------------------- | 52 | // +---------------------------------------------------- | |
51 | // 1ã¤ã®è‰²ã®ãŸã‚ã®æ§‹é€ 体 | 53 | // 1ã¤ã®è‰²ã®ãŸã‚ã®æ§‹é€ 体 | |
52 | // +---------------------------------------------------- | 54 | // +---------------------------------------------------- | |
53 | struct ic2COLOR { | 55 | struct ic2COLOR { | |
54 | float r; | 56 | float r; | |
55 | float g; | 57 | float g; | |
56 | float b; | 58 | float b; | |
57 | }; | 59 | }; | |
58 | 60 | |||
59 | // +---------------------------------------------------- | 61 | // +---------------------------------------------------- | |
60 | // 1ã¤ã®ä¸‰è§’形パッãƒã®ãŸã‚ã®æ§‹é€ 体 | 62 | // 1ã¤ã®ä¸‰è§’形パッãƒã®ãŸã‚ã®æ§‹é€ 体 | |
61 | // 次ã®ä¸‰è§’形パッãƒã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’æŒã¤ã€‚ | 63 | // 次ã®ä¸‰è§’形パッãƒã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’æŒã¤ã€‚ | |
62 | // v(st) × v(su) [外ç©]ãŒã“ã®é¢ã®æ³•ç·šãƒ™ã‚¯ãƒˆãƒ«ã‚’æˆã™(å³ãƒã‚¸å¼) | 64 | // v(st) × v(su) [外ç©]ãŒã“ã®é¢ã®æ³•ç·šãƒ™ã‚¯ãƒˆãƒ«ã‚’æˆã™(å³ãƒã‚¸å¼) | |
63 | // +---------------------------------------------------- | 65 | // +---------------------------------------------------- | |
64 | struct ic2PATCH { | 66 | struct ic2PATCH { | |
65 | struct ic2POINT s; // é ‚ç‚¹s | 67 | struct ic2POINT s; // é ‚ç‚¹s | |
66 | struct ic2POINT t; // é ‚ç‚¹t | 68 | struct ic2POINT t; // é ‚ç‚¹t | |
67 | struct ic2POINT u; // é ‚ç‚¹u | 69 | struct ic2POINT u; // é ‚ç‚¹u | |
68 | struct ic2POINT n; // 法線ベクトル(æ£è¦åŒ–ã•ã‚ŒãŸæ–¹å‘ベクトル) | 70 | struct ic2POINT n; // 法線ベクトル(æ£è¦åŒ–ã•ã‚ŒãŸæ–¹å‘ベクトル) | |
69 | struct ic2POINT b; // パッãƒã®é‡å¿ƒ | 71 | struct ic2POINT b; // パッãƒã®é‡å¿ƒ | |
70 | float l; // 法線ベクトル表示時ã®é•·ã•è£œæ£ (l * n) | 72 | float l; // 法線ベクトル表示時ã®é•·ã•è£œæ£ (l * n) | |
71 | struct ic2COLOR c; // 色ã®å¼·åº¦ (通常ã¯0.0 - 1.0) | 73 | struct ic2COLOR c; // 色ã®å¼·åº¦ (通常ã¯0.0 - 1.0) | |
72 | struct ic2PATCH *next; // 次ã®ä¸‰è§’形パッãƒã¸ã®ãƒã‚¤ãƒ³ã‚¿ | 74 | struct ic2PATCH *next; // 次ã®ä¸‰è§’形パッãƒã¸ã®ãƒã‚¤ãƒ³ã‚¿ | |
73 | }; | 75 | }; | |
74 | 76 | |||
75 | // +++-------------------------------------------------- | 77 | // +++-------------------------------------------------- | |
76 | // 法線方å‘ベクトルã®è¨ˆç®— | 78 | // 法線方å‘ベクトルã®è¨ˆç®— | |
77 | // +++-------------------------------------------------- | 79 | // +++-------------------------------------------------- | |
78 | // glEnable(GL_NORMALIZE) ã§æ³•ç·šãƒ™ã‚¯ãƒˆãƒ«ã¯å¸¸ã«æ£è¦åŒ–ã—ã¦è§£é‡ˆã•ã›ã‚‹ã®ã§ã“ã“ã§ã¯æ£è¦åŒ–ä¸è¦ | 80 | // glEnable(GL_NORMALIZE) ã§æ³•ç·šãƒ™ã‚¯ãƒˆãƒ«ã¯å¸¸ã«æ£è¦åŒ–ã—ã¦è§£é‡ˆã•ã›ã‚‹ã®ã§ã“ã“ã§ã¯æ£è¦åŒ–ä¸è¦ | |
79 | // ï¼“é ‚ç‚¹ s-t-u , 2ベクトル st and su, 法線ベクトル n | 81 | // ï¼“é ‚ç‚¹ s-t-u , 2ベクトル st and su, 法線ベクトル n | |
80 | static void ic2_SetPatchNormal (struct ic2PATCH *p) { | 82 | static void ic2_SetPatchNormal (struct ic2PATCH *p) { | |
81 | struct ic2POINT oa, ob; | 83 | struct ic2POINT oa, ob; | |
82 | oa.x = p->t.x - p->s.x; | 84 | oa.x = p->t.x - p->s.x; | |
83 | oa.y = p->t.y - p->s.y; | 85 | oa.y = p->t.y - p->s.y; | |
84 | oa.z = p->t.z - p->s.z; | 86 | oa.z = p->t.z - p->s.z; | |
85 | ob.x = p->u.x - p->s.x; | 87 | ob.x = p->u.x - p->s.x; | |
86 | ob.y = p->u.y - p->s.y; | 88 | ob.y = p->u.y - p->s.y; | |
87 | ob.z = p->u.z - p->s.z; | 89 | ob.z = p->u.z - p->s.z; | |
88 | p->n.x = oa.y * ob.z - oa.z * ob.y; | 90 | p->n.x = oa.y * ob.z - oa.z * ob.y; | |
89 | p->n.y = oa.z * ob.x - oa.x * ob.z; | 91 | p->n.y = oa.z * ob.x - oa.x * ob.z; | |
90 | p->n.z = oa.x * ob.y - oa.y * ob.x; | 92 | p->n.z = oa.x * ob.y - oa.y * ob.x; | |
91 | } | 93 | } | |
92 | 94 | |||
93 | // +++-------------------------------------------------- | 95 | // +++-------------------------------------------------- | |
94 | // パッãƒã«é–¢ã™ã‚‹è¿½åŠ 属性ã®è¨ˆç®—(é‡å¿ƒã¨è¡¨ç¤ºç”¨é•·ã•è£œæ£é …) | 96 | // パッãƒã«é–¢ã™ã‚‹è¿½åŠ 属性ã®è¨ˆç®—(é‡å¿ƒã¨è¡¨ç¤ºç”¨é•·ã•è£œæ£é …) | |
95 | // +++-------------------------------------------------- | 97 | // +++-------------------------------------------------- | |
96 | static void ic2_SetPatchMoreAttributes (struct ic2PATCH *p) { | 98 | static void ic2_SetPatchMoreAttributes (struct ic2PATCH *p) { | |
97 | 99 | |||
98 | // パッãƒé‡å¿ƒã®è¨ˆç®— | 100 | // パッãƒé‡å¿ƒã®è¨ˆç®— | |
99 | p->b.x = (p->s.x + p->t.x + p->u.x) / 3; | 101 | p->b.x = (p->s.x + p->t.x + p->u.x) / 3; | |
100 | p->b.y = (p->s.y + p->t.y + p->u.y) / 3; | 102 | p->b.y = (p->s.y + p->t.y + p->u.y) / 3; | |
101 | p->b.z = (p->s.z + p->t.z + p->u.z) / 3; | 103 | p->b.z = (p->s.z + p->t.z + p->u.z) / 3; | |
102 | 104 | |||
103 | // 法線ベクトル表示時ã®é•·ã•è£œæ£é …ã®è¨ˆç®— | 105 | // 法線ベクトル表示時ã®é•·ã•è£œæ£é …ã®è¨ˆç®— | |
104 | p->l = sqrt(p->n.x * p->n.x + p->n.y * p->n.y + p->n.z * p->n.z); | 106 | p->l = sqrt(p->n.x * p->n.x + p->n.y * p->n.y + p->n.z * p->n.z); | |
105 | if (p->l != 0.0) { | 107 | if (p->l != 0.0) { | |
106 | p->l = sqrt(p->l) / p->l; | 108 | p->l = sqrt(p->l) / p->l; | |
107 | } | 109 | } | |
108 | } | 110 | } | |
109 | 111 | |||
110 | // +++-------------------------------------------------- | 112 | // +++-------------------------------------------------- | |
111 | // æ–°ã—ã„三角形パッãƒæ§‹é€ 体(ic2PATCH)ã®ãƒ¡ãƒ¢ãƒªç¢ºä¿ã¨åˆæœŸåŒ– | 113 | // æ–°ã—ã„三角形パッãƒæ§‹é€ 体(ic2PATCH)ã®ãƒ¡ãƒ¢ãƒªç¢ºä¿ã¨åˆæœŸåŒ– | |
112 | // +++-------------------------------------------------- | 114 | // +++-------------------------------------------------- | |
113 | static struct ic2PATCH *ic2_NewPATCH (void) { | 115 | static struct ic2PATCH *ic2_NewPATCH (void) { | |
114 | struct ic2PATCH *newpatch = NULL; | 116 | struct ic2PATCH *newpatch = NULL; | |
115 | 117 | |||
116 | newpatch = (struct ic2PATCH *)calloc(1, sizeof(struct ic2PATCH)); | 118 | newpatch = (struct ic2PATCH *)calloc(1, sizeof(struct ic2PATCH)); | |
117 | return (newpatch); | 119 | return (newpatch); | |
118 | } | 120 | } | |
119 | 121 | |||
120 | // +++-------------------------------------------------- | 122 | // +++-------------------------------------------------- | |
121 | // 三角形パッãƒæ§‹é€ 体(ic2PATCH)1ã¤åˆ†ã®èªã¿è¾¼ã¿ | 123 | // 三角形パッãƒæ§‹é€ 体(ic2PATCH)1ã¤åˆ†ã®èªã¿è¾¼ã¿ | |
122 | // +++-------------------------------------------------- | 124 | // +++-------------------------------------------------- | |
123 | static int ic2_InsertPATCH (struct ic2PATCH **firstpatchptr, char *onelinedata) { | 125 | static int ic2_InsertPATCH (struct ic2PATCH **firstpatchptr, char *onelinedata) { | |
124 | // (1) æ–‡å—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã¯å˜åœ¨ã™ã‚‹ã‹ | 126 | // (1) æ–‡å—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã¯å˜åœ¨ã™ã‚‹ã‹ | |
125 | // (2) メモリ確ä¿/下請㑠| 127 | // (2) メモリ確ä¿/下請㑠| |
126 | // (3) 値ã®èªã¿è¾¼ã¿ | 128 | // (3) 値ã®èªã¿è¾¼ã¿ | |
127 | // (4) ic2PATCHãƒªã‚¹ãƒˆæ§‹é€ ã¸ã®çµ„ã¿è¾¼ã¿ | 129 | // (4) ic2PATCHãƒªã‚¹ãƒˆæ§‹é€ ã¸ã®çµ„ã¿è¾¼ã¿ | |
128 | struct ic2PATCH *newpatch = NULL; // 三角形パッãƒæ§‹é€ 体ヘã®ãƒã‚¤ãƒ³ã‚¿ | 130 | struct ic2PATCH *newpatch = NULL; // 三角形パッãƒæ§‹é€ 体ヘã®ãƒã‚¤ãƒ³ã‚¿ | |
129 | int number_of_element = 0; // èªã¿è¾¼ã‚ãŸé …目数 | 131 | int number_of_element = 0; // èªã¿è¾¼ã‚ãŸé …目数 | |
130 | 132 | |||
131 | // (1) æ–‡å—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã¯å˜åœ¨ã™ã‚‹ã‹ | 133 | // (1) æ–‡å—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã¯å˜åœ¨ã™ã‚‹ã‹ | |
132 | if (onelinedata == NULL) return 1; | 134 | if (onelinedata == NULL) return 1; | |
133 | 135 | |||
134 | // (2) メモリ確ä¿/下請㑠| 136 | // (2) メモリ確ä¿/下請㑠| |
135 | if ((newpatch = ic2_NewPATCH()) == NULL) { | 137 | if ((newpatch = ic2_NewPATCH()) == NULL) { | |
136 | printf("ic2_InsertPATCH: Memory allocation failed.\n"); | 138 | printf("ic2_InsertPATCH: Memory allocation failed.\n"); | |
137 | return 2; | 139 | return 2; | |
138 | } | 140 | } | |
139 | 141 | |||
140 | // (3) 値ã®èªã¿è¾¼ã¿ | 142 | // (3) 値ã®èªã¿è¾¼ã¿ | |
141 | number_of_element = | 143 | number_of_element = | |
142 | sscanf(onelinedata, "%f %f %f %f %f %f %f %f %f %f %f %f", | 144 | sscanf(onelinedata, "%f %f %f %f %f %f %f %f %f %f %f %f", | |
143 | &newpatch->s.x, &newpatch->s.y, &newpatch->s.z, | 145 | &newpatch->s.x, &newpatch->s.y, &newpatch->s.z, | |
144 | &newpatch->t.x, &newpatch->t.y, &newpatch->t.z, | 146 | &newpatch->t.x, &newpatch->t.y, &newpatch->t.z, | |
145 | &newpatch->u.x, &newpatch->u.y, &newpatch->u.z, | 147 | &newpatch->u.x, &newpatch->u.y, &newpatch->u.z, | |
146 | &newpatch->c.r, &newpatch->c.g, &newpatch->c.b); | 148 | &newpatch->c.r, &newpatch->c.g, &newpatch->c.b); | |
147 | if (number_of_element != 12) { | 149 | if (number_of_element != 12) { | |
148 | printf("ic2_InsertPATCH: format error (%d elements found)\n", number_of_element); | 150 | printf("ic2_InsertPATCH: format error (%d elements found)\n", number_of_element); | |
149 | printf("ic2_InsertPATCH: \"%s\"\n", onelinedata); | 151 | printf("ic2_InsertPATCH: \"%s\"\n", onelinedata); | |
150 | free(newpatch); | 152 | free(newpatch); | |
151 | return 3; | 153 | return 3; | |
152 | } | 154 | } | |
153 | 155 | |||
154 | // (3.5) 法線ベクトルã®è¨ˆç®— | 156 | // (3.5) 法線ベクトルã®è¨ˆç®— | |
155 | ic2_SetPatchNormal(newpatch); | 157 | ic2_SetPatchNormal(newpatch); | |
156 | 158 | |||
157 | // (3.6) パッãƒã«é–¢ã™ã‚‹è¿½åŠ 属性ã®è¨ˆç®—(é‡å¿ƒã¨è¡¨ç¤ºç”¨é•·ã•è£œæ£é …) | 159 | // (3.6) パッãƒã«é–¢ã™ã‚‹è¿½åŠ 属性ã®è¨ˆç®—(é‡å¿ƒã¨è¡¨ç¤ºç”¨é•·ã•è£œæ£é …) | |
158 | ic2_SetPatchMoreAttributes(newpatch); | 160 | ic2_SetPatchMoreAttributes(newpatch); | |
159 | 161 | |||
160 | // (4) ic2PATCHãƒªã‚¹ãƒˆæ§‹é€ ã¸ã®çµ„ã¿è¾¼ã¿ | 162 | // (4) ic2PATCHãƒªã‚¹ãƒˆæ§‹é€ ã¸ã®çµ„ã¿è¾¼ã¿ | |
161 | // *newpatch ã‚’ 三角形パッãƒé›†åˆã®å…ˆé ã«æŒ¿å…¥ | 163 | // *newpatch ã‚’ 三角形パッãƒé›†åˆã®å…ˆé ã«æŒ¿å…¥ | |
162 | newpatch->next = *firstpatchptr; | 164 | newpatch->next = *firstpatchptr; | |
163 | *firstpatchptr = newpatch; | 165 | *firstpatchptr = newpatch; | |
164 | return 0; | 166 | return 0; | |
165 | } | 167 | } | |
166 | 168 | |||
167 | // +---------------------------------------------------- | 169 | // +---------------------------------------------------- | |
168 | // モデルã®ãƒ•ã‚¡ã‚¤ãƒ«ã‹ã‚‰ã®èªè¾¼ | 170 | // モデルã®ãƒ•ã‚¡ã‚¤ãƒ«ã‹ã‚‰ã®èªè¾¼ | |
169 | // +---------------------------------------------------- | 171 | // +---------------------------------------------------- | |
170 | // è¿”å€¤ï¼šè² ... エラー | 172 | // è¿”å€¤ï¼šè² ... エラー | |
171 | // 返値:ï¼ãªã„ã—æ£å€¤ ... èªã¿è¾¼ã¿ã«æˆåŠŸã—ãŸãƒ‘ッãƒæ•° | 173 | // 返値:ï¼ãªã„ã—æ£å€¤ ... èªã¿è¾¼ã¿ã«æˆåŠŸã—ãŸãƒ‘ッãƒæ•° | |
172 | int ic2_ReadModel(char *filename, struct ic2PATCH **firstpatchptr) { | 174 | int ic2_ReadModel(char *filename, struct ic2PATCH **firstpatchptr) { | |
173 | FILE *filetoopen = NULL; // A pointer to FILE structure | 175 | FILE *filetoopen = NULL; // A pointer to FILE structure | |
174 | char oneline[256]; // 1行分ã®ãƒãƒƒãƒ•ã‚¡,固定長ã«ã—ã¦ãŠãã¨sizeof()ãŒåˆ©ç”¨å¯èƒ½ | 176 | char oneline[256]; // 1行分ã®ãƒãƒƒãƒ•ã‚¡,固定長ã«ã—ã¦ãŠãã¨sizeof()ãŒåˆ©ç”¨å¯èƒ½ | |
175 | char firstword[256]; // コメント行ã‹ã©ã†ã‹ã®åˆ¤å®šç”¨ | 177 | char firstword[256]; // コメント行ã‹ã©ã†ã‹ã®åˆ¤å®šç”¨ | |
176 | int linenumber = 0; // ファイルä¸ã®è¡Œç•ªå· | 178 | int linenumber = 0; // ファイルä¸ã®è¡Œç•ªå· | |
177 | int patchnumber = 0; // パッãƒæ•° | 179 | int patchnumber = 0; // パッãƒæ•° | |
178 | 180 | |||
179 | // We need at least one option to indicate a file to open | 181 | // We need at least one option to indicate a file to open | |
180 | if (filename == NULL) { | 182 | if (filename == NULL) { | |
181 | printf("Error: You need to specify a one file to open.\n"); | 183 | printf("Error: You need to specify a one file to open.\n"); | |
182 | return -1; | 184 | return -1; | |
183 | } | 185 | } | |
184 | 186 | |||
185 | // Try to open it | 187 | // Try to open it | |
186 | filetoopen = fopen(filename, "r"); | 188 | filetoopen = fopen(filename, "r"); | |
187 | if (filetoopen == NULL) { | 189 | if (filetoopen == NULL) { | |
188 | printf("Error: Failed to open/read \"%s\".\n", filename); | 190 | printf("Error: Failed to open/read \"%s\".\n", filename); | |
189 | return -2; | 191 | return -2; | |
190 | } | 192 | } | |
191 | printf("Reading model from \"%s\"\n", filename); | 193 | printf("Reading model from \"%s\"\n", filename); | |
192 | 194 | |||
193 | // 1行ãšã¤èªè¾¼ | 195 | // 1行ãšã¤èªè¾¼ | |
194 | while (fgets(oneline, sizeof(oneline), filetoopen) != NULL) { | 196 | while (fgets(oneline, sizeof(oneline), filetoopen) != NULL) { | |
195 | linenumber++; | 197 | linenumber++; | |
196 | 198 | |||
197 | // ã‚‚ã—行内ã«ï¼‘æ–‡å—ã‚‚ãªã‘ã‚Œã°ï¼ˆï¼‘å˜èªžã‚‚ãªã‘ã‚Œã°ï¼‰æ¬¡è¡Œã¸ | 199 | // ã‚‚ã—行内ã«ï¼‘æ–‡å—ã‚‚ãªã‘ã‚Œã°ï¼ˆï¼‘å˜èªžã‚‚ãªã‘ã‚Œã°ï¼‰æ¬¡è¡Œã¸ | |
198 | if (sscanf(oneline, "%256s", firstword) < 1) | 200 | if (sscanf(oneline, "%256s", firstword) < 1) | |
199 | continue; | 201 | continue; | |
200 | // ã‚‚ã—å…ˆé ãŒ#ã§å§‹ã¾ã£ã¦ã„ã‚Œã°æ¬¡è¡Œã¸ | 202 | // ã‚‚ã—å…ˆé ãŒ#ã§å§‹ã¾ã£ã¦ã„ã‚Œã°æ¬¡è¡Œã¸ | |
201 | if (firstword[0] == '#') | 203 | if (firstword[0] == '#') | |
202 | continue; | 204 | continue; | |
203 | // ä»–ã®ã‚¨ãƒ©ãƒ¼ãƒˆãƒ©ãƒƒãƒ— | 205 | // ä»–ã®ã‚¨ãƒ©ãƒ¼ãƒˆãƒ©ãƒƒãƒ— | |
204 | if (0) { | 206 | if (0) { | |
205 | printf("Skip(line=%d): %s\n", linenumber, oneline); | 207 | printf("Skip(line=%d): %s\n", linenumber, oneline); | |
206 | continue; | 208 | continue; | |
207 | } | 209 | } | |
208 | 210 | |||
209 | if (ic2_InsertPATCH(firstpatchptr, oneline)) { | 211 | if (ic2_InsertPATCH(firstpatchptr, oneline)) { | |
210 | printf("Model reading is interrupted.\n"); | 212 | printf("Model reading is interrupted.\n"); | |
211 | break; | 213 | break; | |
212 | } | 214 | } | |
213 | patchnumber++; | 215 | patchnumber++; | |
214 | } | 216 | } | |
215 | 217 | |||
216 | // And close it | 218 | // And close it | |
217 | if (fclose(filetoopen) != 0) { | 219 | if (fclose(filetoopen) != 0) { | |
218 | printf("Error: Failed to close \"%s\".\n", filename); | 220 | printf("Error: Failed to close \"%s\".\n", filename); | |
219 | // error, but we get data anyway... | 221 | // error, but we get data anyway... | |
220 | } | 222 | } | |
221 | 223 | |||
222 | printf("Finish reading the model (%d patches).\n", patchnumber); | 224 | printf("Finish reading the model (%d patches).\n", patchnumber); | |
223 | return patchnumber; | 225 | return patchnumber; | |
224 | } | 226 | } | |
225 | 227 | |||
226 | // ----------------------------------------------------- | 228 | // ----------------------------------------------------- | |
227 | // 三角形パッãƒæ§‹é€ 体(ic2PATCH)リストã®è¡¨ç¤º | 229 | // 三角形パッãƒæ§‹é€ 体(ic2PATCH)リストã®è¡¨ç¤º | |
228 | // ----------------------------------------------------- | 230 | // ----------------------------------------------------- | |
229 | int ic2_PrintPATCHList (struct ic2PATCH *firstpatchptr) { | 231 | int ic2_PrintPATCHList (struct ic2PATCH *firstpatchptr) { | |
230 | struct ic2PATCH *p; | 232 | struct ic2PATCH *p; | |
231 | int np = 0; | 233 | int np = 0; | |
232 | 234 | |||
233 | for (p = firstpatchptr; p != NULL; p = p->next) { | 235 | for (p = firstpatchptr; p != NULL; p = p->next) { | |
234 | np++; | 236 | np++; | |
235 | printf("PATCH: (%g, %g, %g), (%g, %g, %g), (%g, %g, %g), rgb=[%g, %g, %g] ", | 237 | printf("PATCH: (%g, %g, %g), (%g, %g, %g), (%g, %g, %g), rgb=[%g, %g, %g] ", | |
236 | p->s.x, p->s.y, p->s.z, | 238 | p->s.x, p->s.y, p->s.z, | |
237 | p->t.x, p->t.y, p->t.z, | 239 | p->t.x, p->t.y, p->t.z, | |
238 | p->u.x, p->u.y, p->u.z, | 240 | p->u.x, p->u.y, p->u.z, | |
239 | p->c.r, p->c.g, p->c.b); | 241 | p->c.r, p->c.g, p->c.b); | |
240 | printf("n=(%g, %g, %g), b=(%g, %g, %g), l=%g\n", | 242 | printf("n=(%g, %g, %g), b=(%g, %g, %g), l=%g\n", | |
241 | p->n.x, p->n.y, p->n.z, | 243 | p->n.x, p->n.y, p->n.z, | |
242 | p->b.x, p->b.y, p->b.z, | 244 | p->b.x, p->b.y, p->b.z, | |
243 | p->l); | 245 | p->l); | |
244 | } | 246 | } | |
245 | 247 | |||
246 | return np; | 248 | return np; | |
247 | } | 249 | } | |
248 | 250 | |||
249 | // *********************************************************************** | 251 | // *********************************************************************** | |
250 | // gl utilitiess ********************************************************* | 252 | // gl utilitiess ********************************************************* | |
251 | 253 | |||
252 | // +---------------------------------------------------- | 254 | // +---------------------------------------------------- | |
253 | // MODELVIEW Matrix 㨠PROJECTION を表示ã™ã‚‹ | 255 | // MODELVIEW Matrix 㨠PROJECTION を表示ã™ã‚‹ | |
254 | // +---------------------------------------------------- | 256 | // +---------------------------------------------------- | |
255 | void ic2_ShowMATRIX (char *str) { | 257 | void ic2_ShowMATRIX (char *str) { | |
256 | GLfloat m[16]; // GL_MODELVIEW matrix | 258 | GLfloat m[16]; // GL_MODELVIEW matrix | |
257 | GLfloat p[16]; // GL_PROJECTION matrix | 259 | GLfloat p[16]; // GL_PROJECTION matrix | |
258 | 260 | |||
259 | glGetFloatv(GL_MODELVIEW_MATRIX , m); // MODELVIEWã®ã‚¹ã‚¿ãƒƒã‚¯ãƒˆãƒƒãƒ—matrixã‚’mã«ã‚³ãƒ”ー | 261 | glGetFloatv(GL_MODELVIEW_MATRIX , m); // MODELVIEWã®ã‚¹ã‚¿ãƒƒã‚¯ãƒˆãƒƒãƒ—matrixã‚’mã«ã‚³ãƒ”ー | |
260 | glGetFloatv(GL_PROJECTION_MATRIX, p); // PROJECTIONã®ã‚¹ã‚¿ãƒƒã‚¯ãƒˆãƒƒãƒ—matrixã‚’pã«ã‚³ãƒ”ー | 262 | glGetFloatv(GL_PROJECTION_MATRIX, p); // PROJECTIONã®ã‚¹ã‚¿ãƒƒã‚¯ãƒˆãƒƒãƒ—matrixã‚’pã«ã‚³ãƒ”ー | |
261 | if (str != NULL) printf("<< %s >>\n", str); | 263 | if (str != NULL) printf("<< %s >>\n", str); | |
262 | printf("MODELVIEW Matrix PROJECTION Matrix\n"); | 264 | printf("MODELVIEW Matrix PROJECTION Matrix\n"); | |
263 | printf("%7.3f %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n", | 265 | printf("%7.3f %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n", | |
264 | m[ 0], m[ 4], m[ 8], m[12], p[ 0], p[ 4], p[ 8], p[12]); | 266 | m[ 0], m[ 4], m[ 8], m[12], p[ 0], p[ 4], p[ 8], p[12]); | |
265 | printf("%7.3f %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n", | 267 | printf("%7.3f %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n", | |
266 | m[ 1], m[ 5], m[ 9], m[13], p[ 1], p[ 5], p[ 9], p[13]); | 268 | m[ 1], m[ 5], m[ 9], m[13], p[ 1], p[ 5], p[ 9], p[13]); | |
267 | printf("%7.3f %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n", | 269 | printf("%7.3f %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n", | |
268 | m[ 2], m[ 6], m[10], m[14], p[ 2], p[ 6], p[10], p[14]); | 270 | m[ 2], m[ 6], m[10], m[14], p[ 2], p[ 6], p[10], p[14]); | |
269 | printf("%7.3f %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n", | 271 | printf("%7.3f %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n", | |
270 | m[ 3], m[ 7], m[11], m[15], p[ 3], p[ 7], p[11], p[15]); | 272 | m[ 3], m[ 7], m[11], m[15], p[ 3], p[ 7], p[11], p[15]); | |
271 | } | 273 | } | |
272 | 274 | |||
273 | // *********************************************************************** | 275 | // *********************************************************************** | |
274 | // objects_embeded ******************************************************* | 276 | // objects_embeded ******************************************************* | |
275 | 277 | |||
276 | // +---------------------------------------------------- | 278 | // +---------------------------------------------------- | |
277 | // æ£æ–¹å½¢ã‚’æã | 279 | // æ£æ–¹å½¢ã‚’æã | |
278 | // +---------------------------------------------------- | 280 | // +---------------------------------------------------- | |
279 | void ic2_FigSquare (float s) { | 281 | void ic2_FigSquare (float s) { | |
280 | glDisable(GL_LIGHTING); // å…‰æºã«ã‚ˆã‚‹ã‚·ã‚§ãƒ¼ãƒ‡ã‚£ãƒ³ã‚°ã‚’一旦切る | 282 | glDisable(GL_LIGHTING); // å…‰æºã«ã‚ˆã‚‹ã‚·ã‚§ãƒ¼ãƒ‡ã‚£ãƒ³ã‚°ã‚’一旦切る | |
281 | 283 | |||
282 | // æ£æ–¹å½¢ï¼ˆZ=0ã®å¹³é¢å†…ã€+/- 0.9) | 284 | // æ£æ–¹å½¢ï¼ˆZ=0ã®å¹³é¢å†…ã€+/- 0.9) | |
283 | glBegin(GL_LINE_LOOP); { | 285 | glBegin(GL_LINE_LOOP); { | |
284 | glColor3f(1.0, 1.0, 1.0); | 286 | glColor3f(1.0, 1.0, 1.0); | |
285 | glVertex3f(s * -1, s * -1, 0.0); | 287 | glVertex3f(s * -1, s * -1, 0.0); | |
286 | glVertex3f(s * +1, s * -1, 0.0); | 288 | glVertex3f(s * +1, s * -1, 0.0); | |
287 | glVertex3f(s * +1, s * +1, 0.0); | 289 | glVertex3f(s * +1, s * +1, 0.0); | |
288 | glVertex3f(s * -1, s * +1, 0.0); | 290 | glVertex3f(s * -1, s * +1, 0.0); | |
289 | } glEnd(); | 291 | } glEnd(); | |
290 | 292 | |||
291 | // 3軸 | 293 | // 3軸 | |
292 | glBegin(GL_LINES); { | 294 | glBegin(GL_LINES); { | |
293 | glColor3f(1.0, 0.5, 0.5); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.85, 0.0, 0.0); // X (red) | 295 | glColor3f(1.0, 0.5, 0.5); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.85, 0.0, 0.0); // X (red) | |
294 | glColor3f(0.5, 1.0, 0.5); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 0.70, 0.0); // Y (green) | 296 | glColor3f(0.5, 1.0, 0.5); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 0.70, 0.0); // Y (green) | |
295 | glColor3f(0.5, 0.5, 1.0); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 0.0, 1.0); // Z (blue) | 297 | glColor3f(0.5, 0.5, 1.0); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 0.0, 1.0); // Z (blue) | |
296 | } glEnd(); | 298 | } glEnd(); | |
297 | 299 | |||
298 | glEnable(GL_LIGHTING); // å…‰æºã«ã‚ˆã‚‹ã‚·ã‚§ãƒ¼ãƒ‡ã‚£ãƒ³ã‚°ã‚’開始ã™ã‚‹ | 300 | glEnable(GL_LIGHTING); // å…‰æºã«ã‚ˆã‚‹ã‚·ã‚§ãƒ¼ãƒ‡ã‚£ãƒ³ã‚°ã‚’開始ã™ã‚‹ | |
299 | } | 301 | } | |
300 | 302 | |||
301 | // +---------------------------------------------------- | 303 | // +---------------------------------------------------- | |
302 | // ティーãƒãƒƒãƒˆã‚’æã (glutã®ä½œã‚Šä»˜ã‘関数ã®ï¼‘ã¤) | 304 | // ティーãƒãƒƒãƒˆã‚’æã (glutã®ä½œã‚Šä»˜ã‘関数ã®ï¼‘ã¤) | |
303 | // +---------------------------------------------------- | 305 | // +---------------------------------------------------- | |
304 | void ic2_FigSolidTeapot (float s) { | 306 | void ic2_FigSolidTeapot (float s) { | |
305 | GLfloat obj_ref[] = {1.0, 1.0, 0.3, 1.0}; // teapotã®è‰²æƒ…å ± (DIFFUSE用) | 307 | GLfloat obj_ref[] = {1.0, 1.0, 0.3, 1.0}; // teapotã®è‰²æƒ…å ± (DIFFUSE用) | |
306 | GLfloat obj_shn[] = {10.0}; // teapotã®è‰²æƒ…å ± (SHININESS用) | 308 | GLfloat obj_shn[] = {10.0}; // teapotã®è‰²æƒ…å ± (SHININESS用) | |
307 | 309 | |||
308 | // 色ã®è¨å®š | 310 | // 色ã®è¨å®š | |
309 | glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, obj_ref); | 311 | glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, obj_ref); | |
310 | glMaterialfv(GL_FRONT, GL_SHININESS, obj_shn); | 312 | glMaterialfv(GL_FRONT, GL_SHININESS, obj_shn); | |
311 | 313 | |||
312 | glutSolidTeapot(s); | 314 | glutSolidTeapot(s); | |
313 | } | 315 | } | |
314 | 316 | |||
315 | // *********************************************************************** | 317 | // *********************************************************************** | |
316 | // objects_model ********************************************************* | 318 | // objects_model ********************************************************* | |
317 | 319 | |||
318 | // +---------------------------------------------------- | 320 | // +---------------------------------------------------- | |
319 | // ファイルã‹ã‚‰ã®ç‰©ä½“を表示 | 321 | // ファイルã‹ã‚‰ã®ç‰©ä½“を表示 | |
320 | // +---------------------------------------------------- | 322 | // +---------------------------------------------------- | |
321 | int ic2_DrawModel (struct ic2PATCH *firstpatchptr) { | 323 | int ic2_DrawModel (struct ic2PATCH *firstpatchptr) { | |
322 | struct ic2PATCH *p; // パッãƒæ§‹é€ 体ã¸ã®ãƒã‚¤ãƒ³ã‚¿ | 324 | struct ic2PATCH *p; // パッãƒæ§‹é€ 体ã¸ã®ãƒã‚¤ãƒ³ã‚¿ | |
323 | 325 | |||
324 | for (p = firstpatchptr; p != NULL; p = p->next) { | 326 | for (p = firstpatchptr; p != NULL; p = p->next) { | |
325 | GLfloat v[4]; | 327 | GLfloat v[4]; | |
326 | 328 | |||
327 | // é¢ã®è‰²è¦ç´ (å射特性)をDiffuseã¨Specularã«ã¤ã„ã¦æŒ‡ç¤º | 329 | // é¢ã®è‰²è¦ç´ (å射特性)をDiffuseã¨Specularã«ã¤ã„ã¦æŒ‡ç¤º | |
328 | v[0] = p->c.r; v[1] = p->c.g; v[2] = p->c.b; v[3] = 1.0; | 330 | v[0] = p->c.r; v[1] = p->c.g; v[2] = p->c.b; v[3] = 1.0; | |
329 | glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, v); | 331 | glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, v); | |
330 | v[0] = 10.0; | 332 | v[0] = 10.0; | |
331 | glMaterialfv(GL_FRONT, GL_SHININESS, v); | 333 | glMaterialfv(GL_FRONT, GL_SHININESS, v); | |
332 | 334 | |||
333 | // é¢ã®æ³•ç·šã‚’指示 | 335 | // é¢ã®æ³•ç·šã‚’指示 | |
334 | glNormal3f(p->n.x, p->n.y, p->n.z); | 336 | glNormal3f(p->n.x, p->n.y, p->n.z); | |
335 | 337 | |||
336 | // é¢ã‚’構æˆã™ã‚‹ï¼“é ‚ç‚¹ã‚’æŒ‡ç¤º | 338 | // é¢ã‚’構æˆã™ã‚‹ï¼“é ‚ç‚¹ã‚’æŒ‡ç¤º | |
337 | glBegin(GL_TRIANGLES); { | 339 | glBegin(GL_TRIANGLES); { | |
338 | glVertex3f(p->s.x, p->s.y, p->s.z); | 340 | glVertex3f(p->s.x, p->s.y, p->s.z); | |
339 | glVertex3f(p->t.x, p->t.y, p->t.z); | 341 | glVertex3f(p->t.x, p->t.y, p->t.z); | |
340 | glVertex3f(p->u.x, p->u.y, p->u.z); | 342 | glVertex3f(p->u.x, p->u.y, p->u.z); | |
341 | } glEnd(); | 343 | } glEnd(); | |
342 | 344 | |||
343 | // 法線ã®è¡¨ç¤º | 345 | // 法線ã®è¡¨ç¤º | |
344 | if (tgl_shownormal == 1) { | 346 | if (tgl_shownormal == 1) { | |
345 | glDisable(GL_LIGHTING); | 347 | glDisable(GL_LIGHTING); | |
346 | glColor3f(0.3, 1.0, 0.4); | 348 | glColor3f(0.3, 1.0, 0.4); | |
347 | glBegin(GL_LINES); { | 349 | glBegin(GL_LINES); { | |
348 | glVertex3f(p->b.x, p->b.y, p->b.z); | 350 | glVertex3f(p->b.x, p->b.y, p->b.z); | |
349 | glVertex3f(p->b.x + p->l * p->n.x, p->b.y + p->l * p->n.y, p->b.z + p->l * p->n.z); | 351 | glVertex3f(p->b.x + p->l * p->n.x, p->b.y + p->l * p->n.y, p->b.z + p->l * p->n.z); | |
350 | } glEnd(); | 352 | } glEnd(); | |
351 | glEnable(GL_LIGHTING); | 353 | glEnable(GL_LIGHTING); | |
352 | } | 354 | } | |
353 | 355 | |||
354 | } | 356 | } | |
355 | return 0; | 357 | return 0; | |
356 | } | 358 | } | |
357 | 359 | |||
358 | // *********************************************************************** | 360 | // *********************************************************************** | |
359 | // lighting ************************************************************** | 361 | // lighting ************************************************************** | |
360 | 362 | |||
361 | // +---------------------------------------------------- | 363 | // +---------------------------------------------------- | |
362 | // å…‰æºã‚’ç”¨æ„ | 364 | // å…‰æºã‚’ç”¨æ„ | |
363 | // +---------------------------------------------------- | 365 | // +---------------------------------------------------- | |
364 | // X Y Z Diff(R,G,B) Spec(R,G,B) | 366 | // X Y Z Diff(R,G,B) Spec(R,G,B) | |
365 | // 1.0 2.0 3.0 0.2 0.2 0.2 0.4 0.4 0.4 | 367 | // 1.0 2.0 3.0 0.2 0.2 0.2 0.4 0.4 0.4 | |
366 | // -1.0 2.0 3.0 0.4 0.4 0.4 0.4 0.4 0.4 | 368 | // -1.0 2.0 3.0 0.4 0.4 0.4 0.4 0.4 0.4 | |
367 | // 0.0 4.0 0.0 1.0 1.0 1.0 1.0 1.0 1.0 | 369 | // 0.0 4.0 0.0 1.0 1.0 1.0 1.0 1.0 1.0 | |
368 | void ic2_LightSetA (void) { | 370 | void ic2_LightSetA (void) { | |
369 | static int initflag = 0; | 371 | static int initflag = 0; | |
370 | 372 | |||
371 | if (initflag == 0) { | 373 | if (initflag == 0) { | |
372 | glEnable(GL_DEPTH_TEST); // デプスãƒãƒƒãƒ•ã‚¡ã«ã‚ˆã‚‹æ画を行ㆠ| 374 | glEnable(GL_DEPTH_TEST); // デプスãƒãƒƒãƒ•ã‚¡ã«ã‚ˆã‚‹æ画を行ㆠ| |
373 | glEnable(GL_NORMALIZE); // 法線ベクトルを常ã«æ£è¦åŒ–ã—ã¦è§£é‡ˆã•ã›ã‚‹ | 375 | glEnable(GL_NORMALIZE); // 法線ベクトルを常ã«æ£è¦åŒ–ã—ã¦è§£é‡ˆã•ã›ã‚‹ | |
374 | glEnable(GL_LIGHTING); // å…‰æºã«ã‚ˆã‚‹ã‚·ã‚§ãƒ¼ãƒ‡ã‚£ãƒ³ã‚°ã‚’開始ã™ã‚‹ | 376 | glEnable(GL_LIGHTING); // å…‰æºã«ã‚ˆã‚‹ã‚·ã‚§ãƒ¼ãƒ‡ã‚£ãƒ³ã‚°ã‚’開始ã™ã‚‹ | |
375 | glEnable(GL_LIGHT0); // LIGHT0 を利用 | 377 | glEnable(GL_LIGHT0); // LIGHT0 を利用 | |
376 | glEnable(GL_LIGHT1); // LIGHT1 を利用 | 378 | glEnable(GL_LIGHT1); // LIGHT1 を利用 | |
377 | glEnable(GL_LIGHT2); // LIGHT2 を利用 | 379 | glEnable(GL_LIGHT2); // LIGHT2 を利用 | |
378 | initflag = 1; | 380 | initflag = 1; | |
379 | } | 381 | } | |
380 | 382 | |||
381 | GLfloat val[4]; | 383 | GLfloat val[4]; | |
382 | 384 | |||
383 | val[0] = 1.0; val[1] = 2.0; val[2] = 3.0; val[3] = 1.0; glLightfv(GL_LIGHT0, GL_POSITION, val); | 385 | val[0] = 1.0; val[1] = 2.0; val[2] = 3.0; val[3] = 1.0; glLightfv(GL_LIGHT0, GL_POSITION, val); | |
384 | val[0] = 0.2; val[1] = 0.2; val[2] = 0.2; val[3] = 1.0; glLightfv(GL_LIGHT0, GL_DIFFUSE, val); | 386 | val[0] = 0.2; val[1] = 0.2; val[2] = 0.2; val[3] = 1.0; glLightfv(GL_LIGHT0, GL_DIFFUSE, val); | |
385 | val[0] = 0.4; val[1] = 0.4; val[2] = 0.4; val[3] = 1.0; glLightfv(GL_LIGHT0, GL_SPECULAR, val); | 387 | val[0] = 0.4; val[1] = 0.4; val[2] = 0.4; val[3] = 1.0; glLightfv(GL_LIGHT0, GL_SPECULAR, val); | |
386 | 388 | |||
387 | val[0] = -1.0; val[1] = 2.0; val[2] = 3.0; val[3] = 1.0; glLightfv(GL_LIGHT1, GL_POSITION, val); | 389 | val[0] = -1.0; val[1] = 2.0; val[2] = 3.0; val[3] = 1.0; glLightfv(GL_LIGHT1, GL_POSITION, val); | |
388 | val[0] = 0.4; val[1] = 0.4; val[2] = 0.4; val[3] = 1.0; glLightfv(GL_LIGHT1, GL_DIFFUSE, val); | 390 | val[0] = 0.4; val[1] = 0.4; val[2] = 0.4; val[3] = 1.0; glLightfv(GL_LIGHT1, GL_DIFFUSE, val); | |
389 | val[0] = 0.4; val[1] = 0.4; val[2] = 0.4; val[3] = 1.0; glLightfv(GL_LIGHT1, GL_SPECULAR, val); | 391 | val[0] = 0.4; val[1] = 0.4; val[2] = 0.4; val[3] = 1.0; glLightfv(GL_LIGHT1, GL_SPECULAR, val); | |
390 | 392 | |||
391 | val[0] = 0.0; val[1] = 4.0; val[2] = 0.0; val[3] = 1.0; glLightfv(GL_LIGHT2, GL_POSITION, val); | 393 | val[0] = 0.0; val[1] = 4.0; val[2] = 0.0; val[3] = 1.0; glLightfv(GL_LIGHT2, GL_POSITION, val); | |
392 | val[0] = 1.0; val[1] = 1.0; val[2] = 1.0; val[3] = 1.0; glLightfv(GL_LIGHT2, GL_DIFFUSE, val); | 394 | val[0] = 1.0; val[1] = 1.0; val[2] = 1.0; val[3] = 1.0; glLightfv(GL_LIGHT2, GL_DIFFUSE, val); | |
393 | val[0] = 1.0; val[1] = 1.0; val[2] = 1.0; val[3] = 1.0; glLightfv(GL_LIGHT2, GL_SPECULAR, val); | 395 | val[0] = 1.0; val[1] = 1.0; val[2] = 1.0; val[3] = 1.0; glLightfv(GL_LIGHT2, GL_SPECULAR, val); | |
394 | } | 396 | } | |
395 | 397 | |||
396 | // *********************************************************************** | 398 | // *********************************************************************** | |
397 | // camera work *********************************************************** | 399 | // camera work *********************************************************** | |
398 | 400 | |||
399 | // +---------------------------------------------------- | 401 | // +---------------------------------------------------- | |
400 | // カメラã®æŠ•å½±è¡Œåˆ—ã‚’è¨å®š | 402 | // カメラã®æŠ•å½±è¡Œåˆ—ã‚’è¨å®š | |
401 | // +---------------------------------------------------- | 403 | // +---------------------------------------------------- | |
402 | // 利用ã™ã‚‹å¤§åŸŸå¤‰æ•°ï¼š window_w, window_h | 404 | // 利用ã™ã‚‹å¤§åŸŸå¤‰æ•°ï¼š window_w, window_h | |
403 | // window_w/window_hã®å¤‰åŒ–ã«å¯¾ã—ã¦ã€ç‰©ä½“ã®è¦‹ã‹ã‘ã®å¤§ãã•ãŒå¤‰ã‚らãªã„よã†ã«æç”» | 405 | // window_w/window_hã®å¤‰åŒ–ã«å¯¾ã—ã¦ã€ç‰©ä½“ã®è¦‹ã‹ã‘ã®å¤§ãã•ãŒå¤‰ã‚らãªã„よã†ã«æç”» | |
404 | // → ortho_unit ãŒé‡è¦ï¼ | 406 | // → ortho_unit ãŒé‡è¦ï¼ | |
405 | // | 407 | // | |
406 | void ic2_SetUpCamera_Ortho (void) { | 408 | void ic2_SetUpCamera_Ortho (void) { | |
407 | float wlimit, hlimit; | 409 | float wlimit, hlimit; | |
408 | wlimit = (window_w/2) / ortho_unit; | 410 | wlimit = (window_w/2) / ortho_unit; | |
409 | hlimit = (window_h/2) / ortho_unit; | 411 | hlimit = (window_h/2) / ortho_unit; | |
410 | 412 | |||
411 | // glOrtho(左端, å³ç«¯, 下端, 上端, 近接å´ã‚¯ãƒªãƒƒãƒ”ングé¢, é æ–¹å´ã‚¯ãƒªãƒƒãƒ”ングé¢) | 413 | // glOrtho(左端, å³ç«¯, 下端, 上端, 近接å´ã‚¯ãƒªãƒƒãƒ”ングé¢, é æ–¹å´ã‚¯ãƒªãƒƒãƒ”ングé¢) | |
412 | glMatrixMode(GL_PROJECTION); | 414 | glMatrixMode(GL_PROJECTION); | |
413 | glLoadIdentity(); // 毎フレームå†è¨å®šã™ã‚‹ã®ã§PROJECTION行列スタックトップã®åˆæœŸåŒ–ãŒå¿…è¦ã« | 415 | glLoadIdentity(); // 毎フレームå†è¨å®šã™ã‚‹ã®ã§PROJECTION行列スタックトップã®åˆæœŸåŒ–ãŒå¿…è¦ã« | |
414 | glOrtho(-wlimit, wlimit, -hlimit, hlimit, -1.0, 1.0); | 416 | glOrtho(-wlimit, wlimit, -hlimit, hlimit, -1.0, 1.0); | |
415 | glMatrixMode(GL_MODELVIEW); | 417 | glMatrixMode(GL_MODELVIEW); | |
416 | } | 418 | } | |
417 | 419 | |||
418 | // *********************************************************************** | 420 | // *********************************************************************** | |
419 | // rendering ************************************************************* | 421 | // rendering ************************************************************* | |
420 | 422 | |||
421 | // +---------------------------------------------------- | 423 | // +---------------------------------------------------- | |
422 | // スクリーンã«æç”»ã™ã‚‹ | 424 | // スクリーンã«æç”»ã™ã‚‹ | |
423 | // +---------------------------------------------------- | 425 | // +---------------------------------------------------- | |
424 | void ic2_DrawFrame (void) { | 426 | void ic2_DrawFrame (void) { | |
425 | 427 | |||
426 | // (å‰å‡¦ç†) 以å‰ã«glClearColor()ã§æŒ‡å®šã—ãŸè‰²ã§å¡—ã‚Šæ½°ã™ | 428 | // (å‰å‡¦ç†) 以å‰ã«glClearColor()ã§æŒ‡å®šã—ãŸè‰²ã§å¡—ã‚Šæ½°ã™ | |
427 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | 429 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |
428 | // (å‰å‡¦ç†) 今回CGã‚’æç”»ã™ã‚‹ç¯„囲 | 430 | // (å‰å‡¦ç†) 今回CGã‚’æç”»ã™ã‚‹ç¯„囲 | |
429 | glViewport(0, 0, window_w, window_h); | 431 | glViewport(0, 0, window_w, window_h); | |
430 | 432 | |||
431 | // (1) カメラã®è¨ç½® | 433 | // (1) カメラã®è¨ç½® | |
432 | ic2_SetUpCamera_Ortho(); | 434 | ic2_SetUpCamera_Ortho(); | |
433 | 435 | |||
434 | // (2) å…‰æºã®è¨ç½® | 436 | // (2) å…‰æºã®è¨ç½® | |
435 | ic2_LightSetA(); | 437 | ic2_LightSetA(); | |
436 | 438 | |||
437 | // (3) 物体ã®è¨ç½® | 439 | // (3) 物体ã®è¨ç½® | |
440 | // 一時的ãªå…‰æºç’°å¢ƒã®æ“作時ã«ã¯ãƒãƒƒã‚¯ã—ãŸè¡Œåˆ—を上乗㛠| |||
441 | if (tgl_movelightonly == 1) { | |||
442 | glMatrixMode(GL_MODELVIEW); | |||
443 | glPushMatrix(); | |||
444 | glLoadMatrixf(mvmlocked); | |||
445 | } | |||
438 | if (tgl_showpredefined == 1) { | 446 | if (tgl_showpredefined == 1) { | |
439 | // 物体æç”»:æ£æ–¹å½¢ | 447 | // 物体æç”»:æ£æ–¹å½¢ | |
440 | ic2_FigSquare(0.9); | 448 | ic2_FigSquare(0.9); | |
441 | // 物体æç”»:ティーãƒãƒƒãƒˆ | 449 | // 物体æç”»:ティーãƒãƒƒãƒˆ | |
442 | ic2_FigSolidTeapot(0.5); | 450 | ic2_FigSolidTeapot(0.5); | |
443 | } | 451 | } | |
444 | ic2_DrawModel(firstpatchptr); | 452 | ic2_DrawModel(firstpatchptr); | |
453 | // 一時的ãªå…‰æºç’°å¢ƒã®æ“作時ã«ã¯ä¸Šä¹—ã›ã—ãŸè¡Œåˆ—を廃棄 | |||
454 | if (tgl_movelightonly == 1) { | |||
455 | glPopMatrix(); | |||
456 | } | |||
445 | 457 | |||
446 | // (後処ç†) スクリーンã®åˆ‡ã‚Šæ›¿ãˆ | 458 | // (後処ç†) スクリーンã®åˆ‡ã‚Šæ›¿ãˆ | |
447 | glutSwapBuffers(); | 459 | glutSwapBuffers(); | |
448 | 460 | |||
449 | } | 461 | } | |
450 | 462 | |||
451 | // *********************************************************************** | 463 | // *********************************************************************** | |
452 | // callbacks ************************************************************* | 464 | // callbacks ************************************************************* | |
453 | 465 | |||
454 | // +---------------------------------------------------- | 466 | // +---------------------------------------------------- | |
455 | // ã‚ーãŒä½•ã‹æŠ¼ã•ã‚ŒãŸã¨ãã®å¯¾ç–用関数 | 467 | // ã‚ーãŒä½•ã‹æŠ¼ã•ã‚ŒãŸã¨ãã®å¯¾ç–用関数 | |
456 | // +---------------------------------------------------- | 468 | // +---------------------------------------------------- | |
457 | // glutKeyboardFunc()ã«ã¦ç™»éŒ²äºˆå®š | 469 | // glutKeyboardFunc()ã«ã¦ç™»éŒ²äºˆå®š | |
458 | // 引数 : key ... å…¥åŠ›æ–‡å— | 470 | // 引数 : key ... å…¥åŠ›æ–‡å— | |
459 | // 引数 : x ... æ–‡å—ãŒæŠ¼ã•ã‚ŒãŸã¨ãã®ãƒžã‚¦ã‚¹ã‚«ãƒ¼ã‚½ãƒ«ã®ï¼¸ä½ç½® | 471 | // 引数 : x ... æ–‡å—ãŒæŠ¼ã•ã‚ŒãŸã¨ãã®ãƒžã‚¦ã‚¹ã‚«ãƒ¼ã‚½ãƒ«ã®ï¼¸ä½ç½® | |
460 | // 引数 : y ... æ–‡å—ãŒæŠ¼ã•ã‚ŒãŸã¨ãã®ãƒžã‚¦ã‚¹ã‚«ãƒ¼ã‚½ãƒ«ã®ï¼¹ä½ç½® | 472 | // 引数 : y ... æ–‡å—ãŒæŠ¼ã•ã‚ŒãŸã¨ãã®ãƒžã‚¦ã‚¹ã‚«ãƒ¼ã‚½ãƒ«ã®ï¼¹ä½ç½® | |
461 | void ic2_NormalKeyInput (unsigned char key, int x, int y) { | 473 | void ic2_NormalKeyInput (unsigned char key, int x, int y) { | |
462 | float delta_t = 0.1; // [unit] | 474 | float delta_t = 0.1; // [unit] | |
463 | float delta_r = 1.0; // [degree] | 475 | float delta_r = 1.0; // [degree] | |
464 | 476 | |||
465 | switch (key) { | 477 | switch (key) { | |
466 | case 'q' : | 478 | case 'q' : | |
467 | case 'Q' : | 479 | case 'Q' : | |
468 | case 27 : // ESCã‚ーã®ã“㨠| 480 | case 27 : // ESCã‚ーã®ã“㨠| |
469 | exit (0); | 481 | exit (0); | |
470 | break; | 482 | break; | |
471 | 483 | |||
472 | // Translation -_+ : [X]h_l [Y]n_u [Z]j_k | 484 | // Translation -_+ : [X]h_l [Y]n_u [Z]j_k | |
473 | case 'h': glTranslatef(delta_t * -1, 0, 0); break; | 485 | case 'h': glTranslatef(delta_t * -1, 0, 0); break; | |
474 | case 'l': glTranslatef(delta_t * +1, 0, 0); break; | 486 | case 'l': glTranslatef(delta_t * +1, 0, 0); break; | |
475 | case 'n': glTranslatef(0, delta_t * -1, 0); break; | 487 | case 'n': glTranslatef(0, delta_t * -1, 0); break; | |
476 | case 'u': glTranslatef(0, delta_t * +1, 0); break; | 488 | case 'u': glTranslatef(0, delta_t * +1, 0); break; | |
477 | case 'j': glTranslatef(0, 0, delta_t * -1); break; | 489 | case 'j': glTranslatef(0, 0, delta_t * -1); break; | |
478 | case 'k': glTranslatef(0, 0, delta_t * +1); break; | 490 | case 'k': glTranslatef(0, 0, delta_t * +1); break; | |
479 | 491 | |||
480 | // Rotation -_+ : [Y]a_f [Z]s_d [X]x_w | 492 | // Rotation -_+ : [Y]a_f [Z]s_d [X]x_w | |
481 | case 'x': glRotatef(delta_r * -1, 1, 0, 0); break; | 493 | case 'x': glRotatef(delta_r * -1, 1, 0, 0); break; | |
482 | case 'w': glRotatef(delta_r * +1, 1, 0, 0); break; | 494 | case 'w': glRotatef(delta_r * +1, 1, 0, 0); break; | |
483 | case 'a': glRotatef(delta_r * -1, 0, 1, 0); break; | 495 | case 'a': glRotatef(delta_r * -1, 0, 1, 0); break; | |
484 | case 'f': glRotatef(delta_r * +1, 0, 1, 0); break; | 496 | case 'f': glRotatef(delta_r * +1, 0, 1, 0); break; | |
485 | case 's': glRotatef(delta_r * -1, 0, 0, 1); break; | 497 | case 's': glRotatef(delta_r * -1, 0, 0, 1); break; | |
486 | case 'd': glRotatef(delta_r * +1, 0, 0, 1); break; | 498 | case 'd': glRotatef(delta_r * +1, 0, 0, 1); break; | |
487 | 499 | |||
488 | // [Scale] v_b | 500 | // [Scale] v_b | |
489 | case 'v': glScalef(0.95, 0.95, 0.95); break; | 501 | case 'v': glScalef(0.95, 0.95, 0.95); break; | |
490 | case 'b': glScalef(1.05, 1.05, 1.05); break; | 502 | case 'b': glScalef(1.05, 1.05, 1.05); break; | |
491 | 503 | |||
492 | // [Reset] | 504 | // [Reset] | |
493 | case 'R': | 505 | case 'R': | |
494 | glMatrixMode(GL_MODELVIEW); | 506 | glMatrixMode(GL_MODELVIEW); | |
495 | glPopMatrix(); // ä¿è·ã•ã‚Œã¦ãŸç¬¬ï¼‘階層ã«é™ã‚Šã‚‹ | 507 | glPopMatrix(); // ä¿è·ã•ã‚Œã¦ãŸç¬¬ï¼‘階層ã«é™ã‚Šã‚‹ | |
496 | glPushMatrix(); // ä¿è·ã•ã‚Œã¦ãŸç¬¬ï¼‘階層ã‹ã‚‰ã‚³ãƒ”ーã—ã¦ã‚¹ã‚¿ãƒƒã‚¯ãƒˆãƒƒãƒ—を1ã¤ä¸Šã’ã‚‹ | 508 | glPushMatrix(); // ä¿è·ã•ã‚Œã¦ãŸç¬¬ï¼‘階層ã‹ã‚‰ã‚³ãƒ”ーã—ã¦ã‚¹ã‚¿ãƒƒã‚¯ãƒˆãƒƒãƒ—を1ã¤ä¸Šã’ã‚‹ | |
497 | break; | 509 | break; | |
498 | 510 | |||
499 | // [Show Stacktop MODELVIEW Matrix] | 511 | // [Show Stacktop MODELVIEW Matrix] | |
500 | case 'p': | 512 | case 'p': | |
501 | ic2_ShowMATRIX("Current status"); | 513 | ic2_ShowMATRIX("Current status"); | |
502 | break; | 514 | break; | |
503 | 515 | |||
504 | // [Toggle Objects] T | 516 | // [Toggle Objects] T | |
505 | case 'T': tgl_showpredefined *= -1; break; | 517 | case 'T': tgl_showpredefined *= -1; break; | |
506 | // [Toggle Normals] N | 518 | // [Toggle Normals] N | |
507 | case 'N': tgl_shownormal *= -1; break; | 519 | case 'N': tgl_shownormal *= -1; break; | |
520 | // [Move only lights temporarily] L | |||
521 | case 'L': | |||
522 | tgl_movelightonly *= -1; | |||
523 | if (tgl_movelightonly == 1) { | |||
524 | // ã“ã®æ™‚点ã®MODELVIEW行列をä¿å˜ã—ã¦ãƒãƒƒã‚¯çŠ¶æ…‹ã«ã™ã‚‹ | |||
525 | glMatrixMode(GL_MODELVIEW); | |||
526 | glGetFloatv(GL_MODELVIEW_MATRIX , mvmlocked); | |||
527 | } else { | |||
528 | // ãƒãƒƒã‚¯çŠ¶æ…‹ã‚’開始ã—ãŸã¨ãã®çŠ¶æ³ã«å¾©å¸° | |||
529 | glMatrixMode(GL_MODELVIEW); | |||
530 | glLoadMatrixf(mvmlocked); | |||
531 | } | |||
532 | break; | |||
508 | } | 533 | } | |
509 | 534 | |||
510 | // 次ã®ãƒ¡ã‚¤ãƒ³ãƒ«ãƒ¼ãƒ—(glutMainLoop)ã§ã®ç¹°ã‚Šè¿”ã—時ã«æ画をè¦æ±‚ | 535 | // 次ã®ãƒ¡ã‚¤ãƒ³ãƒ«ãƒ¼ãƒ—(glutMainLoop)ã§ã®ç¹°ã‚Šè¿”ã—時ã«æ画をè¦æ±‚ | |
511 | glutPostWindowRedisplay(window_id); | 536 | glutPostWindowRedisplay(window_id); | |
512 | } | 537 | } | |
513 | 538 | |||
514 | // +---------------------------------------------------- | 539 | // +---------------------------------------------------- | |
515 | // ウィンドウサイズã®å¤‰æ›´ãŒç”Ÿã˜ãŸã¨ãã®å¯¾ç–用関数 | 540 | // ウィンドウサイズã®å¤‰æ›´ãŒç”Ÿã˜ãŸã¨ãã®å¯¾ç–用関数 | |
516 | // +---------------------------------------------------- | 541 | // +---------------------------------------------------- | |
517 | // glutReshapeFunc()ã«ã¦ç™»éŒ² | 542 | // glutReshapeFunc()ã«ã¦ç™»éŒ² | |
518 | void ic2_ReshapeWindow (int w, int h) { | 543 | void ic2_ReshapeWindow (int w, int h) { | |
519 | 544 | |||
520 | // æ–°ã—ã„ウィンドウサイズを大域変数ã«ã‚»ãƒƒãƒˆ | 545 | // æ–°ã—ã„ウィンドウサイズを大域変数ã«ã‚»ãƒƒãƒˆ | |
521 | window_w = w; window_h = h; | 546 | window_w = w; window_h = h; | |
522 | 547 | |||
523 | // 次ã®ãƒ¡ã‚¤ãƒ³ãƒ«ãƒ¼ãƒ—(glutMainLoop)ã§ã®ç¹°ã‚Šè¿”ã—時ã«æ画をè¦æ±‚ | 548 | // 次ã®ãƒ¡ã‚¤ãƒ³ãƒ«ãƒ¼ãƒ—(glutMainLoop)ã§ã®ç¹°ã‚Šè¿”ã—時ã«æ画をè¦æ±‚ | |
524 | glutPostWindowRedisplay(window_id); | 549 | glutPostWindowRedisplay(window_id); | |
525 | } | 550 | } | |
526 | 551 | |||
527 | // +---------------------------------------------------- | 552 | // +---------------------------------------------------- | |
528 | // OpenGLã¨ã—ã¦ã®Windowã®åˆæœŸåŒ– | 553 | // OpenGLã¨ã—ã¦ã®Windowã®åˆæœŸåŒ– | |
529 | // +---------------------------------------------------- | 554 | // +---------------------------------------------------- | |
530 | void ic2_BootWindow (char winname[]) { | 555 | void ic2_BootWindow (char winname[]) { | |
531 | 556 | |||
532 | // ダブルãƒãƒƒãƒ•ã‚¡,RGB表色モード,デプスãƒãƒƒãƒ•ã‚¡ を利用 | 557 | // ダブルãƒãƒƒãƒ•ã‚¡,RGB表色モード,デプスãƒãƒƒãƒ•ã‚¡ を利用 | |
533 | glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); | 558 | glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); | |
534 | 559 | |||
535 | // ウィンドウã®å¤§ãã• | 560 | // ウィンドウã®å¤§ãã• | |
536 | glutInitWindowSize(window_w, window_h); | 561 | glutInitWindowSize(window_w, window_h); | |
537 | 562 | |||
538 | // ウィンドウを開ã | 563 | // ウィンドウを開ã | |
539 | window_id = glutCreateWindow(winname); | 564 | window_id = glutCreateWindow(winname); | |
540 | 565 | |||
541 | // レンダリングã«ã¯Smooth Shadingを採用 | 566 | // レンダリングã«ã¯Smooth Shadingを採用 | |
542 | glShadeModel(GL_SMOOTH); | 567 | glShadeModel(GL_SMOOTH); | |
543 | 568 | |||
544 | // ウィンドウ全体を書ãç›´ã™ã¨ãã®è‰²(ã“ã“ã§ã¯é»’) | 569 | // ウィンドウ全体を書ãç›´ã™ã¨ãã®è‰²(ã“ã“ã§ã¯é»’) | |
545 | glClearColor(0.0, 0.0, 0.0, 0.0); | 570 | glClearColor(0.0, 0.0, 0.0, 0.0); | |
546 | 571 | |||
547 | // åˆæœŸMODELVIEW matrixã®ä¿è· | 572 | // åˆæœŸMODELVIEW matrixã®ä¿è· | |
548 | glMatrixMode(GL_MODELVIEW); | 573 | glMatrixMode(GL_MODELVIEW); | |
549 | glPushMatrix(); // 以後本プãƒã‚°ãƒ©ãƒ ã§ã¯ GL_MODELVIEW スタックã®ï¼’層目以上ã§ä½œæ¥ | 574 | glPushMatrix(); // 以後本プãƒã‚°ãƒ©ãƒ ã§ã¯ GL_MODELVIEW スタックã®ï¼’層目以上ã§ä½œæ¥ | |
550 | 575 | |||
551 | // Callback関数をè¨å®š (イベント処ç†) | 576 | // Callback関数をè¨å®š (イベント処ç†) | |
552 | glutIdleFunc(ic2_DrawFrame); // 暇ã ã£ãŸã‚‰ãƒ•ãƒ¬ãƒ¼ãƒ ã‚’æã(よã„実装ã§ã¯ãªã„) | 577 | glutIdleFunc(ic2_DrawFrame); // 暇ã ã£ãŸã‚‰ãƒ•ãƒ¬ãƒ¼ãƒ ã‚’æã(よã„実装ã§ã¯ãªã„) | |
553 | glutKeyboardFunc(ic2_NormalKeyInput); // ã‚ーãŒæŠ¼ã•ã‚ŒãŸã¨ãã®å¯¾ç– | 578 | glutKeyboardFunc(ic2_NormalKeyInput); // ã‚ーãŒæŠ¼ã•ã‚ŒãŸã¨ãã®å¯¾ç– | |
554 | glutReshapeFunc(ic2_ReshapeWindow); // ウィンドウサイズ変更ãŒæ¤œçŸ¥ã•ã‚ŒãŸã¨ãã®å¯¾ç– | 579 | glutReshapeFunc(ic2_ReshapeWindow); // ウィンドウサイズ変更ãŒæ¤œçŸ¥ã•ã‚ŒãŸã¨ãã®å¯¾ç– | |
555 | } | 580 | } | |
556 | 581 | |||
557 | // *********************************************************************** | 582 | // *********************************************************************** | |
558 | // main ***************************************************************** | 583 | // main ***************************************************************** | |
559 | // +---------------------------------------------------- | 584 | // +---------------------------------------------------- | |
560 | // Main Function | 585 | // Main Function | |
561 | // +---------------------------------------------------- | 586 | // +---------------------------------------------------- | |
562 | int main (int argc, char *argv[]) { | 587 | int main (int argc, char *argv[]) { | |
563 | int numberpatches = 0; | 588 | int numberpatches = 0; | |
564 | 589 | |||
565 | // model ファイルã®èªã¿è¾¼ã¿ | 590 | // model ファイルã®èªã¿è¾¼ã¿ | |
566 | if (argc <= 1) { | 591 | if (argc <= 1) { | |
567 | printf("Error: no model file is specified.\n"); | 592 | printf("Error: no model file is specified.\n"); | |
568 | return 1; | 593 | return 1; | |
569 | } | 594 | } | |
570 | numberpatches = ic2_ReadModel(argv[1], &firstpatchptr); | 595 | numberpatches = ic2_ReadModel(argv[1], &firstpatchptr); | |
571 | if (numberpatches < 0) { | 596 | if (numberpatches < 0) { | |
572 | printf("Error: invalid model \"%s\", reading failed.\n", argv[1]); | 597 | printf("Error: invalid model \"%s\", reading failed.\n", argv[1]); | |
573 | return 1; | 598 | return 1; | |
574 | } | 599 | } | |
575 | printf("Number of Patches in the model = %d \n", numberpatches); | 600 | printf("Number of Patches in the model = %d \n", numberpatches); | |
576 | ic2_PrintPATCHList(firstpatchptr); | 601 | ic2_PrintPATCHList(firstpatchptr); | |
577 | 602 | |||
578 | // glutライブラリã«ã‚ˆã‚‹å¼•æ•°ã®è§£é‡ˆ | 603 | // glutライブラリã«ã‚ˆã‚‹å¼•æ•°ã®è§£é‡ˆ | |
579 | glutInit(&argc, argv); | 604 | glutInit(&argc, argv); | |
580 | 605 | |||
581 | // OpenGL Window ã®åˆæœŸåŒ– | 606 | // OpenGL Window ã®åˆæœŸåŒ– | |
582 | ic2_BootWindow(argv[0]); | 607 | ic2_BootWindow(argv[0]); | |
583 | 608 | |||
584 | // ç„¡é™ãƒ«ãƒ¼ãƒ—ã®é–‹å§‹ | 609 | // ç„¡é™ãƒ«ãƒ¼ãƒ—ã®é–‹å§‹ | |
585 | glutMainLoop(); | 610 | glutMainLoop(); | |
586 | 611 | |||
587 | return 0; | 612 | return 0; | |
588 | } | 613 | } |