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