Mercurial > hg > Game > Cerium
annotate Renderer/Engine/SceneGraph.cc @ 1299:f0e805c09ed6 draft
minor fix xml_walk and pickup_float, not work yet.
author | Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 04 Dec 2011 18:50:53 +0900 |
parents | 90efd2aac2cb |
children | ab9b7d21b32b |
rev | line source |
---|---|
539 | 1 #include <iostream> |
2 #include <SDL.h> | |
3 #include <SDL_opengl.h> | |
4 #include <SDL_image.h> | |
5 #include <libxml/parser.h> | |
1049
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
6 #include <string.h> |
539 | 7 #include "SceneGraph.h" |
8 #include "xml.h" | |
1050 | 9 #include "matrix_calc.h" |
539 | 10 #include "TextureHash.h" |
11 #include "texture.h" | |
12 #include "TaskManager.h" | |
1125 | 13 #include "polygon_pack.h" |
1205
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
14 #include <ft2build.h> |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
15 #include <freetype/freetype.h> |
539 | 16 |
17 using namespace std; | |
18 | |
19 SceneGraphPtr scene_graph = NULL; | |
20 SceneGraphPtr scene_graph_viewer = NULL; | |
21 | |
22 static TextureHash texture_hash; | |
860 | 23 texture_list list[TABLE_SIZE]; |
24 | |
539 | 25 extern int decode(char *cont, FILE *outfile); |
26 | |
27 static void | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
28 no_move(SceneGraphPtr self, void *sgroot_, int screen_w, int screen_h) {} |
539 | 29 |
30 static void | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
31 no_collision(SceneGraphPtr self, void *sgroot_, int screen_w, int screen_h, |
539 | 32 SceneGraphPtr tree) {} |
33 | |
34 /** | |
35 * 事前に計算したテクスチャの最大縮小率 scale まで、 | |
36 * テクスチャを 1/2 縮小していく。 | |
37 * このとき、テクスチャは TEXTURE_SPLIT_PIXELx2 のブロック (Tile) で分割し、 | |
38 * これらを連続したメモリ領域に格納していく。 | |
39 * 以下の (1), (2), (3) を Tapestry と呼ぶ | |
40 * | |
41 * 例 scale = 4 の場合 | |
42 * | |
43 * Tapestry(1) 1/1 | |
44 * +---+---+---+---+ | |
45 * | 0 | 1 | 2 | 3 | | |
46 * +---+---+---+---+ | |
47 * | 4 | 5 | 6 | 7 | (2) 1/2 | |
48 * +---+---+---+---+ +---+---+ | |
49 * | 8 | 9 | 10| 11| | 16| 17| (3) 1/4 | |
50 * +---+---+---+---+ +---+---+ +---+ | |
51 * | 12| 13| 14| 15| | 18| 19| | 20| | |
52 * +---+---+---+---+ +---+---+ +---| | |
53 * | |
54 * (1) (2) (3) | |
55 * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | |
56 * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * | * | * | 14| 15| 16| 17| 18| 19| 20| | |
57 * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | |
58 * | |
59 * @param[in] tex_w Width of orignal texture | |
60 * @param[in] tex_h Height of orignal texture | |
61 * @param[in] tex_src Original texture | |
62 * @param[in] all_pixel_num Tapestry の合計 pixel 数 | |
63 * @param[in] scale テクスチャの最大縮小率 (= 2^n) | |
64 * @return (1) のアドレス | |
65 */ | |
1049
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
66 |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
67 |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
68 uint32 white[256] __attribute__((aligned(16))); |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
69 |
539 | 70 static uint32* |
1049
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
71 makeTapestry(TaskManager *manager, uint32 tex_w, uint32 tex_h, uint32 *tex_src, |
539 | 72 int all_pixel_num, int scale_cnt) |
73 { | |
1049
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
74 if (tex_w==0 && tex_h==0) { |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
75 // non texture case |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
76 uint32 pattern = SDL_BYTEORDER == SDL_LIL_ENDIAN? 0x00ffffff : 0xffffff00; /* OpenGL RGBA masks */ |
1053 | 77 if (white[0]!=pattern) { // dumb! |
78 #if 1 | |
79 for(int i=0;i<256;i++) | |
80 white[i] = pattern; | |
81 #else | |
1049
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
82 memset_pattern4(white,&pattern,256); |
1053 | 83 #endif |
84 } | |
1049
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
85 return white; |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
86 } |
539 | 87 |
1049
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
88 uint32 t = 0; |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
89 uint32 diff = TEXTURE_SPLIT_PIXEL; |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
90 uint32 p_diff = 1; |
539 | 91 |
92 uint32 *tex_dest = (uint32*)manager->allocate(sizeof(int)*all_pixel_num); | |
1092
b99abedb5523
fix h w in makeTapestry
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1053
diff
changeset
|
93 // uint32 *tex_src_max = (uint32*)( tex_src + tex_h*tex_w); |
539 | 94 |
1092
b99abedb5523
fix h w in makeTapestry
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1053
diff
changeset
|
95 // uint32 alpha = SDL_BYTEORDER == SDL_LIL_ENDIAN? 0xff000000 : 0xff; /* OpenGL RGBA masks */ |
b99abedb5523
fix h w in makeTapestry
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1053
diff
changeset
|
96 uint32 alpha = tex_src[0]; |
1049
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
97 |
539 | 98 while (scale_cnt) { |
1049
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
99 // we should use average, except clear one |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
100 for (uint32 y = 0; y < align(tex_h,diff); y += diff) { |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
101 for (uint32 x = 0; x < align(tex_w,diff); x += diff) { |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
102 for (uint32 j = 0; j < diff; j += p_diff) { |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
103 for (uint32 i = 0; i < diff; i += p_diff) { |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
104 tex_dest[t++] = |
1092
b99abedb5523
fix h w in makeTapestry
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1053
diff
changeset
|
105 (x+i<tex_w && y+j<tex_h) ? tex_src[(x+i) + tex_w*(y+j)]: alpha; |
539 | 106 } |
107 } | |
108 } | |
109 } | |
110 | |
1092
b99abedb5523
fix h w in makeTapestry
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1053
diff
changeset
|
111 diff <<= 1; p_diff <<= 1; |
539 | 112 scale_cnt >>= 1; |
113 } | |
114 | |
115 return tex_dest; | |
116 } | |
117 | |
118 | |
119 /** | |
120 * 何の情報も持ってない SceneGraph の生成 | |
121 * 今のところ、とりあえず木構造の繋がりに使うぐらい | |
122 */ | |
1143 | 123 SceneGraph::SceneGraph(TaskManager *manager) |
539 | 124 { |
1129 | 125 |
539 | 126 init(); |
1143 | 127 |
1169 | 128 matrix = (float*)manager->allocate(sizeof(float)*16); |
129 real_matrix = (float*)manager->allocate(sizeof(float)*16); | |
130 texture_info = (texture_list*)manager->allocate(sizeof(texture_list)); | |
1143 | 131 |
132 texture_info->texture_id = -1; | |
133 | |
134 for (int i = 0; i < 16; i++) { | |
135 matrix[i] = 0; | |
136 real_matrix[i] = 0; | |
137 } | |
1292
90efd2aac2cb
add matrix test and debug light vector
Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
1277
diff
changeset
|
138 |
1254 | 139 for (int i = 0; i < 4; i++) { |
140 matrix[i*4+i] = 1; | |
141 real_matrix[i*4+i] = 1; | |
142 } | |
1143 | 143 |
144 | |
539 | 145 finalize = &SceneGraph::finalize_copy; |
146 | |
147 this->name = "NULLPO"; | |
1141 | 148 |
539 | 149 } |
150 | |
151 /** | |
152 * orig のコピーとして SceneGraph を生成する | |
153 */ | |
1169 | 154 SceneGraph::SceneGraph( TaskManager *manager, SceneGraphPtr orig) |
539 | 155 { |
908 | 156 |
539 | 157 init(); |
1129 | 158 |
539 | 159 memcpy(this, orig, sizeof(SceneGraph)); |
160 | |
1169 | 161 matrix = (float*)manager->allocate(sizeof(float)*16); |
162 real_matrix = (float*)manager->allocate(sizeof(float)*16); | |
163 texture_info = (texture_list*)manager->allocate(sizeof(texture_list)); | |
164 | |
165 for (int i = 0; i < 16; i++) { | |
166 matrix[i] = orig->matrix[i]; | |
167 real_matrix[i] = orig->real_matrix[i]; | |
168 } | |
169 | |
170 memcpy(texture_info, orig->texture_info, sizeof(texture_list)); | |
171 | |
539 | 172 // コピーしない |
173 //flag_remove = 0; | |
174 //flag_drawable = 1; | |
175 next = NULL; | |
176 prev = NULL; | |
177 last = NULL; | |
178 | |
179 parent = NULL; | |
180 brother = NULL; | |
181 children = NULL; | |
182 lastChild = NULL; | |
183 | |
184 finalize = &SceneGraph::finalize_copy; | |
185 | |
186 frame = 0; | |
187 } | |
188 | |
189 | |
190 /* construct polygon from xmlNode. */ | |
191 SceneGraph::SceneGraph(TaskManager *manager, xmlNodePtr surface) | |
192 { | |
1143 | 193 |
539 | 194 init(); |
1143 | 195 |
1226
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
196 matrix = (float*)manager->allocate(sizeof(float)*16*2); |
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
197 real_matrix = matrix+16; |
1169 | 198 texture_info = (texture_list*)manager->allocate(sizeof(texture_list)); |
1143 | 199 texture_info->texture_id = -1; |
1125 | 200 |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
201 //size : 頂点の数かな |
539 | 202 size = atoi((char *)xmlGetProp(surface,(xmlChar *)"size")); |
203 name = (char *)xmlGetProp(surface,(xmlChar *)"name"); | |
204 parent_name = (char *)xmlGetProp(surface,(xmlChar *)"parent"); | |
205 | |
908 | 206 for (int i = 0; i < 16; i++) { |
1130 | 207 matrix[i] = 0; |
908 | 208 real_matrix[i] = 0; |
209 } | |
1226
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
210 for (int i = 0; i < 4; i++) { |
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
211 matrix[i*4+i] = 1; |
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
212 real_matrix[i*4+i] = 1; |
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
213 } |
908 | 214 |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
215 if (size % 3 != 0) { |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
216 printf("vertex size is error. size %% 3 = %lld\n", size % 3); |
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
217 } |
1299
f0e805c09ed6
minor fix xml_walk and pickup_float, not work yet.
Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
1292
diff
changeset
|
218 |
1253
bb9c885c1cb5
COLLADA add read node
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
1226
diff
changeset
|
219 /* |
bb9c885c1cb5
COLLADA add read node
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
1226
diff
changeset
|
220 * MAX_SIZE_TRIANGLE:128 |
bb9c885c1cb5
COLLADA add read node
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
1226
diff
changeset
|
221 */ |
1299
f0e805c09ed6
minor fix xml_walk and pickup_float, not work yet.
Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
1292
diff
changeset
|
222 |
1136 | 223 if (size > 0) { |
1299
f0e805c09ed6
minor fix xml_walk and pickup_float, not work yet.
Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
1292
diff
changeset
|
224 |
f0e805c09ed6
minor fix xml_walk and pickup_float, not work yet.
Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
1292
diff
changeset
|
225 /* |
f0e805c09ed6
minor fix xml_walk and pickup_float, not work yet.
Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
1292
diff
changeset
|
226 * size/3 : 三角形の数 |
1253
bb9c885c1cb5
COLLADA add read node
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
1226
diff
changeset
|
227 * MAX_SIZE_TRIANGLE : 128 |
1299
f0e805c09ed6
minor fix xml_walk and pickup_float, not work yet.
Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
1292
diff
changeset
|
228 * polygon の数から、PolygonPackの数を決定する |
1253
bb9c885c1cb5
COLLADA add read node
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
1226
diff
changeset
|
229 */ |
1299
f0e805c09ed6
minor fix xml_walk and pickup_float, not work yet.
Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
1292
diff
changeset
|
230 |
1136 | 231 pp_num = (size/3 + MAX_SIZE_TRIANGLE - 1) / MAX_SIZE_TRIANGLE; |
232 pp = (PolygonPack*)manager->allocate(sizeof(PolygonPack)*pp_num); | |
233 } else { | |
234 pp_num = 0; | |
235 pp = NULL; | |
236 } | |
906
becd6fad3ae0
coord_pack is stuffed with infomation of create polygon at spe.
Yutaka_Kinjyo
parents:
891
diff
changeset
|
237 |
539 | 238 get_data(manager, surface->children); |
239 | |
240 finalize = &SceneGraph::finalize_original; | |
1108 | 241 |
539 | 242 } |
243 | |
1253
bb9c885c1cb5
COLLADA add read node
Yuhi TOMARI <e095740@ie.u-ryukyu.ac.jp>
parents:
1226
diff
changeset
|
244 |
1211 | 245 SceneGraph::SceneGraph(TaskManager *manager,const char *font,int pixels,Uint32 color,const char *string_name) { |
1205
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
246 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
247 init(); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
248 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
249 this->matrix = (float*)manager->allocate(sizeof(float)*16); |
1226
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
250 this->real_matrix = this->matrix+16; |
1205
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
251 this->texture_info = (texture_list*)manager->allocate(sizeof(texture_list)); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
252 texture_info->texture_id = -1; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
253 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
254 //size : 頂点の数かな |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
255 size = 6; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
256 parent_name = NULL; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
257 name = string_name; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
258 for (int i = 0; i < 16; i++) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
259 matrix[i] = 0; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
260 real_matrix[i] = 0; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
261 } |
1226
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
262 for (int i = 0; i < 4; i++) { |
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
263 matrix[i*4+i] = 1; |
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
264 real_matrix[i*4+i] = 1; |
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
265 } |
1205
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
266 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
267 if (size % 3 != 0) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
268 printf("vertex size is error. size %% 3 = %lld\n", size % 3); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
269 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
270 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
271 if (size > 0) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
272 pp_num = (size/3 + MAX_SIZE_TRIANGLE - 1) / MAX_SIZE_TRIANGLE; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
273 pp = (PolygonPack*)manager->allocate(sizeof(PolygonPack)*pp_num); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
274 } else { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
275 pp_num = 0; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
276 pp = NULL; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
277 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
278 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
279 create_font_data(manager, font, pixels, color, string_name); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
280 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
281 finalize = &SceneGraph::finalize_original; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
282 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
283 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
284 void |
1211 | 285 SceneGraph::create_font_data(TaskManager *manager,const char *font ,int pixels, Uint32 color, const char *string_name) |
1205
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
286 { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
287 //font_coordinate(pixels/2,pixels); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
288 font_normal(); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
289 font_model(); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
290 //font_texture(); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
291 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
292 get_font_image(manager, font, pixels, color, string_name); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
293 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
294 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
295 void |
1211 | 296 SceneGraph::get_font_image(TaskManager *manager,const char *font ,int pixels ,Uint32 color, const char *string_name) |
1205
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
297 { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
298 int tex_id; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
299 if (texture_hash.hash_regist(string_name, tex_id)) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
300 SDL_Surface *texture_image = load_font_image(font,pixels,color,string_name); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
301 if(!texture_image){ |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
302 printf("Can't load image %s\n",string_name); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
303 exit(0); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
304 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
305 texture_info->texture_id = makeTapestries(manager, texture_image,tex_id); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
306 printf("%d\n",texture_info->texture_id); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
307 tex_id = texture_info->texture_id; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
308 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
309 } else { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
310 texture_info->texture_id = tex_id; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
311 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
312 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
313 texture_info->t_w = list[tex_id].t_w; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
314 texture_info->t_h = list[tex_id].t_h; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
315 texture_info->pixels_orig = list[tex_id].pixels_orig; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
316 texture_info->pixels = list[tex_id].pixels; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
317 texture_info->scale_max = list[tex_id].scale_max; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
318 texture_info->texture_image = list[tex_id].texture_image; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
319 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
320 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
321 SDL_Surface* |
1211 | 322 SceneGraph::load_font_image(const char *font ,int pixel,Uint32 color , const char *string_name) |
1205
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
323 { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
324 //printf("laod_font_iamge"); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
325 FT_Library library; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
326 FT_Error err; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
327 err = FT_Init_FreeType(&library); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
328 if(err){ |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
329 exit(1); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
330 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
331 FT_Face face; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
332 err = FT_New_Face(library,font,0,&face);//font:フォントファイルのパス |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
333 if(err){ |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
334 exit(1); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
335 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
336 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
337 err = FT_Set_Pixel_Sizes(face,pixel,pixel); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
338 if(err){ |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
339 exit(1); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
340 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
341 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
342 u_int32_t changecode[256] = {0}; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
343 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
344 conv(string_name+5,strlen(string_name+5),changecode); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
345 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
346 unsigned int characode = changecode[0]; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
347 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
348 err = FT_Load_Char(face,characode,0); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
349 if(err){ |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
350 exit(1); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
351 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
352 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
353 err = FT_Render_Glyph(face->glyph,FT_RENDER_MODE_MONO); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
354 if(err){ |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
355 exit(1); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
356 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
357 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
358 FT_Bitmap *bm = &face->glyph->bitmap; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
359 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
360 //baseline計算 y_ppem(nominal height) - bitmap_top(topからのbaseline) |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
361 float baseline = face->size->metrics.y_ppem - face->glyph->bitmap_top; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
362 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
363 float row = 1; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
364 float width = 1; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
365 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
366 font_coordinate(baseline,face->glyph->bitmap.rows,face->glyph->bitmap.width); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
367 this->seq = face->glyph->bitmap.width; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
368 font_texture(row,width); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
369 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
370 int index = 0; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
371 Uint32 *pixels = (Uint32*)malloc(bm->rows*bm->pitch*8*4); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
372 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
373 for (int row = 0; row < bm->rows; row ++) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
374 for (int col = 0; col < bm->pitch; col ++) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
375 int c = bm->buffer[bm->pitch * row + col]; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
376 for (int bit = 7; bit >= 0; bit --) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
377 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
378 if (((c >> bit) & 1) == 0) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
379 //printf(" "); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
380 pixels[index++] = 0x0000000; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
381 } else { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
382 //printf("##"); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
383 //pixels[index++] = 0x00ffffff; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
384 pixels[index++] = color; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
385 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
386 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
387 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
388 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
389 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
390 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
391 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
392 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
393 SDL_Surface *texture_image = SDL_CreateRGBSurfaceFrom(pixels, bm->pitch*8, bm->rows, |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
394 32, bm->pitch*8*4, redMask, |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
395 greenMask, blueMask, alphaMask); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
396 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
397 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
398 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
399 if (!texture_image) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
400 printf("error\n"); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
401 return 0; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
402 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
403 SDL_Surface *tmpImage |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
404 = SDL_CreateRGBSurface(SDL_HWSURFACE, texture_image->w, |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
405 texture_image->h, 32, redMask, |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
406 greenMask, blueMask, alphaMask); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
407 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
408 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
409 SDL_Surface *converted; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
410 converted = SDL_ConvertSurface(texture_image, tmpImage->format, |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
411 SDL_HWSURFACE); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
412 if (converted != NULL) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
413 SDL_FreeSurface(texture_image); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
414 texture_image = converted; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
415 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
416 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
417 return texture_image; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
418 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
419 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
420 void |
1211 | 421 SceneGraph::conv(const char *str, int length, u_int32_t *out) { |
1205
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
422 int oindex = 0; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
423 int i = 0; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
424 while (i < length) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
425 out[oindex] = str[i++] & 0xff; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
426 int len = 0; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
427 u_int32_t mask; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
428 for (mask = 0x80; out[oindex] & mask; mask >>= 1) { |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
429 out[oindex] -= mask; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
430 len++; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
431 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
432 int j; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
433 for (j = 1; j < len; j++) |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
434 out[oindex] = (out[oindex] << 6) | (str[i++] & 0x3f); |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
435 oindex++; |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
436 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
437 } |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
438 |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
439 /*文字のSceneGraphを生成する*/ |
b8adf4e95e96
add createStringFont()
Takao YONAMINE <e095763@ie.u-ryukyu.ac.jp>
parents:
1184
diff
changeset
|
440 |
539 | 441 void |
724
6e9e4726113e
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
442 SceneGraph::init() |
539 | 443 { |
444 next = NULL; | |
445 prev = NULL; | |
446 last = NULL; | |
447 | |
448 parent = NULL; | |
449 brother = NULL; | |
450 children = NULL; | |
451 lastChild = NULL; | |
452 | |
453 stack_xyz[0] = 0.0f; | |
454 stack_xyz[2] = 0.0f; | |
455 stack_xyz[1] = 0.0f; | |
456 stack_angle[0] = 0.0f; | |
457 stack_angle[1] = 0.0f; | |
458 stack_angle[2] = 0.0f; | |
459 | |
460 size = 0; | |
1141 | 461 pp_num = 0; |
462 | |
539 | 463 //data = NULL; |
1128 | 464 |
539 | 465 move = no_move; |
466 collision = no_collision; | |
467 | |
468 flag_remove = 0; | |
469 flag_drawable = 1; | |
470 sgid = -1; | |
471 gid = -1; | |
472 | |
473 frame = 0; | |
474 } | |
475 | |
724
6e9e4726113e
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
476 SceneGraph::~SceneGraph() |
539 | 477 { |
478 (this->*finalize)(); | |
479 } | |
480 | |
481 /** | |
482 * xml ファイルから生成されたオリジナル SceneGraph なので | |
483 * polygon data を削除 | |
484 */ | |
485 void | |
724
6e9e4726113e
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
486 SceneGraph::finalize_original() |
539 | 487 { |
488 //delete [] data; | |
860 | 489 |
1126
6043da6e48f1
complete compile but not work yet.
yutaka@localhost.localdomain
parents:
1125
diff
changeset
|
490 free(pp); |
1142
801d57ae1e29
cut compile CreatePolygonTask on spe side because not enough spe memory. We have to use code loading.
yutaka@localhost.localdomain
parents:
1141
diff
changeset
|
491 free(matrix); |
801d57ae1e29
cut compile CreatePolygonTask on spe side because not enough spe memory. We have to use code loading.
yutaka@localhost.localdomain
parents:
1141
diff
changeset
|
492 free(real_matrix); |
801d57ae1e29
cut compile CreatePolygonTask on spe side because not enough spe memory. We have to use code loading.
yutaka@localhost.localdomain
parents:
1141
diff
changeset
|
493 free(texture_info); |
860 | 494 |
539 | 495 } |
496 | |
497 /** | |
498 * SceneGraph ID から生成された、コピー SceneGraph なので | |
499 * polygon data は削除しない。オリジナルの方で削除する。 | |
500 */ | |
501 void | |
724
6e9e4726113e
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
502 SceneGraph::finalize_copy() |
539 | 503 { |
1142
801d57ae1e29
cut compile CreatePolygonTask on spe side because not enough spe memory. We have to use code loading.
yutaka@localhost.localdomain
parents:
1141
diff
changeset
|
504 |
801d57ae1e29
cut compile CreatePolygonTask on spe side because not enough spe memory. We have to use code loading.
yutaka@localhost.localdomain
parents:
1141
diff
changeset
|
505 free(matrix); |
801d57ae1e29
cut compile CreatePolygonTask on spe side because not enough spe memory. We have to use code loading.
yutaka@localhost.localdomain
parents:
1141
diff
changeset
|
506 free(real_matrix); |
1169 | 507 free(texture_info); |
539 | 508 } |
509 | |
510 | |
511 /** | |
512 * add Children | |
513 * 親の登録と、brother のリストへ加える | |
514 * | |
515 * @param child new child | |
516 */ | |
517 SceneGraphPtr | |
518 SceneGraph::addChild(SceneGraphPtr child) | |
519 { | |
520 /* childrenのリストの最後に加える (brother として)*/ | |
521 if (this->lastChild != NULL) { | |
522 SceneGraphPtr last = this->lastChild; | |
523 last->brother = child; | |
850 | 524 //child->parent = this; |
525 //return child; | |
539 | 526 } |
891 | 527 |
539 | 528 this->lastChild = child; |
891 | 529 |
539 | 530 if (this->children == NULL) { |
531 this->children = child; | |
532 } | |
891 | 533 |
539 | 534 child->parent = this; |
535 | |
536 return child; | |
537 } | |
538 | |
539 | |
540 /** | |
541 * add Brother | |
542 * addChild() でも brother の操作をしないといけないので、そっちに回す | |
543 * | |
544 * @param bro new Brother | |
545 */ | |
546 SceneGraphPtr | |
547 SceneGraph::addBrother(SceneGraphPtr bro) | |
548 { | |
549 if (this->parent) { | |
550 parent->addChild(bro); | |
551 } else { | |
552 fprintf(stderr, "error : SceneGraph::%s : %s doesn't have parent\n", | |
553 __FUNCTION__, this->name); | |
554 } | |
555 | |
556 return bro; | |
557 } | |
558 | |
559 /* thisの子や子孫にnameのものが存在すればそいつを返す なければNULL. */ | |
560 SceneGraphPtr | |
561 SceneGraph::searchSceneGraph(const char *name) | |
562 { | |
563 SceneGraphPtr tmp; | |
564 SceneGraphPtr result; | |
565 | |
566 /* 本人か */ | |
567 if( 0==strcmp(this->name, name) ) return this; | |
568 | |
569 /* 子供から再帰的に探す */ | |
570 for(tmp = this->children; tmp; tmp = tmp->next) { | |
571 if ((result=tmp->searchSceneGraph(name)) != NULL) | |
572 return result; | |
573 } | |
574 | |
575 /* 無かったら NULL. */ | |
576 return NULL; | |
577 } | |
578 | |
579 void | |
724
6e9e4726113e
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
580 SceneGraph::tree_check() |
539 | 581 { |
582 SceneGraphPtr t = this; | |
583 | |
584 while(t) | |
585 { | |
586 cout << "my_name : " << t->name << endl; | |
587 if(t->children != NULL) | |
588 { | |
589 cout << "--move children : " << t->children->name << endl; | |
590 t = t->children; | |
591 } | |
592 else if(t->brother != NULL) | |
593 { | |
594 cout << "--move brother : " << t->brother->name << endl; | |
595 t = t->brother; | |
596 } | |
597 else | |
598 { | |
599 while(t) | |
600 { | |
601 if(t->brother != NULL) | |
602 { | |
603 cout << "--move brother : " << t->brother->name << endl; | |
604 t = t->brother; | |
605 break; | |
606 } | |
607 else | |
608 { | |
609 if(t->parent) | |
610 { | |
611 cout << "--move parent : " << t->parent->name << endl; | |
612 } | |
613 t = t->parent; | |
614 } | |
615 } | |
616 } | |
617 } | |
618 } | |
619 | |
620 | |
621 void | |
724
6e9e4726113e
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
622 SceneGraph::print_member() |
539 | 623 { |
624 cout << "size = " << size << endl; | |
625 cout << "name = " << name << endl; | |
626 cout << "parent_name = " << parent_name << endl; | |
627 | |
628 if (parent != NULL) { | |
629 cout << "parent->name = " << parent->name << endl; | |
630 } | |
631 | |
632 if (children != NULL) { | |
633 cout << "children->name = " << children->name << endl; | |
634 } | |
635 } | |
636 | |
637 | |
638 /* | |
639 * surface nodeからポリゴンの情報を読み出す 再帰しない | |
640 */ | |
641 void | |
642 SceneGraph::get_data(TaskManager *manager, xmlNodePtr cur) | |
643 { | |
644 //char *image_name; | |
645 | |
646 for(;cur;cur=cur->next) | |
647 { | |
648 if(!xmlStrcmp(cur->name,(xmlChar*)"coordinate")) | |
649 { | |
650 char *cont = (char *)xmlNodeGetContent(cur); | |
651 pickup_coordinate(cont); | |
652 } | |
653 else if(!xmlStrcmp(cur->name,(xmlChar*)"normal")) | |
654 { | |
655 char *cont = (char *)xmlNodeGetContent(cur); | |
656 pickup_normal(cont); | |
657 } | |
658 else if(!xmlStrcmp(cur->name,(xmlChar*)"model")) | |
659 { | |
660 char *cont = (char *)xmlNodeGetContent(cur); | |
661 pickup_model(cont); | |
662 } | |
663 else if(!xmlStrcmp(cur->name,(xmlChar*)"texture")) | |
664 { | |
665 char *cont = (char *)xmlNodeGetContent(cur); | |
666 pickup_texture(cont); | |
667 } | |
668 else if(!xmlStrcmp(cur->name,(xmlChar*)"imageflag")) | |
669 { | |
670 int id; | |
671 char *filename = (char *)xmlGetProp(cur, (xmlChar *)"name"); | |
672 texture_hash.hash_regist(filename, id); | |
673 } | |
674 else if(!xmlStrcmp(cur->name,(xmlChar*)"image")) | |
675 { | |
676 get_image(manager, cur); | |
677 } | |
678 } | |
679 } | |
680 | |
1166
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
681 static int |
1211 | 682 is_bmp(const char *name) { |
1166
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
683 int bmp = 0; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
684 |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
685 while(*name) { |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
686 if (bmp==0 && *name=='.') bmp = 1; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
687 else if (bmp==1 && (*name=='b' || *name=='B')) bmp = 2; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
688 else if (bmp==2 && (*name=='m' || *name=='M')) bmp = 3; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
689 else if (bmp==3 && (*name=='p' || *name=='P')) bmp = 4; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
690 else bmp = 0; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
691 name++; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
692 } |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
693 return bmp==4; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
694 } |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
695 |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
696 #if (__LITTLE_ENDIAN__) |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
697 #define LITTLEENDIAN 1 |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
698 #else |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
699 #define LITTLEENDIAN 0 |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
700 #endif |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
701 |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
702 static void |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
703 make_black_alpha(SDL_Surface *texture_image) |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
704 { |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
705 int tex_w = texture_image->w; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
706 int tex_h = texture_image->h; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
707 #if LITTLEENDIAN |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
708 uint32 alpha = 0x000000ff; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
709 #else |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
710 uint32 alpha = 0xff000000; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
711 #endif |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
712 |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
713 uint32 *pixels = (uint32*)texture_image->pixels; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
714 int i; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
715 for(i=0;i<tex_w*tex_h;i++) { |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
716 uint32 pixel = pixels[i] & ~alpha; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
717 if (pixel==0) { |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
718 pixels[i] = 0; |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
719 } |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
720 } |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
721 } |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
722 |
539 | 723 SDL_Surface* |
1211 | 724 SceneGraph::load_decode_image(const char *file_name, const char *image_name, xmlNodePtr cur) |
539 | 725 { |
1211 | 726 int fd = mkstemp((char *)image_name); |
539 | 727 FILE *outfile = fdopen(fd, "wb"); |
728 | |
729 if (NULL == outfile) { | |
730 cout << "error open file\n"; | |
731 return 0; | |
732 } | |
733 | |
734 char *cont = (char *)xmlNodeGetContent(cur); | |
735 //decode(cont, image_name); | |
736 decode(cont, outfile); | |
737 fclose(outfile); | |
738 | |
1166
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
739 int alpha_black = is_bmp(file_name); |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
740 |
539 | 741 |
742 /** | |
743 * image を 32bit(RGBA) に変換する | |
744 */ | |
745 SDL_Surface *texture_image = IMG_Load(image_name); | |
580
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
746 if (!texture_image) return 0; |
539 | 747 SDL_Surface *tmpImage |
1123 | 748 = SDL_CreateRGBSurface(SDL_HWSURFACE, texture_image->w, |
996 | 749 texture_image->h, 32, redMask, |
750 greenMask, blueMask, alphaMask); | |
751 | |
752 //= SDL_CreateRGBSurface(SDL_HWSURFACE, 0, | |
753 // 0, 32, redMask, | |
754 // greenMask, blueMask, alphaMask); | |
539 | 755 SDL_Surface *converted; |
756 converted = SDL_ConvertSurface(texture_image, tmpImage->format, | |
996 | 757 SDL_HWSURFACE); |
758 | |
759 //SDL_SetAlpha(converted, 0, 0); | |
760 | |
539 | 761 if (converted != NULL) { |
762 SDL_FreeSurface(texture_image); | |
763 texture_image = converted; | |
764 } | |
765 | |
1166
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
766 if (alpha_black) { |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
767 make_black_alpha(texture_image); |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
768 } |
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
769 |
942
27df980045b5
FB mode is working again on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
930
diff
changeset
|
770 // this->gl_tex = SDL_GL_LoadTexture(texture_image); |
539 | 771 return texture_image; |
772 } | |
773 | |
774 int | |
775 SceneGraph::makeTapestries(TaskManager *manager, SDL_Surface *texture_image, int id) { | |
776 uint32 *tapestry; | |
777 int scale = 1; | |
778 int tex_w = texture_image->w; | |
779 int tex_h = texture_image->h; | |
780 int all_pixel_num = 0; | |
1047
f87218eed9fc
broken texure ( h/w != 2^n ) protection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1033
diff
changeset
|
781 int nw = tex_w; |
f87218eed9fc
broken texure ( h/w != 2^n ) protection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1033
diff
changeset
|
782 int nh = tex_h; |
539 | 783 |
784 /** | |
785 * テクスチャの w or h が 8 pixel で分割できる間、 | |
786 * 1/2 の縮小画像を作る。 | |
787 * ここでは、最大の scale (1/scale) を見つける | |
788 * | |
789 * (ex) | |
790 * (128,128) => 64,64 : 32,32: 16,16 : 8,8 | |
791 * scale = 16 | |
792 * (128, 64) => 64,32 : 32,16: 16,8 | |
793 * scale = 8 | |
1049
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
794 * 8 pixcel align してない場合は、透明に 8 pixcel に拡張する |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
795 * (200, 57) => 200,64 : 100,32 : 56,16: 32,8 (16,1 : 8,1 まで落すべき? 32byte) |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
796 * scale = 32 |
539 | 797 */ |
1047
f87218eed9fc
broken texure ( h/w != 2^n ) protection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1033
diff
changeset
|
798 |
1049
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
799 do { |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
800 tex_w = align(tex_w,8); |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
801 tex_h = align(tex_h,8); |
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
802 all_pixel_num += tex_w * tex_h; |
539 | 803 tex_w >>= 1; /* tex_w /= 2 */ |
804 tex_h >>= 1; | |
805 scale <<= 1; /* scale *= 2 */ | |
1049
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
806 } while( tex_w >8 || tex_h > 8 ); |
539 | 807 |
1049
91500a6c4def
non 2^n texture tapestry generation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1047
diff
changeset
|
808 scale >>= 1; // 必ず 1 以上になる |
539 | 809 |
810 tapestry = makeTapestry(manager, texture_image->w, texture_image->h, | |
811 (uint32*)texture_image->pixels, | |
812 all_pixel_num, scale); | |
813 | |
1047
f87218eed9fc
broken texure ( h/w != 2^n ) protection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1033
diff
changeset
|
814 list[id].t_w = nw; |
f87218eed9fc
broken texure ( h/w != 2^n ) protection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1033
diff
changeset
|
815 list[id].t_h = nh; |
539 | 816 list[id].pixels_orig = (Uint32*)texture_image->pixels; |
817 list[id].pixels = tapestry; | |
818 list[id].scale_max = scale; | |
942
27df980045b5
FB mode is working again on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
930
diff
changeset
|
819 list[id].texture_image = texture_image; |
539 | 820 |
821 return id; | |
822 } | |
823 | |
824 void | |
825 SceneGraph::get_image(TaskManager *manager, xmlNodePtr cur) | |
826 { | |
827 char image_name[20] = "/tmp/image_XXXXXX"; | |
828 char *filename = (char *)xmlGetProp(cur, (xmlChar *)"name"); | |
829 | |
830 if (filename == NULL || filename[0] == 0) { | |
831 return; | |
832 } | |
833 | |
834 /** | |
835 * image_name を既に Load していれば何もしない | |
836 */ | |
837 int tex_id; | |
1184 | 838 if (texture_hash.sg_hash_regist(filename, tex_id) == -1) { |
539 | 839 |
1166
38111db531e0
bmp's black has 0 alpha value for compatibility
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1143
diff
changeset
|
840 SDL_Surface *texture_image = load_decode_image(filename, image_name, cur); |
580
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
841 if (texture_image==0) { |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
842 printf("Can't load image %s\n",filename); |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
843 exit(0); |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
844 } |
1130 | 845 texture_info->texture_id = makeTapestries(manager, texture_image, tex_id); |
846 tex_id = texture_info->texture_id; | |
539 | 847 |
848 if (unlink(image_name)) { | |
849 cout << "unlink error\n"; | |
850 } | |
851 } else { | |
852 /** | |
853 * 以前に Load されている Texture を共用 | |
854 */ | |
1130 | 855 texture_info->texture_id = tex_id; |
539 | 856 } |
857 | |
860 | 858 // こんなことすると list[] のいみあるのかなーと |
859 // 微妙に思う、自分で書き換えた感想 by gongo | |
1130 | 860 texture_info->t_w = list[tex_id].t_w; |
861 texture_info->t_h = list[tex_id].t_h;; | |
862 texture_info->pixels_orig = list[tex_id].pixels_orig; | |
863 texture_info->pixels = list[tex_id].pixels; | |
864 texture_info->scale_max = list[tex_id].scale_max; | |
865 texture_info->texture_image = list[tex_id].texture_image; | |
860 | 866 |
539 | 867 } |
868 | |
869 | |
870 void | |
724
6e9e4726113e
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
871 SceneGraph::delete_data() |
539 | 872 { |
873 SceneGraphPtr n = this->next, m; | |
874 | |
875 //n = this; | |
876 //delete [] n->data; | |
877 | |
878 if (next) { | |
879 while (n) { | |
880 m = n->next; | |
881 delete n; | |
882 n = m; | |
883 } | |
884 } | |
885 } | |
886 | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
887 /* move_func 実行 sgroot 渡す */ |
539 | 888 void |
889 SceneGraph::move_execute(int w, int h) | |
890 { | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
891 (*move)(this, this->sgroot, w, h); |
539 | 892 } |
893 | |
894 void | |
895 SceneGraph::collision_check(int w, int h, SceneGraphPtr tree) | |
896 { | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
897 (*collision)(this, this->sgroot, w, h, tree); |
539 | 898 } |
899 | |
759
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
900 void |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
901 SceneGraph::create_sg_execute() |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
902 { |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
903 (*create_sg)(this->sgroot, property, update_property); |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
904 } |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
905 |
1033
a9581a9df440
add application main method and task.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
996
diff
changeset
|
906 void |
a9581a9df440
add application main method and task.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
996
diff
changeset
|
907 SceneGraph::set_move_collision(move_func new_move) |
a9581a9df440
add application main method and task.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
996
diff
changeset
|
908 { |
a9581a9df440
add application main method and task.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
996
diff
changeset
|
909 this->move = new_move; |
a9581a9df440
add application main method and task.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
996
diff
changeset
|
910 } |
a9581a9df440
add application main method and task.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
996
diff
changeset
|
911 |
a9581a9df440
add application main method and task.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
996
diff
changeset
|
912 void |
a9581a9df440
add application main method and task.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
996
diff
changeset
|
913 SceneGraph::set_move_collision(collision_func new_collision) |
a9581a9df440
add application main method and task.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
996
diff
changeset
|
914 { |
a9581a9df440
add application main method and task.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
996
diff
changeset
|
915 this->collision = new_collision; |
a9581a9df440
add application main method and task.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
996
diff
changeset
|
916 } |
539 | 917 |
918 void | |
919 SceneGraph::set_move_collision(move_func new_move, | |
920 collision_func new_collision) | |
921 { | |
922 this->move = new_move; | |
923 this->collision = new_collision; | |
924 } | |
925 | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
926 |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
927 void |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
928 SceneGraph::set_move_collision(move_func new_move, |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
929 collision_func new_collision, void *sgroot_) |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
930 { |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
931 this->move = new_move; |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
932 this->collision = new_collision; |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
933 // add |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
934 this->sgroot = sgroot_; |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
935 } |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
580
diff
changeset
|
936 |
539 | 937 void |
759
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
938 SceneGraph::set_move_collision(move_func new_move, |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
939 collision_func new_collision, create_sg_func new_create_sg) |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
940 { |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
941 this->move = new_move; |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
942 this->collision = new_collision; |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
943 this->create_sg = new_create_sg; |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
944 } |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
945 |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
724
diff
changeset
|
946 void |
539 | 947 SceneGraph::add_next(SceneGraphPtr next) |
948 { | |
949 /* next のリストの最後に加える */ | |
950 if (this->next != NULL) { | |
951 SceneGraphPtr tmp = this->last; | |
952 tmp->next = next; | |
953 } else { | |
954 this->next = next; | |
955 } | |
956 | |
957 this->last = next; | |
958 } | |
959 | |
960 /** | |
961 * SceneGraph の clone | |
962 * @return clone SceneGraph | |
963 */ | |
964 SceneGraphPtr | |
1136 | 965 SceneGraph::clone(TaskManager *manager) { |
966 | |
1169 | 967 SceneGraphPtr p = new SceneGraph(manager, this); |
1136 | 968 |
1140
3975c384ff93
SceneGraph initalize... can worked on Mac OS X. not check Cell arch.
Yutaka_Kinjyo
parents:
1136
diff
changeset
|
969 |
539 | 970 return p; |
971 } | |
972 | |
973 /** | |
974 * SceneGraph の clone | |
975 * 予め allocate されてる領域への placement new を行う | |
976 * | |
977 * @param buf clone 領域 | |
978 * @return clone SceneGraph | |
979 */ | |
1169 | 980 |
539 | 981 SceneGraphPtr |
1169 | 982 SceneGraph::clone(TaskManager *manager, void *buf) { |
983 SceneGraphPtr p = new(buf) SceneGraph(manager, this); | |
539 | 984 return p; |
985 } | |
986 | |
987 void | |
724
6e9e4726113e
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
988 SceneGraph::remove() |
539 | 989 { |
990 this->flag_remove = 1; | |
991 } | |
992 | |
993 /** | |
994 * tree から node を削除する | |
995 * | |
996 * @param tree SceneGraphTree | |
997 * @return node削除後の SceneGraphTree | |
998 */ | |
999 SceneGraphPtr | |
1000 SceneGraph::realRemoveFromTree(SceneGraphPtr tree) | |
1001 { | |
1002 SceneGraphPtr node = this; | |
1003 SceneGraphPtr parent = node->parent; | |
1004 SceneGraphPtr ret = tree; | |
1005 | |
1006 if (parent) { | |
1007 SceneGraphPtr brother = parent->children; | |
1008 SceneGraphPtr p, p1 = NULL; | |
1009 | |
1010 p = brother; | |
1011 if (p) { | |
1012 if (p == node) { | |
1013 parent->children = NULL; | |
1014 parent->lastChild = NULL; | |
1015 } else { | |
1016 p1 = p->brother; | |
1017 | |
1018 while (p1 && p1 != node) { | |
1019 p1 = p1->brother; | |
1020 p = p->brother; | |
1021 } | |
1022 | |
1023 if (p1) { | |
1024 p->brother = p1->brother; | |
1025 | |
1026 // node が最後尾なら、lastChild を変更 | |
1027 if (parent->lastChild == p1) { | |
1028 parent->lastChild = p; | |
1029 } | |
1030 } else { | |
1031 // Can't find remove node | |
1032 } | |
1033 } | |
1034 } | |
1035 } else { | |
1036 // 親が居ない = tree root なので | |
1037 // NULL を返す | |
1038 ret = NULL; | |
1039 } | |
1040 | |
1041 return ret; | |
1042 } | |
1043 | |
1044 /** | |
1045 * list から node を削除する | |
1046 * | |
1047 * @param list SceneGraphList | |
1048 * @return node削除後の SceneGraphList | |
1049 */ | |
1050 SceneGraphPtr | |
1051 SceneGraph::realRemoveFromList(SceneGraphPtr list) | |
1052 { | |
1053 SceneGraphPtr node = this; | |
1054 SceneGraphPtr prev = node->prev; | |
1055 SceneGraphPtr next = node->next; | |
1056 SceneGraphPtr ret = list; | |
1057 | |
1058 if (prev) { | |
1059 prev->next = next; | |
1060 } else { | |
1061 ret = next; | |
1062 } | |
1063 | |
1064 if (next) { | |
1065 next->prev = prev; | |
1066 } | |
1067 | |
1068 return ret; | |
1069 } | |
1070 | |
1071 int | |
724
6e9e4726113e
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
1072 SceneGraph::isRemoved() |
539 | 1073 { |
1074 return flag_remove; | |
1075 } | |
1076 | |
1077 /** | |
1078 * 平行移動 | |
1079 * | |
1080 * @param x Ttranslate in the x direction | |
1081 * @param y Ttranslate in the y direction | |
1082 * @param z Ttranslate in the z direction | |
1083 */ | |
1084 void | |
1085 SceneGraph::translate(float x, float y, float z) | |
1086 { | |
1226
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
1087 this->matrix[3] += x; |
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
1088 this->matrix[4+3] += y; |
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
1089 this->matrix[8+3] += z; |
539 | 1090 } |
1091 | |
1092 /** | |
1093 * x 軸方向への平行移動 | |
1094 * | |
1095 * @param x Ttranslate in the x direction | |
1096 */ | |
1097 void | |
1098 SceneGraph::translateX(float x) | |
1099 { | |
1226
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
1100 this->matrix[3] += x; |
539 | 1101 } |
1102 | |
1103 /** | |
1104 * y 軸方向への平行移動 | |
1105 * | |
1106 * @param y Ttranslate in the y direction | |
1107 */ | |
1108 void | |
1109 SceneGraph::translateY(float y) | |
1110 { | |
1226
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
1111 this->matrix[4+3] += y; |
539 | 1112 } |
1113 | |
1114 /** | |
1115 * z 軸方向への平行移動 | |
1116 * | |
1117 * @param z Ttranslate in the z direction | |
1118 */ | |
1119 void | |
1120 SceneGraph::translateZ(float z) | |
1121 { | |
1226
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
1122 this->matrix[8+3] += z; |
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
1123 } |
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
1124 |
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
1125 void |
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
1126 SceneGraph::angleIt(float *angle) |
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
1127 { |
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
1128 float m[16]; |
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
1129 float t[4] = {0,0,0,0}; |
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
1130 for(int i=0;i<16;i++) m[i] = matrix[i]; |
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
1131 get_matrix(matrix, angle, t, m); |
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
1132 get_matrix(real_matrix, angle, t, m); |
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
1133 } |
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
1134 |
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
1135 void |
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
1136 SceneGraph::scaleIt(float *scale) |
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
1137 { |
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
1138 for(int i=0;i<4;i++) { |
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
1139 for(int j=0;i<3;j++) { |
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
1140 matrix[i*4+j] = matrix[i*4+j]*scale[i]; |
1276
e92f00ed2fc0
apply view matrix to normal vector
Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
1226
diff
changeset
|
1141 /* real_matrix は スケールする必要はないかも */ |
1226
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
1142 real_matrix[i*4+j] = real_matrix[i*4+j]*scale[i]; |
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
1143 } |
636dfdc30176
new API for SceneGraph
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1211
diff
changeset
|
1144 } |
539 | 1145 } |
724
6e9e4726113e
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
1146 |
6e9e4726113e
Small clean up of Rendering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
653
diff
changeset
|
1147 /* end */ |