Mercurial > hg > Game > Cerium
annotate Renderer/Engine/polygon.cc @ 1205:b8adf4e95e96 draft
add createStringFont()
author | Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 21 Jul 2011 18:56:08 +0900 |
parents | 786e800abfb4 |
children | bb9c885c1cb5 |
rev | line source |
---|---|
539 | 1 #include <iostream> |
2 #include <SDL.h> | |
3 #include <SDL_opengl.h> | |
4 #include <SDL_image.h> | |
5 #include "polygon.h" | |
6 #include "xml.h" | |
1050 | 7 #include "matrix_calc.h" |
539 | 8 #include "triangle.h" |
9 #include "vertex.h" | |
10 #include "Span.h" | |
11 #include "SpanC.h" | |
12 #include "scene_graph_pack.h" | |
13 #include "error.h" | |
14 #include "viewer_types.h" | |
15 using namespace std; | |
16 | |
17 | |
1130 | 18 |
19 | |
20 Polygon::Polygon() | |
539 | 21 { |
1050 | 22 position_init(); |
539 | 23 } |
24 | |
25 void | |
26 Polygon::position_init(void) | |
27 { | |
1129 | 28 |
539 | 29 xyz[0] = 0; |
30 xyz[1] = 0; | |
31 xyz[2] = 0; | |
32 xyz[3] = 1; | |
33 c_xyz[0] = 0; | |
34 c_xyz[1] = 0; | |
35 c_xyz[2] = 0; | |
36 c_xyz[3] = 1; | |
37 angle[0] = 0; | |
38 angle[1] = 0; | |
39 angle[2] = 0; | |
40 angle[3] = 1; | |
1050 | 41 scale[0] = 1; |
42 scale[1] = 1; | |
43 scale[2] = 1; | |
539 | 44 |
861 | 45 |
539 | 46 } |
47 | |
48 void Polygon::pickup_coordinate(char *cont) | |
49 { | |
860 | 50 |
1128 | 51 // size は頂点の数, count は面の数 |
906
becd6fad3ae0
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
52 char *tmp_cont = cont; |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
53 int count = size / 3; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
54 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
55 for (int i = 0; i < pp_num; i++) { |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
56 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
57 TrianglePackPtr tri = pp[i].tri; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
58 // TrianglePack の size のチェック |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
59 int tri_size = (count < MAX_SIZE_TRIANGLE) ? count : MAX_SIZE_TRIANGLE ; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
60 pp[i].info.size = tri_size; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
61 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
62 for (int j = 0; j < tri_size; j++) { |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
63 |
1127
c4287bf771a0
CreatePolygonFromSceneGraph can work on Mac OSX.
Yutaka_Kinjyo
parents:
1126
diff
changeset
|
64 tmp_cont = pickup_float(tmp_cont, &(tri[j].ver1.x)); |
c4287bf771a0
CreatePolygonFromSceneGraph can work on Mac OSX.
Yutaka_Kinjyo
parents:
1126
diff
changeset
|
65 tmp_cont = pickup_float(tmp_cont, &(tri[j].ver1.y)); |
c4287bf771a0
CreatePolygonFromSceneGraph can work on Mac OSX.
Yutaka_Kinjyo
parents:
1126
diff
changeset
|
66 tmp_cont = pickup_float(tmp_cont, &(tri[j].ver1.z)); |
c4287bf771a0
CreatePolygonFromSceneGraph can work on Mac OSX.
Yutaka_Kinjyo
parents:
1126
diff
changeset
|
67 |
c4287bf771a0
CreatePolygonFromSceneGraph can work on Mac OSX.
Yutaka_Kinjyo
parents:
1126
diff
changeset
|
68 tmp_cont = pickup_float(tmp_cont, &(tri[j].ver2.x)); |
c4287bf771a0
CreatePolygonFromSceneGraph can work on Mac OSX.
Yutaka_Kinjyo
parents:
1126
diff
changeset
|
69 tmp_cont = pickup_float(tmp_cont, &(tri[j].ver2.y)); |
c4287bf771a0
CreatePolygonFromSceneGraph can work on Mac OSX.
Yutaka_Kinjyo
parents:
1126
diff
changeset
|
70 tmp_cont = pickup_float(tmp_cont, &(tri[j].ver2.z)); |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
71 |
1127
c4287bf771a0
CreatePolygonFromSceneGraph can work on Mac OSX.
Yutaka_Kinjyo
parents:
1126
diff
changeset
|
72 tmp_cont = pickup_float(tmp_cont, &(tri[j].ver3.x)); |
c4287bf771a0
CreatePolygonFromSceneGraph can work on Mac OSX.
Yutaka_Kinjyo
parents:
1126
diff
changeset
|
73 tmp_cont = pickup_float(tmp_cont, &(tri[j].ver3.y)); |
c4287bf771a0
CreatePolygonFromSceneGraph can work on Mac OSX.
Yutaka_Kinjyo
parents:
1126
diff
changeset
|
74 tmp_cont = pickup_float(tmp_cont, &(tri[j].ver3.z)); |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
75 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
76 if (tmp_cont == NULL) |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
77 { |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
78 cout << "Analyzing obj data failed coordinate\n"; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
79 } |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
80 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
81 count -= 1; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
82 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
83 } |
1128 | 84 |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
85 } |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
86 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
87 if (count != 0) { |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
88 printf("miss pickup_coordinate size. diff size = %d\n", count); |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
89 } |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
90 |
539 | 91 } |
92 | |
93 void Polygon::pickup_normal(char *cont) | |
94 { | |
860 | 95 |
96 | |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
97 // size は頂点の数, count は面の数 |
1128 | 98 char *tmp_cont = cont; |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
99 int count = size / 3; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
100 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
101 for (int i = 0; i < pp_num; i++) { |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
102 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
103 TrianglePackPtr tri = pp[i].tri; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
104 // TrianglePack の size のチェック |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
105 int tri_size = (count < MAX_SIZE_TRIANGLE) ? count : MAX_SIZE_TRIANGLE ; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
106 pp[i].info.size = tri_size; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
107 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
108 for (int j = 0; j < tri_size; j++) { |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
109 |
1127
c4287bf771a0
CreatePolygonFromSceneGraph can work on Mac OSX.
Yutaka_Kinjyo
parents:
1126
diff
changeset
|
110 tmp_cont = pickup_float(tmp_cont, &(tri[j].normal1.x)); |
c4287bf771a0
CreatePolygonFromSceneGraph can work on Mac OSX.
Yutaka_Kinjyo
parents:
1126
diff
changeset
|
111 tmp_cont = pickup_float(tmp_cont, &(tri[j].normal1.y)); |
c4287bf771a0
CreatePolygonFromSceneGraph can work on Mac OSX.
Yutaka_Kinjyo
parents:
1126
diff
changeset
|
112 tmp_cont = pickup_float(tmp_cont, &(tri[j].normal1.z)); |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
113 |
1127
c4287bf771a0
CreatePolygonFromSceneGraph can work on Mac OSX.
Yutaka_Kinjyo
parents:
1126
diff
changeset
|
114 tmp_cont = pickup_float(tmp_cont, &(tri[j].normal2.x)); |
c4287bf771a0
CreatePolygonFromSceneGraph can work on Mac OSX.
Yutaka_Kinjyo
parents:
1126
diff
changeset
|
115 tmp_cont = pickup_float(tmp_cont, &(tri[j].normal2.y)); |
c4287bf771a0
CreatePolygonFromSceneGraph can work on Mac OSX.
Yutaka_Kinjyo
parents:
1126
diff
changeset
|
116 tmp_cont = pickup_float(tmp_cont, &(tri[j].normal2.z)); |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
117 |
1127
c4287bf771a0
CreatePolygonFromSceneGraph can work on Mac OSX.
Yutaka_Kinjyo
parents:
1126
diff
changeset
|
118 tmp_cont = pickup_float(tmp_cont, &(tri[j].normal3.x)); |
c4287bf771a0
CreatePolygonFromSceneGraph can work on Mac OSX.
Yutaka_Kinjyo
parents:
1126
diff
changeset
|
119 tmp_cont = pickup_float(tmp_cont, &(tri[j].normal3.y)); |
c4287bf771a0
CreatePolygonFromSceneGraph can work on Mac OSX.
Yutaka_Kinjyo
parents:
1126
diff
changeset
|
120 tmp_cont = pickup_float(tmp_cont, &(tri[j].normal3.z)); |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
121 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
122 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
123 if (tmp_cont == NULL) |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
124 { |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
125 cout << "Analyzing obj data failed coordinate\n"; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
126 } |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
127 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
128 count -= 1; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
129 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
130 } |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
131 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
132 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
133 } |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
134 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
135 if (count != 0) { |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
136 printf("miss pickup_normal size. diff size = %d\n", count); |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
137 } |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
138 |
539 | 139 } |
140 | |
141 void Polygon::pickup_model(char *cont) | |
142 { | |
143 cont = pickup_float(cont,c_xyz); | |
144 cont = pickup_float(cont,c_xyz+1); | |
145 cont = pickup_float(cont,c_xyz+2); | |
146 | |
147 if (cont == NULL) | |
148 { | |
149 cout << "Analyzing obj data failed model\n"; | |
150 } | |
151 } | |
152 | |
153 void Polygon::pickup_texture(char *cont) | |
154 { | |
860 | 155 |
906
becd6fad3ae0
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
156 char *tmp_cont = cont; |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
157 int count = size / 3; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
158 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
159 for (int i = 0; i < pp_num; i++) { |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
160 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
161 TrianglePackPtr tri = pp[i].tri; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
162 // TrianglePack の size のチェック |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
163 int tri_size = (count < MAX_SIZE_TRIANGLE) ? count : MAX_SIZE_TRIANGLE ; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
164 pp[i].info.size = tri_size; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
165 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
166 for (int j = 0; j < tri_size; j++) { |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
167 |
1127
c4287bf771a0
CreatePolygonFromSceneGraph can work on Mac OSX.
Yutaka_Kinjyo
parents:
1126
diff
changeset
|
168 tmp_cont = pickup_float(tmp_cont, &(tri[j].ver1.tex_x)); |
c4287bf771a0
CreatePolygonFromSceneGraph can work on Mac OSX.
Yutaka_Kinjyo
parents:
1126
diff
changeset
|
169 tmp_cont = pickup_float(tmp_cont, &(tri[j].ver1.tex_y)); |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
170 |
1127
c4287bf771a0
CreatePolygonFromSceneGraph can work on Mac OSX.
Yutaka_Kinjyo
parents:
1126
diff
changeset
|
171 tmp_cont = pickup_float(tmp_cont, &(tri[j].ver2.tex_x)); |
c4287bf771a0
CreatePolygonFromSceneGraph can work on Mac OSX.
Yutaka_Kinjyo
parents:
1126
diff
changeset
|
172 tmp_cont = pickup_float(tmp_cont, &(tri[j].ver2.tex_y)); |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
173 |
1127
c4287bf771a0
CreatePolygonFromSceneGraph can work on Mac OSX.
Yutaka_Kinjyo
parents:
1126
diff
changeset
|
174 tmp_cont = pickup_float(tmp_cont, &(tri[j].ver3.tex_x)); |
c4287bf771a0
CreatePolygonFromSceneGraph can work on Mac OSX.
Yutaka_Kinjyo
parents:
1126
diff
changeset
|
175 tmp_cont = pickup_float(tmp_cont, &(tri[j].ver3.tex_y)); |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
176 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
177 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
178 if (tmp_cont == NULL) |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
179 { |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
180 cout << "Analyzing obj data failed coordinate\n"; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
181 } |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
182 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
183 count -= 1; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
184 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
185 } |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
186 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
187 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
188 } |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
189 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
190 if (count != 0) { |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
191 printf("miss pickup_texture size. diff size = %d\n", count); |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
192 } |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
193 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
194 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
195 |
539 | 196 } |
197 | |
198 char *get_pixel(int tx, int ty, SDL_Surface *texture_image) | |
199 { | |
200 return (char*)texture_image->pixels+(texture_image->format->BytesPerPixel*((texture_image->w)*ty+tx)); | |
201 } | |
202 | |
203 unsigned my_ntohl(unsigned u) { | |
204 // rr gg bb 00 | |
205 // rr | |
206 // bb gg rr | |
207 //unsigned u1 = ((u&0xff)<<24) + | |
208 // ((u&0xff00)<<8) + | |
209 // ((u&0xff0000)>>8) + | |
210 // ((u&0xff000000)>>24); | |
211 unsigned u1; | |
212 unsigned b = (u&0xff000000)>>24; | |
213 unsigned g = (u&0xff0000)>>16; | |
214 unsigned r = (u&0xff00)>>8; | |
215 u1 = r + (g<<8) + (b<<16); | |
216 //printf("pixel %x->%x\n",u,u1); | |
217 return u1; | |
218 } | |
219 | |
220 Uint32 Polygon::get_rgb(int tx, int ty) | |
221 { | |
222 SDL_PixelFormat *fmt; | |
223 //Uint32 temp, pixel; | |
224 Uint8 red, green, blue; | |
225 | |
1130 | 226 fmt = texture_info->texture_image->format; |
539 | 227 |
228 if (tx<0) tx = 0; | |
1130 | 229 if (texture_info->texture_image->w-1< tx) tx = texture_info->texture_image->w-1 ; |
539 | 230 if (ty<0) ty = 0; |
1130 | 231 if (texture_info->texture_image->h-1< ty) ty = texture_info->texture_image->h-1 ; |
539 | 232 |
233 | |
234 //SDL_LockSurface(texture_image); | |
1130 | 235 char *p = get_pixel(tx,ty,texture_info->texture_image); |
539 | 236 blue = (Uint8) p[0]; |
237 green = (Uint8) p[1]; | |
238 red = (Uint8) p[2]; | |
239 | |
240 //printf("tx = %d ty = %d ", tx,ty); | |
241 //printf("pixel color => R: %d, G: %d, B: %d\n", red, green, blue); | |
242 | |
243 SDL_PixelFormat *pf = NULL; | |
244 //pf = viewer->screen->format; | |
245 | |
246 //cout << SDL_MapRGB(pf, red, green, blue) << endl; | |
247 return SDL_MapRGB(pf, red, green, blue); | |
248 } | |
1205
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
249 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
250 void Polygon::font_coordinate(int baseline, int row,int width) |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
251 { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
252 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
253 //int count = size / 3; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
254 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
255 for (int i = 0; i < pp_num; i++) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
256 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
257 TrianglePackPtr tri = pp[i].tri; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
258 // TrianglePack の size のチェック |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
259 int tri_size = 2; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
260 pp[i].info.size = tri_size; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
261 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
262 for (int j = 0; j < tri_size; j++) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
263 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
264 tri[j].ver1.x = 0.0 ; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
265 tri[j].ver1.y = 0.0 + baseline; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
266 //tri[j].ver1.y = 0.0; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
267 tri[j].ver1.z = 0.0; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
268 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
269 if(j < 1) |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
270 { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
271 tri[j].ver2.x = 0.0 ; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
272 tri[j].ver2.y = row +baseline; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
273 //tri[j].ver2.y = row; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
274 tri[j].ver2.z = 0.0; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
275 }else{ |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
276 tri[j].ver2.x = width ; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
277 tri[j].ver2.y = 0.0 +baseline; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
278 //tri[j].ver2.y = 0.0; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
279 tri[j].ver2.z = 0.0; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
280 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
281 tri[j].ver3.x = width ; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
282 tri[j].ver3.y =row +baseline; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
283 //tri[j].ver3.y =row; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
284 tri[j].ver3.z = 0.0; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
285 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
286 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
287 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
288 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
289 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
290 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
291 void Polygon::font_normal() |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
292 { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
293 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
294 //テスト用 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
295 float polygon_point[2][9] = { {0,0,1, 0,0,1, 0,0,1}, |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
296 {0,0,1, 0,0,1, 0,0,1} }; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
297 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
298 //int count = size / 3; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
299 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
300 for (int i = 0; i < pp_num; i++) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
301 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
302 TrianglePackPtr tri = pp[i].tri; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
303 // TrianglePack の size のチェック |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
304 int tri_size = 2; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
305 pp[i].info.size = tri_size; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
306 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
307 for (int j = 0; j < tri_size; j++) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
308 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
309 tri[j].normal1.x = polygon_point[j][0]; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
310 tri[j].normal1.y = polygon_point[j][1]; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
311 tri[j].normal1.z = polygon_point[j][2]; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
312 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
313 tri[j].normal2.x = polygon_point[j][3]; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
314 tri[j].normal2.y = polygon_point[j][4]; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
315 tri[j].normal2.z = polygon_point[j][5]; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
316 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
317 tri[j].normal3.x = polygon_point[j][6]; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
318 tri[j].normal3.y = polygon_point[j][7]; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
319 tri[j].normal3.z = polygon_point[j][8]; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
320 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
321 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
322 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
323 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
324 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
325 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
326 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
327 void Polygon::font_model() |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
328 { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
329 //テスト用 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
330 float polygon_point[3] = {0,0,0}; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
331 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
332 c_xyz[0] = polygon_point[0]; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
333 c_xyz[1] = polygon_point[1]; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
334 c_xyz[2] = polygon_point[2]; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
335 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
336 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
337 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
338 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
339 void Polygon::font_texture(float row,float width) |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
340 { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
341 float texture_point[2][7] = { {0,0, 0,1, 1,1}, |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
342 {0,0, 1,0, 1,1} }; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
343 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
344 for (int i = 0; i < pp_num; i++) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
345 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
346 TrianglePackPtr tri = pp[i].tri; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
347 // TrianglePack の size のチェック |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
348 int tri_size = 2; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
349 pp[i].info.size = tri_size; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
350 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
351 for (int j = 0; j < tri_size; j++) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
352 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
353 tri[j].ver1.tex_x = texture_point[j][0]; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
354 tri[j].ver1.tex_y = texture_point[j][1]; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
355 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
356 tri[j].ver2.tex_x = texture_point[j][2]; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
357 tri[j].ver2.tex_y = texture_point[j][3]; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
358 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
359 tri[j].ver3.tex_x = texture_point[j][4]; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
360 tri[j].ver3.tex_y = texture_point[j][5]; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
361 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
362 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
363 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
364 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
365 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
366 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
367 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
368 /*if (count != 0) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
369 printf("miss pickup_texture size. diff size = %d\n", count); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
370 }*/ |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
371 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
372 } |