Mercurial > hg > Members > kono > Cerium
annotate Renderer/Engine/polygon.cc @ 906:348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
author | Yutaka_Kinjyo |
---|---|
date | Mon, 19 Jul 2010 23:40:53 +0900 |
parents | 000a8b63ad9a |
children | 2683838396c6 |
rev | line source |
---|---|
507 | 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" | |
7 #include "sys.h" | |
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 //extern int decode(char *cont, char *file_name); | |
18 extern int decode(char *cont, FILE *outfile); | |
19 | |
20 | |
21 Polygon::Polygon(void) | |
22 { | |
23 xyz[0] = 0; | |
24 xyz[1] = 0; | |
25 xyz[2] = 0; | |
26 xyz[3] = 1; | |
27 c_xyz[0] = 0; | |
28 c_xyz[1] = 0; | |
29 c_xyz[2] = 0; | |
30 c_xyz[3] = 1; | |
31 angle[0] = 0; | |
32 angle[1] = 0; | |
33 angle[2] = 0; | |
34 angle[3] = 1; | |
35 | |
861 | 36 |
37 #if !SPE_CREATE_POLYGON | |
38 | |
507 | 39 for (int i = 0; i < 16; i++) { |
40 matrix[i] = 0; | |
41 } | |
861 | 42 |
43 #endif | |
44 | |
507 | 45 } |
46 | |
47 void | |
48 Polygon::position_init(void) | |
49 { | |
50 xyz[0] = 0; | |
51 xyz[1] = 0; | |
52 xyz[2] = 0; | |
53 xyz[3] = 1; | |
54 c_xyz[0] = 0; | |
55 c_xyz[1] = 0; | |
56 c_xyz[2] = 0; | |
57 c_xyz[3] = 1; | |
58 angle[0] = 0; | |
59 angle[1] = 0; | |
60 angle[2] = 0; | |
61 angle[3] = 1; | |
62 | |
861 | 63 |
64 #if !SPE_CREATE_POLYGON | |
65 | |
507 | 66 for (int i = 0; i < 16; i++) { |
67 matrix[i] = 0; | |
68 } | |
861 | 69 |
70 #endif | |
71 | |
507 | 72 } |
73 | |
74 #if 0 | |
75 void Polygon::draw(SceneGraphPack *sgp) | |
76 { | |
77 float xyz1[4],xyz2[4],xyz3[4]; | |
78 | |
79 /***SceneGraphUpdate***/ | |
80 //sgp_update(); | |
81 for (int i = 0; i < sgp->info.size; i++) { | |
82 SceneGraphNode node = sgp->node[i]; | |
83 | |
84 /***draw***/ | |
85 int n,nt; | |
86 for(n=0,nt=0; n<node.size*3; n+=9,nt+=6) { | |
87 xyz1[0] = node.vertex[n]; | |
88 xyz1[1] = node.vertex[n+1]; | |
89 xyz1[2] = node.vertex[n+2]*-1; | |
90 xyz1[3] = 1; | |
91 xyz2[0] = node.vertex[n+3]; | |
92 xyz2[1] = node.vertex[n+3+1]; | |
93 xyz2[2] = node.vertex[n+3+2]*-1; | |
94 xyz2[3] = 1; | |
95 xyz3[0] = node.vertex[n+6]; | |
96 xyz3[1] = node.vertex[n+6+1]; | |
97 xyz3[2] = node.vertex[n+6+2]*-1; | |
98 xyz3[3] = 1; | |
99 | |
100 rotate(xyz1, node.translation); | |
101 rotate(xyz2, node.translation); | |
102 rotate(xyz3, node.translation); | |
103 | |
104 Vertex *ver1 = new Vertex(xyz1[0],xyz1[1],xyz1[2],node.texture[nt],node.texture[nt+1]); | |
105 Vertex *ver2 = new Vertex(xyz2[0],xyz2[1],xyz2[2],node.texture[nt+2],node.texture[nt+2+1]); | |
106 Vertex *ver3 = new Vertex(xyz3[0],xyz3[1],xyz3[2],node.texture[nt+4],node.texture[nt+4+1]); | |
107 | |
108 Triangle *tri = new Triangle(ver1,ver2,ver3); | |
109 Span_c *span = new Span_c(); | |
110 span->viewer = viewer; | |
111 span->p = this; | |
112 span->create_span(tri,texture_image); | |
113 delete ver1; | |
114 delete ver2; | |
115 delete ver3; | |
116 delete tri; | |
117 delete span; | |
118 } | |
119 } | |
120 } | |
121 | |
122 | |
123 void Polygon::draw(PolygonPack *pp) | |
124 { | |
125 for(int n=0; n<pp->info.size; n++) | |
126 { | |
127 Vertex *ver1 = new Vertex(pp->tri[n].ver1.x,pp->tri[n].ver1.y,pp->tri[n].ver1.z,pp->tri[n].ver1.tex_x,pp->tri[n].ver1.tex_y); | |
128 Vertex *ver2 = new Vertex(pp->tri[n].ver2.x,pp->tri[n].ver2.y,pp->tri[n].ver2.z,pp->tri[n].ver2.tex_x,pp->tri[n].ver2.tex_y); | |
129 Vertex *ver3 = new Vertex(pp->tri[n].ver3.x,pp->tri[n].ver3.y,pp->tri[n].ver3.z,pp->tri[n].ver3.tex_x,pp->tri[n].ver3.tex_y); | |
130 | |
131 Triangle *tri = new Triangle(ver1,ver2,ver3); | |
132 Span_c *span = new Span_c(); | |
133 span->viewer = viewer; | |
134 span->p = this; | |
135 span->create_span(tri,texture_image); | |
136 delete ver1; | |
137 delete ver2; | |
138 delete ver3; | |
139 delete tri; | |
140 delete span; | |
141 } | |
142 } | |
143 | |
144 void Polygon::draw(SpanPack *sp) | |
145 { | |
146 Span *span; | |
147 | |
148 for (int n = 0; n < sp->info.size; n++) { | |
149 span = &sp->span[n]; | |
150 | |
151 //int x = span->x; | |
152 //int y = span->y; | |
153 float z = span->start_z; | |
154 int end = span->length_x; | |
155 float zpos = span->end_z; | |
156 float tex1 = span->tex_x1; | |
157 float tex2 = span->tex_x2; | |
158 float tey1 = span->tex_y1; | |
159 float tey2 = span->tex_y2; | |
160 Uint32 rgb; | |
161 int tex_xpos; | |
162 int tex_ypos; | |
163 int tex_zpos; | |
164 float tex_x, tex_y, tex_z; | |
165 | |
166 if (end == 1) { | |
167 tex_xpos = (int)((span->tex_height-1) * tex1); | |
168 tex_ypos = (int)((span->tex_width-1) * tey1); | |
169 tex_zpos = (int)z; | |
170 rgb = get_rgb(tex_xpos, tex_ypos); | |
171 //viewer->write_pixel(x, y, zpos, rgb); | |
172 } else { | |
173 for (int j = 0; j < end; j++) { | |
174 tex_x = tex1*(end-1-j)/(end-1) + tex2*j/(end-1); | |
175 tex_y = tey1*(end-1-j)/(end-1) + tey2*j/(end-1); | |
176 tex_z = z*(end-1-j)/(end-1) + zpos*j/(end-1); | |
177 if (tex_x > 1) tex_x = 1; | |
178 if (tex_y > 1) tex_y = 1; | |
179 tex_xpos = (int)((span->tex_height-1) * tex_x); | |
180 tex_ypos = (int)((span->tex_width-1) * tex_y); | |
181 rgb = get_rgb(tex_xpos,tex_ypos); | |
182 //viewer->write_pixel(j + x, y, tex_z, rgb); | |
183 } | |
184 } | |
185 } | |
186 } | |
187 | |
188 #endif | |
189 | |
190 void Polygon::pickup_coordinate(char *cont) | |
191 { | |
860 | 192 |
193 #if SPE_CREATE_POLYGON | |
194 | |
195 TrianglePackPtr cur = tri_pack; | |
196 | |
197 for(int n=0; n<size; n+=3) | |
198 { | |
199 | |
200 cont = pickup_float(cont, &cur->ver1.x); | |
201 cont = pickup_float(cont, &cur->ver1.y); | |
202 cont = pickup_float(cont, &cur->ver1.z); | |
203 | |
204 cont = pickup_float(cont, &cur->ver2.x); | |
205 cont = pickup_float(cont, &cur->ver2.y); | |
206 cont = pickup_float(cont, &cur->ver2.z); | |
207 | |
208 cont = pickup_float(cont, &cur->ver3.x); | |
209 cont = pickup_float(cont, &cur->ver3.y); | |
210 cont = pickup_float(cont, &cur->ver3.z); | |
211 | |
212 cur = cur + 1; | |
213 | |
214 if (cont == NULL) | |
215 { | |
216 cout << "Analyzing obj data failed coordinate\n"; | |
217 } | |
218 } | |
219 | |
220 #else | |
221 | |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
222 char *tmp_cont = cont; |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
223 int bound = 8; // coord_vertex size is 8byte. |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
224 int offset = 0; |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
225 |
507 | 226 for(int n=0; n<size*3; n+=3) |
227 { | |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
228 tmp_cont = pickup_float(tmp_cont, coord_xyz+n); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
229 tmp_cont = pickup_float(tmp_cont, coord_xyz+n+1); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
230 tmp_cont = pickup_float(tmp_cont, coord_xyz+n+2); |
507 | 231 |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
232 if (tmp_cont == NULL) |
507 | 233 { |
234 cout << "Analyzing obj data failed coordinate\n"; | |
235 } | |
236 } | |
860 | 237 |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
238 tmp_cont = cont; |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
239 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
240 for(int n=0; n<size; n++) |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
241 { |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
242 tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
243 tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset+1); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
244 tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset+2); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
245 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
246 if (tmp_cont == NULL) |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
247 { |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
248 cout << "Analyzing obj data failed coordinate\n"; |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
249 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
250 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
251 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
252 #if SPE_CREATE_POLYGON_CHECK |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
253 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
254 for (int i = 0; i < size; i++) { |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
255 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
256 if (*(coord_xyz+i*3) != *(coord_pack+i*bound+offset)) { |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
257 printf("hoge\n"); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
258 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
259 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
260 if (*(coord_xyz+i*3+1) != *(coord_pack+i*bound+offset+1)) { |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
261 printf("hoge\n"); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
262 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
263 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
264 if (*(coord_xyz+i*3+2) != *(coord_pack+i*bound+offset+2)) { |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
265 printf("hoge\n"); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
266 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
267 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
268 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
269 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
270 #endif |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
271 |
860 | 272 #endif |
273 | |
507 | 274 } |
275 | |
276 void Polygon::pickup_normal(char *cont) | |
277 { | |
860 | 278 |
279 #if SPE_CREATE_POLYGON | |
280 | |
281 TrianglePackPtr cur = tri_pack; | |
282 | |
283 for(int n=0; n<size; n+=3) | |
284 { | |
285 | |
286 cont = pickup_float(cont, &cur->normal1.x); | |
287 cont = pickup_float(cont, &cur->normal1.y); | |
288 cont = pickup_float(cont, &cur->normal1.z); | |
289 | |
290 cont = pickup_float(cont, &cur->normal2.x); | |
291 cont = pickup_float(cont, &cur->normal2.y); | |
292 cont = pickup_float(cont, &cur->normal2.z); | |
293 | |
294 cont = pickup_float(cont, &cur->normal3.x); | |
295 cont = pickup_float(cont, &cur->normal3.y); | |
296 cont = pickup_float(cont, &cur->normal3.z); | |
297 | |
298 cur = cur + 1; | |
299 | |
300 if (cont == NULL) | |
301 { | |
302 cout << "Analyzing obj data failed coordinate\n"; | |
303 } | |
304 } | |
305 | |
306 #else | |
307 | |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
308 char *tmp_cont = cont; |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
309 int bound = 8; // coord_pack size is 8byte. |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
310 int offset = 5; // coord_pack (xyz(3) + tex_x,tex_y(2) + n_xyz(3)) |
860 | 311 |
507 | 312 for (int n = 0; n<size*3; n += 3) |
313 { | |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
314 tmp_cont = pickup_float(tmp_cont, normal+n); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
315 tmp_cont = pickup_float(tmp_cont, normal+n+1); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
316 tmp_cont = pickup_float(tmp_cont, normal+n+2); |
507 | 317 |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
318 if (tmp_cont == NULL) |
507 | 319 { |
320 cout << "Analyzing obj data failed normal\n"; | |
321 } | |
322 } | |
860 | 323 |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
324 tmp_cont = cont; |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
325 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
326 for(int n=0; n<size; n++) |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
327 { |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
328 tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
329 tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset+1); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
330 tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset+2); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
331 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
332 if (tmp_cont == NULL) |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
333 { |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
334 cout << "Analyzing obj data failed coordinate\n"; |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
335 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
336 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
337 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
338 #if SPE_CREATE_POLYGON_CHECK |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
339 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
340 for (int i = 0; i < size; i++) { |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
341 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
342 if (*(normal+i*3) != *(coord_pack+i*bound+offset)) { |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
343 printf("hoge\n"); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
344 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
345 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
346 if (*(normal+i*3+1) != *(coord_pack+i*bound+offset+1)) { |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
347 printf("hoge\n"); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
348 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
349 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
350 if (*(normal+i*3+2) != *(coord_pack+i*bound+offset+2)) { |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
351 printf("hoge\n"); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
352 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
353 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
354 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
355 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
356 #endif |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
357 |
860 | 358 #endif |
359 | |
507 | 360 } |
361 | |
362 void Polygon::pickup_model(char *cont) | |
363 { | |
364 cont = pickup_float(cont,c_xyz); | |
365 cont = pickup_float(cont,c_xyz+1); | |
366 cont = pickup_float(cont,c_xyz+2); | |
367 | |
368 if (cont == NULL) | |
369 { | |
370 cout << "Analyzing obj data failed model\n"; | |
371 } | |
372 } | |
373 | |
374 void Polygon::pickup_texture(char *cont) | |
375 { | |
860 | 376 |
377 #if SPE_CREATE_POLYGON | |
378 | |
379 TrianglePackPtr cur = tri_pack; | |
380 | |
381 for(int n=0; n<size; n+=3) | |
382 { | |
383 | |
384 cont = pickup_float(cont, &cur->ver1.tex_x); | |
385 cont = pickup_float(cont, &cur->ver1.tex_y); | |
386 | |
387 cont = pickup_float(cont, &cur->ver2.tex_x); | |
388 cont = pickup_float(cont, &cur->ver2.tex_y); | |
389 | |
390 cont = pickup_float(cont, &cur->ver3.tex_x); | |
391 cont = pickup_float(cont, &cur->ver3.tex_y); | |
392 | |
393 cur = cur + 1; | |
394 | |
395 if (cont == NULL) | |
396 { | |
397 cout << "Analyzing obj data failed coordinate\n"; | |
398 } | |
399 } | |
400 | |
401 #else | |
402 | |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
403 char *tmp_cont = cont; |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
404 int bound = 8; // coord_pack size is 8byte. |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
405 int offset = 3; // coord_pack (xyz(3) + tex_x,tex_y(2) + n_xyz(3)) |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
406 |
507 | 407 for (int n = 0; n < size*3; n += 3) |
408 { | |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
409 tmp_cont = pickup_float(tmp_cont, coord_tex+n); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
410 tmp_cont = pickup_float(tmp_cont, coord_tex+n+1); |
507 | 411 coord_tex[n+2] = 1.0; |
412 | |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
413 if (tmp_cont == NULL) |
507 | 414 { |
415 cout << "Analyzing obj data failed texture\n"; | |
416 } | |
417 } | |
860 | 418 |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
419 tmp_cont = cont; |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
420 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
421 for(int n=0; n<size; n++) |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
422 { |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
423 tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
424 tmp_cont = pickup_float(tmp_cont, coord_pack+n*bound+offset+1); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
425 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
426 if (tmp_cont == NULL) |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
427 { |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
428 cout << "Analyzing obj data failed coordinate\n"; |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
429 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
430 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
431 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
432 #if SPE_CREATE_POLYGON_CHECK |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
433 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
434 for (int i = 0; i < size; i++) { |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
435 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
436 if (*(coord_tex+i*3) != *(coord_pack+i*bound+offset)) { |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
437 printf("hoge\n"); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
438 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
439 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
440 if (*(coord_tex+i*3+1) != *(coord_pack+i*bound+offset+1)) { |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
441 printf("hoge\n"); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
442 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
443 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
444 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
445 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
446 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
447 #endif |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
448 |
860 | 449 #endif |
450 | |
507 | 451 } |
452 | |
453 char *get_pixel(int tx, int ty, SDL_Surface *texture_image) | |
454 { | |
455 return (char*)texture_image->pixels+(texture_image->format->BytesPerPixel*((texture_image->w)*ty+tx)); | |
456 } | |
457 | |
458 unsigned my_ntohl(unsigned u) { | |
459 // rr gg bb 00 | |
460 // rr | |
461 // bb gg rr | |
462 //unsigned u1 = ((u&0xff)<<24) + | |
463 // ((u&0xff00)<<8) + | |
464 // ((u&0xff0000)>>8) + | |
465 // ((u&0xff000000)>>24); | |
466 unsigned u1; | |
467 unsigned b = (u&0xff000000)>>24; | |
468 unsigned g = (u&0xff0000)>>16; | |
469 unsigned r = (u&0xff00)>>8; | |
470 u1 = r + (g<<8) + (b<<16); | |
471 //printf("pixel %x->%x\n",u,u1); | |
472 return u1; | |
473 } | |
474 | |
475 Uint32 Polygon::get_rgb(int tx, int ty) | |
476 { | |
477 SDL_PixelFormat *fmt; | |
478 //Uint32 temp, pixel; | |
479 Uint8 red, green, blue; | |
480 | |
481 fmt = texture_image->format; | |
482 | |
483 if (tx<0) tx = 0; | |
484 if (texture_image->w-1< tx) tx = texture_image->w-1 ; | |
485 if (ty<0) ty = 0; | |
486 if (texture_image->h-1< ty) ty = texture_image->h-1 ; | |
487 | |
488 | |
489 | |
490 //SDL_LockSurface(texture_image); | |
491 char *p = get_pixel(tx,ty,texture_image); | |
492 #if 0 | |
493 pixel = my_ntohl(*(Uint32*)p); | |
494 //printf("pixel = %d\n", pixel); | |
495 //printf("pixel %x bpp = %d ",p, fmt->BytesPerPixel); | |
496 //SDL_UnlockSurface(texture_image); | |
497 | |
498 temp = pixel&fmt->Rmask; | |
499 temp = temp>>fmt->Rshift; | |
500 temp = temp<<fmt->Rloss; | |
501 red = (Uint8)temp; | |
502 | |
503 temp = pixel&fmt->Gmask; | |
504 temp = temp>>fmt->Gshift; | |
505 temp = temp<<fmt->Gloss; | |
506 green = (Uint8)temp; | |
507 | |
508 temp = pixel&fmt->Bmask; | |
509 temp = temp>>fmt->Bshift; | |
510 temp = temp<<fmt->Bloss; | |
511 blue = (Uint8)temp; | |
512 #endif | |
513 blue = (Uint8) p[0]; | |
514 green = (Uint8) p[1]; | |
515 red = (Uint8) p[2]; | |
516 | |
517 //printf("tx = %d ty = %d ", tx,ty); | |
518 //printf("pixel color => R: %d, G: %d, B: %d\n", red, green, blue); | |
519 | |
520 SDL_PixelFormat *pf = NULL; | |
521 //pf = viewer->screen->format; | |
522 | |
523 //cout << SDL_MapRGB(pf, red, green, blue) << endl; | |
524 return SDL_MapRGB(pf, red, green, blue); | |
525 } |