diff Renderer/Engine/SceneGraphRoot.cc @ 779:4455e7b0caf3

merged
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 05 Mar 2010 13:12:31 +0900
parents 510424e175ae 2a00c1f470b7
children f2497e0ecd7c
line wrap: on
line diff
--- 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 */