Mercurial > hg > Members > kono > Cerium
annotate Renderer/Engine/polygon.cc @ 1002:c79651141045
many changes.
author | koba <koba@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 24 Oct 2010 19:00:47 +0900 |
parents | 2683838396c6 |
children | 6a80ca9a65d9 |
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 |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
193 char *tmp_cont = cont; |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
194 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
|
195 int offset = 0; |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
196 |
507 | 197 for(int n=0; n<size*3; n+=3) |
198 { | |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
199 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
|
200 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
|
201 tmp_cont = pickup_float(tmp_cont, coord_xyz+n+2); |
507 | 202 |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
203 if (tmp_cont == NULL) |
507 | 204 { |
205 cout << "Analyzing obj data failed coordinate\n"; | |
206 } | |
207 } | |
860 | 208 |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
209 tmp_cont = cont; |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
210 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
211 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
|
212 { |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
213 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
|
214 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
|
215 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
|
216 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
217 if (tmp_cont == NULL) |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
218 { |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
219 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
|
220 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
221 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
222 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
223 #if SPE_CREATE_POLYGON_CHECK |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
224 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
225 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
|
226 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
227 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
|
228 printf("hoge\n"); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
229 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
230 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
231 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
|
232 printf("hoge\n"); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
233 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
234 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
235 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
|
236 printf("hoge\n"); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
237 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
238 |
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 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
241 #endif |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
242 |
507 | 243 } |
244 | |
245 void Polygon::pickup_normal(char *cont) | |
246 { | |
860 | 247 |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
248 char *tmp_cont = cont; |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
249 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
|
250 int offset = 5; // coord_pack (xyz(3) + tex_x,tex_y(2) + n_xyz(3)) |
860 | 251 |
507 | 252 for (int n = 0; n<size*3; n += 3) |
253 { | |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
254 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
|
255 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
|
256 tmp_cont = pickup_float(tmp_cont, normal+n+2); |
507 | 257 |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
258 if (tmp_cont == NULL) |
507 | 259 { |
260 cout << "Analyzing obj data failed normal\n"; | |
261 } | |
262 } | |
860 | 263 |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
264 tmp_cont = cont; |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
265 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
266 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
|
267 { |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
268 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
|
269 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
|
270 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
|
271 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
272 if (tmp_cont == NULL) |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
273 { |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
274 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
|
275 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
276 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
277 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
278 #if SPE_CREATE_POLYGON_CHECK |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
279 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
280 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
|
281 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
282 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
|
283 printf("hoge\n"); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
284 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
285 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
286 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
|
287 printf("hoge\n"); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
288 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
289 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
290 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
|
291 printf("hoge\n"); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
292 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
293 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
294 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
295 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
296 #endif |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
297 |
507 | 298 } |
299 | |
300 void Polygon::pickup_model(char *cont) | |
301 { | |
302 cont = pickup_float(cont,c_xyz); | |
303 cont = pickup_float(cont,c_xyz+1); | |
304 cont = pickup_float(cont,c_xyz+2); | |
305 | |
306 if (cont == NULL) | |
307 { | |
308 cout << "Analyzing obj data failed model\n"; | |
309 } | |
310 } | |
311 | |
312 void Polygon::pickup_texture(char *cont) | |
313 { | |
860 | 314 |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
315 char *tmp_cont = cont; |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
316 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
|
317 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
|
318 |
507 | 319 for (int n = 0; n < size*3; n += 3) |
320 { | |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
321 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
|
322 tmp_cont = pickup_float(tmp_cont, coord_tex+n+1); |
507 | 323 coord_tex[n+2] = 1.0; |
324 | |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
325 if (tmp_cont == NULL) |
507 | 326 { |
327 cout << "Analyzing obj data failed texture\n"; | |
328 } | |
329 } | |
860 | 330 |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
331 tmp_cont = cont; |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
332 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
333 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
|
334 { |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
335 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
|
336 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
|
337 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
338 if (tmp_cont == NULL) |
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 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
|
341 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
342 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
343 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
344 #if SPE_CREATE_POLYGON_CHECK |
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 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
|
347 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
348 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
|
349 printf("hoge\n"); |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
350 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
351 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
352 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
|
353 printf("hoge\n"); |
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 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
357 } |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
358 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
359 #endif |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
360 |
507 | 361 } |
362 | |
363 char *get_pixel(int tx, int ty, SDL_Surface *texture_image) | |
364 { | |
365 return (char*)texture_image->pixels+(texture_image->format->BytesPerPixel*((texture_image->w)*ty+tx)); | |
366 } | |
367 | |
368 unsigned my_ntohl(unsigned u) { | |
369 // rr gg bb 00 | |
370 // rr | |
371 // bb gg rr | |
372 //unsigned u1 = ((u&0xff)<<24) + | |
373 // ((u&0xff00)<<8) + | |
374 // ((u&0xff0000)>>8) + | |
375 // ((u&0xff000000)>>24); | |
376 unsigned u1; | |
377 unsigned b = (u&0xff000000)>>24; | |
378 unsigned g = (u&0xff0000)>>16; | |
379 unsigned r = (u&0xff00)>>8; | |
380 u1 = r + (g<<8) + (b<<16); | |
381 //printf("pixel %x->%x\n",u,u1); | |
382 return u1; | |
383 } | |
384 | |
385 Uint32 Polygon::get_rgb(int tx, int ty) | |
386 { | |
387 SDL_PixelFormat *fmt; | |
388 //Uint32 temp, pixel; | |
389 Uint8 red, green, blue; | |
390 | |
391 fmt = texture_image->format; | |
392 | |
393 if (tx<0) tx = 0; | |
394 if (texture_image->w-1< tx) tx = texture_image->w-1 ; | |
395 if (ty<0) ty = 0; | |
396 if (texture_image->h-1< ty) ty = texture_image->h-1 ; | |
397 | |
398 | |
399 | |
400 //SDL_LockSurface(texture_image); | |
401 char *p = get_pixel(tx,ty,texture_image); | |
402 #if 0 | |
403 pixel = my_ntohl(*(Uint32*)p); | |
404 //printf("pixel = %d\n", pixel); | |
405 //printf("pixel %x bpp = %d ",p, fmt->BytesPerPixel); | |
406 //SDL_UnlockSurface(texture_image); | |
407 | |
408 temp = pixel&fmt->Rmask; | |
409 temp = temp>>fmt->Rshift; | |
410 temp = temp<<fmt->Rloss; | |
411 red = (Uint8)temp; | |
412 | |
413 temp = pixel&fmt->Gmask; | |
414 temp = temp>>fmt->Gshift; | |
415 temp = temp<<fmt->Gloss; | |
416 green = (Uint8)temp; | |
417 | |
418 temp = pixel&fmt->Bmask; | |
419 temp = temp>>fmt->Bshift; | |
420 temp = temp<<fmt->Bloss; | |
421 blue = (Uint8)temp; | |
422 #endif | |
423 blue = (Uint8) p[0]; | |
424 green = (Uint8) p[1]; | |
425 red = (Uint8) p[2]; | |
426 | |
427 //printf("tx = %d ty = %d ", tx,ty); | |
428 //printf("pixel color => R: %d, G: %d, B: %d\n", red, green, blue); | |
429 | |
430 SDL_PixelFormat *pf = NULL; | |
431 //pf = viewer->screen->format; | |
432 | |
433 //cout << SDL_MapRGB(pf, red, green, blue) << endl; | |
434 return SDL_MapRGB(pf, red, green, blue); | |
435 } |