Mercurial > hg > Game > Cerium
annotate Renderer/Engine/spe/CreatePolygonFromSceneGraph.cc @ 1319:31455d34e502 draft
collada file reader minor changes.
author | Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 18 Dec 2011 09:39:14 +0900 |
parents | cc1a50cac83d |
children | 95b114c66e14 |
rev | line source |
---|---|
1013 | 1 /** |
2 * SceneGraph が増えてくると動かなくなるかもしれない。 | |
3 * 一応 mainMem とかで動くようになるとは思うけど。 | |
4 * だめだったら、そこら辺が怪しいと思うべき | |
5 */ | |
6 | |
7 #include "CreatePolygonFromSceneGraph.h" | |
8 #include "polygon_pack.h" | |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
9 #include "texture.h" |
1013 | 10 |
1161
cc1a50cac83d
use MemorySegment API for pp load. do not check execution of the cell side. to be continued..
Yutaka_Kinjyo
parents:
1160
diff
changeset
|
11 #define STATUS_NUM 3 |
cc1a50cac83d
use MemorySegment API for pp load. do not check execution of the cell side. to be continued..
Yutaka_Kinjyo
parents:
1160
diff
changeset
|
12 |
1129 | 13 SchedDefineTask(CreatePolygonFromSceneGraph); |
1013 | 14 |
15 /** | |
16 * ベクトルに行列を乗算する | |
17 * @param[out] v vector (float[4]) | |
18 * @param[in] m matrix (float[16]) | |
19 */ | |
20 static void | |
21 ApplyMatrix(float *v, float *m) | |
22 { | |
23 float t[4]; | |
24 | |
25 t[0] = v[0]; | |
26 t[1] = v[1]; | |
27 t[2] = v[2]; | |
28 t[3] = v[3]; | |
29 | |
30 for (int i = 0; i < 4; i++) { | |
31 v[i] = t[0]*m[i] + t[1]*m[i+4] + t[2]*m[i+8] + t[3]*m[i+12]; | |
32 } | |
33 } | |
34 | |
35 | |
36 static int | |
1129 | 37 run(SchedTask *smanager, void *rbuf, void *wbuf) |
1013 | 38 { |
39 float xyz1[4], xyz2[4], xyz3[4]; | |
40 float normal1[4],normal2[4],normal3[4]; | |
41 | |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
42 //pp, matrix, real_matrix を受け取る |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
43 PolygonPackPtr in_pp = (PolygonPackPtr)smanager->get_input(rbuf, 0); |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
44 float *matrix = (float*)smanager->get_input(rbuf, 1); |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
45 float *real_matrix = (float*)smanager->get_input(rbuf, 2); |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
46 texture_list *tritexinfo = (texture_list*)smanager->get_input(rbuf, 3); |
1129 | 47 |
48 PolygonPackPtr next = (PolygonPackPtr)smanager->get_param(0); | |
1026 | 49 |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
50 PolygonPackPtr out_pp = (PolygonPackPtr)smanager->get_output(wbuf, 0); |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
51 out_pp->info.size = in_pp->info.size; |
1129 | 52 out_pp->next = next; |
53 | |
54 if (in_pp->info.size == 0) { | |
55 printf("in_pp->info.size = 0\n"); | |
56 } | |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
57 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
58 for (int i = 0; i < in_pp->info.size; i++) { |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
59 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
60 TrianglePack tri = in_pp->tri[i]; |
1013 | 61 |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
62 xyz1[0] = tri.ver1.x; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
63 xyz1[1] = tri.ver1.y; |
1129 | 64 xyz1[2] = tri.ver1.z * -1.0f; |
1013 | 65 xyz1[3] = 1.0f; |
66 | |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
67 xyz2[0] = tri.ver2.x; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
68 xyz2[1] = tri.ver2.y; |
1129 | 69 xyz2[2] = tri.ver2.z * -1.0f; |
1013 | 70 xyz2[3] = 1.0f; |
71 | |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
72 xyz3[0] = tri.ver3.x; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
73 xyz3[1] = tri.ver3.y; |
1129 | 74 xyz3[2] = tri.ver3.z * -1.0f; |
1013 | 75 xyz3[3] = 1.0f; |
76 | |
77 // matrix = 回転行列*透視変換行列 | |
78 ApplyMatrix(xyz1, matrix); | |
79 ApplyMatrix(xyz2, matrix); | |
80 ApplyMatrix(xyz3, matrix); | |
81 | |
82 xyz1[0] /= xyz1[2]; | |
83 xyz1[1] /= xyz1[2]; | |
84 xyz2[0] /= xyz2[2]; | |
85 xyz2[1] /= xyz2[2]; | |
86 xyz3[0] /= xyz3[2]; | |
87 xyz3[1] /= xyz3[2]; | |
88 | |
1129 | 89 TrianglePackPtr triangle = &out_pp->tri[i]; |
1026 | 90 |
1129 | 91 triangle->ver1.x = xyz1[0]; |
92 triangle->ver1.y = xyz1[1]; | |
93 triangle->ver1.z = xyz1[2]; | |
94 triangle->ver1.tex_x = tri.ver1.tex_x; | |
95 triangle->ver1.tex_y = tri.ver1.tex_y; | |
1013 | 96 |
1129 | 97 triangle->ver2.x = xyz2[0]; |
98 triangle->ver2.y = xyz2[1]; | |
99 triangle->ver2.z = xyz2[2]; | |
100 triangle->ver2.tex_x = tri.ver2.tex_x; | |
101 triangle->ver2.tex_y = tri.ver2.tex_y; | |
1013 | 102 |
1129 | 103 triangle->ver3.x = xyz3[0]; |
104 triangle->ver3.y = xyz3[1]; | |
105 triangle->ver3.z = xyz3[2]; | |
106 triangle->ver3.tex_x = tri.ver3.tex_x; | |
107 triangle->ver3.tex_y = tri.ver3.tex_y; | |
1013 | 108 |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
109 normal1[0] = tri.normal1.x; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
110 normal1[1] = tri.normal1.y; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
111 normal1[2] = tri.normal1.z * -1.0f; |
1013 | 112 //normal1[3] = 1.0f; |
113 normal1[3] = 0.0f; | |
114 | |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
115 normal2[0] = tri.normal2.x; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
116 normal2[1] = tri.normal2.y; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
117 normal2[2] = tri.normal2.z * -1.0f; |
1013 | 118 //normal2[3] = 1.0f; |
119 normal2[3] = 0.0f; | |
120 | |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
121 normal3[0] = tri.normal3.x; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
122 normal3[1] = tri.normal3.y; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
123 normal3[2] = tri.normal3.z * -1.0f; |
1013 | 124 //normal3[3] = 1.0f; |
125 normal3[3] = 0.0f; | |
126 | |
1129 | 127 ApplyMatrix(normal1,real_matrix); |
128 ApplyMatrix(normal2,real_matrix); | |
129 ApplyMatrix(normal3,real_matrix); | |
1013 | 130 |
131 normal1[0] /= normal1[2]; | |
132 normal1[1] /= normal1[2]; | |
133 | |
134 normal2[0] /= normal2[2]; | |
135 normal2[1] /= normal2[2]; | |
136 | |
137 normal3[0] /= normal3[2]; | |
138 normal3[1] /= normal3[2]; | |
139 | |
1129 | 140 triangle->normal1.x = normal1[0]; |
141 triangle->normal1.y = normal1[1]; | |
142 triangle->normal1.z = normal1[2]; | |
1013 | 143 |
1129 | 144 triangle->normal2.x = normal2[0]; |
145 triangle->normal2.y = normal2[1]; | |
146 triangle->normal2.z = normal2[2]; | |
1013 | 147 |
1129 | 148 triangle->normal3.x = normal3[0]; |
149 triangle->normal3.y = normal3[1]; | |
150 triangle->normal3.z = normal3[2]; | |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
151 |
1129 | 152 triangle->tex_info.addr = tritexinfo->pixels; |
153 triangle->tex_info.width = tritexinfo->t_w; | |
154 triangle->tex_info.height = tritexinfo->t_h; | |
155 triangle->tex_info.scale_max = tritexinfo->scale_max; | |
1161
cc1a50cac83d
use MemorySegment API for pp load. do not check execution of the cell side. to be continued..
Yutaka_Kinjyo
parents:
1160
diff
changeset
|
156 |
cc1a50cac83d
use MemorySegment API for pp load. do not check execution of the cell side. to be continued..
Yutaka_Kinjyo
parents:
1160
diff
changeset
|
157 float y[STATUS_NUM] = { xyz1[1], xyz2[1], xyz3[1] }; |
cc1a50cac83d
use MemorySegment API for pp load. do not check execution of the cell side. to be continued..
Yutaka_Kinjyo
parents:
1160
diff
changeset
|
158 int span_num = 0; |
cc1a50cac83d
use MemorySegment API for pp load. do not check execution of the cell side. to be continued..
Yutaka_Kinjyo
parents:
1160
diff
changeset
|
159 span_num = compare_value(y, STATUS_NUM); |
cc1a50cac83d
use MemorySegment API for pp load. do not check execution of the cell side. to be continued..
Yutaka_Kinjyo
parents:
1160
diff
changeset
|
160 out_pp->info.span_num += span_num; |
cc1a50cac83d
use MemorySegment API for pp load. do not check execution of the cell side. to be continued..
Yutaka_Kinjyo
parents:
1160
diff
changeset
|
161 |
cc1a50cac83d
use MemorySegment API for pp load. do not check execution of the cell side. to be continued..
Yutaka_Kinjyo
parents:
1160
diff
changeset
|
162 |
1013 | 163 } |
1026 | 164 |
1013 | 165 return 0; |
166 } |