Mercurial > hg > Members > kono > Cerium
annotate Renderer/Engine/task/CreatePolygonFromSceneGraph.cc @ 639:70c5c2d2eb24
fix
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 19 Nov 2009 18:45:24 +0900 |
parents | 42c94f85c779 |
children | 510424e175ae |
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 { | |
76 float xyz1[4], xyz2[4], xyz3[4]; | |
77 /* | |
78 *頂点毎に法線ベクトルがある | |
79 *面毎じゃない | |
80 *なにかに使うのかな?わからないから、一応とっておく。 | |
81 *by yutaka | |
82 */ | |
83 float normal1[4],normal2[4],normal3[4]; | |
84 | |
85 SceneGraphPtr sg_top = (SceneGraphPtr)smanager->get_param(0); | |
86 SceneGraphPtr sg = sg_top; | |
87 | |
88 PolygonPackPtr pp | |
89 = (PolygonPackPtr)smanager->allocate(sizeof(PolygonPack)); | |
90 PolygonPackPtr send_pp | |
91 = (PolygonPackPtr)smanager->allocate(sizeof(PolygonPack)); | |
92 PolygonPackPtr pp_addr = (PolygonPackPtr)smanager->get_param(1); | |
93 PolygonPackPtr tmp_pp; | |
94 | |
95 pp->init(); | |
96 send_pp->init(); | |
97 | |
98 while (sg) { | |
99 if (sg->flag_drawable) { // sg->isDrawable() とかの方がよくね? | |
100 for (int i = 0; i < sg->size; i += 3) { | |
101 if (pp->info.size >= MAX_SIZE_TRIANGLE) { | |
102 PolygonPackPtr next; | |
103 | |
104 smanager->mainMem_alloc(0, sizeof(PolygonPack)); | |
105 smanager->mainMem_wait(); | |
106 next = (PolygonPackPtr)smanager->mainMem_get(0); | |
107 | |
108 pp->next = next; | |
109 | |
110 tmp_pp = pp; | |
111 pp = send_pp; | |
112 send_pp = tmp_pp; | |
113 | |
114 smanager->dma_wait(PP_STORE); | |
603
42c94f85c779
long -> memaddr (64 or 32)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
602
diff
changeset
|
115 smanager->dma_store(send_pp, (memaddr)pp_addr, |
507 | 116 sizeof(PolygonPack), PP_STORE); |
117 | |
118 pp_addr = next; | |
119 | |
120 smanager->dma_wait(PP_LOAD); | |
603
42c94f85c779
long -> memaddr (64 or 32)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
602
diff
changeset
|
121 smanager->dma_load(pp, (memaddr)pp_addr, |
507 | 122 sizeof(PolygonPack), PP_LOAD); |
123 smanager->dma_wait(PP_LOAD); | |
124 pp->init(); | |
125 } | |
126 | |
127 TrianglePack *triangle = &pp->tri[pp->info.size++]; | |
128 | |
129 xyz1[0] = sg->coord_xyz[(i+0)*3]; | |
130 xyz1[1] = sg->coord_xyz[(i+0)*3+1]; | |
131 xyz1[2] = sg->coord_xyz[(i+0)*3+2]*-1.0f; | |
132 xyz1[3] = 1.0f; | |
133 | |
134 xyz2[0] = sg->coord_xyz[(i+1)*3]; | |
135 xyz2[1] = sg->coord_xyz[(i+1)*3+1]; | |
136 xyz2[2] = sg->coord_xyz[(i+1)*3+2]*-1.0f; | |
137 xyz2[3] = 1.0f; | |
138 | |
139 xyz3[0] = sg->coord_xyz[(i+2)*3]; | |
140 xyz3[1] = sg->coord_xyz[(i+2)*3+1]; | |
141 xyz3[2] = sg->coord_xyz[(i+2)*3+2]*-1.0f; | |
142 xyz3[3] = 1.0f; | |
143 | |
144 // sg->matrix = 回転行列*透視変換行列 | |
145 ApplyMatrix(xyz1, sg->matrix); | |
146 ApplyMatrix(xyz2, sg->matrix); | |
147 ApplyMatrix(xyz3, sg->matrix); | |
148 | |
149 xyz1[0] /= xyz1[2]; | |
150 xyz1[1] /= xyz1[2]; | |
151 xyz2[0] /= xyz2[2]; | |
152 xyz2[1] /= xyz2[2]; | |
153 xyz3[0] /= xyz3[2]; | |
154 xyz3[1] /= xyz3[2]; | |
155 | |
156 triangle->ver1.x = xyz1[0]; | |
157 triangle->ver1.y = xyz1[1]; | |
158 triangle->ver1.z = xyz1[2]; | |
159 triangle->ver1.tex_x = sg->coord_tex[(i+0)*3]; | |
160 triangle->ver1.tex_y = sg->coord_tex[(i+0)*3+1]; | |
161 | |
162 triangle->ver2.x = xyz2[0]; | |
163 triangle->ver2.y = xyz2[1]; | |
164 triangle->ver2.z = xyz2[2]; | |
165 triangle->ver2.tex_x = sg->coord_tex[(i+1)*3]; | |
166 triangle->ver2.tex_y = sg->coord_tex[(i+1)*3+1]; | |
167 | |
168 triangle->ver3.x = xyz3[0]; | |
169 triangle->ver3.y = xyz3[1]; | |
170 triangle->ver3.z = xyz3[2]; | |
171 triangle->ver3.tex_x = sg->coord_tex[(i+2)*3]; | |
172 triangle->ver3.tex_y = sg->coord_tex[(i+2)*3+1]; | |
173 | |
174 | |
175 normal1[0] = sg->normal[(i+0)*3]; | |
176 normal1[1] = sg->normal[(i+0)*3+1]; | |
177 normal1[2] = sg->normal[(i+0)*3+2]*-1.0f; | |
178 normal1[3] = 1.0f; | |
179 | |
180 normal2[0] = sg->normal[(i+1)*3]; | |
181 normal2[1] = sg->normal[(i+1)*3+1]; | |
182 normal2[2] = sg->normal[(i+1)*3+2]*-1.0f; | |
183 normal2[3] = 1.0f; | |
184 | |
185 normal3[0] = sg->normal[(i+2)*3]; | |
186 normal3[1] = sg->normal[(i+2)*3+1]; | |
187 normal3[2] = sg->normal[(i+2)*3+2]*-1.0f; | |
188 normal3[3] = 1.0f; | |
189 | |
190 ApplyNormalMatrix(normal1,sg->matrix); | |
191 | |
597 | 192 //ここでpolygonに法線ベクトルの情報がわたった |
507 | 193 |
194 triangle->normal1.x = normal1[0]; | |
195 triangle->normal1.y = normal1[1]; | |
196 triangle->normal1.z = normal1[2]; | |
197 | |
198 triangle->normal2.x = normal2[0]; | |
199 triangle->normal2.y = normal2[1]; | |
200 triangle->normal2.z = normal2[2]; | |
201 | |
202 triangle->normal3.x = normal3[0]; | |
203 triangle->normal3.y = normal3[1]; | |
204 triangle->normal3.z = normal3[2]; | |
205 | |
206 | |
207 | |
208 triangle->tex_info.addr = sg->texture_info.pixels; | |
209 triangle->tex_info.width = sg->texture_info.t_w; | |
210 triangle->tex_info.height = sg->texture_info.t_h; | |
211 triangle->tex_info.scale_max = sg->texture_info.scale_max; | |
212 } | |
213 } | |
214 | |
215 if (sg->children != NULL) { | |
216 sg = sg->children; | |
217 } else if (sg->brother != NULL) { | |
218 sg = sg->brother; | |
219 } else { | |
220 while (sg) { | |
221 if (sg->brother != NULL) { | |
222 sg = sg->brother; | |
223 break; | |
224 } else { | |
225 if (sg->parent == NULL) { | |
226 sg = NULL; | |
227 break; | |
228 } else { | |
229 sg = sg->parent; | |
230 } | |
231 } | |
232 } | |
233 } | |
234 } | |
235 | |
236 smanager->dma_wait(PP_STORE); | |
603
42c94f85c779
long -> memaddr (64 or 32)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
602
diff
changeset
|
237 smanager->dma_store(pp, (memaddr)pp_addr, |
507 | 238 sizeof(PolygonPack), PP_STORE); |
239 smanager->dma_wait(PP_STORE); | |
240 | |
241 free(pp); | |
242 free(send_pp); | |
243 | |
244 return 0; | |
245 } |