Mercurial > hg > Game > Cerium
annotate Renderer/Engine/SceneGraphRoot.cc @ 851:621954669342 draft
createSceneGraph(): error message add.
author | tkaito |
---|---|
date | Sun, 06 Jun 2010 06:32:00 +0900 |
parents | a033d464c812 |
children | a215927a9885 |
rev | line source |
---|---|
539 | 1 #include <SDL.h> |
2 #include <SDL_image.h> | |
3 #include <libxml/parser.h> | |
4 #include "SceneGraphRoot.h" | |
5 #include "xml.h" | |
6 #include "sys.h" | |
7 #include "TextureHash.h" | |
8 #include "texture.h" | |
562 | 9 //#include "SGList.h" |
10 #include "Application.h" | |
539 | 11 |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
12 static int cnt = 0; |
562 | 13 static const int SGLIST_LENGTH = 138; |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
14 static int sg_src_size = SGLIST_LENGTH ; |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
15 static int sg_src_id = -1; |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
16 static SceneGraphPtr *sg_src; |
562 | 17 |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
18 |
558 | 19 SceneGraphRoot *sgroot; |
20 | |
539 | 21 SceneGraphRoot::SceneGraphRoot(float w, float h) |
22 { | |
562 | 23 // SGLIST_LENGTH 決め打ちかぁ、動的生成にする場合上限決めておいた方がいいのかな |
24 // | |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
25 sg_src = (SceneGraphPtr*) malloc(sizeof(SceneGraphPtr)*SGLIST_LENGTH); |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
26 |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
597
diff
changeset
|
27 camera = new Camera(w, h, this); |
779 | 28 |
539 | 29 iterator = new SceneGraphIterator; |
30 controller = create_controller(); | |
31 | |
32 sg_exec_tree = NULL; | |
33 sg_draw_tree = NULL; | |
34 sg_available_list = NULL; | |
35 sg_remove_list = NULL; | |
36 | |
562 | 37 sgroot = this; |
38 | |
759
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
39 screen_w = (int)w; |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
40 screen_h = (int)h; |
761 | 41 int light_num = 4; |
793 | 42 light_sysswitch = 0; |
761 | 43 |
44 for (int i = 0; i < light_num; i++) { | |
45 light[i] = new SceneGraph; | |
46 light[i]->xyz[0] = 0; | |
47 light[i]->xyz[1] = 0; | |
48 light[i]->xyz[2] = 0; | |
792 | 49 |
793 | 50 light_switch[i] = 0; |
792 | 51 |
761 | 52 } |
747 | 53 |
759
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
54 move_finish_flag = 0; |
677
24054155368c
add Load light info for some spe
yutaka@henri.cr.ie.u-ryukyu.ac.jp
parents:
653
diff
changeset
|
55 |
539 | 56 // TODO |
57 // 今はとりあえず camera を Root にしています | |
58 // 今はそれすらもしてません | |
59 //sg_exec_tree = camera; | |
60 } | |
61 | |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
62 SceneGraphRoot::~SceneGraphRoot() |
539 | 63 { |
64 SceneGraphPtr p = sg_available_list; | |
65 | |
66 while (p) { | |
67 SceneGraphPtr tmp = p->next; | |
68 delete p; | |
69 p = tmp; | |
70 cnt--; | |
71 } | |
72 | |
73 p = sg_remove_list; | |
74 | |
75 while (p) { | |
76 SceneGraphPtr tmp = p->next; | |
77 delete p; | |
78 p = tmp; | |
79 cnt--; | |
80 } | |
81 | |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
82 free(sg_src); |
539 | 83 delete camera; |
761 | 84 int light_num = 4; |
85 for (int i = 0; i < light_num; i++) { | |
86 delete light[i]; | |
87 } | |
539 | 88 delete iterator; |
89 delete controller; | |
90 } | |
91 | |
92 /** | |
93 * xml ファイルから生成された SceneGraph を sg_src に登録する。 | |
94 * | |
95 * @param sg SceneGraph created by xmlfile | |
96 */ | |
97 void | |
98 SceneGraphRoot::registSceneGraph(SceneGraphPtr sg) | |
99 { | |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
100 int dup; |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
101 if ((dup = getSgid(sg->name))>=0) { // while... |
576 | 102 sg_src[dup]->name = ""; |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
103 // we should remove this. but some one may use it... |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
104 } |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
105 if (sg_src_id+1> sg_src_size) { |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
106 sg_src_size *= 2; |
582 | 107 sg_src = (SceneGraphPtr*)realloc(sg_src, sg_src_size*sizeof(SceneGraphPtr)); |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
108 } |
580
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
109 sg->sgid = ++sg_src_id; |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
110 sg_src[sg->sgid] = sg; |
539 | 111 } |
112 | |
848 | 113 |
539 | 114 void |
115 SceneGraphRoot::addNext(SceneGraphPtr sg) | |
116 { | |
117 SceneGraphPtr last = sg_available_list; | |
118 | |
119 if (!last) { | |
120 sg_available_list = sg; | |
121 } else { | |
122 while (last->next) { | |
123 last = last->next; | |
124 } | |
125 last->next = sg; | |
126 sg->prev = last; | |
127 } | |
128 | |
129 cnt++; | |
130 } | |
131 | |
132 /* XMLファイルからポリゴンを作成 */ | |
133 void | |
134 SceneGraphRoot::createFromXMLfile(TaskManager *manager, const char *xmlfile) | |
135 { | |
136 xmlDocPtr doc; | |
137 xmlNodePtr cur; | |
138 SceneGraphPtr tmp; | |
562 | 139 |
539 | 140 /* パース DOM生成 */ |
141 doc = xmlParseFile(xmlfile); | |
142 cur = xmlDocGetRootElement(doc); | |
143 | |
144 /* ?? */ | |
145 xmlStrcmp(cur->name,(xmlChar*)"OBJECT-3D"); | |
146 | |
147 /* XMLのノードを一つずつ解析 */ | |
148 for (cur=cur->children; cur; cur=cur->next) { | |
562 | 149 /* 扱うのはsurfaceオンリー */ |
150 if (xmlStrcmp(cur->name,(xmlChar*)"surface") != 0) { | |
151 continue; | |
152 } | |
539 | 153 |
562 | 154 /* ポリゴン(SceneGraph)生成 */ |
155 tmp = new SceneGraph(manager, cur); | |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
156 registSceneGraph(tmp); |
539 | 157 } |
158 xmlFreeDoc(doc); | |
580
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
159 } |
562 | 160 |
580
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
161 void |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
162 SceneGraphRoot::createFromXMLmemory(TaskManager *manager, SceneGraph *node, char *data, int len) |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
163 { |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
164 xmlDocPtr doc; |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
165 xmlNodePtr cur; |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
166 |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
167 // size は取れるはず、テスト用に mmap したデータを使う |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
168 /* パース DOM生成 */ |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
169 |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
170 doc = xmlParseMemory(data, len); |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
171 cur = xmlDocGetRootElement(doc); |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
172 |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
173 /* ?? */ |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
174 xmlStrcmp(cur->name,(xmlChar*)"OBJECT-3D"); |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
175 |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
176 /* XMLのノードを一つずつ解析 */ |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
177 for (cur=cur->children; cur; cur=cur->next) { |
586 | 178 /* 扱うのはsurfaceオンリー */ |
179 if (xmlStrcmp(cur->name,(xmlChar*)"surface") != 0) { | |
180 continue; | |
181 } | |
182 /* ポリゴン(SceneGraph)生成 */ | |
183 SceneGraphPtr original = new SceneGraph(manager, cur); | |
184 registSceneGraph(original); | |
185 SceneGraphPtr clone = createSceneGraph(original->sgid); | |
186 node->addChild(clone); | |
580
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
187 } |
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
188 xmlFreeDoc(doc); |
539 | 189 } |
190 | |
191 SceneGraphPtr | |
192 SceneGraphRoot::createSceneGraph(int id) | |
193 { | |
194 SceneGraphPtr src; | |
195 SceneGraphPtr p; | |
196 | |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
197 if (id < 0 || id > sg_src_size) { |
851 | 198 printf("error: createSceneGraph(int id): id not found.\n"); |
199 return NULL; | |
539 | 200 } |
201 | |
202 /* オリジナルの SceneGraph */ | |
562 | 203 src = sg_src[id]; |
539 | 204 |
205 /* ユーザーにはオリジナルの clone を返す */ | |
206 p = src->clone(); | |
207 | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
597
diff
changeset
|
208 /* move, collision に 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:
597
diff
changeset
|
209 p->sgroot = (void *)this; |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
597
diff
changeset
|
210 |
539 | 211 addNext(p); |
212 | |
213 return p; | |
214 } | |
215 | |
562 | 216 |
217 | |
218 | |
219 SceneGraphPtr | |
220 SceneGraphRoot::createSceneGraph(const char *name) | |
221 { | |
222 SceneGraphPtr src; | |
223 SceneGraphPtr p; | |
224 | |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
225 int id = getSgid(name); |
562 | 226 if (id < 0) { |
851 | 227 printf("error: createSceneGraph(name): name object not found.\n"); |
228 return NULL; | |
562 | 229 } |
230 | |
231 /* オリジナルの SceneGraph */ | |
232 src = sg_src[id]; | |
233 | |
234 /* ユーザーにはオリジナルの clone を返す */ | |
235 p = src->clone(); | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
597
diff
changeset
|
236 |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
597
diff
changeset
|
237 /* move, collision に 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:
597
diff
changeset
|
238 p->sgroot = (void *)this; |
562 | 239 |
240 addNext(p); | |
241 | |
242 return p; | |
243 } | |
244 | |
245 int | |
246 SceneGraphRoot::getSgid(const char *name) | |
247 { | |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
248 for(int i =0;i<= sg_src_id; i++) { |
576 | 249 if (sg_src[i] && strcmp(name,sg_src[i]->name) == 0) |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
250 return i; |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
251 } |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
252 return -1; |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
253 } |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
254 |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
255 int |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
256 SceneGraphRoot::getLast() |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
257 { |
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
258 if (sg_src_id>=0) |
580
ec9dd24c2dc8
add all object in file in dynamic_create
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
576
diff
changeset
|
259 return sg_src[sg_src_id]->sgid; |
575
341f1f881a9b
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
260 return -1; |
562 | 261 } |
262 | |
539 | 263 /** |
264 * 何も表示しない、move,collision もしない SceneGraph を生成 | |
265 * いずれ、Transform3D 的なものに回す予定 | |
266 */ | |
267 SceneGraphPtr | |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
268 SceneGraphRoot::createSceneGraph() |
539 | 269 { |
270 SceneGraphPtr p = new SceneGraph; | |
271 | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
597
diff
changeset
|
272 /* move, collision に 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:
597
diff
changeset
|
273 p->sgroot = (void *)this; |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
597
diff
changeset
|
274 |
539 | 275 addNext(p); |
276 p->flag_drawable = 0; | |
277 | |
278 return p; | |
279 } | |
280 | |
281 void | |
282 SceneGraphRoot::speExecute(int screen_w, int screen_h) | |
283 { | |
284 | |
285 SceneGraphPtr list = sg_available_list; | |
286 // SceneGraphPtr t = sg_exec_tree; | |
287 // SceneGraphPtr cur_parent = camera; | |
288 | |
289 // 前フレームで描画した SceneGraph は削除 | |
290 allRemove(sg_remove_list); | |
291 | |
292 // 前フレームに作られた SceneGraph は描画用に移行 | |
293 // 現フレームでの操作は以下の tree,list には適用されない | |
294 sg_draw_tree = sg_exec_tree; | |
295 sg_remove_list = sg_available_list; | |
296 | |
297 // 現フレームで新しく SceneGraph がコピーされるので初期化 | |
298 sg_exec_tree = NULL; | |
299 sg_available_list = NULL; | |
300 | |
301 camera->move_execute(screen_w, screen_h); | |
302 camera->update(screen_w, screen_h); | |
303 | |
304 camera->children = NULL; | |
305 camera->lastChild = NULL; | |
306 | |
307 list->move_execute(screen_w, screen_h); | |
308 list->collision_check(screen_w, screen_h, list); | |
309 | |
310 list->frame++; | |
311 list = list->next; | |
312 | |
313 if(sg_exec_tree != NULL) { | |
314 return; | |
315 } | |
316 | |
317 /*removeのflagをもとにtreeを形成*/ | |
318 /* spe から送り返されてきた property の配列を見て生成する for()*/ | |
319 /* | |
562 | 320 for (Property *t = (Property*)app->property[0]; is_end(t); t++){ |
321 SceneGraphPtr s = app->scenegraph_factory(t); // SceneGraphNode を作る | |
322 t->scenegraph = s; // property list には SceneGraphへのポインタが入っている | |
323 app->scenegraph_connector(property[0], s); // add する | |
324 } | |
325 */ | |
326 | |
327 | |
328 // 現在、allExecute が終わった時点では | |
329 // camera->children が User SceneGraph の root になる | |
330 | |
331 /** | |
332 * NULL じゃなかったら、setSceneData が呼ばれてるから | |
333 * そっちを次の Scene にする | |
334 */ | |
335 | |
336 sg_exec_tree = camera->children; | |
337 } | |
338 | |
539 | 339 |
340 | |
341 void | |
342 SceneGraphRoot::allExecute(int screen_w, int screen_h) | |
343 { | |
344 SceneGraphPtr list = sg_available_list; | |
345 SceneGraphPtr t = sg_exec_tree; | |
346 SceneGraphPtr cur_parent = camera; | |
347 | |
348 // 前フレームで描画した SceneGraph は削除 | |
349 allRemove(sg_remove_list); | |
350 | |
351 // 前フレームに作られた SceneGraph は描画用に移行 | |
352 // 現フレームでの操作は以下の tree,list には適用されない | |
353 sg_draw_tree = sg_exec_tree; | |
354 sg_remove_list = sg_available_list; | |
355 | |
356 // 現フレームで新しく SceneGraph がコピーされるので初期化 | |
357 sg_exec_tree = NULL; | |
358 sg_available_list = NULL; | |
359 | |
360 camera->move_execute(screen_w, screen_h); | |
361 camera->update(screen_w, screen_h); | |
362 | |
363 camera->children = NULL; | |
364 camera->lastChild = NULL; | |
365 | |
366 /*まずは全部動作させる*/ | |
367 while (list) { | |
368 | |
369 list->move_execute(screen_w, screen_h); | |
370 list->collision_check(screen_w, screen_h, list); | |
371 | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
597
diff
changeset
|
372 list->frame++; |
539 | 373 list = list->next; |
758 | 374 } |
539 | 375 |
761 | 376 int light_num = 4; |
377 for (int i = 0; i < light_num; i++) { | |
747 | 378 |
761 | 379 get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, camera->matrix); |
380 | |
381 light_vector[i*4] = 0.0f; | |
382 light_vector[i*4+1] = 0.0f; | |
383 light_vector[i*4+2] = 0.0f; | |
384 light_vector[i*4+3] = 1.0f; | |
747 | 385 |
761 | 386 ApplyMatrix(&light_vector[i*4], light[i]->matrix); |
387 | |
388 light_vector[i*4] /= light_vector[i*4+2]; | |
389 light_vector[i*4+1] /= light_vector[i*4+2]; | |
747 | 390 |
764 | 391 /*SIMD演算のため*/ |
392 light_vector[i*4+2] *= -1; | |
393 light_vector[i*4+3] *= -1; | |
394 | |
761 | 395 } |
396 | |
747 | 397 |
539 | 398 if(sg_exec_tree != NULL) { |
758 | 399 return; |
539 | 400 } |
401 | |
402 /*removeのflagをもとにtreeを形成*/ | |
403 while (t) { | |
751
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
404 SceneGraphPtr c = NULL; |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
405 if (!t->isRemoved()) { |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
406 c = t->clone(); |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
407 addNext(c); |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
408 cur_parent->addChild(c); |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
409 c->frame = t->frame; |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
410 /*親の回転、座標から、子の回転、座標を算出*/ |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
411 get_matrix(c->matrix, c->angle, c->xyz, cur_parent->matrix); |
747 | 412 /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ |
751
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
413 get_matrix(c->real_matrix, c->angle, c->xyz, cur_parent->real_matrix); |
845 | 414 //get_matrix(c->real_matrix, c->angle, c->xyz, camera->real_matrix); |
415 | |
751
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
416 } |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
417 |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
418 if (t->children != NULL && c != NULL) { |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
419 cur_parent = c; |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
420 t = t->children; |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
421 } else if (t->brother != NULL) { |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
422 t = t->brother; |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
423 } else { |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
424 while (t) { |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
425 if (t->brother != NULL) { |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
426 t = t->brother; |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
427 break; |
539 | 428 } else { |
751
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
429 if (t->parent == NULL) { |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
430 t = NULL; |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
431 break; |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
432 } else { |
539 | 433 cur_parent = cur_parent->parent; |
434 t = t->parent; | |
751
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
435 } |
539 | 436 } |
751
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
437 } |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
438 } |
539 | 439 } |
440 | |
441 | |
442 | |
443 // 現在、allExecute が終わった時点では | |
444 // camera->children が User SceneGraph の root になる | |
445 | |
446 /** | |
447 * NULL じゃなかったら、setSceneData が呼ばれてるから | |
448 * そっちを次の Scene にする | |
449 */ | |
450 | |
451 sg_exec_tree = camera->children; | |
452 } | |
453 | |
454 void | |
758 | 455 SceneGraphRoot::oneExecute(int screen_w, int screen_h) |
456 { | |
457 SceneGraphPtr list = sg_available_list; | |
759
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
458 //SceneGraphPtr t = sg_exec_tree; |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
459 //SceneGraphPtr cur_parent = camera; |
758 | 460 |
461 // 前フレームで描画した SceneGraph は削除 | |
462 allRemove(sg_remove_list); | |
463 | |
464 // 前フレームに作られた SceneGraph は描画用に移行 | |
465 // 現フレームでの操作は以下の tree,list には適用されない | |
466 sg_draw_tree = sg_exec_tree; | |
467 sg_remove_list = sg_available_list; | |
468 | |
469 // 現フレームで新しく SceneGraph がコピーされるので初期化 | |
470 sg_exec_tree = NULL; | |
471 sg_available_list = NULL; | |
472 | |
473 camera->move_execute(screen_w, screen_h); | |
474 camera->update(screen_w, screen_h); | |
475 | |
476 camera->children = NULL; | |
477 camera->lastChild = NULL; | |
478 | |
479 /* ここから */ | |
480 list->move_execute(screen_w, screen_h); | |
759
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
481 // ここで move_execute から実行される move_task の処理が終わるまで待ちたい |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
482 //while(move_finish_flag == 0) {} |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
483 //move_finish_flag = 0; |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
484 |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
485 list->create_sg_execute(); |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
486 |
758 | 487 list->collision_check(screen_w, screen_h, list); |
488 /* ここまで exec_task にする */ | |
489 | |
490 | |
491 /* ここから下を exec_task の post_func に*/ | |
492 list->frame++; | |
493 list = list->next; | |
494 | |
761 | 495 |
496 int light_num = 4; | |
497 for (int i = 0; i < light_num; i++) { | |
758 | 498 |
761 | 499 get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, camera->matrix); |
500 | |
501 light_vector[i*4] = 0.0f; | |
502 light_vector[i*4+1] = 0.0f; | |
503 light_vector[i*4+2] = 0.0f; | |
504 light_vector[i*4+3] = 1.0f; | |
758 | 505 |
761 | 506 ApplyMatrix(&light_vector[i*4], light[i]->matrix); |
507 | |
508 light_vector[i*4] /= light_vector[i*4+2]; | |
509 light_vector[i*4+1] /= light_vector[i*4+2]; | |
758 | 510 |
761 | 511 } |
758 | 512 |
513 if(sg_exec_tree != NULL) { | |
514 return; | |
515 } | |
516 } | |
517 | |
759
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
518 /* |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
519 ExecMove task の post func として呼んでやる |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
520 */ |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
521 void |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
522 SceneGraphRoot::move_finish() |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
523 { |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
524 list->collision_check(screen_w, screen_h, list); |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
525 |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
526 list->frame++; |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
527 //list = list->next; |
761 | 528 |
529 int light_num = 4; | |
530 for (int i = 0; i < light_num; i++) { | |
759
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
531 |
761 | 532 get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, camera->matrix); |
533 | |
534 light_vector[i*4] = 0.0f; | |
535 light_vector[i*4+1] = 0.0f; | |
536 light_vector[i*4+2] = 0.0f; | |
537 light_vector[i*4+3] = 1.0f; | |
759
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
538 |
761 | 539 ApplyMatrix(&light_vector[i*4], light[i]->matrix); |
540 | |
541 light_vector[i*4] /= light_vector[i*4+2]; | |
542 light_vector[i*4+1] /= light_vector[i*4+2]; | |
759
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
543 |
768
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
764
diff
changeset
|
544 light_vector[i*4+2] *= -1; |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
764
diff
changeset
|
545 light_vector[i*4+3] *= -1; |
761 | 546 } |
759
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
547 |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
548 //sgchange->viewer->light_xyz_stock = getLightVector(); |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
549 } |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
550 |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
551 |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
552 void |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
553 SceneGraphRoot::appTaskRegist(regist_func new_register) |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
554 { |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
555 this->regist = new_register; |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
556 } |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
557 |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
558 void |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
559 SceneGraphRoot::regist_execute() |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
560 { |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
561 (*regist)(this); |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
562 } |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
563 |
758 | 564 void |
539 | 565 SceneGraphRoot::allRemove(SceneGraphPtr list) |
566 { | |
567 SceneGraphPtr p = list; | |
759
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
568 |
539 | 569 while (p) { |
759
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
570 SceneGraphPtr p1 = p->next; |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
571 delete p; |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
572 p = p1; |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
573 cnt--; |
539 | 574 } |
575 } | |
576 | |
577 void | |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
578 SceneGraphRoot::checkRemove() |
539 | 579 { |
580 SceneGraphPtr p = sg_available_list; | |
581 SceneGraphPtr p1; | |
759
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
582 |
539 | 583 while (p) { |
759
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
584 p1 = p->next; |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
585 if (p->isRemoved()) { |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
586 sg_exec_tree = p->realRemoveFromTree(sg_exec_tree); |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
587 sg_available_list = p->realRemoveFromList(sg_available_list); |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
588 } |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
589 delete p; |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
590 p = p1; |
539 | 591 } |
592 } | |
593 | |
594 SceneGraphPtr | |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
595 SceneGraphRoot::getExecuteSceneGraph() |
539 | 596 { |
597 return sg_exec_tree; | |
598 } | |
599 | |
600 SceneGraphPtr | |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
601 SceneGraphRoot::getDrawSceneGraph() |
539 | 602 { |
603 return sg_draw_tree; | |
604 } | |
605 | |
606 void | |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
607 SceneGraphRoot::updateControllerState() |
539 | 608 { |
609 controller->check(); | |
610 } | |
611 | |
612 void | |
613 SceneGraphRoot::setSceneData(SceneGraphPtr sg) | |
614 { | |
615 sg_exec_tree = sg; | |
616 } | |
617 | |
618 Pad* | |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
619 SceneGraphRoot::getController() |
539 | 620 { |
621 return controller; | |
622 } | |
623 | |
624 SceneGraphIteratorPtr | |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
625 SceneGraphRoot::getIterator() |
539 | 626 { |
627 iterator->set(sg_remove_list); | |
628 return iterator; | |
629 } | |
630 | |
631 SceneGraphIteratorPtr | |
632 SceneGraphRoot::getIterator(SceneGraphPtr list) | |
633 { | |
634 iterator->set(list); | |
635 return iterator; | |
636 } | |
637 | |
638 CameraPtr | |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
639 SceneGraphRoot::getCamera() |
539 | 640 { |
641 return camera; | |
642 } | |
597 | 643 |
747 | 644 |
645 SceneGraphPtr | |
761 | 646 SceneGraphRoot::getLight(int id) |
597 | 647 { |
648 | |
761 | 649 return light[id]; |
597 | 650 |
651 } | |
747 | 652 |
653 | |
654 float* | |
655 SceneGraphRoot::getLightVector() | |
656 { | |
657 return light_vector; | |
658 } | |
779 | 659 |
792 | 660 int* |
661 SceneGraphRoot::getLightSwitch() | |
662 { | |
663 return light_switch; | |
664 } | |
665 | |
666 int | |
667 SceneGraphRoot::getLightSysSwitch() | |
668 { | |
669 return light_sysswitch; | |
670 } | |
671 | |
793 | 672 void |
673 SceneGraphRoot::OnLightSwitch(int id) | |
674 { | |
675 light_switch[id] = 1; | |
676 } | |
677 | |
678 void | |
679 SceneGraphRoot::OffLightSwitch(int id) | |
680 { | |
681 light_switch[id] = 0; | |
682 } | |
683 | |
684 void | |
685 SceneGraphRoot::OnLightSysSwitch() | |
686 { | |
687 | |
688 light_sysswitch = 1; | |
689 | |
690 } | |
691 | |
692 void | |
693 SceneGraphRoot::OffLightSysSwitch() | |
694 { | |
695 | |
696 light_sysswitch = 0; | |
697 | |
698 } | |
699 | |
779 | 700 /* end */ |