changeset 199:eb20274baa7c

add SceneGraph(ieshoot), add SystemSceneGraph(Camera)
author gongo@gendarme.cr.ie.u-ryukyu.ac.jp
date Mon, 26 Jan 2009 14:02:45 +0900
parents 57921c8d21c5
children 10ad99550ee8
files TaskManager/Test/test_render/Button.cpp TaskManager/Test/test_render/Button.h TaskManager/Test/test_render/Camera.h TaskManager/Test/test_render/ChangeLog TaskManager/Test/test_render/Keyboard.cpp TaskManager/Test/test_render/Makefile.def TaskManager/Test/test_render/SceneGraph.cpp TaskManager/Test/test_render/SceneGraph.h TaskManager/Test/test_render/SceneGraphRoot.cpp TaskManager/Test/test_render/SceneGraphRoot.h TaskManager/Test/test_render/ieshoot.cpp TaskManager/Test/test_render/main.cpp TaskManager/Test/test_render/universe.cpp TaskManager/Test/test_render/viewer.cpp
diffstat 14 files changed, 252 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/Test/test_render/Button.cpp	Mon Jan 26 10:38:29 2009 +0900
+++ b/TaskManager/Test/test_render/Button.cpp	Mon Jan 26 14:02:45 2009 +0900
@@ -24,3 +24,21 @@
     hold = 0;
     release = 1;
 }
+
+int
+Button::isPush(void)
+{
+    return push;
+}
+
+int
+Button::isHold(void)
+{
+    return hold;
+}
+
+int
+Button::isRelease(void)
+{
+    return release;
+}
--- a/TaskManager/Test/test_render/Button.h	Mon Jan 26 10:38:29 2009 +0900
+++ b/TaskManager/Test/test_render/Button.h	Mon Jan 26 14:02:45 2009 +0900
@@ -11,6 +11,9 @@
 
     void push_work(void);
     void release_work(void);
+    int isPush(void);
+    int isHold(void);
+    int isRelease(void);
 };
 
 #endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TaskManager/Test/test_render/Camera.h	Mon Jan 26 14:02:45 2009 +0900
@@ -0,0 +1,11 @@
+#ifndef INCLUDE_CAMERA
+#define INCLUDE_CAMERA
+
+class Camera : public SceneGraph {
+public:
+    Camera(void) {}
+};
+
+typedef Camera *CameraPtr;
+
+#endif
--- a/TaskManager/Test/test_render/ChangeLog	Mon Jan 26 10:38:29 2009 +0900
+++ b/TaskManager/Test/test_render/ChangeLog	Mon Jan 26 14:02:45 2009 +0900
@@ -1,3 +1,19 @@
+2009-01-26  Wataru MIYAGUNI  <gongo@cr.ie.u-ryukyu.ac.jp>
+
+	* Camera.h (class Camera): add
+	とりあえず Camera を作って、これを SceneGraph の Top にした。
+
+	* SceneGraph.cpp (SceneGraph::realRemoveFromTree): add
+	realRemove() の Tree構造用。削除後の tree top を返す様にしている。
+	まあ top が消えなければ返す必要も無いし、top が消えるってことは
+	SceneGraph そのものが消えるってことでそうは無い・・はずだけどね。
+	(SceneGraph::realRemoveFromList): add
+	realRemove() の list用。削除後の list top を返す様にしている。
+	(SceneGraph::realRemoveFromTree): fix
+	< p->next = p1->next;
+	===
+	> p->brother = p1->brother;
+
 2009-01-25  Wataru MIYAGUNI  <gongo@cr.ie.u-ryukyu.ac.jp>
 
 	* add (tools/create_sglist): new
--- a/TaskManager/Test/test_render/Keyboard.cpp	Mon Jan 26 10:38:29 2009 +0900
+++ b/TaskManager/Test/test_render/Keyboard.cpp	Mon Jan 26 14:02:45 2009 +0900
@@ -43,7 +43,6 @@
     }
 
     if (keys[SDLK_a] == SDL_PRESSED) {
-	printf("ahsas\n");
 	square.push_work();
     } else {
 	square.release_work();
--- a/TaskManager/Test/test_render/Makefile.def	Mon Jan 26 10:38:29 2009 +0900
+++ b/TaskManager/Test/test_render/Makefile.def	Mon Jan 26 14:02:45 2009 +0900
@@ -12,7 +12,7 @@
 #CERIUM = ../../..
 
 CC      = g++
-CFLAGS  = -O9 -g -Wall# -DDEBUG
+CFLAGS  = -O0 -g -Wall# -DDEBUG
 
 INCLUDE = -I$(CERIUM)/include/TaskManager -I.
 LIBS = -L$(CERIUM)/TaskManager
\ No newline at end of file
--- a/TaskManager/Test/test_render/SceneGraph.cpp	Mon Jan 26 10:38:29 2009 +0900
+++ b/TaskManager/Test/test_render/SceneGraph.cpp	Mon Jan 26 14:02:45 2009 +0900
@@ -119,6 +119,8 @@
     stack_angle[1] = 0.0f;
     stack_angle[2] = 0.0f;
 
+    data = NULL;
+
     texture_id = -1;
     move = no_move;
     collision = no_collision;
@@ -577,52 +579,83 @@
     this->flag_remove = 1;
 }
 
-void
-SceneGraph::realRemove(void)
+/**
+ * tree から node を削除する
+ * 
+ * @param tree SceneGraphTree
+ * @param node 削除後の SceneGraphTree
+ */
+SceneGraphPtr
+SceneGraph::realRemoveFromTree(SceneGraphPtr tree)
 {
     SceneGraphPtr node = this;
+    SceneGraphPtr parent = node->parent;
+    SceneGraphPtr ret = tree;
 
+    if (parent) {
+	SceneGraphPtr brother = parent->children;
+	SceneGraphPtr p, p1 = NULL;
+
+	p = brother;
+	if (p) {
+	    if (p == node) {
+		parent->children = NULL;
+		parent->lastChild = NULL;
+	    } else {
+		p1 = p->next;
+
+		while (p1 && p1 != node) {
+		    p1 = p1->next;
+		    p = p->next;
+		}
+	    
+		if (p1) {
+		    p->brother = p1->brother;
+
+		    // node が最後尾なら、lastChild を変更
+		    if (parent->lastChild == p1) {
+			parent->lastChild = p;
+		    }
+		} else {
+		    // Can't find remove node
+		}
+	    }
+	}
+    } else {
+	// 親が居ない = tree root なので
+	// NULL を返す
+	ret = NULL;
+    }
+
+    delete node;
+    return ret;
+}
+
+/**
+ * list から node を削除する
+ * 
+ * @param list SceneGraphList
+ * @param node 削除後の SceneGraphList
+ */
+SceneGraphPtr
+SceneGraph::realRemoveFromList(SceneGraphPtr list)
+{
+    SceneGraphPtr node = this;
     SceneGraphPtr prev = node->prev;
     SceneGraphPtr next = node->next;
+    SceneGraphPtr ret = list;
     
     if (prev) {
 	prev->next = next;
+    } else {
+	ret = next;
     }
+
     if (next) {
 	next->prev = prev;
     }
 
-    SceneGraphPtr parent = node->parent;
-    SceneGraphPtr brother = parent->children;
-    SceneGraphPtr p, p1 = NULL;
-
-    p = brother;
-    if (p) {
-	if (p == node) {
-	    parent->children = NULL;
-	    parent->lastChild = NULL;
-	} else {
-	    p1 = p->next;
-
-	    while (p1 && p1 != node) {
-		p1 = p1->next;
-		p = p->next;
-	    }
-	    
-	    if (p1) {
-		p->next = p1->next;
-
-		// node が最後尾なら、lastChild を変更
-		if (parent->lastChild == p1) {
-		    parent->lastChild = p;
-		}
-	    } else {
-		// Can't find remove node
-	    }
-	}
-    }
-
-    delete node;
+    return ret;
 }
 
 int
--- a/TaskManager/Test/test_render/SceneGraph.h	Mon Jan 26 10:38:29 2009 +0900
+++ b/TaskManager/Test/test_render/SceneGraph.h	Mon Jan 26 14:02:45 2009 +0900
@@ -59,11 +59,10 @@
 			    move_func new_move, collision_func new_collision);
     void set_move_collision(move_func new_move, collision_func new_collision);
     void remove(void);
-    void realRemove(void);
+    SceneGraphPtr realRemoveFromTree(SceneGraphPtr tree);
+    SceneGraphPtr realRemoveFromList(SceneGraphPtr list);
     int isRemoved(void);
 
-
-
     static void createFromXMLfile(const char *);
     static SceneGraphPtr createSceneGraph(int id);
 
--- a/TaskManager/Test/test_render/SceneGraphRoot.cpp	Mon Jan 26 10:38:29 2009 +0900
+++ b/TaskManager/Test/test_render/SceneGraphRoot.cpp	Mon Jan 26 14:02:45 2009 +0900
@@ -11,9 +11,15 @@
 SceneGraphRoot::SceneGraphRoot(void)
 {
     sg_src = new SceneGraphPtr[SGLIST_LENGTH];
+    camera = new Camera;
+
     sg_exec_list = NULL;
     sg_draw_list = NULL;
     sg_available_list = NULL;
+
+    // TODO
+    //   今はとりあえず camera を Root にしています
+    sg_exec_list = camera;
 }
 
 SceneGraphRoot::~SceneGraphRoot(void)
@@ -27,6 +33,7 @@
     }
 
     delete [] sg_src;
+    delete camera;
 }
 
 void
@@ -160,10 +167,14 @@
     while (p) {
 	p1 = p->next;
 	if (p->isRemoved()) {
-	    p->realRemove();
+	    sg_exec_list = p->realRemoveFromTree(sg_exec_list);
+	    sg_available_list = p->realRemoveFromList(sg_available_list);
 	}
 	p = p1;
     }
+
+    // 現在、exec と draw は別で処理できてないので、一緒にする
+    sg_draw_list = sg_exec_list;
 }
 
 SceneGraphPtr
@@ -187,5 +198,13 @@
 void
 SceneGraphRoot::setSceneData(SceneGraphPtr sg)
 {
-    sg_draw_list = sg_exec_list = sg;
+    //sg_draw_list = sg_exec_list = sg;
+    sg_exec_list->addChild(sg);
+    sg_draw_list = sg_exec_list;
 }
+
+Pad*
+SceneGraphRoot::getController(void)
+{
+    return controller;
+}
--- a/TaskManager/Test/test_render/SceneGraphRoot.h	Mon Jan 26 10:38:29 2009 +0900
+++ b/TaskManager/Test/test_render/SceneGraphRoot.h	Mon Jan 26 14:02:45 2009 +0900
@@ -5,6 +5,10 @@
 #  include "SceneGraph.h"
 #endif
 
+#ifndef INCLUDED_CAMERA
+#  include "Camera.h"
+#endif
+
 class SceneGraphRoot {
 public:
     /* Constructor, Destructor */
@@ -27,6 +31,9 @@
     // コントローラーオブジェクト (Keyboard, Joystick, ..)
     Pad *controller;
 
+    // カメラオブジェクト
+    Camera *camera;
+
     /**
      * Functions
      */
@@ -34,6 +41,7 @@
     void createFromXMLfile(const char *);
     SceneGraphPtr createSceneGraph(int id);
     void setSceneData(SceneGraphPtr sg);
+    Pad *getController(void);
 
     /* Other System API */
     void allExecute(int screen_w, int screen_h);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TaskManager/Test/test_render/ieshoot.cpp	Mon Jan 26 14:02:45 2009 +0900
@@ -0,0 +1,95 @@
+#include "SceneGraphRoot.h"
+#include "SGList.h"
+
+static const int jiki_speed = 6.0f;
+static const int jiki_radius = 32.0f;
+static const int tama_speed = 10.0f;
+
+static void
+iejiki_collision(SceneGraphPtr node, int screen_w, int screen_h,
+	       SceneGraphPtr tree)
+{
+}
+
+static void
+ietama_collision(SceneGraphPtr node, int screen_w, int screen_h,
+	       SceneGraphPtr tree)
+{
+}
+
+
+static void
+ietama_move(SceneGraphPtr node, int screen_w, int screen_h)
+{
+    node->xyz[1] -= tama_speed;
+
+    // 描画領域から抜けたら削除
+    if (node->xyz[1] < 0) {
+	node->remove();
+    }
+}
+
+static void
+iejiki_move(SceneGraphPtr node, int screen_w, int screen_h)
+{
+    Pad *pad = sgroot->getController();
+
+    if (pad->left.isPush()
+	|| pad->left.isHold()) {
+	node->xyz[0] -= jiki_speed;
+
+	if (node->xyz[0] - jiki_radius< 0) {
+	    node->xyz[0] = jiki_radius;
+	}
+    }
+
+    if (pad->right.isPush()
+	|| pad->right.isHold()) {
+	node->xyz[0] += jiki_speed;
+
+	if (node->xyz[0] + jiki_radius > screen_w) {
+	    node->xyz[0] = screen_w - jiki_radius;
+	}
+    }
+
+    if (pad->up.isPush()
+	|| pad->up.isHold()) {
+	node->xyz[1] -= jiki_speed;
+
+	if (node->xyz[1] - jiki_radius < 0) {
+	    node->xyz[1] = jiki_radius;
+	}
+    }
+
+    if (pad->down.isPush()
+	|| pad->down.isHold()) {
+	node->xyz[1] += jiki_speed;
+
+	if (node->xyz[1] + jiki_radius > screen_h) {
+	    node->xyz[1] = screen_h - jiki_radius;
+	}
+    }
+
+    if (pad->circle.isPush()) {
+	SceneGraphPtr ietama = sgroot->createSceneGraph(IETAMA);
+	ietama->set_move_collision(ietama_move, ietama_collision);
+	ietama->xyz[0] = node->xyz[0];
+	ietama->xyz[1] = node->xyz[1];
+	node->addBrother(ietama);
+    }
+}
+
+
+void
+ieshoot_init(void)
+{
+    SceneGraphPtr iejiki;
+
+    sgroot->createFromXMLfile("xml_file/iejiki.xml");
+    sgroot->createFromXMLfile("xml_file/ietama.xml");
+
+    iejiki = sgroot->createSceneGraph(IEJIKI);
+    iejiki->set_move_collision(iejiki_move, iejiki_collision);
+
+    sgroot->setSceneData(iejiki);
+}
--- a/TaskManager/Test/test_render/main.cpp	Mon Jan 26 10:38:29 2009 +0900
+++ b/TaskManager/Test/test_render/main.cpp	Mon Jan 26 14:02:45 2009 +0900
@@ -19,10 +19,11 @@
   -sg Draw SceneGraph\n\
       0: Joystick の 丸ボタン(Keyboard だとx) を押すと、キューブが二つに分かれる\n\
       1: 0 のキューブが大きい版\n\
-      2: スネークさんが写るだけ 576x384 版\n\
-      3: スネークさんが写るだけ 800x600 版\n\
-      4: 何かの画像 1920x1080\n\
-      5 以降: キューブが跳ね返りながら、勝手にキューブが増えて行く";
+      2: テクスチャテスト:576x384\n\
+      3: テクスチャテスト:1024x768\n\
+      4: テクスチャテスト:2048x1536\n\
+      5: 地球が動き、その周りを月が自転、公転する\n\
+      6 以降: キューブが跳ね返りながら、勝手にキューブが増えて行く\n";
 
 int
 init(int argc, char *argv[])
--- a/TaskManager/Test/test_render/universe.cpp	Mon Jan 26 10:38:29 2009 +0900
+++ b/TaskManager/Test/test_render/universe.cpp	Mon Jan 26 14:02:45 2009 +0900
@@ -5,7 +5,7 @@
 int moonrem = 0;
 
 static void
-cube_collision(SceneGraphPtr node, int screen_w, int screen_h,
+earth_collision(SceneGraphPtr node, int screen_w, int screen_h,
 	       SceneGraphPtr tree)
 {
 }
@@ -20,7 +20,6 @@
 moon_move(SceneGraphPtr node, int screen_w, int screen_h)
 {
     node->angle[0] += 3.0f;
-    printf("%f\n", node->angle[0]);
     if (node->angle[0] > 360.0f) {
 	node->remove();
 	//node->angle[0] = 0.0f;
@@ -30,7 +29,7 @@
 
 
 static void
-cube_move(SceneGraphPtr node, int screen_w, int screen_h)
+earthmove(SceneGraphPtr node, int screen_w, int screen_h)
 {
     node->angle[1] += 1.0f;
     if (node->angle[1] > 360.0f) {
@@ -67,7 +66,7 @@
     moon = sgroot->createSceneGraph(Moon);
 
     // SceneGraph の move と collision を設定
-    earth->set_move_collision(cube_move, cube_collision);
+    earth->set_move_collision(earthmove, earth_collision);
     earth->stack_xyz[0] = 3.0f;
     earth->stack_xyz[1] = 3.0f;
     moon->set_move_collision(moon_move, moon_collision);
--- a/TaskManager/Test/test_render/viewer.cpp	Mon Jan 26 10:38:29 2009 +0900
+++ b/TaskManager/Test/test_render/viewer.cpp	Mon Jan 26 14:02:45 2009 +0900
@@ -108,7 +108,8 @@
 extern void node_init(void);
 extern void create_cube_split(int);
 extern void panel_init(int);
-extern void universe_init();
+extern void universe_init(void);
+extern void ieshoot_init(void);
 
 void
 Viewer::run_init(const char *xml, int sg_number)
@@ -137,7 +138,7 @@
 	universe_init();
 	break;
     case 6:
-	node_init();
+	ieshoot_init();
 	break;
     default:
 	node_init();