changeset 779:4455e7b0caf3

merged
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 05 Mar 2010 13:12:31 +0900
parents 2b5ff18976cb (current diff) 97a514cf6ad3 (diff)
children 50cff7c4d255
files Renderer/Engine/Camera.cc Renderer/Engine/Makefile.def Renderer/Engine/SceneGraphRoot.cc Renderer/Engine/SgChange.cc Renderer/Engine/SgChange.h Renderer/Engine/global_alloc.h Renderer/Engine/spe/DataLoad.cc Renderer/Engine/spe/DataUpdate.cc Renderer/Engine/spe/DrawSpan.cc Renderer/Engine/spe/Makefile Renderer/Engine/spe/spe-main.cc Renderer/Engine/task/DataLoad.cc Renderer/Engine/task/DataUpdate.cc Renderer/Engine/task/task_init.cc Renderer/Engine/viewer.cc Renderer/Engine/viewer.h Renderer/Test/Makefile.cell Renderer/Test/Makefile.def Renderer/Test/Makefile.macosx Renderer/Test/SgRootChange.cc Renderer/Test/ball_bound.h Renderer/Test/property_test.cc Renderer/Test/property_test.h Renderer/Test/vacuum.cc
diffstat 43 files changed, 1676 insertions(+), 292 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/RenderingTasks.h	Fri Mar 05 12:51:36 2010 +0900
+++ b/Renderer/Engine/RenderingTasks.h	Fri Mar 05 13:12:31 2010 +0900
@@ -18,6 +18,8 @@
      SetTexture,
 
      Move,
+     RunMove,
+     ExecMove,
      Draw,
 
      // Dummy,
@@ -30,7 +32,9 @@
      ChainMove,
      ChainCal,
      ChainInit,
-
+     PropertyTask,
+     UniverseTask,
+     ChainTask,
 
      RUN_FINISH,
 
--- a/Renderer/Engine/SceneGraph.cc	Fri Mar 05 12:51:36 2010 +0900
+++ b/Renderer/Engine/SceneGraph.cc	Fri Mar 05 13:12:31 2010 +0900
@@ -535,6 +535,12 @@
     (*collision)(this, this->sgroot, w, h, tree);
 }
 
+void
+SceneGraph::create_sg_execute()
+{
+    (*create_sg)(this->sgroot, property, update_property);
+}
+
 
 void
 SceneGraph::set_move_collision(move_func new_move,
@@ -556,6 +562,15 @@
 }
 
 void
+SceneGraph::set_move_collision(move_func new_move,
+                               collision_func new_collision, create_sg_func new_create_sg)
+{
+    this->move = new_move;
+    this->collision = new_collision;
+    this->create_sg = new_create_sg;
+}
+
+void
 SceneGraph::add_next(SceneGraphPtr next)
 {
     /* next のリストの最後に加える */
--- a/Renderer/Engine/SceneGraph.h	Fri Mar 05 12:51:36 2010 +0900
+++ b/Renderer/Engine/SceneGraph.h	Fri Mar 05 13:12:31 2010 +0900
@@ -12,6 +12,7 @@
 //                               SceneGraph* tree);
 typedef void (*collision_func)(SceneGraph* node, void *sgroot, int screen_w, int screen_h,
                                SceneGraph* tree);
+typedef void (*create_sg_func)(void *sgroot, void *property, void *update_property);
 typedef SceneGraph* SceneGraphPtr;
 
 class SceneGraph : public Polygon {
@@ -34,7 +35,12 @@
 	int seq;
 	
     int property_size;
-    void* propertyptr;
+    void *propertyptr;
+    //void *property;
+    //void *update_property;
+    memaddr property;
+    memaddr update_property;
+
 
     // xml ファイルから生成した時のオブジェクトリスト
     SceneGraphPtr next;
@@ -65,6 +71,7 @@
     // 関数ポインタ
     move_func move;
     collision_func collision;
+    create_sg_func create_sg;
 
     // desutroctor で呼ばれる
     void (SceneGraph::*finalize)(void);
@@ -74,6 +81,7 @@
     void finalize_copy(void);
     void move_execute(int screen_w, int screen_h);
     void collision_check(int screen_w, int screen_h, SceneGraphPtr tree);
+    void create_sg_execute();
     void all_execute(int screen_w, int screen_h);
 
     void add_next(SceneGraphPtr next);
@@ -84,6 +92,7 @@
     SceneGraphPtr searchSceneGraph(const char *name);
     void set_move_collision(move_func new_move, collision_func new_collision);
     void set_move_collision(move_func new_move, collision_func new_collision, void *sgroot);
+    void set_move_collision(move_func new_move, collision_func new_collision, create_sg_func new_create_sg);
     void remove(void);
     SceneGraphPtr realRemoveFromTree(SceneGraphPtr tree);
     SceneGraphPtr realRemoveFromList(SceneGraphPtr list);
--- a/Renderer/Engine/SceneGraphRoot.cc	Fri Mar 05 12:51:36 2010 +0900
+++ b/Renderer/Engine/SceneGraphRoot.cc	Fri Mar 05 13:12:31 2010 +0900
@@ -25,7 +25,7 @@
     sg_src = (SceneGraphPtr*) malloc(sizeof(SceneGraphPtr)*SGLIST_LENGTH);
 
     camera = new Camera(w, h, this);
-    light = new SceneGraph;
+
     iterator = new SceneGraphIterator;
     controller = create_controller();
 
@@ -36,13 +36,18 @@
 
     sgroot = this;
 
-    //int size = 4;
-    //light_vector = (float*)malloc(sizeof(float)*size);
+    screen_w = (int)w;
+    screen_h = (int)h;
+    int light_num = 4;
 
-    light->xyz[0] = 0;
-    light->xyz[1] = 0;
-    light->xyz[2] = 0;
+    for (int i = 0; i < light_num; i++) {
+      light[i] = new SceneGraph;
+      light[i]->xyz[0] = 0;
+      light[i]->xyz[1] = 0;
+      light[i]->xyz[2] = 0;
+    }
 
+    move_finish_flag = 0;
 
     // TODO
     //   今はとりあえず camera を Root にしています
@@ -72,7 +77,10 @@
 
     free(sg_src);
     delete camera;
-    delete light;
+    int light_num = 4;
+    for (int i = 0; i < light_num; i++) {
+      delete light[i];
+    }
     delete iterator;
     delete controller;
 }
@@ -321,61 +329,6 @@
     sg_exec_tree = camera->children;
 }
 
-void
-SceneGraphRoot::speExecute(int screen_w, int screen_h, Application *app)
-{
-    // SceneGraphPtr t = sg_exec_tree;
-    // SceneGraphPtr cur_parent = camera;
-
-    // 前フレームで描画した SceneGraph は削除
-    allRemove(sg_remove_list);
-
-    // 前フレームに作られた SceneGraph は描画用に移行
-    // 現フレームでの操作は以下の tree,list には適用されない
-    sg_draw_tree = sg_exec_tree;
-    sg_remove_list = sg_available_list;
-
-    // 現フレームで新しく SceneGraph がコピーされるので初期化
-    sg_exec_tree = NULL;
-    sg_available_list = NULL;
-
-    camera->move_execute(screen_w, screen_h);
-    camera->update(screen_w, screen_h);
-
-    camera->children = NULL;
-    camera->lastChild = NULL;
-    
-
-    if(sg_exec_tree != NULL) {
-	return;
-    }
-
-    /*removeのflagをもとにtreeを形成*/
-    /* spe から送り返されてきた property の配列を見て生成する for()*/
-    /* Application内に移動 */
-
-    // app->property_ope(sg_available_list);
-
-    /* 
-    for (Property *t = (Property *)properties[0]; is_end(t); t++){
-	SceneGraphPtr s = app->scenegraph_factory(t); // SceneGraphNode を作る
-	t->scenegraph = s; // property list には SceneGraphへのポインタが入っている
-	app->scenegraph_connector(property[0], s); // add する
-    }  
-    */
-    
-    
-
-    // 現在、allExecute が終わった時点では
-    // camera->children が User SceneGraph の root になる
-
-    /**
-     * NULL じゃなかったら、setSceneData が呼ばれてるから
-     * そっちを次の Scene にする
-     */
-
-    sg_exec_tree = camera->children;
-}
 
 
 void
@@ -411,60 +364,69 @@
         
 	list->frame++; 
         list = list->next;
+    }    
+
+    int light_num = 4;
+    for (int i = 0; i < light_num; i++) {
+
+      get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, camera->matrix);
+      
+      light_vector[i*4] = 0.0f;
+      light_vector[i*4+1] = 0.0f;
+      light_vector[i*4+2] = 0.0f;
+      light_vector[i*4+3] = 1.0f;
+
+      ApplyMatrix(&light_vector[i*4], light[i]->matrix);
+      
+      light_vector[i*4] /= light_vector[i*4+2];
+      light_vector[i*4+1] /= light_vector[i*4+2];
+
+      /*SIMD演算のため*/
+      light_vector[i*4+2] *= -1;
+      light_vector[i*4+3] *= -1;
+
     }
 
-    get_matrix(light->matrix, light->angle, light->xyz, camera->matrix);
-
-    light_vector[0] = 0.0f;
-    light_vector[1] = 0.0f;
-    light_vector[2] = 0.0f;
-    light_vector[3] = 1.0f;
-
-    ApplyMatrix(light_vector, light->matrix);
-
-    light_vector[0] /= light_vector[2];
-    light_vector[1] /= light_vector[2];
    
     if(sg_exec_tree != NULL) {
-		return;
+	return;
     }
 
     /*removeのflagをもとにtreeを形成*/
     while (t) {
-		SceneGraphPtr c = NULL;
-		if (!t->isRemoved()) {
-			c = t->clone();	    
-			addNext(c);
-			cur_parent->addChild(c);
-			c->frame = t->frame;
-            /*親の回転、座標から、子の回転、座標を算出*/
-            get_matrix(c->matrix, c->angle, c->xyz, cur_parent->matrix);
+	SceneGraphPtr c = NULL;
+	if (!t->isRemoved()) {
+	    c = t->clone();	    
+	    addNext(c);
+	    cur_parent->addChild(c);
+	    c->frame = t->frame;
+	    /*親の回転、座標から、子の回転、座標を算出*/
+	    get_matrix(c->matrix, c->angle, c->xyz, cur_parent->matrix);
 	    /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/
-            get_matrix(c->real_matrix, c->angle, c->xyz, cur_parent->real_matrix);
-        } 
-
-		if (t->children != NULL && c != NULL) {
-			cur_parent = c;
-			t = t->children;
-		} else if (t->brother != NULL) {
-			t = t->brother;
+	    get_matrix(c->real_matrix, c->angle, c->xyz, cur_parent->real_matrix);
+	} 
+	
+	if (t->children != NULL && c != NULL) {
+	    cur_parent = c;
+	    t = t->children;
+	} else if (t->brother != NULL) {
+	    t = t->brother;
+	} else {
+	    while (t) {
+		if (t->brother != NULL) {
+		    t = t->brother;
+		    break;
 		} else {
-			while (t) {
-				if (t->brother != NULL) {
-					t = t->brother;
-					break;
-				} else {
-					if (t->parent == NULL) {
-						t = NULL;
-						break;
-					} else {
+		    if (t->parent == NULL) {
+			t = NULL;
+			break;
+		    } else {
                         cur_parent = cur_parent->parent;
                         t = t->parent;
-			
-					}
-				}
-			}	    
+		    }
 		}
+	    }	    
+	}
     }
 
       
@@ -481,15 +443,125 @@
 }
 
 void
+SceneGraphRoot::oneExecute(int screen_w, int screen_h)
+{
+    SceneGraphPtr list = sg_available_list;
+    //SceneGraphPtr t = sg_exec_tree;
+    //SceneGraphPtr cur_parent = camera;
+
+    // 前フレームで描画した SceneGraph は削除
+    allRemove(sg_remove_list);
+
+    // 前フレームに作られた SceneGraph は描画用に移行
+    // 現フレームでの操作は以下の tree,list には適用されない
+    sg_draw_tree = sg_exec_tree;
+    sg_remove_list = sg_available_list;
+
+    // 現フレームで新しく SceneGraph がコピーされるので初期化
+    sg_exec_tree = NULL;
+    sg_available_list = NULL;
+
+    camera->move_execute(screen_w, screen_h);
+    camera->update(screen_w, screen_h);
+
+    camera->children = NULL;
+    camera->lastChild = NULL;
+
+    /* ここから */
+    list->move_execute(screen_w, screen_h);
+    // ここで move_execute から実行される move_task の処理が終わるまで待ちたい
+    //while(move_finish_flag == 0) {}
+    //move_finish_flag = 0;
+
+    list->create_sg_execute();
+    
+    list->collision_check(screen_w, screen_h, list);	
+    /* ここまで exec_task にする */
+    
+    
+    /* ここから下を exec_task の post_func に*/
+    list->frame++; 
+    list = list->next;
+
+
+    int light_num = 4;
+    for (int i = 0; i < light_num; i++) {
+
+      get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, camera->matrix);
+      
+      light_vector[i*4] = 0.0f;
+      light_vector[i*4+1] = 0.0f;
+      light_vector[i*4+2] = 0.0f;
+      light_vector[i*4+3] = 1.0f;
+
+      ApplyMatrix(&light_vector[i*4], light[i]->matrix);
+      
+      light_vector[i*4] /= light_vector[i*4+2];
+      light_vector[i*4+1] /= light_vector[i*4+2];
+
+    }
+   
+    if(sg_exec_tree != NULL) {
+	return;
+    }
+}
+
+/*
+  ExecMove task の post func として呼んでやる
+ */
+void
+SceneGraphRoot::move_finish()
+{    
+    list->collision_check(screen_w, screen_h, list);	
+
+    list->frame++; 
+    //list = list->next;
+
+    int light_num = 4;
+    for (int i = 0; i < light_num; i++) {
+
+      get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, camera->matrix);
+      
+      light_vector[i*4] = 0.0f;
+      light_vector[i*4+1] = 0.0f;
+      light_vector[i*4+2] = 0.0f;
+      light_vector[i*4+3] = 1.0f;
+
+      ApplyMatrix(&light_vector[i*4], light[i]->matrix);
+      
+      light_vector[i*4] /= light_vector[i*4+2];
+      light_vector[i*4+1] /= light_vector[i*4+2];
+
+      light_vector[i*4+2] *= -1;
+      light_vector[i*4+3] *= -1;
+    }    
+    
+    //sgchange->viewer->light_xyz_stock = getLightVector();
+}
+
+
+void
+SceneGraphRoot::appTaskRegist(regist_func new_register)
+{
+    this->regist = new_register;
+}
+
+void
+SceneGraphRoot::regist_execute()
+{
+    (*regist)(this);
+}
+
+void
 SceneGraphRoot::allRemove(SceneGraphPtr list)
 {
     SceneGraphPtr p = list;
-
+    
     while (p) {
-		SceneGraphPtr p1 = p->next;
-		delete p;
-		p = p1;
-		cnt--;
+	SceneGraphPtr p1 = p->next;
+	delete p;
+	p = p1;
+	cnt--;
     }
 }
 
@@ -498,15 +570,15 @@
 {
     SceneGraphPtr p = sg_available_list;
     SceneGraphPtr p1;
-
+    
     while (p) {
-		p1 = p->next;
-		if (p->isRemoved()) {
-			sg_exec_tree = p->realRemoveFromTree(sg_exec_tree);
-			sg_available_list = p->realRemoveFromList(sg_available_list);
-		}
-		delete p;
-		p = p1;
+	p1 = p->next;
+	if (p->isRemoved()) {
+	    sg_exec_tree = p->realRemoveFromTree(sg_exec_tree);
+	    sg_available_list = p->realRemoveFromList(sg_available_list);
+	}
+	delete p;
+	p = p1;
     }
 }
 
@@ -562,10 +634,10 @@
 
 
 SceneGraphPtr
-SceneGraphRoot::getLight()
+SceneGraphRoot::getLight(int id)
 {
 
-  return light;
+  return light[id];
 
 }
 
@@ -575,3 +647,5 @@
 {
   return light_vector;
 }
+
+/* end */
--- a/Renderer/Engine/SceneGraphRoot.h	Fri Mar 05 12:51:36 2010 +0900
+++ b/Renderer/Engine/SceneGraphRoot.h	Fri Mar 05 13:12:31 2010 +0900
@@ -14,6 +14,9 @@
 
 class Application;
 
+class SceneGraphRoot;
+typedef void (*regist_func)(SceneGraphRoot *sgroot);
+
 class SceneGraphRoot {
 public:
     /* Constructor, Destructor */
@@ -27,6 +30,7 @@
     // Static Singleton
     // SceneGraphPtr *sg_src;
     // int sg_src_length;
+    SceneGraphPtr list;
 
     // move, collision 用の SceneGraph (tree)
     SceneGraphPtr sg_exec_tree;
@@ -52,9 +56,11 @@
     Camera *camera;
 
     // 光源のオブジェクト
-    SceneGraphPtr light;
+    SceneGraphPtr light[4];
     // 光源の疑似 xml file
-    float light_vector[4];
+    // 光源は4つで決め打ち。                                                         
+    // 4 * lightnum (4) = 16;
+    float light_vector[16];
 
     // SceneGraphIterator
     SceneGraphIteratorPtr iterator;
@@ -62,6 +68,19 @@
     // fd of Linda taple space
     int tid;
 
+    // move task test flag
+    int move_finish_flag;
+
+    // 関数ポインタ
+    regist_func regist;
+    // application で実行する task
+    HTaskPtr move_exec_task;
+
+    // とりあえず
+    int screen_w;
+    int screen_h;
+
+
     /**
      * Functions
      */
@@ -72,21 +91,25 @@
     SceneGraphPtr createSceneGraph();
     SceneGraphPtr createSceneGraph(const char *name);
     int getSgid(const char *name);
+    void appTaskRegist(regist_func new_regist);
 
     void setSceneData(SceneGraphPtr sg);
     Pad *getController();
     SceneGraphIteratorPtr getIterator();
     SceneGraphIteratorPtr getIterator(SceneGraphPtr list);
     CameraPtr getCamera();
-    SceneGraphPtr getLight();
+    SceneGraphPtr getLight(int id);
     float* getLightVector();
 
     /* Other System API */
     void allExecute(int screen_w, int screen_h);
+    void oneExecute(int screen_w, int screen_h);
     void checkRemove();
     SceneGraphPtr getExecuteSceneGraph();
     SceneGraphPtr getDrawSceneGraph();
     void updateControllerState();
+    void regist_execute();
+    void move_finish();
 
     void speExecute(int screen_w, int screen_h);
     void speExecute(int screen_w, int screen_h, Application *app);
--- a/Renderer/Engine/SgChange.cc	Fri Mar 05 12:51:36 2010 +0900
+++ b/Renderer/Engine/SgChange.cc	Fri Mar 05 13:12:31 2010 +0900
@@ -15,8 +15,8 @@
 #include "global_alloc.h"
 
 static void post2runLoop(SchedTask *s, void *viewer, void *s1);
+static void post2run(SchedTask *s, void *viewer, void *s1);
 static void post2runDraw(SchedTask *s, void *viewer, void *s1);
-static void post2runMove(SchedTask *s, void *viewer, void *s1);
 static void post2rendering(SchedTask *s, void *viewer, void *s1);
 
 /* measure for FPS (Frame Per Second) */
@@ -26,7 +26,6 @@
 
 /* Data Pack sent to Other CPUs (ex. SPE) */
 extern SceneGraphPack *sgpack;
-extern PolygonPack *ppack;
 extern SpanPackPtr spackList;
 extern SpanPackPtr *spackList_ptr;
 
@@ -55,34 +54,29 @@
 {
     HTaskPtr task_next = initLoop();
     
-    task_next->set_post(&post2runLoop, (void *)this, 0); // set_post(function(this->run_loop()), NULL)
+    task_next->set_post(&post2run, (void *)this, 0);
     task_next->spawn();
 }
 
 
 
 static void
-post2runLoop(SchedTask *s, void *sgchange_, void *arg)
+post2run(SchedTask *s, void *sgchange_, void *arg)
 {
     SgChange *sgchange = (SgChange*)sgchange_;
     HTaskPtr task_next = sgchange->manager->create_task(Dummy);
     sgchange->run_loop(task_next);
-
     psx_sync_n();
 }
 
 void
-SgChange::exchange_sgroot()
+SgChange::pass_draw_tree()
 {
-    SceneGraphRoot *tmp;
-    tmp = sgroot_A;
-    sgroot_A = sgroot_B;
-    sgroot_B = tmp;
+    sgroot_B->sg_draw_tree = sgroot_A->sg_exec_tree;
 }
 
 void
 SgChange::run_loop(HTaskPtr task_next)
-{
     viewer->dev->clear_screen();
 
     bool quit_flg;
@@ -99,11 +93,7 @@
         spackList[i-1].reinit(i*split_screen_h);
     }
 
-    //exchange_sgroot();
-
     sgroot_A->updateControllerState();
-    sgroot_A->allExecute(viewer->width, viewer->height);
-    viewer->light_xyz_stock = sgroot_A->getLightVector();
 
     HTaskPtr loop_task  = manager->create_task(Dummy);
     loop_task->set_post(post2runLoop, (void *)this, 0);
@@ -111,33 +101,45 @@
     HTaskPtr draw_task  = manager->create_task(Dummy);
     draw_task->set_post(post2rendering, (void *)this, 0);
 
-    HTaskPtr move_task  = manager->create_task(Dummy);
-    move_task->set_post(post2runMove, (void *)this, 0);
+    /*
+      application 側で sgroot に task を生成登録する
+      引数を渡したりは後でやる。
+      登録された関数を実行して task を生成登録する。
+    */
+    sgroot_A->regist_execute();
 
+    //HTaskPtr move_task  = manager->create_task(RunMove);
+    HTaskPtr move_task  = manager->create_task(ExecMove);
+    move_task->set_param(0, (memaddr)this);
+    move_task->set_param(1, viewer->width);
+    move_task->set_param(2, viewer->height);
+
+    /*
+      TTaskPtr move_finish = manager->create_task(Dummy);
+      loop_task->wait_for(move_finish);
+      move_finish は app の move_task の post_func で実行させてやる
+    */
+
+    /*
+      描画終了確認用のダミータスク
+      描画の最後で spwan させる
+    */
     HTaskPtr dummy_task = manager->create_task(Dummy);
 
     draw_finish = dummy_task;
+
     loop_task->wait_for(draw_finish);
-    loop_task->wait_for(move_task);
-
-    move_task->spawn();
-    draw_task->spawn();
-    loop_task->spawn();
-}
+    // move_task に wait_for ではなく sgroot_A->move_exec_task に wait_for するべき
+    // どこかで move_exec_task->spawn() しないとな
+    loop_task->wait_for(sgroot_A->move_exec_task);
 
-static void 
-post2runMove(SchedTask *s, void *viewer_, void *arg)
-{
-    SgChange *viewer = (SgChange *)viewer_;
-    HTaskPtr task_next = viewer->manager->create_task(Dummy);
-    viewer->run_move(task_next);
-}
+    //loop_task->wait_for(move_task);
+    
 
-void
-SgChange::run_move(HTaskPtr task_next)
-{
-    sgroot_A->updateControllerState();
-    sgroot_A->allExecute(viewer->width, viewer->height);
+    draw_task->spawn();
+    // この時点で app の task_id を知っていないとダメか
+    move_task->spawn();
+    loop_task->spawn();
 }
 
 static void 
@@ -152,7 +154,7 @@
 void 
 SgChange::rendering(HTaskPtr task_next)
 {
-    viewer->common_rendering(task_next, sgroot_A);
+    viewer->common_rendering(task_next, sgroot_B);
     
     task_next->set_post(post2runDraw, (void*)this, 0);
     task_next->spawn();
--- a/Renderer/Engine/SgChange.h	Fri Mar 05 12:51:36 2010 +0900
+++ b/Renderer/Engine/SgChange.h	Fri Mar 05 13:12:31 2010 +0900
@@ -41,7 +41,7 @@
     void rendering(HTaskPtr task_next);
     HTaskPtr initLoop();
 
-    virtual void exchange_sgroot();
+    void pass_draw_tree();
     void mainLoop();
 
     void createFromXMLfile(const char *file)
--- a/Renderer/Engine/spe/ChainCal.cc	Fri Mar 05 12:51:36 2010 +0900
+++ b/Renderer/Engine/spe/ChainCal.cc	Fri Mar 05 13:12:31 2010 +0900
@@ -8,86 +8,87 @@
 /* これは必須 */
 SchedDefineTask(ChainCal);
 
-#define CHAIN_LEN 50
+#define CHAIN_LEN	50
 
-static const    double m = 100.0;
-static const    double k = 7000.0;
-static const    double g = 9.8;
-static const    double dt = 0.003;
-static const    double chain_width = 10;
-static const    double safe = 0.995;
+static const    double	m	    = 100.0;
+static const    double	k	    = 7000.0;
+static const    double	g	    = 9.8;
+static const    double	dt	    = 0.003;
+static const    double	chain_width = 10;
+static const    double	safe	    = 0.995;
 
 typedef struct {
-    double x, y, next_x, next_y;
-    double vx, vy, next_vx, next_vy;
-    double angle[3];
-    int can_move;
-    uint32 parent;
-    int id;
+    double	x, y, next_x, next_y;
+    double	vx, vy, next_vx, next_vy;
+    double	angle[3];
+    int		can_move;
+    uint32	parent;
+    int		id;
     //int parent;
 } ChainProperty, *ChainPropertyPtr;
 
 static int
 run(SchedTask *s,void *rbuf, void *wbuf)
 {
-	ChainPropertyPtr property = (ChainPropertyPtr)s->get_input(rbuf, 0);
-    ChainPropertyPtr update_property = (ChainPropertyPtr)s->get_output(wbuf, 0);
+    ChainPropertyPtr	property	= (ChainPropertyPtr)s->get_input(rbuf, 0);
+    ChainPropertyPtr	update_property = (ChainPropertyPtr)s->get_output(wbuf, 0);
 
 //    ChainPropertyPtr property = (ChainPropertyPtr)rbuf;
-//    int id = get_param(0);
+//    int id			= get_param(0);
     
     //ChainPropertyPtr o_property = (ChainPropertyPtr)wbuf;
     
     for(int cnt = 0; cnt < 600; cnt++) {
-		for(int i = 0; i < CHAIN_LEN; i++) {
-			if(property[i].can_move) {
-				double dx = property[i-1].x - property[i].x;
-				double dy = property[i-1].y - property[i].y;
-				double l = sqrt(dx * dx + dy * dy);
-				double a = k * (l - chain_width) / m;
-				double ax = a * dx / l;
-				double ay = a * dy / l;
-				if(i < CHAIN_LEN - 1) {
-					dx = property[i+1].x - property[i].x;
-					dy = property[i+1].y - property[i].y;
-					l = sqrt(dx * dx + dy * dy);
-					a = k * (l - chain_width) / m;
-					ax += a * dx / l;
-					ay += a * dy / l;
-				}
-				ay += g;
-				property[i].vx *= safe;
-				property[i].vy *= safe;
-				property[i].next_vx = property[i].vx + ax * dt;
-				property[i].next_vy = property[i].vy + ay * dt;
-				property[i].next_x = property[i].x + property[i].vx * dt;
-				property[i].next_y = property[i].y + property[i].vy * dt;
-			} else {
-				property[i].next_x = property[i].x;
-				property[i].next_y = property[i].y;
-			}
+	for(int i = 0; i < CHAIN_LEN; i++) {
+	    if(property[i].can_move) {
+		double	dx  = property[i-1].x - property[i].x;
+		double	dy  = property[i-1].y - property[i].y;
+		double	l   = sqrt(dx * dx + dy * dy);
+		double	a   = k * (l - chain_width) / m;
+		double	ax  = a * dx / l;
+		double	ay  = a * dy / l;
+		if(i < CHAIN_LEN - 1) {
+		    dx  = property[i+1].x - property[i].x;
+		    dy  = property[i+1].y - property[i].y;
+		    l   = sqrt(dx * dx + dy * dy);
+		    a   = k * (l - chain_width) / m;
+		    ax += a * dx / l;
+		    ay += a * dy / l;
 		}
-		for(int i = 0; i < CHAIN_LEN; i++) {
-			property[i].vx = property[i].next_vx;
-			property[i].vy = property[i].next_vy;
-			property[i].x = property[i].next_x;
-			property[i].y = property[i].next_y;
-		}
+		ay		    += g;
+		property[i].vx	    *= safe;
+		property[i].vy	    *= safe;
+		property[i].next_vx  = property[i].vx + ax *		dt;
+		property[i].next_vy  = property[i].vy + ay *		dt;
+		property[i].next_x   = property[i].x + property[i].vx *	dt;
+		property[i].next_y   = property[i].y + property[i].vy *	dt;
+	    } else {
+		property[i].next_x   = property[i].x;
+		property[i].next_y   = property[i].y;
+	    }
+	}
+	for(int i = 0; i < CHAIN_LEN; i++) {
+	    property[i].vx = property[i].next_vx;
+	    property[i].vy = property[i].next_vy;
+	    property[i].x  = property[i].next_x;
+	    property[i].y  = property[i].next_y;
+	}
     }
 	
     for (int j = 0; j < CHAIN_LEN; j++) {
-		int p, n;
-		int id = property[j].id;
-		p = n = id;
-		if(p != 0) {
-			p--;
-		}
-		if(n != CHAIN_LEN - 1) {
-			n++;
-		}
-		property[j].angle[2-(id%2)*2]
-			= 90 + atan((property[p].next_y - property[n].next_y) / (property[p].next_x - property[n].next_x)) * 180 / M_PI;
+	int	p, n;
+	int	id = property[j].id;
+	p	   = n = id;
+	if(p != 0) {
+	    p--;
+	}
+	if(n != CHAIN_LEN - 1) {
+	    n++;
+	}
+	property[j].angle[2-(id%2)*2]
+	    = 90 + atan((property[p].next_y - property[n].next_y) / (property[p].next_x - property[n].next_x)) * 180 / M_PI;
     }
-    memcpy((void*)update_property, (void*)property, sizeof(ChainProperty) * CHAIN_LEN);    
+
+    memcpy((void*)update_property, (void*)property, sizeof(ChainProperty) *	CHAIN_LEN);    
     return 0;
 }
--- a/Renderer/Engine/spe/DataLoad.cc	Fri Mar 05 12:51:36 2010 +0900
+++ b/Renderer/Engine/spe/DataLoad.cc	Fri Mar 05 13:12:31 2010 +0900
@@ -13,13 +13,9 @@
   int size = (int)s->get_param(0);
   int load_id = (int)s->get_param(1);
 
-  //printf("size %d",sizeof(float)*length);
 
   s->global_alloc(load_id, size);
 
-  //MemList *ml = s->createMemList(length,length);
-  //s->global_set(load_id, (void *)ml);
-
   return 0;
 }
 
--- a/Renderer/Engine/spe/DrawSpan.cc	Fri Mar 05 12:51:36 2010 +0900
+++ b/Renderer/Engine/spe/DrawSpan.cc	Fri Mar 05 13:12:31 2010 +0900
@@ -10,6 +10,8 @@
 #include "SchedTask.h"
 #include "Tapestry.h"
 #include "SpanPack.h"
+#include <spu_intrinsics.h>
+#include <math.h>
 
 #if (__LITTLE_ENDIAN__)
 #define LITTLEENDIAN 1
@@ -55,12 +57,39 @@
                                   SchedTask *smanager,int x, int y, float z, int world_x, int world_y, float world_z);
 
 
-static float
-innerProduct1(float *v0, float *v1)
+
+static inline void
+normalize(vector float& v0, vector float& v1)
 {
-    return (v0[0]*v1[0] + v0[1]*v1[1] + v0[2]*v1[2]);
+  float norm;
+  vector float ret __attribute__((aligned(16))) = {0,0,0,0};
+
+  ret = spu_mul(v0,v1);
+  norm = (ret[0] + ret[1] + ret[2]);
+
+  ret = (vector float)spu_splats(norm);
+  ret = spu_rsqrte(ret);
+  v0 = spu_mul(v1,ret);
 }
 
+static inline float
+innerProduct1(vector float& v0, vector float& v1)
+{
+
+  vector float ret __attribute__((aligned(16))) = {0,0,0,0};
+  float inner;
+  ret = spu_mul(v0,v1);
+
+  inner = (ret[0] + ret[1] + ret[2]);
+  if (inner < 0) {
+    inner = 0;
+  }
+
+  return inner;
+}
+
+
+
 
 /**
  * テクスチャは、TEXTURE_SPLIT_PIXEL^2 のブロックに分割する
@@ -330,7 +359,7 @@
     float zpos2 = span->end_z;
 
     //spanを右から左に見ていくうちに、zが下がるのか、上がっていくのか。
-    float z_inclination = (zpos1 - zpos2) / x_len;
+    float z_inclination = (zpos2 - zpos1) / x_len;
     float world_z = zpos2;
 
     // Tile 内での座標
@@ -342,7 +371,7 @@
     for (int j = je; j >= js; j--) {
         float tex_x, tex_y, tex_z;
 
-	world_z += z_inclination;
+	world_z -= z_inclination;
 
         localx = getLocalX(x-1+j);
 
@@ -387,13 +416,8 @@
 		    int world_x, int world_y, float world_z)
 
 {
+
     unsigned char rgb[4];
-    int light_rgb;
-    int flag;
-    float normal_vector[4] = {normal_x,normal_y,normal_z,0};
-    // 光のベクトル,きめうちしちゃった。どうにかする
-    float light_vector[4] = {0,0,-1,0};
-    float inner_product;
 
     // 引数で受け取った color の rgb 情報の抜き出し
 #if LITTLEENDIAN
@@ -408,21 +432,53 @@
     rgb[0] = (color & 0x000000ff);
 #endif
 
-    // 法線ベクトルと光源ベクトルとの内積をとる
-    inner_product = innerProduct1(normal_vector,light_vector);
-    // 内積がマイナスの場合は色がない。
-    flag = (inner_product > 0);
+
+    vector float *light_xyz = (vector float*)smanager->global_get(Light);
+
+    vector float v_rgb __attribute__((aligned(16))) = {(float)rgb[0],(float)rgb[1],(float)rgb[2],0};
+    vector float normal_vector __attribute__((aligned(16))) = {normal_x,normal_y,normal_z,0};
+    vector float light_vector __attribute__((aligned(16))) = {0,0,0,0};
+    vector float v_inner __attribute__((aligned(16)));
+    vector float v_world[4] __attribute__((aligned(16))) = {{world_x, world_y, -world_z, 0},
+                                                            {world_x, world_y, -world_z, 0},
+                                                            {world_x, world_y, -world_z, 0},
+                                                            {0,       0,        0,       0}};
+
+
+    int light_rgb;
+    float inner_product;
+
+    normalize(normal_vector, normal_vector);
+
+    vector float vtmp_rgb __attribute__((aligned(16))) = {0,0,0,0};
 
-    // 内積を rgb にかけていく
-    rgb[0] = (unsigned char)(rgb[0]*inner_product*flag);
-    rgb[1] = (unsigned char)(rgb[1]*inner_product*flag);
-    rgb[2] = (unsigned char)(rgb[2]*inner_product*flag);
+    int light_num = 4;
+
+    for (int i = 0; i < light_num; i++) {
+
+      light_vector = spu_sub(v_world[i],light_xyz[i]);
+      normalize(light_vector, light_vector);
+      inner_product = innerProduct1(normal_vector,light_vector);
+      v_inner = spu_splats(inner_product);
+      vtmp_rgb = spu_madd(v_rgb,v_inner,vtmp_rgb);
+
+    }
+
+    vector unsigned int v_flag __attribute__((aligned(16)));
+    vector float max_rgb __attribute__((aligned(16))) = (vector float)spu_splats((float)255.0f);
+
+    v_flag = spu_cmpgt(max_rgb,vtmp_rgb);
+    vtmp_rgb = spu_sel(max_rgb,vtmp_rgb,v_flag);
+
+    vector unsigned int last_rgb __attribute__((aligned(16)));
+    last_rgb = spu_convtu(vtmp_rgb,0);
+
 
     //計算した rgb を light_rgb にまとめる。
 #if LITTLEENDIAN
-    light_rgb = (rgb[0] << 24) + (rgb[1] << 16) + (rgb[2] << 8) + (rgb[3]);
+    light_rgb = (last_rgb[0] << 24) + (last_rgb[1] << 16) + (last_rgb[2] << 8) + (last_rgb[3]);
 #else
-    light_rgb = (rgb[3] << 24) + (rgb[2] << 16) + (rgb[1] << 8) + (rgb[0]);
+    light_rgb = (last_rgb[3] << 24) + (last_rgb[2] << 16) + (last_rgb[1] << 8) + (last_rgb[0]);
 #endif
 
     return light_rgb;
--- a/Renderer/Engine/spe/Makefile	Fri Mar 05 12:51:36 2010 +0900
+++ b/Renderer/Engine/spe/Makefile	Fri Mar 05 13:12:31 2010 +0900
@@ -10,7 +10,8 @@
 OBJS = $(SRCS:.cc=.o)
 
 CC      = spu-g++
-CFLAGS  = -Wall -fno-exceptions -fno-rtti $(OPT)#-DDEBUG
+CFLAGS  = -Wall -fno-exceptions -fno-rtti $(OPT)#-DDEBUG 
+
 INCLUDE = -I$(TOP)/include/TaskManager -I. -I..
 LIBS    = -L$(TOP)/TaskManager -lspemanager
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/spe/Property.cc	Fri Mar 05 13:12:31 2010 +0900
@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include "Property.h"
+#include "Func.h"
+#include "types.h"
+
+/* これは必須 */
+SchedDefineTask(PropertyTask);
+
+typedef struct {
+    float xyz[3];
+    const char *name;
+} Property, *PropertyPtr;
+
+static int
+run(SchedTask *s,void *rbuf, void *wbuf)
+{
+    PropertyPtr	property	= (PropertyPtr)s->get_input(rbuf, 0);
+    PropertyPtr	update_property = (PropertyPtr)s->get_output(wbuf, 0);
+
+    property->xyz[0] += 1.0f;
+    property->xyz[1] += 1.0f;
+    property->xyz[2] += 1.0f;
+
+    memcpy((void*)update_property, (void*)property, sizeof(Property));
+
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/spe/Property.h	Fri Mar 05 13:12:31 2010 +0900
@@ -0,0 +1,9 @@
+#ifndef INCLUDED_TASK_PROPERTY
+#define INCLUDED_TASK_PROPERTY
+
+#ifndef INCLUDED_SCHED_TASK
+#  include "SchedTask.h"
+#endif
+
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/spe/chain_move.cc	Fri Mar 05 13:12:31 2010 +0900
@@ -0,0 +1,128 @@
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include "chain_move.h"
+#include "Func.h"
+#include "types.h"
+
+/* これは必須 */
+SchedDefineTask(ChainTask);
+
+static const int PROPERTY_LENGTH = 50;
+static float m = 100.0;
+static float k = 7000.0;
+static float g = 9.8;
+static float dt = 0.003;
+static float chain_width = 10;
+static float safe = 0.995;
+
+typedef struct {
+    float xyz[3];
+    float angle[3];
+    float stack_xyz[3];
+    float next_xyz[3];
+    float v_xyz[3];
+    float next_v_xyz[3];
+    int property_index;
+    int parent_index;
+    int have_parent;
+    int can_move;
+    memaddr parent;
+    memaddr children;
+    memaddr node;
+    int sgid;
+} *PropertyPtr, Property;
+
+static int
+run(SchedTask *s,void *rbuf, void *wbuf)
+{
+    PropertyPtr	property	= (PropertyPtr)s->get_input(rbuf, 0);
+    PropertyPtr	update_property = (PropertyPtr)s->get_output(wbuf, 0);
+
+    property[0].can_move = 0;
+    //property[1].can_move = 0;
+
+    for(int cnt = 0; cnt < 600; cnt++) {
+	for(int i = 0; i < PROPERTY_LENGTH; i++) {
+	    if(property[i].can_move) {
+#if 0
+		vector float v_x1 __attribute__((aligned(16))) = { property[i-1].xyz[0],
+								   property[i].xyz[0],
+								   property[i+1].xyz[0], 
+								   property[i+2].xyz[0]};
+		vector float v_x2 __attribute__((aligned(16))) = { property[i].xyz[0],
+								   property[i+1].xyz[0],
+								   property[i+2].xyz[0],
+								   property[i+3].xyz[0]};
+		vector float v_dx __attribute__((aligned(16))) = spu_sub(v_x1, v_x2);
+
+		vector float v_y1 __attribute__((aligned(16))) = { property[i-1].xyz[1],
+								   property[i].xyz[1],
+								   property[i+1].xyz[1], 
+								   property[i+2].xyz[1]};
+		vector float v_y2 __attribute__((aligned(16))) = { property[i].xyz[1],
+								   property[i+1].xyz[1],
+								   property[i+2].xyz[1],
+								   property[i+3].xyz[1]};
+		vector float v_dy __attribute__((aligned(16))) = spu_sub(v_x1, v_x2);
+
+		dx = spu_mule(dx, dx);
+		dy = spu_mule(dy, dy);
+		vector float v_l __attribute__((aligned(16)));
+		
+#else
+		float dx = property[i-1].xyz[0] - property[i].xyz[0];
+		float dy = property[i-1].xyz[1] - property[i].xyz[1];
+		float l = sqrt(dx * dx + dy * dy);
+		float a = k * (l - chain_width) / m;
+		float ax = a * dx / l;
+		float ay = a * dy / l;
+		if(i < PROPERTY_LENGTH - 1) {
+		    dx = property[i+1].xyz[0] - property[i].xyz[0];
+		    dy = property[i+1].xyz[1] - property[i].xyz[1];
+		    l = sqrt(dx * dx + dy * dy);
+		    a = k * (l - chain_width) / m;
+		    ax += a * dx / l;
+		    ay += a * dy / l;
+		}
+		ay += g;
+		property[i].v_xyz[0] *= safe;
+		property[i].v_xyz[1] *= safe;
+		property[i].next_v_xyz[0] = property[i].v_xyz[0] + ax * dt;
+		property[i].next_v_xyz[1] = property[i].v_xyz[1] + ay * dt;
+		property[i].next_xyz[0] = property[i].xyz[0] + property[i].v_xyz[0] * dt;
+		property[i].next_xyz[1] = property[i].xyz[1] + property[i].v_xyz[1] * dt;
+	    } else {
+		property[i].next_xyz[0] = property[i].xyz[0];
+		property[i].next_xyz[1] = property[i].xyz[1];
+	    }
+#endif
+	}
+
+	for(int i = 0; i < PROPERTY_LENGTH; i++) {
+	    property[i].v_xyz[0] = property[i].next_v_xyz[0];
+	    property[i].v_xyz[1] = property[i].next_v_xyz[1];
+	    property[i].xyz[0] = property[i].next_xyz[0];
+	    property[i].xyz[1] = property[i].next_xyz[1];
+	}
+    }
+
+    for(int i = 0; i < PROPERTY_LENGTH; i++) {
+	int id = property[i].property_index;
+	int p, n;	
+	p = n = id;
+	if(p != 0) {
+	    p--;
+	}
+	if(n != PROPERTY_LENGTH - 1) {
+	    n++;
+	}
+	property[i].angle[2-(id%2)*2]
+	    = 90 + atan((property[p].next_xyz[1] - property[n].next_xyz[1])
+			/ (property[p].next_xyz[0] - property[n].next_xyz[0])) * 180 / M_PI;
+    }
+
+    memcpy((void*)update_property, (void*)property, sizeof(Property)*PROPERTY_LENGTH);
+
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/spe/chain_move.h	Fri Mar 05 13:12:31 2010 +0900
@@ -0,0 +1,9 @@
+#ifndef INCLUDED_TASK_CHAIN
+#define INCLUDED_TASK_CHAIN
+
+#ifndef INCLUDED_SCHED_TASK
+#  include "SchedTask.h"
+#endif
+
+
+#endif
--- a/Renderer/Engine/spe/spe-main.cc	Fri Mar 05 12:51:36 2010 +0900
+++ b/Renderer/Engine/spe/spe-main.cc	Fri Mar 05 13:12:31 2010 +0900
@@ -21,6 +21,10 @@
 SchedExternTask(InitKey);
 SchedExternTask(UpdateKey);
 
+SchedExternTask(PropertyTask);
+SchedExternTask(UniverseTask);
+SchedExternTask(ChainTask);
+
 void
 task_init(Scheduler *s)
 {
@@ -40,6 +44,10 @@
 
     SchedRegister( ShowTime);
 
-	SchedRegister( InitKey);
-	SchedRegister( UpdateKey);
+    SchedRegister( InitKey);
+    SchedRegister( UpdateKey);
+
+    SchedRegister( PropertyTask);
+    SchedRegister( UniverseTask);
+    SchedRegister( ChainTask);
 }
--- a/Renderer/Engine/spe/texture.h	Fri Mar 05 12:51:36 2010 +0900
+++ b/Renderer/Engine/spe/texture.h	Fri Mar 05 13:12:31 2010 +0900
@@ -1,2 +1,2 @@
 #define MAX_LOAD_SIZE 16384
-#define TEXTURE2_ID 13
+#define TEXTURE_ID 13
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/spe/universe_move.cc	Fri Mar 05 13:12:31 2010 +0900
@@ -0,0 +1,50 @@
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include "universe_move.h"
+#include "Func.h"
+#include "types.h"
+
+/* これは必須 */
+SchedDefineTask(UniverseTask);
+
+typedef struct {
+    float xyz[3];
+    float angle[3];
+    float stack_xyz[3];
+    int property_index;
+    int parent_index;
+    int have_parent;
+    memaddr parent;
+    memaddr children;
+    memaddr node;
+    const char *name;
+} *PropertyPtr, Property;
+
+static int
+run(SchedTask *s,void *rbuf, void *wbuf)
+{
+    PropertyPtr	property	= (PropertyPtr)s->get_input(rbuf, 0);
+    PropertyPtr	update_property = (PropertyPtr)s->get_output(wbuf, 0);
+    int screen_w = 1920;
+    int screen_h = 1080;
+
+    property[0].angle[1] += 1.0f;
+    if (property[0].angle[1] > 360.0f) {
+	property[0].angle[1] = 0.0f;
+    }
+
+    property[0].xyz[0] += property[0].stack_xyz[0];
+    if ((int)property[0].xyz[0] > screen_w || (int)property[0].xyz[0] < 0) {
+	property[0].stack_xyz[0] = -property[0].stack_xyz[0];
+    }
+
+    property[0].xyz[1] += property[0].stack_xyz[1];
+    if ((int)property[0].xyz[1] > screen_h || (int)property[0].xyz[1] < 0) {
+	property[0].stack_xyz[1] = -property[0].stack_xyz[1];
+    }
+
+    memcpy((void*)update_property, (void*)property, sizeof(Property)*2);
+
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/spe/universe_move.h	Fri Mar 05 13:12:31 2010 +0900
@@ -0,0 +1,9 @@
+#ifndef INCLUDED_TASK_UNIVERSE
+#define INCLUDED_TASK_UNIVERSE
+
+#ifndef INCLUDED_SCHED_TASK
+#  include "SchedTask.h"
+#endif
+
+
+#endif
--- a/Renderer/Engine/task/CreatePolygonFromSceneGraph.cc	Fri Mar 05 12:51:36 2010 +0900
+++ b/Renderer/Engine/task/CreatePolygonFromSceneGraph.cc	Fri Mar 05 13:12:31 2010 +0900
@@ -168,17 +168,20 @@
                 normal1[0] = sg->normal[(i+0)*3];
                 normal1[1] = sg->normal[(i+0)*3+1];
                 normal1[2] = sg->normal[(i+0)*3+2]*-1.0f;
-                normal1[3] = 1.0f;
+                //normal1[3] = 1.0f;
+		normal1[3] = 0.0f;
 
                 normal2[0] = sg->normal[(i+1)*3];
                 normal2[1] = sg->normal[(i+1)*3+1];
                 normal2[2] = sg->normal[(i+1)*3+2]*-1.0f;
-                normal2[3] = 1.0f;
+                //normal2[3] = 1.0f;
+                normal2[3] = 0.0f;
 
                 normal3[0] = sg->normal[(i+2)*3];
                 normal3[1] = sg->normal[(i+2)*3+1];
                 normal3[2] = sg->normal[(i+2)*3+2]*-1.0f;
-                normal3[3] = 1.0f;
+		//normal3[3] = 1.0f;
+                normal3[3] = 0.0f;
 
                 ApplyNormalMatrix(normal1,sg->real_matrix);
                 ApplyNormalMatrix(normal2,sg->real_matrix);
--- a/Renderer/Engine/task/Draw.cc	Fri Mar 05 12:51:36 2010 +0900
+++ b/Renderer/Engine/task/Draw.cc	Fri Mar 05 13:12:31 2010 +0900
@@ -1,13 +1,97 @@
-#include <stdlib.h>
-#include <string.h>
-#include "Draw.h"
-#include "viewer_types.h"
+//#include "RunDraw.h"
+#include "SchedTask.h"
 
 SchedDefineTask(Draw);
 
 static int
-run(SchedTask *s,void *rbuf, void *wbuf)
+run(SchedTask *smanager, void *rbuf, void *wbuf)
 {
+#if 0
+    PolygonPack *pp = (PolygonPack*)smanager->get_input(rbuf, 0);
+    PolygonPack *next_pp = 
+	(PolygonPack*)smanager->allocate(sizeof(PolygonPack));
+    PolygonPack *free_pp = next_pp;
+    PolygonPack *tmp_pp;
+
+    TrianglePackPtr triPack;
+    VertexPackPtr vMin, vMid, vMax;
+    VertexPackPtr vMid10
+	= (VertexPackPtr)smanager->allocate(sizeof(VertexPack));
+    NormalPackPtr normal1,normal2, normal3;
+    SpanPackPtr *spackList = (SpanPackPtr*)smanager->get_input(rbuf, 1);
+    spack = (SpanPackPtr)smanager->get_input(rbuf, 2);
+    send_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack));
+    prev_index = (long)smanager->get_param(0);
+
+    // spack と send_spack は swap しながら DMA を繰り返すので
+    // 自分で allocate した send_spack を覚えてないといけない
+    SpanPackPtr free_spack = send_spack;
+
+    int charge_y_top = (long)smanager->get_param(1);
+    int charge_y_end = (long)smanager->get_param(2);
+
+    do {
+	if (pp->next != NULL) {
+	    smanager->dma_load(next_pp, (memaddr)pp->next,
+			       sizeof(PolygonPack), POLYGON_PACK_LOAD);
+	} else {
+	    next_pp = NULL;
+	}
+
+	for (int i = 0; i < pp->info.size; i++) {
+	    triPack = &pp->tri[i];
+
+	    TriangleTexInfoPtr tri_tex_info = &triPack->tex_info;
+
+	    make_vertex(triPack, &vMin, &vMid, &vMax, &normal1, &normal2, &normal3);
+	    make_vMid10(vMid10, vMin, vMid, vMax);
+
+	    /**
+	     * ポリゴンを、x軸に水平に分割して二つの三角形を作り、
+	     * それぞれから Span を求める
+	     *
+	     *      vMax
+	     *        |\
+	     *        | \
+	     *        |  \
+	     *        |   \
+	     * vMid10 ------ vMid
+	     *        |   /
+	     *        |  /
+	     *        | /
+	     *        |/
+	     *      vMin
+	     *
+	     * (vMax, vMid, vMin) という triangle を
+	     * (vMax, vMid, vMid10) (vMin, vMid, vMid10) という
+	     * 二つの Triangle に分けている
+	     */
+	    half_triangle(smanager, spackList, charge_y_top, charge_y_end,
+			  tri_tex_info, vMin, vMid, vMid10,
+                          normal1,normal2,normal3,
+			  (int)(vMax->y - vMin->y), vMax->tex_y - vMin->tex_y);
+	    half_triangle(smanager, spackList, charge_y_top, charge_y_end,
+			  tri_tex_info, vMax, vMid, vMid10,
+                          normal1,normal2,normal3,
+			  (int)(vMax->y - vMin->y), vMax->tex_y - vMin->tex_y);
+	}
+
+	smanager->dma_wait(POLYGON_PACK_LOAD);	
+
+	tmp_pp = pp;
+	pp = next_pp;
+	next_pp = tmp_pp;
+    } while (pp);
+
+    smanager->dma_wait(SPAN_PACK_STORE);
+    smanager->dma_store(spack, (memaddr)spackList[prev_index],
+			sizeof(SpanPack), SPAN_PACK_STORE);
+    smanager->dma_wait(SPAN_PACK_STORE);
+
+    free(free_pp);
+    free(free_spack);
+    free(vMid10);
 
     return 0;
+#endif
 }
--- a/Renderer/Engine/task/DrawSpan.cc	Fri Mar 05 12:51:36 2010 +0900
+++ b/Renderer/Engine/task/DrawSpan.cc	Fri Mar 05 13:12:31 2010 +0900
@@ -387,13 +387,17 @@
 		    int world_x, int world_y, float world_z)
 
 {
+
+
     unsigned char rgb[4];
     int light_rgb;
     int flag;
     float normal_vector[4] = {normal_x,normal_y,normal_z,0};
-    // 光のベクトル,きめうちしちゃった。どうにかする
-    float light_vector[4] = {0,0,-1,0};
+    float light_vector[4];
     float inner_product;
+    float *light_xyz = (float*)smanager->global_get(Light);
+
+    normalize(normal_vector, normal_vector);
 
     // 引数で受け取った color の rgb 情報の抜き出し
 #if LITTLEENDIAN
@@ -408,15 +412,41 @@
     rgb[0] = (color & 0x000000ff);
 #endif
 
-    // 法線ベクトルと光源ベクトルとの内積をとる
-    inner_product = innerProduct1(normal_vector,light_vector);
-    // 内積がマイナスの場合は色がない。
-    flag = (inner_product > 0);
+    int tmp_rgb[3] = {0,0,0};
+    int light_num = 4;
+    for (int i = 0; i < light_num; i++) {
+
+      light_vector[0] = world_x - light_xyz[i*4];
+      light_vector[1] = world_y - light_xyz[i*4+1];
+      light_vector[2] = light_xyz[i*4+2] - world_z;
+      light_vector[3] = light_xyz[i*4+3];
+
+      normalize(light_vector, light_vector);
+
+      // 法線ベクトルと光源ベクトルとの内積をとる
+      inner_product = innerProduct1(normal_vector,light_vector);
+
+      //printf("inner_product %f\n",inner_product);
 
-    // 内積を rgb にかけていく
-    rgb[0] = (unsigned char)(rgb[0]*inner_product*flag);
-    rgb[1] = (unsigned char)(rgb[1]*inner_product*flag);
-    rgb[2] = (unsigned char)(rgb[2]*inner_product*flag);
+      // 内積がマイナスの場合は色がない。
+      flag = (inner_product > 0);
+
+      // 内積を rgb にかけていく
+      tmp_rgb[0] += (unsigned char)(rgb[0]*inner_product*flag);
+      tmp_rgb[1] += (unsigned char)(rgb[1]*inner_product*flag);
+      tmp_rgb[2] += (unsigned char)(rgb[2]*inner_product*flag);
+
+    }
+
+    int rgb_flag[3];
+    for (int i = 0; i < 3; i++) {
+      rgb_flag[i] = (tmp_rgb[i] > 255);
+    }
+
+    rgb[0] = tmp_rgb[0]*(1 - rgb_flag[0]) + 255*(rgb_flag[0]);
+    rgb[1] = tmp_rgb[1]*(1 - rgb_flag[1]) + 255*(rgb_flag[1]);
+    rgb[2] = tmp_rgb[2]*(1 - rgb_flag[2]) + 255*(rgb_flag[2]);
+
 
     //計算した rgb を light_rgb にまとめる。
 #if LITTLEENDIAN
@@ -426,6 +456,7 @@
 #endif
 
     return light_rgb;
+
 }
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/task/ExecMove.cc	Fri Mar 05 13:12:31 2010 +0900
@@ -0,0 +1,40 @@
+#include <stdlib.h>
+#include <string.h>
+#include "ExecMove.h"
+#include "SgChange.h"
+#include "SceneGraphRoot.h"
+
+SchedDefineTask(ExecMove);
+
+static int
+run(SchedTask *smanager, void *rbuf , void *wbuf)
+{
+    SgChange *sgchange = (SgChange *)smanager->get_param(0);
+    //SceneGraphRoot *sgroot = (SceneGraphRoot *)smanager->get_param(0);
+    SceneGraphRoot *sgroot = sgchange->sgroot_A;
+    int screen_w = (int)smanager->get_param(1);
+    int screen_h = (int)smanager->get_param(2);
+
+    //sgroot->updateControllerState();
+
+    SceneGraphPtr list = sgroot->sg_available_list;
+    sgroot->allRemove(sgroot->sg_remove_list);
+
+    sgroot->sg_draw_tree = sgroot->sg_exec_tree;
+    sgroot->sg_remove_list = sgroot->sg_available_list;
+
+    sgroot->sg_exec_tree = NULL;
+    sgroot->sg_available_list = NULL;
+
+    sgroot->camera->move_execute(screen_w, screen_h);
+    sgroot->camera->update(screen_w, screen_h);
+
+    sgroot->camera->children = NULL;
+    sgroot->camera->lastChild = NULL;
+
+    list->move_execute(screen_w, screen_h);
+
+    sgroot->list = list;
+    
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/task/ExecMove.h	Fri Mar 05 13:12:31 2010 +0900
@@ -0,0 +1,7 @@
+#ifndef INCLUDED_EXEC_MOVE
+#define INCLUDED_EXEC_MOVE
+
+#include "SceneGraphRoot.h"
+#include "SchedTask.h"
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/task/Property.cc	Fri Mar 05 13:12:31 2010 +0900
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include "Property.h"
+#include "Func.h"
+#include "types.h"
+
+/* これは必須 */
+SchedDefineTask(PropertyTask);
+
+typedef struct {
+    float x, y, z;
+} Property, *PropertyPtr;
+
+static int
+run(SchedTask *s,void *rbuf, void *wbuf)
+{
+    PropertyPtr	property	= (PropertyPtr)s->get_input(rbuf, 0);
+    PropertyPtr	update_property = (PropertyPtr)s->get_output(wbuf, 0);
+
+    property->x += 1.0f;
+    property->y += 1.0f;
+    property->z += 1.0f;
+
+    memcpy((void*)update_property, (void*)property, sizeof(Property));
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/task/Property.h	Fri Mar 05 13:12:31 2010 +0900
@@ -0,0 +1,9 @@
+#ifndef INCLUDED_TASK_PROPERTY
+#define INCLUDED_TASK_PROPERTY
+
+#ifndef INCLUDED_SCHED_TASK
+#  include "SchedTask.h"
+#endif
+
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/task/RunMove.cc	Fri Mar 05 13:12:31 2010 +0900
@@ -0,0 +1,21 @@
+#include <stdlib.h>
+#include <string.h>
+#include "RunMove.h"
+#include "SgChange.h"
+
+SchedDefineTask(RunMove);
+
+static int
+run(SchedTask *smanager, void *rbuf , void *wbuf)
+{
+    //SceneGraphRoot *sgroot = (SceneGraphRoot *)smanager->get_param(0);    
+    SgChange *sgchange = (SgChange *)smanager->get_param(0);
+    int width  = (int)smanager->get_param(1);
+    int height = (int)smanager->get_param(2);
+    SceneGraphRoot *sgroot = sgchange->sgroot_A;
+    sgroot->updateControllerState();
+    sgroot->oneExecute(width, height);
+    sgchange->viewer->light_xyz_stock = sgroot->getLightVector();
+
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/task/RunMove.h	Fri Mar 05 13:12:31 2010 +0900
@@ -0,0 +1,7 @@
+#ifndef INCLUDED_RUN_MOVE
+#define INCLUDED_RUN_MOVE
+
+#include "SceneGraphRoot.h"
+#include "SchedTask.h"
+
+#endif
--- a/Renderer/Engine/task/task_init.cc	Fri Mar 05 12:51:36 2010 +0900
+++ b/Renderer/Engine/task/task_init.cc	Fri Mar 05 13:12:31 2010 +0900
@@ -28,6 +28,10 @@
 SchedExternTask(InitKey);
 
 SchedExternTask(Switch);
+SchedExternTask(RunMove);
+
+SchedExternTask(PropertyTask);
+SchedExternTask(ExecMove);
 
 
 /**
@@ -62,5 +66,8 @@
 
     // usr
     SchedRegister( ChainMove);
+    SchedRegister( RunMove);
+    SchedRegister( PropertyTask);
+    SchedRegister( ExecMove);
 
 }
--- a/Renderer/Engine/task/texture.h	Fri Mar 05 12:51:36 2010 +0900
+++ b/Renderer/Engine/task/texture.h	Fri Mar 05 13:12:31 2010 +0900
@@ -1,2 +1,2 @@
 #define MAX_LOAD_SIZE 16384
-#define TEXTURE2_ID 13
+#define TEXTURE_ID 13
--- a/Renderer/Engine/viewer.cc	Fri Mar 05 12:51:36 2010 +0900
+++ b/Renderer/Engine/viewer.cc	Fri Mar 05 13:12:31 2010 +0900
@@ -105,13 +105,15 @@
     sgroot = new SceneGraphRoot(this->width, this->height);
     sgroot->tmanager = manager;
     
-    int size = sizeof(float)*4;
+    int size = sizeof(float)*4*4; //xyz+alfa(4) * light_num(4)
+    int light_size = size / sizeof(float);
 
+    light_xyz_stock = (float *)manager->allocate(size);
     light_xyz = (float *)manager->allocate(size);
-    light_xyz[0] = 0.0f;
-    light_xyz[1] = 0.0f;
-    light_xyz[2] = 0.0f;
-    light_xyz[3] = 0.0f;
+
+    for (int i = 0; i < light_size ; i++) {
+      light_xyz[i] = 0.0f;
+    }
 
     HTaskPtr data_load;
     data_load = manager->create_task(DataLoad);
@@ -129,7 +131,6 @@
     }
 
     MainLoop *mainloop = app->init(this, this->width, this->height);
-
     mainloop->mainLoop();
 }
 
@@ -469,16 +470,16 @@
     //task_next = manager->create_task(Dummy);
     //task_next->set_post(post2runLoop, (void*)this);
 
-    //Light info update
+   //Light info update
                                                                    
     HTaskPtr data_update;
     HTaskPtr data_update_wait;
-    int size = sizeof(float)*4;
+    int size = sizeof(float)*4*4; //xyz+alfa(4) * light_num(4) 
+    int light_size = size / sizeof(float);
 
-    light_xyz[0] = light_xyz_stock[0]; 
-    light_xyz[1] = light_xyz_stock[1]; 
-    light_xyz[2] = light_xyz_stock[2]; 
-    light_xyz[3] = light_xyz_stock[3]; 
+    for (int i = 0; i < light_size; i++) {
+      light_xyz[i] = light_xyz_stock[i]; 
+    }
     
     data_update_wait = manager->create_task(DataUpdate);
     data_update_wait->add_inData(light_xyz,size);
--- a/Renderer/Test/Chain.h	Fri Mar 05 12:51:36 2010 +0900
+++ b/Renderer/Test/Chain.h	Fri Mar 05 13:12:31 2010 +0900
@@ -17,7 +17,7 @@
 
     SceneGraphPtr scenegraph_factory(void *p, int size);
     SceneGraphPtr scenegraph_connector(void *p, int size, SceneGraphPtr s, SceneGraphPtr sg_available_list);
-	void init(TaskManager *manager, int w, int h);
+    void init(TaskManager *manager, int w, int h);
     void init_chain_vars(ChainPropertyPtr cv);
     void chain_move(TaskManager *manager, SceneGraphPtr sg, int w, int h);
     void chain_collision(SceneGraphPtr sg, int w, int h, SceneGraphPtr osg);
--- a/Renderer/Test/Makefile.cell	Fri Mar 05 12:51:36 2010 +0900
+++ b/Renderer/Test/Makefile.cell	Fri Mar 05 13:12:31 2010 +0900
@@ -11,7 +11,8 @@
 .cc.o:
 	$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
 
-ALL = spe-main ball_bound boss1_action direction gaplant ieshoot node panel universe untitled vacuum dynamic viewer SgRootChange
+ALL = spe-main ball_bound boss1_action direction gaplant ieshoot node panel universe untitled vacuum dynamic viewer SgRootChange property_test create_task property_universe chain_old property_chain
+
 all: $(ALL)
 
 speobject:
@@ -78,7 +79,27 @@
 
 SG_CHANGE_OBJ = SgRootChange.o
 SgRootChange : $(SG_CHANGE_OBJ) 
-	   $(CC) -o $@ $?   $(LIBS)
+	$(CC) -o $@ $?   $(LIBS)
+
+PROPERTY_TEST_OBJ = property_test.o
+property_test : $(PROPERTY_TEST_OBJ)
+	$(CC) -o $@ $?   $(LIBS)
+
+CREATE_TASK_OBJ = create_task.o
+create_task : $(CREATE_TASK_OBJ)
+	$(CC) -o $@ $?   $(LIBS)
+
+P_UNIVERSE_OBJ = property_universe.o
+property_universe : $(P_UNIVERSE_OBJ)
+	$(CC) -o $@ $?   $(LIBS)
+
+CHAIN_OLD = chain_old.o
+chain_old : $(CHAIN_OLD)
+	$(CC) -o $@ $? $(LIBS)
+
+P_CHAIN_OBJ = property_chain.o
+property_chain : $(P_CHAIN_OBJ)
+	$(CC) -o $@ $? $(LIBS)
 	
 debug: $(TARGET)
 	sudo ppu-gdb ./$(TARGET) 
--- a/Renderer/Test/Makefile.macosx	Fri Mar 05 12:51:36 2010 +0900
+++ b/Renderer/Test/Makefile.macosx	Fri Mar 05 13:12:31 2010 +0900
@@ -10,7 +10,8 @@
 .cc.o:
 	$(CC) $(CFLAGS)  -c $< -o $@
 
-ALL =  ball_bound boss1_action direction gaplant ieshoot node panel universe untitled vacuum property_test send_linda dynamic writer chain_old SgRootChange 
+ALL =  ball_bound boss1_action direction gaplant ieshoot node panel universe untitled vacuum property_test send_linda dynamic writer chain_old SgRootChange
+
 oFLAGS=-g -O2
 CFLAGt=-g -O2
 all: $(ALL)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Test/create_task.cc	Fri Mar 05 13:12:31 2010 +0900
@@ -0,0 +1,183 @@
+#include <math.h>
+#include <stdlib.h>
+#include "SceneGraphRoot.h"
+#include "MainLoop.h"
+#include "create_task.h"
+#include "types.h"
+#include "Func.h"
+#include "sys.h"
+#include "SgChange.h"
+
+Property *property, *update_property;
+
+// prototype
+static void collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, SceneGraphPtr tree);
+static void move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h);
+static void createSceneGraphFromProperty(SchedTask *s, void *sgroot, void *arg1);
+//static void createSceneGraphFromProperty(void *sgroot, void *property_, void *update_property_);
+static void set_property(Property *p, SceneGraphPtr sg);
+static void regist_task(SceneGraphRoot *sgroot);
+
+static void
+move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
+{
+    SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
+    //TaskManager *manager = sgroot->tmanager;
+    //HTaskPtr property_task = manager->create_task(PropertyTask);
+    HTaskPtr property_task = sgroot->move_exec_task;
+
+    property_task->add_inData(property, sizeof(Property));
+    property_task->add_outData(update_property, sizeof(Property));
+
+    //property_task->add_inData((Property *)node->property, sizeof(Property));
+    //property_task->add_outData((Property *)node->update_property, sizeof(Property));
+    property_task->set_cpu(SPE_ANY);
+    
+    property_task->set_post(createSceneGraphFromProperty, (void *)sgroot, 0);
+    property_task->spawn();
+}
+
+static void
+collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h,
+	  SceneGraphPtr tree)
+{
+}
+
+#if 1
+static void
+createSceneGraphFromProperty(SchedTask *s, void *sgroot_, void *arg1)
+{
+    SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
+    SceneGraphPtr node;
+
+    // ここが allExecute の tree をたどって clone して行くところに相当する
+    node = sgroot->createSceneGraph(update_property->name);
+    //node = sgroot->createSceneGraph("Ball");
+    node->set_move_collision(move, collision);
+    node->xyz[0] = update_property->xyz[0];
+    node->xyz[1] = update_property->xyz[1];
+    node->xyz[2] = update_property->xyz[2];
+
+    // get matrix
+    get_matrix(node->matrix, node->angle, node->xyz, sgroot->camera->matrix);
+    get_matrix(node->real_matrix, node->angle, node->xyz, sgroot->camera->real_matrix);
+
+    sgroot->setSceneData(node);
+
+    Property *tmp = property;
+    property = update_property;
+    update_property = tmp;
+
+    sgroot->move_finish();
+}
+#else
+static void
+createSceneGraphFromProperty(void *sgroot_, void *property_, void *update_property_)
+{
+    SceneGraphPtr node;
+    SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
+    Property *property = (Property *)property_;
+    Property *update_property = (Property *)update_property_;
+
+    node = sgroot->createSceneGraph(update_property->name);
+    //node = sgroot->createSceneGraph("Ball");
+    //node->set_move_collision(move, collision);
+    node->set_move_collision(move, collision, createSceneGraphFromProperty);
+    node->xyz[0] = update_property->xyz[0];
+    node->xyz[1] = update_property->xyz[1];
+    node->xyz[2] = update_property->xyz[2];
+    sgroot->setSceneData(node);
+
+    Property *tmp = property;
+    property = update_property;
+    update_property = tmp;    
+}
+#endif
+
+
+static void
+regist_task(SceneGraphRoot *sgroot)
+{
+    TaskManager *manager = sgroot->tmanager;
+    HTaskPtr property_task = manager->create_task(PropertyTask);
+    sgroot->move_exec_task = property_task;
+}
+
+
+
+
+static void
+set_property(Property *p, SceneGraphPtr sg)
+{
+    p->xyz[0] = sg->xyz[0];
+    p->xyz[1] = sg->xyz[1];
+    p->xyz[2] = sg->xyz[2];
+    p->name = sg->name;
+}
+
+MainLoopPtr 
+create_task::init(Viewer *viewer, int screen_w, int screen_h)
+{
+    // SgChange を使うための2行
+    SgChange *sgroot = new SgChange(viewer);
+    sgroot->run_init();
+    // 上で書いた regist_task() を登録
+    sgroot->sgroot_A->appTaskRegist(regist_task);
+
+    property        = (Property *)sgroot->manager->allocate(sizeof(Property));
+    update_property = (Property *)sgroot->manager->allocate(sizeof(Property));
+    /*
+    Property *property        = (Property *)sgroot->manager->allocate(sizeof(Property));
+    Property *update_property = (Property *)sgroot->manager->allocate(sizeof(Property));
+    */
+
+    SceneGraphPtr ball;
+
+    sgroot->createFromXMLfile("xml_file/Ball.xml");
+
+    ball = sgroot->createSceneGraph("Ball");
+    ball->set_move_collision(move, collision);
+    //ball->set_move_collision(move, collision, createSceneGraphFromProperty);
+
+    ball->xyz[0] = screen_w/2;
+    ball->xyz[1] = screen_h/2;
+    ball->xyz[2] = 30.0f;
+
+    //SceneGraph に property を持たせておく
+    ball->property = (memaddr)property;
+    ball->update_property = (memaddr)update_property;
+
+    set_property(property, ball);
+    
+    sgroot->setSceneData(ball);
+
+    return sgroot;
+}
+
+extern Application *
+application() {
+    return new create_task();
+}
+
+const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n";
+
+extern int init(TaskManager *manager, int argc, char *argv[]);
+extern void task_initialize();
+static void TMend(TaskManager *manager);
+
+int
+TMmain(TaskManager *manager, int argc, char *argv[])
+{
+    task_initialize();
+    manager->set_TMend(TMend);
+    return init(manager, argc, argv);
+
+}
+
+void
+TMend(TaskManager *manager)
+{
+    printf("test_nogl end\n");
+}
+
+/* end */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Test/create_task.h	Fri Mar 05 13:12:31 2010 +0900
@@ -0,0 +1,17 @@
+#include <math.h>
+#include <stdlib.h>
+#include "SceneGraphRoot.h"
+#include "Application.h"
+#include "MainLoop.h"
+#include "viewer.h"
+
+typedef struct {
+    float xyz[3];  // 12 byte
+    const char *name;
+} *PropertyPtr, Property;
+
+class create_task : public Application {
+
+    MainLoopPtr init(Viewer *viewer, int screen_w, int screen_h);
+
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Test/property_chain.cc	Fri Mar 05 13:12:31 2010 +0900
@@ -0,0 +1,258 @@
+#include <math.h>
+#include <stdlib.h>
+#include "SceneGraphRoot.h"
+#include "MainLoop.h"
+#include "property_chain.h"
+#include "types.h"
+#include "Func.h"
+#include "sys.h"
+#include "SgChange.h"
+
+#define FALSE 0
+#define TRUE !FALSE
+static const int PROPERTY_LENGTH = 50;
+static double chain_width = 10;
+
+typedef struct {
+    float xyz[3];
+    float angle[3];
+    float stack_xyz[3];
+    float next_xyz[3];
+    float v_xyz[3];
+    float next_v_xyz[3];
+    int property_index;
+    int parent_index;
+    int have_parent;
+    int can_move;
+    memaddr parent;
+    memaddr children;
+    memaddr node;
+    int sgid;
+} *PropertyPtr, Property;
+
+
+Property *property, *update_property;
+
+// prototype
+static void collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, SceneGraphPtr tree);
+static void move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h);
+static void createSceneGraphFromProperty(SchedTask *s, void *sgroot, void *arg1);
+static void set_property(Property *p, SceneGraphPtr sg, int index);
+static void apply_property(SceneGraphPtr sg, Property *p);
+static void regist_task(SceneGraphRoot *sgroot);
+static void set_relation(SceneGraphPtr parent, SceneGraphPtr child);
+
+static void
+init_chain(Property *p) {
+    for (int i = 0; i < 3; i++) {
+	p->xyz[i] = 0;
+	p->angle[i] = 0;
+	p->stack_xyz[i] = 0;
+	p->next_xyz[i] = 0;
+	p->v_xyz[i] = 0;
+	p->next_v_xyz[i] = 0;
+    }
+
+    p->property_index = 0;
+    p->parent_index = 0;
+    p->have_parent = 0;
+    p->can_move = TRUE;
+    p->parent = NULL;
+    p->children = NULL;
+    p->node = NULL;
+}
+
+static void
+move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
+{
+    SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
+    HTaskPtr property_task = sgroot->move_exec_task;
+
+    property_task->add_inData(property, sizeof(Property)*PROPERTY_LENGTH);
+    property_task->add_outData(update_property, sizeof(Property)*PROPERTY_LENGTH);
+    property_task->set_cpu(SPE_ANY);
+    property_task->set_post(createSceneGraphFromProperty, (void *)sgroot, 0);
+    property_task->spawn();
+}
+
+static void
+collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h,
+	  SceneGraphPtr tree)
+{
+}
+
+static void
+createSceneGraphFromProperty(SchedTask *s, void *sgroot_, void *arg1)
+{
+    SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
+    SceneGraphPtr camera = sgroot->camera;
+    SceneGraphPtr p_node;
+    SceneGraphPtr root;
+    
+    // ここが allExecute の tree をたどって clone して行くところに相当する
+    Property *p;
+    
+    for (int i = 0; i < PROPERTY_LENGTH; i++) {
+	p = &update_property[i];
+	SceneGraphPtr node = sgroot->createSceneGraph(p->sgid);
+	apply_property(node, p);    
+    }
+	
+    for (int j = 0; j < PROPERTY_LENGTH; j++) {
+	p = &update_property[j];
+	p_node = (SceneGraphPtr)p->node;
+	if (p->have_parent) {
+	    SceneGraphPtr parent = (SceneGraphPtr)update_property[p->parent_index].node;
+	    parent->addChild(p_node);
+	    get_matrix(p_node->matrix, p_node->angle, p_node->xyz, parent->matrix);
+	    get_matrix(p_node->real_matrix, p_node->angle, p_node->xyz, parent->real_matrix);
+	} else {
+	    get_matrix(p_node->matrix, p_node->angle, p_node->xyz, camera->matrix);
+	    get_matrix(p_node->real_matrix, p_node->angle, p_node->xyz, camera->real_matrix);
+	}
+    }
+
+    root = (SceneGraphPtr)update_property[0].node;
+    root->set_move_collision(move, collision);
+    sgroot->setSceneData(root);
+
+    Property *tmp = property;
+    property = update_property;
+    update_property = tmp;
+
+    sgroot->move_finish();
+}
+
+static void
+apply_property(SceneGraphPtr node, Property *p)
+{
+    for (int i = 0; i < 3; i++) {
+	node->xyz[i] = p->xyz[i];
+	node->angle[i] = p->angle[i];
+	node->stack_xyz[i] = p->stack_xyz[i];
+    }
+    p->node = (memaddr)node;
+    node->property = (memaddr)p;
+}
+
+/*
+  ここで必要な値をプロパティに格納
+ */
+static void
+set_property(Property *p, SceneGraphPtr node, int index)
+{
+    for (int i = 0; i < 3; i++) {
+	p->xyz[i] = node->xyz[i];
+	p->angle[i] = node->angle[i];
+	p->stack_xyz[i] = node->stack_xyz[i];
+    }
+    p->parent = (memaddr)node->parent;
+    p->children = (memaddr)node->children;
+    p->property_index = index;    
+    p->sgid = node->sgid;
+    p->node = (memaddr)node;
+    node->property = (memaddr)p;
+}
+
+static void
+regist_task(SceneGraphRoot *sgroot)
+{
+    TaskManager *manager = sgroot->tmanager;
+    HTaskPtr task = manager->create_task(ChainTask);
+    // sgroot->setExecTask(task); とやるべき?
+    sgroot->move_exec_task = task;
+}
+
+/*
+  Property に親子関係を書き込む
+  これも API に入れちゃっていいかな
+ */
+static void
+set_relation(SceneGraphPtr parent, SceneGraphPtr child)
+{
+    Property *p = (Property *)parent->property;
+    Property *c = (Property *)child->property;
+    p->children = (memaddr)child;
+    c->parent = (memaddr)parent;
+    c->parent_index = p->property_index;
+    c->have_parent = 1;
+}
+
+MainLoopPtr 
+property_chain::init(Viewer *viewer, int screen_w, int screen_h)
+{
+    // SgChange を使うための2行
+    SgChange *sgroot = new SgChange(viewer);
+    sgroot->run_init();
+    // 上で書いた regist_task() を登録
+    // sgroot->appTaskRegist(regist_task); がいいかな
+    sgroot->sgroot_A->appTaskRegist(regist_task);
+
+    property        = (Property *)sgroot->manager->allocate(sizeof(Property)*PROPERTY_LENGTH);
+    update_property = (Property *)sgroot->manager->allocate(sizeof(Property)*PROPERTY_LENGTH);
+
+    // property の初期化 application ごとに固有
+    for(int i = 0; i < PROPERTY_LENGTH; i++) {
+	init_chain(&property[i]);
+    }
+
+    SceneGraphPtr root_chain, chain;
+    sgroot->createFromXMLfile("xml_file/chain.xml");
+    root_chain = sgroot->createSceneGraph("CHAIN");
+    //root_chain->xyz[0] = screen_w / 2;
+    //root_chain->xyz[0] = screen_w / 4;
+    root_chain->xyz[0] = 300.0f;
+    root_chain->xyz[1] = 0.0f;
+    root_chain->set_move_collision(move, collision);
+    set_property(&property[0], root_chain, 0);
+    
+    for (int i = 1; i < PROPERTY_LENGTH; i++) {
+	chain = sgroot->createSceneGraph("CHAIN");
+	chain->xyz[0] = 0;
+	chain->xyz[1] = chain_width * i;
+	chain->angle[1] = -90 * (i % 2);
+	root_chain->addChild(chain);
+	set_property(&property[i], chain, i);
+	set_relation(root_chain, chain);
+    }
+
+    // root の set_property は SceneGraph を作成してから実行
+    // addChild したら set_relation しないとだめ、あんまりにもあんまり
+
+    /*
+      apply_property は post_func の createSceneGraphFromProperty 中で使う
+      apply_property は sgroot に持たせてもいいと思います○
+    */
+    
+    sgroot->setSceneData(root_chain);
+
+    return sgroot;
+}
+
+extern Application *
+application() {
+    return new property_chain();
+}
+
+const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n";
+
+extern int init(TaskManager *manager, int argc, char *argv[]);
+extern void task_initialize();
+static void TMend(TaskManager *manager);
+
+int
+TMmain(TaskManager *manager, int argc, char *argv[])
+{
+    task_initialize();
+    manager->set_TMend(TMend);
+    return init(manager, argc, argv);
+
+}
+
+void
+TMend(TaskManager *manager)
+{
+    printf("test_nogl end\n");
+}
+
+/* end */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Test/property_chain.h	Fri Mar 05 13:12:31 2010 +0900
@@ -0,0 +1,12 @@
+#include <math.h>
+#include <stdlib.h>
+#include "SceneGraphRoot.h"
+#include "Application.h"
+#include "MainLoop.h"
+#include "viewer.h"
+
+class property_chain : public Application {
+
+    MainLoopPtr init(Viewer *viewer, int screen_w, int screen_h);
+
+};
--- a/Renderer/Test/property_test.cc	Fri Mar 05 12:51:36 2010 +0900
+++ b/Renderer/Test/property_test.cc	Fri Mar 05 13:12:31 2010 +0900
@@ -9,8 +9,7 @@
 ChainPropertyPtr properties[2];
 ChainProperty cv[CHAIN_LEN];
 
-
-void createSceneGraphFromProperty(SceneGraphPtr root, ChainPropertyPtr cv, Viewer *sgroot);
+void createSceneGraphFromProperty(SceneGraphPtr root, ChainPropertyPtr cv, SgChange *sgroot);
 
 void
 init_chainold_vars(ChainPropertyPtr cv) {
@@ -140,7 +139,7 @@
 
 
 void
-createSceneGraphFromProperty(SceneGraphPtr root, ChainPropertyPtr cv, Viewer *sgroot)
+createSceneGraphFromProperty(SceneGraphPtr root, ChainPropertyPtr cv, SgChange *sgroot)
 {
     SceneGraphPtr node;
 
--- a/Renderer/Test/property_test.h	Fri Mar 05 12:51:36 2010 +0900
+++ b/Renderer/Test/property_test.h	Fri Mar 05 13:12:31 2010 +0900
@@ -1,4 +1,5 @@
-#include "Application.h"
+
+#include "SgChange.h"
 
 typedef void (*spe_move_func)(void *cv, int screen_w, int screen_h);
 typedef void (*spe_collision_func)(void *cv, int screen_w, int screen_h);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Test/property_universe.cc	Fri Mar 05 13:12:31 2010 +0900
@@ -0,0 +1,202 @@
+#include <math.h>
+#include <stdlib.h>
+#include "SceneGraphRoot.h"
+#include "MainLoop.h"
+#include "property_universe.h"
+#include "types.h"
+#include "Func.h"
+#include "sys.h"
+#include "SgChange.h"
+
+static const int PROPERTY_LENGTH = 2;
+
+Property *property, *update_property;
+
+// prototype
+static void collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, SceneGraphPtr tree);
+static void move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h);
+static void createSceneGraphFromProperty(SchedTask *s, void *sgroot, void *arg1);
+static void set_property(Property *p, SceneGraphPtr sg, int index);
+static void apply_property(SceneGraphPtr sg, Property *p);
+static void regist_task(SceneGraphRoot *sgroot);
+static void set_relation(SceneGraphPtr parent, SceneGraphPtr child);
+
+static void
+move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
+{
+    SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
+    HTaskPtr property_task = sgroot->move_exec_task;
+
+    property_task->add_inData(property, sizeof(Property)*PROPERTY_LENGTH);
+    property_task->add_outData(update_property, sizeof(Property)*PROPERTY_LENGTH);
+    property_task->set_cpu(SPE_ANY);    
+    property_task->set_post(createSceneGraphFromProperty, (void *)sgroot, 0);
+    property_task->spawn();
+}
+
+static void
+collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h,
+	  SceneGraphPtr tree)
+{
+}
+
+static void
+createSceneGraphFromProperty(SchedTask *s, void *sgroot_, void *arg1)
+{
+    SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
+    SceneGraphPtr camera = sgroot->camera;
+    SceneGraphPtr p_node;
+    
+    // ここが allExecute の tree をたどって clone して行くところに相当する
+    Property *p;
+    
+    for (int i = 0; i < PROPERTY_LENGTH; i++) {
+	p = &update_property[i];
+	SceneGraphPtr node = sgroot->createSceneGraph(p->name);
+	if (strcmp(node->name, "Earth") == 0) {
+	    node->set_move_collision(move, collision);
+	}
+	apply_property(node, p);    
+    }
+	
+    for (int j = 0; j < PROPERTY_LENGTH; j++) {
+	p = &update_property[j];
+	p_node = (SceneGraphPtr)p->node;
+	if (p->have_parent) {
+	    SceneGraphPtr parent = (SceneGraphPtr)update_property[p->parent_index].node;
+	    parent->addChild(p_node);
+	    get_matrix(p_node->matrix, p_node->angle, p_node->xyz, parent->matrix);
+	    get_matrix(p_node->real_matrix, p_node->angle, p_node->xyz, parent->real_matrix);
+	} else {
+	    get_matrix(p_node->matrix, p_node->angle, p_node->xyz, camera->matrix);
+	    get_matrix(p_node->real_matrix, p_node->angle, p_node->xyz, camera->real_matrix);
+	}
+    }
+
+    sgroot->setSceneData((SceneGraphPtr)update_property[0].node);
+
+    Property *tmp = property;
+    property = update_property;
+    update_property = tmp;
+
+    sgroot->move_finish();
+}
+
+static void
+apply_property(SceneGraphPtr node, Property *p)
+{
+    for (int i = 0; i < 3; i++) {
+	node->xyz[i] = p->xyz[i];
+	node->angle[i] = p->angle[i];
+	node->stack_xyz[i] = p->stack_xyz[i];
+    }
+    p->node = (memaddr)node;
+    node->property = (memaddr)p;
+}
+
+/*
+  ここで必要な値をプロパティに格納
+ */
+static void
+set_property(Property *p, SceneGraphPtr node, int index)
+{
+    for (int i = 0; i < 3; i++) {
+	p->xyz[i] = node->xyz[i];
+	p->angle[i] = node->angle[i];
+	p->stack_xyz[i] = node->stack_xyz[i];
+    }
+    p->parent = (memaddr)node->parent;
+    p->children = (memaddr)node->children;
+    p->name = node->name;
+    p->property_index = index;    
+    
+    p->node = (memaddr)node;
+    node->property = (memaddr)p;
+}
+
+static void
+regist_task(SceneGraphRoot *sgroot)
+{
+    TaskManager *manager = sgroot->tmanager;
+    HTaskPtr task = manager->create_task(UniverseTask);
+    // sgroot->setExecTask(task); とやるべき?
+    sgroot->move_exec_task = task;
+}
+
+static void
+set_relation(SceneGraphPtr parent, SceneGraphPtr child)
+{
+    /*
+    child->property->parent_index = parent->property->property_index;
+    child->property->have_parent = 1;
+    */
+
+    Property *p = (Property *)parent->property;
+    Property *c = (Property *)child->property;
+    c->parent_index = p->property_index;
+    c->have_parent = 1;
+
+}
+
+MainLoopPtr 
+property_universe::init(Viewer *viewer, int screen_w, int screen_h)
+{
+    // SgChange を使うための2行
+    SgChange *sgroot = new SgChange(viewer);
+    sgroot->run_init();
+    // 上で書いた regist_task() を登録
+    // sgroot->appTaskRegist(regist_task); がいいかな
+    sgroot->sgroot_A->appTaskRegist(regist_task);
+
+    int root_obj_index = 0;
+    property        = (Property *)sgroot->manager->allocate(sizeof(Property)*PROPERTY_LENGTH);
+    update_property = (Property *)sgroot->manager->allocate(sizeof(Property)*PROPERTY_LENGTH);
+
+    SceneGraphPtr earth;
+    sgroot->createFromXMLfile("xml_file/universe.xml");
+    earth = sgroot->createSceneGraph("Earth");
+    earth->set_move_collision(move, collision);
+    earth->xyz[0] = screen_w / 2;
+    earth->xyz[1] = screen_h / 2;
+
+    SceneGraphPtr moon;
+    moon = sgroot->createSceneGraph("Moon");
+
+    earth->addChild(moon);
+
+    set_property(&property[root_obj_index], earth, 0);
+    set_property(&property[1], moon, 1);
+    set_relation(earth, moon);
+    
+    sgroot->setSceneData(earth);
+
+    return sgroot;
+}
+
+extern Application *
+application() {
+    return new property_universe();
+}
+
+const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n";
+
+extern int init(TaskManager *manager, int argc, char *argv[]);
+extern void task_initialize();
+static void TMend(TaskManager *manager);
+
+int
+TMmain(TaskManager *manager, int argc, char *argv[])
+{
+    task_initialize();
+    manager->set_TMend(TMend);
+    return init(manager, argc, argv);
+
+}
+
+void
+TMend(TaskManager *manager)
+{
+    printf("test_nogl end\n");
+}
+
+/* end */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Test/property_universe.h	Fri Mar 05 13:12:31 2010 +0900
@@ -0,0 +1,30 @@
+#include <math.h>
+#include <stdlib.h>
+#include "SceneGraphRoot.h"
+#include "Application.h"
+#include "MainLoop.h"
+#include "viewer.h"
+
+typedef struct {
+    float xyz[3];  // 12 byte
+    float angle[3];
+    float stack_xyz[3];
+    int property_index;
+    int parent_index;
+    int have_parent;
+    /*
+    SceneGraphPtr parent;
+    SceneGraphPtr children;
+    SceneGraphPtr node;
+    */
+    memaddr parent;
+    memaddr children;
+    memaddr node;
+    const char *name;
+} *PropertyPtr, Property;
+
+class property_universe : public Application {
+
+    MainLoopPtr init(Viewer *viewer, int screen_w, int screen_h);
+
+};
--- a/Renderer/Test/universe.cc	Fri Mar 05 12:51:36 2010 +0900
+++ b/Renderer/Test/universe.cc	Fri Mar 05 13:12:31 2010 +0900
@@ -17,7 +17,7 @@
 static void
 moon_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
 {
-    node->angle[0] += 3.0f;
+  //node->angle[0] += 3.0f;
 }
 
 
@@ -53,8 +53,8 @@
 
     // SceneGraph の move と collision を設定
     earth->set_move_collision(earth_move, earth_collision);
-    earth->stack_xyz[0] = 3.0f;
-    earth->stack_xyz[1] = 3.0f;
+    earth->xyz[0] = screen_w / 2;
+    earth->xyz[1] = screen_h / 2;
     
     moon = sgroot->createSceneGraph("Moon");
     moon->set_move_collision(moon_move, moon_collision);