diff TaskManager/Test/test_render/SceneGraph.cpp @ 138:3fd24be89d02

オブジェクトを増やして複数の表示に成功。 TODO:オブジェクトの削除
author gongo@charles.cr.ie.u-ryukyu.ac.jp
date Fri, 28 Nov 2008 12:16:24 +0900
parents 6cf991f28c6c
children c948f4ebde62
line wrap: on
line diff
--- a/TaskManager/Test/test_render/SceneGraph.cpp	Fri Nov 28 10:07:48 2008 +0900
+++ b/TaskManager/Test/test_render/SceneGraph.cpp	Fri Nov 28 12:16:24 2008 +0900
@@ -12,10 +12,11 @@
 extern int decode(char *cont, FILE *outfile);
 
 static void
-no_move(SceneGraphPtr self) {}
+no_move(SceneGraphPtr self, int screen_w, int screen_h) {}
 
 static void
-no_collision(SceneGraphPtr self, SceneGraphPtr tree) {}
+no_collision(SceneGraphPtr self, int screen_w, int screen_h,
+	     SceneGraphPtr tree) {}
 
 SceneGraph::SceneGraph(void)
 {
@@ -26,6 +27,14 @@
     brother = NULL;
     children = NULL;
     lastChild = NULL;
+
+    stack_xyz[0] = 0.0f;
+    stack_xyz[2] = 0.0f;
+    stack_xyz[1] = 0.0f;
+    stack_angle[0] = 0.0f;
+    stack_angle[1] = 0.0f;
+    stack_angle[2] = 0.0f;
+
     move = no_move;
     collision = no_collision;
 }
@@ -128,6 +137,24 @@
     return child;
 }
 
+/* 兄弟を追加  */
+SceneGraph*
+SceneGraph::addBrother(SceneGraph *bro)
+{
+    SceneGraphPtr sg = this->brother;
+
+    if (sg != NULL) {
+	while (sg->brother) {
+	    sg = sg->brother;
+	}
+	sg->brother = bro;
+    } else {
+	this->brother = bro;
+    }
+
+    return bro;
+}
+
 /* thisの子や子孫にnameのものが存在すればそいつを返す なければNULL.  */
 SceneGraph*
 SceneGraph::searchSceneGraph(char *name)
@@ -299,26 +326,26 @@
 }
 
 void
-SceneGraph::move_execute(void)
+SceneGraph::move_execute(int w, int h)
 {
-    (*move)(this);
+    (*move)(this, w, h);
 }
 
 void
-SceneGraph::collision_check(SceneGraph *tree)
+SceneGraph::collision_check(int w, int h, SceneGraph *tree)
 {
-    (*collision)(this, tree);
+    (*collision)(this, w, h, tree);
 }
 
 void
-SceneGraph::all_execute(void)
+SceneGraph::all_execute(int screen_w, int screen_h)
 {
     SceneGraphPtr top = this;
     SceneGraphPtr t = top;
 
     while (t) {
-	t->move_execute();
-	t->collision_check(top);
+	t->move_execute(screen_w, screen_h);
+	t->collision_check(screen_w, screen_h, top);
 
 	if (t->parent != NULL) {
 	    get_matrix(t->matrix, t->angle, t->xyz, t->parent->matrix);
@@ -369,3 +396,30 @@
 
     this->last = next;
 }
+
+SceneGraph*
+SceneGraph::clone(void) {
+    SceneGraphPtr p = new SceneGraph;
+    memcpy(p, this, sizeof(SceneGraph));
+
+
+    // どっかで関数にまとめるか
+    p->next = NULL;
+    p->last = NULL;
+
+    p->parent = NULL;
+    p->brother = NULL;
+    p->children = NULL;
+    p->lastChild = NULL;
+    p->move = no_move;
+    p->collision = no_collision;
+
+    p->stack_xyz[0] = 0.0f;
+    p->stack_xyz[2] = 0.0f;
+    p->stack_xyz[1] = 0.0f;
+    p->stack_angle[0] = 0.0f;
+    p->stack_angle[1] = 0.0f;
+    p->stack_angle[2] = 0.0f;
+    
+    return p;
+}