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