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