changeset 1352:57c3b08b76b5 draft

add matrix list
author Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
date Tue, 17 Jan 2012 17:55:52 +0900
parents e51127dbd63c
children df50c95267ba
files Renderer/Engine/SceneGraphRoot.cc Renderer/Engine/task/CreatePolygonFromSceneGraph.cc Renderer/Engine/viewer.cc Renderer/Test/universe.cc
diffstat 4 files changed, 114 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/SceneGraphRoot.cc	Sun Jan 15 23:21:39 2012 +0900
+++ b/Renderer/Engine/SceneGraphRoot.cc	Tue Jan 17 17:55:52 2012 +0900
@@ -873,9 +873,8 @@
      * (polygon_vertex) * camera->(s)
      */
 
-    //matrix4x4(camera->matrix, camera->m_view, camera->m_pers);
+    matrix4x4(camera->out_matrix, camera->m_view, camera->m_pers);
     lightCalc(camera);
-    copyMatrix(camera->matrix, camera->m_view);
     copyTree(sg_draw_tree, camera);
 
     // 現在、allExecute が終わった時点では
@@ -889,13 +888,86 @@
     sg_exec_tree = camera->children;
 }
 
+struct st_matrix {
+    float *m;
+    st_matrix *next;
+    st_matrix *prev;
+};
+
+typedef struct matrix_list {
+    int length;
+    st_matrix *first;
+    st_matrix *end;
+}matrix_list, *matrix_listp;
+
+static void
+initList(matrix_list *list) {
+    list->first = NULL;
+    list->end = NULL;
+    list->length = 0;
+}
+
+
+static void
+addMatrix(matrix_list *list, float *matrix) {
+
+    ++list->length;
+
+    st_matrix *sm = new st_matrix;
+    sm->m = matrix;
+    sm->next = NULL;
+    sm->prev = NULL;
+    
+    if (list->first == NULL && list->end == NULL) {
+        list->first = list->end = sm;
+        return;
+    }
+    list->end->next = sm;
+    sm->prev = list->end;
+    list->end = sm;
+}
+
+static void
+popMatrix(matrix_list *list) {
+
+    st_matrix *end = list->end;
+    --list->length;
+
+    if (end != list->first) {
+        st_matrix *new_end = end->prev;
+        new_end->next = NULL;
+        list->end = new_end;
+    } else {
+        list->first = NULL;
+        list->end = NULL;
+    }
+
+    delete end;
+}
+
+static void
+removeMatrix(matrix_list *list) {
+    st_matrix *p = list->first;
+    while (p) {
+	st_matrix *p1 = p->next;
+	delete p;
+	p = p1;
+    }
+}
+
+
 void
 SceneGraphRoot::copyTree(SceneGraphPtr t, SceneGraphPtr cur_parent)
 {
     // SceneGraphPtr t = sg_draw_tree;
 
+    // 
+    //int matrix_size = 16; // 4x4の行列の大きさ
+    matrix_list *mlist = new matrix_list;
+    initList(mlist);
+    addMatrix(mlist, cur_parent->matrix);
+
     /*removeのflagをもとにtreeを形成*/
-
     while (t) {
 	SceneGraphPtr c = NULL;
 	if (!t->isRemoved()) {
@@ -905,13 +977,36 @@
 	    c->frame = t->frame;
 	    /*親の回転、座標から、子の回転、座標を算出*/
 	    //get_matrix(c->matrix, c->angle, c->xyz, cur_parent->matrix);
-            float m[16];
-            for(int i=0;i<16;i++) m[i] = c->matrix[i];
-            matrix4x4(c->matrix, m, cur_parent->matrix);
+            
+            /***** 
+               // うーん、SceneGraphRoot内で task create しちゃっていいのか?
+
+               HTaskPtr cmat = create_task_array(CALC_MATRIX, 1, 1, mlist->length+1, 1); // +1は自分の分
+
+               int index = 0;
+               for (st_matrixp m = list->fisrt; m != NULL; m = m->next) {
+                 cmat->set_inData(index, m->matrix, sizeof(float)*matrix_size);
+                 index++;
+               }
+               cmat->set_inData(index, t->matrix, sizeof(float)*matrix_size);
+
+               cmat->set_outData(0, c->out_matrix, sizeof(float)*matrix_size);
+               cmat->set_cpu(SPE_ANY);
+               task_next->wait_for(cmat);
+               cmat->spawn_task_array(cmat->next());
+               cmat->spawn();
+
+               // きちんと matrix を list にできるかテストしなきゃ
+             ******/
+
+            // どこかで、オブジェクトの状態は保持してないといけない。
+            // なので、c->matrix でもつ。 
+            matrix4x4(c->out_matrix, c->matrix, cur_parent->out_matrix);
 	}
 
 
 	if (t->children != NULL && c != NULL) {
+            addMatrix(mlist, t->matrix);
 	    cur_parent = c;
 	    t = t->children;
 	} else if (t->brother != NULL) {
@@ -926,6 +1021,7 @@
 			t = NULL;
 			break;
 		    } else {
+                        popMatrix(mlist);
                         cur_parent = cur_parent->parent;
                         t = t->parent;
 		    }
@@ -934,6 +1030,9 @@
 	}
     }
 
+    removeMatrix(mlist);
+    delete mlist;
+
 }
 
 
@@ -1040,6 +1139,7 @@
     }
 }
 
+// 呼ばれてない
 void
 SceneGraphRoot::checkRemove()
 {
--- a/Renderer/Engine/task/CreatePolygonFromSceneGraph.cc	Sun Jan 15 23:21:39 2012 +0900
+++ b/Renderer/Engine/task/CreatePolygonFromSceneGraph.cc	Tue Jan 17 17:55:52 2012 +0900
@@ -107,23 +107,20 @@
     //pp, matrix, を受け取る
     PolygonPackPtr in_pp      = (PolygonPackPtr)smanager->get_input(rbuf, 0);
     // w = world, v = view, p = perspective
-    float *wv_matrix         = (float*)smanager->get_input(rbuf, 1);
-    float *m_pers           = (float*)smanager->get_input(rbuf, 2);
-    float *m_screen           = (float*)smanager->get_input(rbuf, 3);
+    float *wvp_matrix         = (float*)smanager->get_input(rbuf, 1);
+    float *m_screen           = (float*)smanager->get_input(rbuf, 2);
 
     float normal_matrix[16]; 
   
-    for (int i = 0; i<16; i++) normal_matrix[i] = wv_matrix[i];
+    for (int i = 0; i<16; i++) normal_matrix[i] = wvp_matrix[i];
     normal_matrix[4*0+3] = normal_matrix[4*1+3] = normal_matrix[4*2+3] = 0;
     normal_matrix[4*3] = normal_matrix[4*3+1] = normal_matrix[4*3+2] = 0;
     normal_matrix[4*3+3] = 1;
 
-    float wvp_matrix[16]; // wvp matrix
     float matrix[16]; // wvps matrix
-    matrix4x4(wvp_matrix, wv_matrix, m_pers);
     matrix4x4(matrix, wvp_matrix, m_screen);
 
-    texture_list *tritexinfo  = (texture_list*)smanager->get_input(rbuf, 4);
+    texture_list *tritexinfo  = (texture_list*)smanager->get_input(rbuf, 3);
     
     PolygonPackPtr next = (PolygonPackPtr)smanager->get_param(0);
 
--- a/Renderer/Engine/viewer.cc	Sun Jan 15 23:21:39 2012 +0900
+++ b/Renderer/Engine/viewer.cc	Tue Jan 17 17:55:52 2012 +0900
@@ -457,8 +457,6 @@
 
      */
     
-
-
     HTaskPtr game_task_array = 0;
 
     /* GameTask の処理の終了を待ってからポリゴンを作る */
@@ -480,8 +478,7 @@
 	  HTaskPtr create_pp = manager->create_task(CreatePolygonFromSceneGraph);
 	  
 	  create_pp->add_inData(&t->pp[i], sizeof(PolygonPack));
-	  create_pp->add_inData(t->matrix, sizeof(float)*16);
-          create_pp->add_inData(camera->m_pers, sizeof(float)*16);
+	  create_pp->add_inData(t->out_matrix, sizeof(float)*16);
 	  create_pp->add_inData(camera->m_screen, sizeof(float)*16);
 	  create_pp->add_inData(t->texture_info, sizeof(texture_list));
 	  
--- a/Renderer/Test/universe.cc	Sun Jan 15 23:21:39 2012 +0900
+++ b/Renderer/Test/universe.cc	Tue Jan 17 17:55:52 2012 +0900
@@ -26,19 +26,19 @@
 earth_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
 {
     //node->angle[1] += 1.0f;
-    //node->angleIt(1, 0, 0);
+    node->angleIt(0, 1, 0);
     //if (node->angle[1] > 360.0f) {
 	//node->angle[1] = 0.0f;
     //}
 
     //node->xyz[0] += node->stack_xyz[0];
-    //node->translateX(node->stack_xyz[0]);
+    node->translateX(node->stack_xyz[0]);
     if ((int)node->matrix[12] > screen_w || (int)node->matrix[12] < 0) {
 	node->stack_xyz[0] = -node->stack_xyz[0];
     }
 
     //node->xyz[1] += node->stack_xyz[1];
-    //node->translateY(node->stack_xyz[1]);
+    node->translateY(node->stack_xyz[1]);
     if ((int)node->matrix[13] > screen_h || (int)node->matrix[13] < 0) {
 	node->stack_xyz[1] = -node->stack_xyz[1];
     }