Mercurial > hg > Members > kono > Cerium
annotate Renderer/Engine/polygon.cc @ 1047:6a80ca9a65d9
broken texure ( h/w != 2^n ) protection
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 08 Dec 2010 05:38:45 +0900 |
parents | 2683838396c6 |
children |
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 | |
18 Polygon::Polygon(void) | |
19 { | |
20 xyz[0] = 0; | |
21 xyz[1] = 0; | |
22 xyz[2] = 0; | |
23 xyz[3] = 1; | |
24 c_xyz[0] = 0; | |
25 c_xyz[1] = 0; | |
26 c_xyz[2] = 0; | |
27 c_xyz[3] = 1; | |
28 angle[0] = 0; | |
29 angle[1] = 0; | |
30 angle[2] = 0; | |
31 angle[3] = 1; | |
32 | |
861 | 33 |
34 #if !SPE_CREATE_POLYGON | |
35 | |
507 | 36 for (int i = 0; i < 16; i++) { |
37 matrix[i] = 0; | |
38 } | |
861 | 39 |
40 #endif | |
41 | |
507 | 42 } |
43 | |
44 void | |
45 Polygon::position_init(void) | |
46 { | |
47 xyz[0] = 0; | |
48 xyz[1] = 0; | |
49 xyz[2] = 0; | |
50 xyz[3] = 1; | |
51 c_xyz[0] = 0; | |
52 c_xyz[1] = 0; | |
53 c_xyz[2] = 0; | |
54 c_xyz[3] = 1; | |
55 angle[0] = 0; | |
56 angle[1] = 0; | |
57 angle[2] = 0; | |
58 angle[3] = 1; | |
59 | |
861 | 60 |
61 #if !SPE_CREATE_POLYGON | |
62 | |
507 | 63 for (int i = 0; i < 16; i++) { |
64 matrix[i] = 0; | |
65 } | |
861 | 66 |
67 #endif | |
68 | |
507 | 69 } |
70 | |
71 #if 0 | |
72 void Polygon::draw(SceneGraphPack *sgp) | |
73 { | |
74 float xyz1[4],xyz2[4],xyz3[4]; | |
75 | |
76 /***SceneGraphUpdate***/ | |
77 //sgp_update(); | |
78 for (int i = 0; i < sgp->info.size; i++) { | |
79 SceneGraphNode node = sgp->node[i]; | |
80 | |
81 /***draw***/ | |
82 int n,nt; | |
83 for(n=0,nt=0; n<node.size*3; n+=9,nt+=6) { | |
84 xyz1[0] = node.vertex[n]; | |
85 xyz1[1] = node.vertex[n+1]; | |
86 xyz1[2] = node.vertex[n+2]*-1; | |
87 xyz1[3] = 1; | |
88 xyz2[0] = node.vertex[n+3]; | |
89 xyz2[1] = node.vertex[n+3+1]; | |
90 xyz2[2] = node.vertex[n+3+2]*-1; | |
91 xyz2[3] = 1; | |
92 xyz3[0] = node.vertex[n+6]; | |
93 xyz3[1] = node.vertex[n+6+1]; | |
94 xyz3[2] = node.vertex[n+6+2]*-1; | |
95 xyz3[3] = 1; | |
96 | |
97 rotate(xyz1, node.translation); | |
98 rotate(xyz2, node.translation); | |
99 rotate(xyz3, node.translation); | |
100 | |
101 Vertex *ver1 = new Vertex(xyz1[0],xyz1[1],xyz1[2],node.texture[nt],node.texture[nt+1]); | |
102 Vertex *ver2 = new Vertex(xyz2[0],xyz2[1],xyz2[2],node.texture[nt+2],node.texture[nt+2+1]); | |
103 Vertex *ver3 = new Vertex(xyz3[0],xyz3[1],xyz3[2],node.texture[nt+4],node.texture[nt+4+1]); | |
104 | |
105 Triangle *tri = new Triangle(ver1,ver2,ver3); | |
106 Span_c *span = new Span_c(); | |
107 span->viewer = viewer; | |
108 span->p = this; | |
109 span->create_span(tri,texture_image); | |
110 delete ver1; | |
111 delete ver2; | |
112 delete ver3; | |
113 delete tri; | |
114 delete span; | |
115 } | |
116 } | |
117 } | |
118 | |
119 | |
120 void Polygon::draw(PolygonPack *pp) | |
121 { | |
122 for(int n=0; n<pp->info.size; n++) | |
123 { | |
124 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); | |
125 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); | |
126 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); | |
127 | |
128 Triangle *tri = new Triangle(ver1,ver2,ver3); | |
129 Span_c *span = new Span_c(); | |
130 span->viewer = viewer; | |
131 span->p = this; | |
132 span->create_span(tri,texture_image); | |
133 delete ver1; | |
134 delete ver2; | |
135 delete ver3; | |
136 delete tri; | |
137 delete span; | |
138 } | |
139 } | |
140 | |
141 void Polygon::draw(SpanPack *sp) | |
142 { | |
143 Span *span; | |
144 | |
145 for (int n = 0; n < sp->info.size; n++) { | |
146 span = &sp->span[n]; | |
147 | |
148 //int x = span->x; | |
149 //int y = span->y; | |
150 float z = span->start_z; | |
151 int end = span->length_x; | |
152 float zpos = span->end_z; | |
153 float tex1 = span->tex_x1; | |
154 float tex2 = span->tex_x2; | |
155 float tey1 = span->tex_y1; | |
156 float tey2 = span->tex_y2; | |
157 Uint32 rgb; | |
158 int tex_xpos; | |
159 int tex_ypos; | |
160 int tex_zpos; | |
161 float tex_x, tex_y, tex_z; | |
162 | |
163 if (end == 1) { | |
164 tex_xpos = (int)((span->tex_height-1) * tex1); | |
165 tex_ypos = (int)((span->tex_width-1) * tey1); | |
166 tex_zpos = (int)z; | |
167 rgb = get_rgb(tex_xpos, tex_ypos); | |
168 //viewer->write_pixel(x, y, zpos, rgb); | |
169 } else { | |
170 for (int j = 0; j < end; j++) { | |
171 tex_x = tex1*(end-1-j)/(end-1) + tex2*j/(end-1); | |
172 tex_y = tey1*(end-1-j)/(end-1) + tey2*j/(end-1); | |
173 tex_z = z*(end-1-j)/(end-1) + zpos*j/(end-1); | |
174 if (tex_x > 1) tex_x = 1; | |
175 if (tex_y > 1) tex_y = 1; | |
176 tex_xpos = (int)((span->tex_height-1) * tex_x); | |
177 tex_ypos = (int)((span->tex_width-1) * tex_y); | |
178 rgb = get_rgb(tex_xpos,tex_ypos); | |
179 //viewer->write_pixel(j + x, y, tex_z, rgb); | |
180 } | |
181 } | |
182 } | |
183 } | |
184 | |
185 #endif | |
186 | |
187 void Polygon::pickup_coordinate(char *cont) | |
188 { | |
860 | 189 |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
190 char *tmp_cont = cont; |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
191 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
|
192 int offset = 0; |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
193 |
507 | 194 for(int n=0; n<size*3; n+=3) |
195 { | |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
196 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
|
197 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
|
198 tmp_cont = pickup_float(tmp_cont, coord_xyz+n+2); |
507 | 199 |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
200 if (tmp_cont == NULL) |
507 | 201 { |
202 cout << "Analyzing obj data failed coordinate\n"; | |
203 } | |
204 } | |
860 | 205 |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
206 tmp_cont = cont; |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
207 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
208 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
|
209 { |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
210 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
|
211 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
|
212 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
|
213 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
214 if (tmp_cont == NULL) |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
215 { |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
216 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
|
217 } |
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 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
220 #if SPE_CREATE_POLYGON_CHECK |
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 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
|
223 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
224 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
|
225 printf("hoge\n"); |
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 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
228 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
|
229 printf("hoge\n"); |
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 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
232 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
|
233 printf("hoge\n"); |
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 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
236 } |
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 #endif |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
239 |
507 | 240 } |
241 | |
242 void Polygon::pickup_normal(char *cont) | |
243 { | |
860 | 244 |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
245 char *tmp_cont = cont; |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
246 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
|
247 int offset = 5; // coord_pack (xyz(3) + tex_x,tex_y(2) + n_xyz(3)) |
860 | 248 |
507 | 249 for (int n = 0; n<size*3; n += 3) |
250 { | |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
251 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
|
252 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
|
253 tmp_cont = pickup_float(tmp_cont, normal+n+2); |
507 | 254 |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
255 if (tmp_cont == NULL) |
507 | 256 { |
257 cout << "Analyzing obj data failed normal\n"; | |
258 } | |
259 } | |
860 | 260 |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
261 tmp_cont = cont; |
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 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
|
264 { |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
265 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
|
266 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
|
267 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
|
268 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
269 if (tmp_cont == NULL) |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
270 { |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
271 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
|
272 } |
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 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
275 #if SPE_CREATE_POLYGON_CHECK |
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 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
|
278 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
279 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
|
280 printf("hoge\n"); |
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 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
283 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
|
284 printf("hoge\n"); |
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 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
287 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
|
288 printf("hoge\n"); |
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 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
291 } |
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 #endif |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
294 |
507 | 295 } |
296 | |
297 void Polygon::pickup_model(char *cont) | |
298 { | |
299 cont = pickup_float(cont,c_xyz); | |
300 cont = pickup_float(cont,c_xyz+1); | |
301 cont = pickup_float(cont,c_xyz+2); | |
302 | |
303 if (cont == NULL) | |
304 { | |
305 cout << "Analyzing obj data failed model\n"; | |
306 } | |
307 } | |
308 | |
309 void Polygon::pickup_texture(char *cont) | |
310 { | |
860 | 311 |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
312 char *tmp_cont = cont; |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
313 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
|
314 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
|
315 |
507 | 316 for (int n = 0; n < size*3; n += 3) |
317 { | |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
318 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
|
319 tmp_cont = pickup_float(tmp_cont, coord_tex+n+1); |
507 | 320 coord_tex[n+2] = 1.0; |
321 | |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
322 if (tmp_cont == NULL) |
507 | 323 { |
324 cout << "Analyzing obj data failed texture\n"; | |
325 } | |
326 } | |
860 | 327 |
906
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
328 tmp_cont = cont; |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
329 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
330 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
|
331 { |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
332 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
|
333 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
|
334 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
335 if (tmp_cont == NULL) |
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 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
|
338 } |
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 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
341 #if SPE_CREATE_POLYGON_CHECK |
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 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
|
344 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
345 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
|
346 printf("hoge\n"); |
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 |
348b48db317e
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
861
diff
changeset
|
349 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
|
350 printf("hoge\n"); |
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 |
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 |
507 | 358 } |
359 | |
360 char *get_pixel(int tx, int ty, SDL_Surface *texture_image) | |
361 { | |
362 return (char*)texture_image->pixels+(texture_image->format->BytesPerPixel*((texture_image->w)*ty+tx)); | |
363 } | |
364 | |
365 unsigned my_ntohl(unsigned u) { | |
366 // rr gg bb 00 | |
367 // rr | |
368 // bb gg rr | |
369 //unsigned u1 = ((u&0xff)<<24) + | |
370 // ((u&0xff00)<<8) + | |
371 // ((u&0xff0000)>>8) + | |
372 // ((u&0xff000000)>>24); | |
373 unsigned u1; | |
374 unsigned b = (u&0xff000000)>>24; | |
375 unsigned g = (u&0xff0000)>>16; | |
376 unsigned r = (u&0xff00)>>8; | |
377 u1 = r + (g<<8) + (b<<16); | |
378 //printf("pixel %x->%x\n",u,u1); | |
379 return u1; | |
380 } | |
381 | |
382 Uint32 Polygon::get_rgb(int tx, int ty) | |
383 { | |
384 SDL_PixelFormat *fmt; | |
385 //Uint32 temp, pixel; | |
386 Uint8 red, green, blue; | |
387 | |
388 fmt = texture_image->format; | |
389 | |
390 if (tx<0) tx = 0; | |
391 if (texture_image->w-1< tx) tx = texture_image->w-1 ; | |
392 if (ty<0) ty = 0; | |
393 if (texture_image->h-1< ty) ty = texture_image->h-1 ; | |
394 | |
395 | |
396 | |
397 //SDL_LockSurface(texture_image); | |
398 char *p = get_pixel(tx,ty,texture_image); | |
399 #if 0 | |
400 pixel = my_ntohl(*(Uint32*)p); | |
401 //printf("pixel = %d\n", pixel); | |
402 //printf("pixel %x bpp = %d ",p, fmt->BytesPerPixel); | |
403 //SDL_UnlockSurface(texture_image); | |
404 | |
405 temp = pixel&fmt->Rmask; | |
406 temp = temp>>fmt->Rshift; | |
407 temp = temp<<fmt->Rloss; | |
408 red = (Uint8)temp; | |
409 | |
410 temp = pixel&fmt->Gmask; | |
411 temp = temp>>fmt->Gshift; | |
412 temp = temp<<fmt->Gloss; | |
413 green = (Uint8)temp; | |
414 | |
415 temp = pixel&fmt->Bmask; | |
416 temp = temp>>fmt->Bshift; | |
417 temp = temp<<fmt->Bloss; | |
418 blue = (Uint8)temp; | |
419 #endif | |
420 blue = (Uint8) p[0]; | |
421 green = (Uint8) p[1]; | |
422 red = (Uint8) p[2]; | |
423 | |
424 //printf("tx = %d ty = %d ", tx,ty); | |
425 //printf("pixel color => R: %d, G: %d, B: %d\n", red, green, blue); | |
426 | |
427 SDL_PixelFormat *pf = NULL; | |
428 //pf = viewer->screen->format; | |
429 | |
430 //cout << SDL_MapRGB(pf, red, green, blue) << endl; | |
431 return SDL_MapRGB(pf, red, green, blue); | |
432 } |