Mercurial > hg > Members > kono > Cerium
annotate Renderer/Engine/task/CreatePolygonFromSceneGraph.cc @ 884:7c5a30983efa
obj_move fix
author | tkaito |
---|---|
date | Mon, 12 Jul 2010 04:12:13 +0900 |
parents | 649e4cb84683 |
children | bed529c55eda |
rev | line source |
---|---|
507 | 1 /** |
2 * SceneGraph が増えてくると動かなくなるかもしれない。 | |
3 * 一応 mainMem とかで動くようになるとは思うけど。 | |
4 * だめだったら、そこら辺が怪しいと思うべき | |
5 */ | |
6 | |
7 #include "CreatePolygonFromSceneGraph.h" | |
8 #include "polygon_pack.h" | |
9 #include "scene_graph_pack.h" | |
10 | |
11 SchedDefineTask(CreatePolygonFromSceneGraph); | |
12 | |
13 #define SG_PACK_LOAD 10 | |
14 #define SG_NODE_LOAD 11 | |
15 #define PP_LOAD 12 | |
16 #define PP_STORE 13 | |
17 | |
18 /** | |
19 * ベクトルに行列を乗算する | |
20 * @param[out] v vector (float[4]) | |
21 * @param[in] m matrix (float[16]) | |
22 */ | |
23 static void | |
24 ApplyMatrix(float *v, float *m) | |
25 { | |
26 float t[4]; | |
27 | |
28 t[0] = v[0]; | |
29 t[1] = v[1]; | |
30 t[2] = v[2]; | |
31 t[3] = v[3]; | |
32 | |
33 for (int i = 0; i < 4; i++) { | |
34 v[i] = t[0]*m[i] + t[1]*m[i+4] + t[2]*m[i+8] + t[3]*m[i+12]; | |
35 } | |
36 } | |
37 | |
38 static void | |
39 ApplyNormalMatrix(float *v, float *m) | |
40 { | |
41 float t[4]; | |
42 | |
43 t[0] = v[0]; | |
44 t[1] = v[1]; | |
45 t[2] = v[2]; | |
46 | |
47 for (int i = 0; i < 3; i++) { | |
48 v[i] = t[0]*m[i] + t[1]*m[i+4] + t[2]*m[i+8]; | |
49 } | |
50 } | |
51 | |
52 | |
53 /** | |
54 * 行列の積 | |
55 * | |
56 * @param[out] m0 output matrix | |
57 * @param[in] m1 input left matrix | |
58 * @param[in] m2 input right matrix | |
59 */ | |
60 /* | |
61 static void | |
62 MulMatrix(float *m0, float *m1, float *m2) //xyz[16] | |
63 { | |
64 for(int t = 0; t < 16; t += 4) { | |
65 for (int i = 0; i < 4; i++) { | |
66 m0[t+i] = | |
67 m1[t+0]*m2[ i ] + m1[t+1]*m2[i+ 4] + | |
68 m1[t+2]*m2[i+8] + m1[t+3]*m2[i+12]; | |
69 } | |
70 } | |
71 } | |
72 */ | |
73 static int | |
74 run(SchedTask *smanager, void *rbuf, void *wbuf) | |
75 { | |
860 | 76 |
77 #if !SPE_CREATE_POLYGON | |
78 | |
507 | 79 float xyz1[4], xyz2[4], xyz3[4]; |
80 float normal1[4],normal2[4],normal3[4]; | |
81 | |
82 SceneGraphPtr sg_top = (SceneGraphPtr)smanager->get_param(0); | |
83 SceneGraphPtr sg = sg_top; | |
84 | |
85 PolygonPackPtr pp | |
86 = (PolygonPackPtr)smanager->allocate(sizeof(PolygonPack)); | |
87 PolygonPackPtr send_pp | |
88 = (PolygonPackPtr)smanager->allocate(sizeof(PolygonPack)); | |
89 PolygonPackPtr pp_addr = (PolygonPackPtr)smanager->get_param(1); | |
90 PolygonPackPtr tmp_pp; | |
91 | |
92 pp->init(); | |
93 send_pp->init(); | |
94 | |
95 while (sg) { | |
96 if (sg->flag_drawable) { // sg->isDrawable() とかの方がよくね? | |
97 for (int i = 0; i < sg->size; i += 3) { | |
98 if (pp->info.size >= MAX_SIZE_TRIANGLE) { | |
99 PolygonPackPtr next; | |
100 | |
101 smanager->mainMem_alloc(0, sizeof(PolygonPack)); | |
102 smanager->mainMem_wait(); | |
103 next = (PolygonPackPtr)smanager->mainMem_get(0); | |
104 | |
105 pp->next = next; | |
106 | |
107 tmp_pp = pp; | |
108 pp = send_pp; | |
109 send_pp = tmp_pp; | |
110 | |
111 smanager->dma_wait(PP_STORE); | |
603
42c94f85c779
long -> memaddr (64 or 32)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
602
diff
changeset
|
112 smanager->dma_store(send_pp, (memaddr)pp_addr, |
507 | 113 sizeof(PolygonPack), PP_STORE); |
114 | |
115 pp_addr = next; | |
116 | |
117 smanager->dma_wait(PP_LOAD); | |
603
42c94f85c779
long -> memaddr (64 or 32)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
602
diff
changeset
|
118 smanager->dma_load(pp, (memaddr)pp_addr, |
507 | 119 sizeof(PolygonPack), PP_LOAD); |
120 smanager->dma_wait(PP_LOAD); | |
121 pp->init(); | |
122 } | |
123 | |
124 TrianglePack *triangle = &pp->tri[pp->info.size++]; | |
125 | |
126 xyz1[0] = sg->coord_xyz[(i+0)*3]; | |
127 xyz1[1] = sg->coord_xyz[(i+0)*3+1]; | |
128 xyz1[2] = sg->coord_xyz[(i+0)*3+2]*-1.0f; | |
129 xyz1[3] = 1.0f; | |
130 | |
131 xyz2[0] = sg->coord_xyz[(i+1)*3]; | |
132 xyz2[1] = sg->coord_xyz[(i+1)*3+1]; | |
133 xyz2[2] = sg->coord_xyz[(i+1)*3+2]*-1.0f; | |
134 xyz2[3] = 1.0f; | |
135 | |
136 xyz3[0] = sg->coord_xyz[(i+2)*3]; | |
137 xyz3[1] = sg->coord_xyz[(i+2)*3+1]; | |
138 xyz3[2] = sg->coord_xyz[(i+2)*3+2]*-1.0f; | |
139 xyz3[3] = 1.0f; | |
140 | |
141 // sg->matrix = 回転行列*透視変換行列 | |
142 ApplyMatrix(xyz1, sg->matrix); | |
143 ApplyMatrix(xyz2, sg->matrix); | |
144 ApplyMatrix(xyz3, sg->matrix); | |
145 | |
146 xyz1[0] /= xyz1[2]; | |
147 xyz1[1] /= xyz1[2]; | |
148 xyz2[0] /= xyz2[2]; | |
149 xyz2[1] /= xyz2[2]; | |
150 xyz3[0] /= xyz3[2]; | |
151 xyz3[1] /= xyz3[2]; | |
152 | |
153 triangle->ver1.x = xyz1[0]; | |
154 triangle->ver1.y = xyz1[1]; | |
155 triangle->ver1.z = xyz1[2]; | |
156 triangle->ver1.tex_x = sg->coord_tex[(i+0)*3]; | |
157 triangle->ver1.tex_y = sg->coord_tex[(i+0)*3+1]; | |
158 | |
159 triangle->ver2.x = xyz2[0]; | |
160 triangle->ver2.y = xyz2[1]; | |
161 triangle->ver2.z = xyz2[2]; | |
162 triangle->ver2.tex_x = sg->coord_tex[(i+1)*3]; | |
163 triangle->ver2.tex_y = sg->coord_tex[(i+1)*3+1]; | |
164 | |
165 triangle->ver3.x = xyz3[0]; | |
166 triangle->ver3.y = xyz3[1]; | |
167 triangle->ver3.z = xyz3[2]; | |
168 triangle->ver3.tex_x = sg->coord_tex[(i+2)*3]; | |
169 triangle->ver3.tex_y = sg->coord_tex[(i+2)*3+1]; | |
170 | |
171 normal1[0] = sg->normal[(i+0)*3]; | |
172 normal1[1] = sg->normal[(i+0)*3+1]; | |
173 normal1[2] = sg->normal[(i+0)*3+2]*-1.0f; | |
762 | 174 //normal1[3] = 1.0f; |
175 normal1[3] = 0.0f; | |
507 | 176 |
177 normal2[0] = sg->normal[(i+1)*3]; | |
178 normal2[1] = sg->normal[(i+1)*3+1]; | |
179 normal2[2] = sg->normal[(i+1)*3+2]*-1.0f; | |
762 | 180 //normal2[3] = 1.0f; |
181 normal2[3] = 0.0f; | |
507 | 182 |
183 normal3[0] = sg->normal[(i+2)*3]; | |
184 normal3[1] = sg->normal[(i+2)*3+1]; | |
185 normal3[2] = sg->normal[(i+2)*3+2]*-1.0f; | |
762 | 186 //normal3[3] = 1.0f; |
187 normal3[3] = 0.0f; | |
507 | 188 |
738 | 189 ApplyNormalMatrix(normal1,sg->real_matrix); |
190 ApplyNormalMatrix(normal2,sg->real_matrix); | |
191 ApplyNormalMatrix(normal3,sg->real_matrix); | |
192 | |
193 normal1[0] /= normal1[2]; | |
194 normal1[1] /= normal1[2]; | |
195 | |
196 normal2[0] /= normal2[2]; | |
197 normal2[1] /= normal2[2]; | |
198 | |
199 normal3[0] /= normal3[2]; | |
200 normal3[1] /= normal3[2]; | |
507 | 201 |
202 triangle->normal1.x = normal1[0]; | |
203 triangle->normal1.y = normal1[1]; | |
204 triangle->normal1.z = normal1[2]; | |
205 | |
206 triangle->normal2.x = normal2[0]; | |
207 triangle->normal2.y = normal2[1]; | |
208 triangle->normal2.z = normal2[2]; | |
209 | |
210 triangle->normal3.x = normal3[0]; | |
211 triangle->normal3.y = normal3[1]; | |
212 triangle->normal3.z = normal3[2]; | |
213 | |
214 triangle->tex_info.addr = sg->texture_info.pixels; | |
215 triangle->tex_info.width = sg->texture_info.t_w; | |
216 triangle->tex_info.height = sg->texture_info.t_h; | |
217 triangle->tex_info.scale_max = sg->texture_info.scale_max; | |
218 } | |
219 } | |
220 | |
221 if (sg->children != NULL) { | |
222 sg = sg->children; | |
223 } else if (sg->brother != NULL) { | |
224 sg = sg->brother; | |
225 } else { | |
226 while (sg) { | |
227 if (sg->brother != NULL) { | |
228 sg = sg->brother; | |
229 break; | |
230 } else { | |
231 if (sg->parent == NULL) { | |
232 sg = NULL; | |
233 break; | |
234 } else { | |
235 sg = sg->parent; | |
236 } | |
237 } | |
238 } | |
239 } | |
240 } | |
241 | |
242 smanager->dma_wait(PP_STORE); | |
603
42c94f85c779
long -> memaddr (64 or 32)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
602
diff
changeset
|
243 smanager->dma_store(pp, (memaddr)pp_addr, |
507 | 244 sizeof(PolygonPack), PP_STORE); |
245 smanager->dma_wait(PP_STORE); | |
246 | |
247 free(pp); | |
248 free(send_pp); | |
249 | |
250 return 0; | |
860 | 251 |
252 #endif | |
253 | |
507 | 254 } |