Mercurial > hg > Game > Cerium
annotate Renderer/Engine/SceneGraphRoot.cc @ 845:71afabd4ba5c draft
light bug fix.
author | Yutaka_Kinjyo |
---|---|
date | Thu, 03 Jun 2010 02:55:29 +0900 |
parents | 66497087393d |
children | a033d464c812 |
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 | |
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); |
845 | 411 //get_matrix(c->real_matrix, c->angle, c->xyz, camera->real_matrix); |
412 | |
751
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
413 } |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
414 |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
415 if (t->children != NULL && c != NULL) { |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
416 cur_parent = c; |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
417 t = t->children; |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
418 } else if (t->brother != NULL) { |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
419 t = t->brother; |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
420 } else { |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
421 while (t) { |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
422 if (t->brother != NULL) { |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
423 t = t->brother; |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
424 break; |
539 | 425 } else { |
751
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
426 if (t->parent == NULL) { |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
427 t = NULL; |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
428 break; |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
429 } else { |
539 | 430 cur_parent = cur_parent->parent; |
431 t = t->parent; | |
751
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
432 } |
539 | 433 } |
751
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
434 } |
1666dba6f6d9
rendering, move_coll parallel running
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
747
diff
changeset
|
435 } |
539 | 436 } |
437 | |
438 | |
439 | |
440 // 現在、allExecute が終わった時点では | |
441 // camera->children が User SceneGraph の root になる | |
442 | |
443 /** | |
444 * NULL じゃなかったら、setSceneData が呼ばれてるから | |
445 * そっちを次の Scene にする | |
446 */ | |
447 | |
448 sg_exec_tree = camera->children; | |
449 } | |
450 | |
451 void | |
758 | 452 SceneGraphRoot::oneExecute(int screen_w, int screen_h) |
453 { | |
454 SceneGraphPtr list = sg_available_list; | |
759
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
455 //SceneGraphPtr t = sg_exec_tree; |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
456 //SceneGraphPtr cur_parent = camera; |
758 | 457 |
458 // 前フレームで描画した SceneGraph は削除 | |
459 allRemove(sg_remove_list); | |
460 | |
461 // 前フレームに作られた SceneGraph は描画用に移行 | |
462 // 現フレームでの操作は以下の tree,list には適用されない | |
463 sg_draw_tree = sg_exec_tree; | |
464 sg_remove_list = sg_available_list; | |
465 | |
466 // 現フレームで新しく SceneGraph がコピーされるので初期化 | |
467 sg_exec_tree = NULL; | |
468 sg_available_list = NULL; | |
469 | |
470 camera->move_execute(screen_w, screen_h); | |
471 camera->update(screen_w, screen_h); | |
472 | |
473 camera->children = NULL; | |
474 camera->lastChild = NULL; | |
475 | |
476 /* ここから */ | |
477 list->move_execute(screen_w, screen_h); | |
759
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
478 // ここで move_execute から実行される move_task の処理が終わるまで待ちたい |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
479 //while(move_finish_flag == 0) {} |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
480 //move_finish_flag = 0; |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
481 |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
482 list->create_sg_execute(); |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
483 |
758 | 484 list->collision_check(screen_w, screen_h, list); |
485 /* ここまで exec_task にする */ | |
486 | |
487 | |
488 /* ここから下を exec_task の post_func に*/ | |
489 list->frame++; | |
490 list = list->next; | |
491 | |
761 | 492 |
493 int light_num = 4; | |
494 for (int i = 0; i < light_num; i++) { | |
758 | 495 |
761 | 496 get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, camera->matrix); |
497 | |
498 light_vector[i*4] = 0.0f; | |
499 light_vector[i*4+1] = 0.0f; | |
500 light_vector[i*4+2] = 0.0f; | |
501 light_vector[i*4+3] = 1.0f; | |
758 | 502 |
761 | 503 ApplyMatrix(&light_vector[i*4], light[i]->matrix); |
504 | |
505 light_vector[i*4] /= light_vector[i*4+2]; | |
506 light_vector[i*4+1] /= light_vector[i*4+2]; | |
758 | 507 |
761 | 508 } |
758 | 509 |
510 if(sg_exec_tree != NULL) { | |
511 return; | |
512 } | |
513 } | |
514 | |
759
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 ExecMove task の post func として呼んでやる |
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 void |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
519 SceneGraphRoot::move_finish() |
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->collision_check(screen_w, screen_h, list); |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
522 |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
523 list->frame++; |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
524 //list = list->next; |
761 | 525 |
526 int light_num = 4; | |
527 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
|
528 |
761 | 529 get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, camera->matrix); |
530 | |
531 light_vector[i*4] = 0.0f; | |
532 light_vector[i*4+1] = 0.0f; | |
533 light_vector[i*4+2] = 0.0f; | |
534 light_vector[i*4+3] = 1.0f; | |
759
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
535 |
761 | 536 ApplyMatrix(&light_vector[i*4], light[i]->matrix); |
537 | |
538 light_vector[i*4] /= light_vector[i*4+2]; | |
539 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
|
540 |
768
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
764
diff
changeset
|
541 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
|
542 light_vector[i*4+3] *= -1; |
761 | 543 } |
759
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 //sgchange->viewer->light_xyz_stock = getLightVector(); |
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 |
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 void |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
550 SceneGraphRoot::appTaskRegist(regist_func 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 this->regist = new_register; |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
553 } |
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 void |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
556 SceneGraphRoot::regist_execute() |
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 (*regist)(this); |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
559 } |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
560 |
758 | 561 void |
539 | 562 SceneGraphRoot::allRemove(SceneGraphPtr list) |
563 { | |
564 SceneGraphPtr p = list; | |
759
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
565 |
539 | 566 while (p) { |
759
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
567 SceneGraphPtr p1 = p->next; |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
568 delete p; |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
569 p = p1; |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
570 cnt--; |
539 | 571 } |
572 } | |
573 | |
574 void | |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
575 SceneGraphRoot::checkRemove() |
539 | 576 { |
577 SceneGraphPtr p = sg_available_list; | |
578 SceneGraphPtr p1; | |
759
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
579 |
539 | 580 while (p) { |
759
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
581 p1 = p->next; |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
582 if (p->isRemoved()) { |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
583 sg_exec_tree = p->realRemoveFromTree(sg_exec_tree); |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
584 sg_available_list = p->realRemoveFromList(sg_available_list); |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
585 } |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
586 delete p; |
45f7ab7101ea
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
758
diff
changeset
|
587 p = p1; |
539 | 588 } |
589 } | |
590 | |
591 SceneGraphPtr | |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
592 SceneGraphRoot::getExecuteSceneGraph() |
539 | 593 { |
594 return sg_exec_tree; | |
595 } | |
596 | |
597 SceneGraphPtr | |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
598 SceneGraphRoot::getDrawSceneGraph() |
539 | 599 { |
600 return sg_draw_tree; | |
601 } | |
602 | |
603 void | |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
604 SceneGraphRoot::updateControllerState() |
539 | 605 { |
606 controller->check(); | |
607 } | |
608 | |
609 void | |
610 SceneGraphRoot::setSceneData(SceneGraphPtr sg) | |
611 { | |
612 sg_exec_tree = sg; | |
613 } | |
614 | |
615 Pad* | |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
616 SceneGraphRoot::getController() |
539 | 617 { |
618 return controller; | |
619 } | |
620 | |
621 SceneGraphIteratorPtr | |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
622 SceneGraphRoot::getIterator() |
539 | 623 { |
624 iterator->set(sg_remove_list); | |
625 return iterator; | |
626 } | |
627 | |
628 SceneGraphIteratorPtr | |
629 SceneGraphRoot::getIterator(SceneGraphPtr list) | |
630 { | |
631 iterator->set(list); | |
632 return iterator; | |
633 } | |
634 | |
635 CameraPtr | |
541
1a31b8820a4d
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
539
diff
changeset
|
636 SceneGraphRoot::getCamera() |
539 | 637 { |
638 return camera; | |
639 } | |
597 | 640 |
747 | 641 |
642 SceneGraphPtr | |
761 | 643 SceneGraphRoot::getLight(int id) |
597 | 644 { |
645 | |
761 | 646 return light[id]; |
597 | 647 |
648 } | |
747 | 649 |
650 | |
651 float* | |
652 SceneGraphRoot::getLightVector() | |
653 { | |
654 return light_vector; | |
655 } | |
779 | 656 |
792 | 657 int* |
658 SceneGraphRoot::getLightSwitch() | |
659 { | |
660 return light_switch; | |
661 } | |
662 | |
663 int | |
664 SceneGraphRoot::getLightSysSwitch() | |
665 { | |
666 return light_sysswitch; | |
667 } | |
668 | |
793 | 669 void |
670 SceneGraphRoot::OnLightSwitch(int id) | |
671 { | |
672 light_switch[id] = 1; | |
673 } | |
674 | |
675 void | |
676 SceneGraphRoot::OffLightSwitch(int id) | |
677 { | |
678 light_switch[id] = 0; | |
679 } | |
680 | |
681 void | |
682 SceneGraphRoot::OnLightSysSwitch() | |
683 { | |
684 | |
685 light_sysswitch = 1; | |
686 | |
687 } | |
688 | |
689 void | |
690 SceneGraphRoot::OffLightSysSwitch() | |
691 { | |
692 | |
693 light_sysswitch = 0; | |
694 | |
695 } | |
696 | |
779 | 697 /* end */ |