Mercurial > hg > Game > Cerium
annotate Renderer/Engine/spe/CreatePolygonFromSceneGraph.cc @ 1129:a8bffdb5d2e3 draft
bus error
author | yutaka@localhost.localdomain |
---|---|
date | Sun, 13 Feb 2011 07:20:55 +0900 |
parents | 6043da6e48f1 |
children | 5664473b4dba |
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 |
1129 | 11 SchedDefineTask(CreatePolygonFromSceneGraph); |
1013 | 12 |
13 /** | |
14 * ベクトルに行列を乗算する | |
15 * @param[out] v vector (float[4]) | |
16 * @param[in] m matrix (float[16]) | |
17 */ | |
18 static void | |
19 ApplyMatrix(float *v, float *m) | |
20 { | |
21 float t[4]; | |
22 | |
23 t[0] = v[0]; | |
24 t[1] = v[1]; | |
25 t[2] = v[2]; | |
26 t[3] = v[3]; | |
27 | |
28 for (int i = 0; i < 4; i++) { | |
29 v[i] = t[0]*m[i] + t[1]*m[i+4] + t[2]*m[i+8] + t[3]*m[i+12]; | |
30 } | |
31 } | |
32 | |
33 | |
34 static int | |
1129 | 35 run(SchedTask *smanager, void *rbuf, void *wbuf) |
1013 | 36 { |
37 float xyz1[4], xyz2[4], xyz3[4]; | |
38 float normal1[4],normal2[4],normal3[4]; | |
39 | |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
40 //pp, matrix, real_matrix を受け取る |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
41 PolygonPackPtr in_pp = (PolygonPackPtr)smanager->get_input(rbuf, 0); |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
42 float *matrix = (float*)smanager->get_input(rbuf, 1); |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
43 float *real_matrix = (float*)smanager->get_input(rbuf, 2); |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
44 texture_list *tritexinfo = (texture_list*)smanager->get_input(rbuf, 3); |
1129 | 45 |
46 PolygonPackPtr next = (PolygonPackPtr)smanager->get_param(0); | |
1026 | 47 |
1018
3a6766377905
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
48 |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
49 PolygonPackPtr out_pp = (PolygonPackPtr)smanager->get_output(wbuf, 0); |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
50 out_pp->info.size = in_pp->info.size; |
1129 | 51 out_pp->next = next; |
52 | |
53 if (in_pp->info.size == 0) { | |
54 printf("in_pp->info.size = 0\n"); | |
55 } | |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
56 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
57 for (int i = 0; i < in_pp->info.size; i++) { |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
58 |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
59 TrianglePack tri = in_pp->tri[i]; |
1013 | 60 |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
61 xyz1[0] = tri.ver1.x; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
62 xyz1[1] = tri.ver1.y; |
1129 | 63 xyz1[2] = tri.ver1.z * -1.0f; |
1013 | 64 xyz1[3] = 1.0f; |
65 | |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
66 xyz2[0] = tri.ver2.x; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
67 xyz2[1] = tri.ver2.y; |
1129 | 68 xyz2[2] = tri.ver2.z * -1.0f; |
1013 | 69 xyz2[3] = 1.0f; |
70 | |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
71 xyz3[0] = tri.ver3.x; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
72 xyz3[1] = tri.ver3.y; |
1129 | 73 xyz3[2] = tri.ver3.z * -1.0f; |
1013 | 74 xyz3[3] = 1.0f; |
75 | |
76 // matrix = 回転行列*透視変換行列 | |
77 ApplyMatrix(xyz1, matrix); | |
78 ApplyMatrix(xyz2, matrix); | |
79 ApplyMatrix(xyz3, matrix); | |
80 | |
81 xyz1[0] /= xyz1[2]; | |
82 xyz1[1] /= xyz1[2]; | |
83 xyz2[0] /= xyz2[2]; | |
84 xyz2[1] /= xyz2[2]; | |
85 xyz3[0] /= xyz3[2]; | |
86 xyz3[1] /= xyz3[2]; | |
87 | |
1129 | 88 TrianglePackPtr triangle = &out_pp->tri[i]; |
1026 | 89 |
1129 | 90 triangle->ver1.x = xyz1[0]; |
91 triangle->ver1.y = xyz1[1]; | |
92 triangle->ver1.z = xyz1[2]; | |
93 triangle->ver1.tex_x = tri.ver1.tex_x; | |
94 triangle->ver1.tex_y = tri.ver1.tex_y; | |
1013 | 95 |
1129 | 96 triangle->ver2.x = xyz2[0]; |
97 triangle->ver2.y = xyz2[1]; | |
98 triangle->ver2.z = xyz2[2]; | |
99 triangle->ver2.tex_x = tri.ver2.tex_x; | |
100 triangle->ver2.tex_y = tri.ver2.tex_y; | |
1013 | 101 |
1129 | 102 triangle->ver3.x = xyz3[0]; |
103 triangle->ver3.y = xyz3[1]; | |
104 triangle->ver3.z = xyz3[2]; | |
105 triangle->ver3.tex_x = tri.ver3.tex_x; | |
106 triangle->ver3.tex_y = tri.ver3.tex_y; | |
1013 | 107 |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
108 normal1[0] = tri.normal1.x; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
109 normal1[1] = tri.normal1.y; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
110 normal1[2] = tri.normal1.z * -1.0f; |
1013 | 111 //normal1[3] = 1.0f; |
112 normal1[3] = 0.0f; | |
113 | |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
114 normal2[0] = tri.normal2.x; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
115 normal2[1] = tri.normal2.y; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
116 normal2[2] = tri.normal2.z * -1.0f; |
1013 | 117 //normal2[3] = 1.0f; |
118 normal2[3] = 0.0f; | |
119 | |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
120 normal3[0] = tri.normal3.x; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
121 normal3[1] = tri.normal3.y; |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
122 normal3[2] = tri.normal3.z * -1.0f; |
1013 | 123 //normal3[3] = 1.0f; |
124 normal3[3] = 0.0f; | |
125 | |
1129 | 126 ApplyMatrix(normal1,real_matrix); |
127 ApplyMatrix(normal2,real_matrix); | |
128 ApplyMatrix(normal3,real_matrix); | |
1013 | 129 |
130 normal1[0] /= normal1[2]; | |
131 normal1[1] /= normal1[2]; | |
132 | |
133 normal2[0] /= normal2[2]; | |
134 normal2[1] /= normal2[2]; | |
135 | |
136 normal3[0] /= normal3[2]; | |
137 normal3[1] /= normal3[2]; | |
138 | |
1129 | 139 triangle->normal1.x = normal1[0]; |
140 triangle->normal1.y = normal1[1]; | |
141 triangle->normal1.z = normal1[2]; | |
1013 | 142 |
1129 | 143 triangle->normal2.x = normal2[0]; |
144 triangle->normal2.y = normal2[1]; | |
145 triangle->normal2.z = normal2[2]; | |
1013 | 146 |
1129 | 147 triangle->normal3.x = normal3[0]; |
148 triangle->normal3.y = normal3[1]; | |
149 triangle->normal3.z = normal3[2]; | |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1026
diff
changeset
|
150 |
1129 | 151 triangle->tex_info.addr = tritexinfo->pixels; |
152 triangle->tex_info.width = tritexinfo->t_w; | |
153 triangle->tex_info.height = tritexinfo->t_h; | |
154 triangle->tex_info.scale_max = tritexinfo->scale_max; | |
1013 | 155 } |
1026 | 156 |
1013 | 157 return 0; |
158 } |