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