changeset 219:0f1ff7b06157

allExecute する度に SceneGraph をコピーしていく様に変更
author gongo@gendarme.local
date Mon, 09 Feb 2009 00:12:40 +0900
parents 961dec5912ef
children 29e338dbc280
files TaskManager/Test/test_render/Camera.cpp 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/SceneGraphRoot.cpp TaskManager/Test/test_render/SceneGraphRoot.h TaskManager/Test/test_render/cube_action.cpp TaskManager/Test/test_render/init_position.cpp TaskManager/Test/test_render/sys.cpp TaskManager/Test/test_render/sys.h TaskManager/Test/test_render/task/CreatePolygonFromSceneGraph.cpp TaskManager/Test/test_render/task/CreateSpan.cpp TaskManager/Test/test_render/task/DrawSpan.cpp TaskManager/Test/test_render/viewer.cpp
diffstat 16 files changed, 320 insertions(+), 97 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/Test/test_render/Camera.cpp	Wed Feb 04 22:54:14 2009 +0900
+++ b/TaskManager/Test/test_render/Camera.cpp	Mon Feb 09 00:12:40 2009 +0900
@@ -9,10 +9,16 @@
     Pad *pad = sgroot->getController();
     CameraPtr node = (CameraPtr)_node;
 
-    if (pad->r2.isPush() || pad->r2.isHold()) {
-	node->xyz[0] += 2.0f;
-    } else if (pad->l2.isPush() || pad->l2.isHold()) {
-	node->xyz[0] -= 2.0f;
+    if (pad->r2.isHold()) {
+	node->angle[1] += 2.0f;
+	if (node->angle[1] > 360.0f) {
+	    node->angle[1] -= 360.0f;
+	}
+    } else if (pad->l2.isHold()) {
+	node->angle[1] -= 2.0f;
+	if (node->angle[1] < 0.0f) {
+	    node->angle[1] += 360.0f;
+	}
     }
 
 #if 0
@@ -40,39 +46,78 @@
 {
     name = (const char*)"Camera";
 
-    lookat_base[0] =  0.0f;
-    lookat_base[1] =  0.0f;
-    lookat_base[2] =  0.0f;
-    lookat_base[3] =  0.0f;
+    zd[0] =  0.0f;
+    zd[1] =  0.0f;
+    zd[2] =  1.0f;
+    zd[3] =  1.0f;
 
-    up_base[0] =  0.0f;
-    up_base[1] = 10.0f;
-    up_base[2] =  0.0f;
-    up_base[3] =  0.0f;
+    yd[0] = 0.0f;
+    yd[1] = 1.0f;
+    yd[2] = 0.0f;
+    yd[3] = 1.0f;
 
     fov  = 60.0f;
     near = 0.0f;
     far  = 1000.0f;
 
-    //xyz[0] = 960.0f;
-    //xyz[1] = 540.0f;
-    xyz[2] = -1000.0f;
+    //xyz[0] = 320.0f;
+    //xyz[1] = 240.0f;
+    //xyz[2] = -100.0f;
+    //xyz[3] = 1.0f;
     
     this->set_move_collision(camera_move, camera_collision);
 }
 
 void
-Camera::getLookAt(float *lookat)
+Camera::createRotMatrix(float *m)
 {
-    subVector(lookat, this->lookat_base, this->xyz);
-    normalize(lookat, lookat);
-}
+    float radx,rady,radz;
+    float cx[4], cy[4], cz[4];
+    float p[4];
+    float *matrix = new float[16];
+
+    radx = angle[0]*3.14/180;
+    rady = angle[1]*3.14/180;
+    radz = angle[2]*3.14/180;
+
+    float sinx = sin(radx);
+    float cosx = cos(radx);
+    float siny = sin(rady);
+    float cosy = cos(rady);
+    float sinz = sin(radz);
+    float cosz = cos(radz);
 
-void
-Camera::getUp(float *up, float *lookat)
-{
-    outerProduct(up, this->up_base, lookat);
-    normalize(up, up);
+    /* View Transform */
+    matrix[0] = cosz*cosy+sinz*sinx*siny;
+    matrix[1] = sinz*cosx;
+    matrix[2] = -cosz*siny+sinz*sinx*cosy;
+    matrix[3] = 0.0f;
+    matrix[4] = -sinz*cosy+cosz*sinx*siny;
+    matrix[5] = cosz*cosx;
+    matrix[6] = sinz*siny+cosz*sinx*cosy;
+    matrix[7] = 0.0f;
+    matrix[8] = cosx*siny;
+    matrix[9] = -sinx;
+    matrix[10] = cosx*cosy;
+    matrix[11] = 0.0f;
+    matrix[12] = 0.0f;
+    matrix[13] = 0.0f;
+    matrix[14] = 0.0f;
+    matrix[15] = 1.0f;
+
+    applyMatrix(cz, matrix, zd);
+    applyMatrix(cy, matrix, yd);
+    applyMatrix(p, matrix, xyz);
+
+    // matrix 使い回すためにクリア
+    unitMatrix(matrix);
+
+    outerProduct(cx, cy, cz);
+    normalize(&matrix[0], cx);
+    normalize(&matrix[8], cz);
+    outerProduct(&matrix[4], &matrix[8], &matrix[0]);
+    transMatrix(matrix, matrix, p);
+    inversMatrix(m, matrix);
 }
 
 void
@@ -158,29 +203,30 @@
 }
 
 void
+Camera::setCamera(float *pose)
+{
+    memcpy(xyz, &pose[12], sizeof(float)*4);
+}
+
+void
 Camera::update(int w, int h)
 {
+#if 0
     // うーん。。。
-    float cx[4];
-    float cy[4];
-    float cz[4];
     float view[16]; // view transform matrix
     float pers[16]; // perspective transform matrix
     float screen[16]; // screen transform matrix
     float tmp[16];
 
-    getLookAt(cz);
-    getUp(cx, cz);
-    outerProduct(cy, cz, cx);
-
     // view tansform
-#if 1
-    createViewTransformMatrix(view, cx, cy, cz);
+    createRotMatrix(view);
     createPerspectiveTransformMatrix(pers, (float)w/(float)h);
     createScreenTransformMatrix(screen, (float)w, (float)h);
     
     matrix4x4(tmp, view, pers);
     matrix4x4(matrix, tmp, screen);
+    //matrix4x4(tmp, pers, view);
+    //matrix4x4(matrix, screen, tmp);
 #else
     get_matrix(matrix, angle, xyz, NULL);
 #endif
--- a/TaskManager/Test/test_render/Camera.h	Wed Feb 04 22:54:14 2009 +0900
+++ b/TaskManager/Test/test_render/Camera.h	Mon Feb 09 00:12:40 2009 +0900
@@ -9,19 +9,20 @@
 public:
     Camera(void);
 
-    float lookat_base[4];
-    float up_base[4];
+    float zd[4]; // direction z
+    float yd[4]; // direction y
     float fov;
     float near;
     float far;
 
+    void createRotMatrix(float *m);
     void createViewTransformMatrix(float*, float*, float*, float*);
     void createPerspectiveTransformMatrix(float *, float);
     void createScreenTransformMatrix(float *sm, float _w, float _h);
 
+
+    void setCamera(float *pose);
     void update(int screen_w, int screen_h);
-    void getLookAt(float *lookat);
-    void getUp(float *up, float *lookat);
 };
 
 typedef Camera *CameraPtr;
--- a/TaskManager/Test/test_render/ChangeLog	Wed Feb 04 22:54:14 2009 +0900
+++ b/TaskManager/Test/test_render/ChangeLog	Mon Feb 09 00:12:40 2009 +0900
@@ -1,3 +1,15 @@
+2009-02-09  Wataru MIYAGUNI  <gongo@cr.ie.u-ryukyu.ac.jp>
+
+	* SceneGraphRoot.cpp (SceneGraphRoot::allExecute)
+	(SceneGraphRoot): fix
+	SceneGraph を root から走査していきながら
+	その都度コピーしていき、最終的に全体の新しい SceneGraph ができる。
+	削除されていればコピーしない、っていうのは簡単だけど
+	追加された場合、コピー元に追加されるのは困るので
+	コピーしたやつに追加って形にしたら今のコードになった。
+	めんどくさいっちゃめんどくさい。もっと綺麗な書き方あるかね
+
+
 2009-02-01  Wataru MIYAGUNI  <gongo@cr.ie.u-ryukyu.ac.jp>
 
 	* SceneGraph.cpp (SceneGraph::SceneGraph)
--- a/TaskManager/Test/test_render/Keyboard.cpp	Wed Feb 04 22:54:14 2009 +0900
+++ b/TaskManager/Test/test_render/Keyboard.cpp	Mon Feb 09 00:12:40 2009 +0900
@@ -84,7 +84,7 @@
 	r1.release_work();
     }
 
-    if (keys[SDLK_o] == SDL_PRESSED) {
+    if (keys[SDLK_p] == SDL_PRESSED) {
 	r2.push_work();
     } else {
 	r2.release_work();
--- a/TaskManager/Test/test_render/Makefile.def	Wed Feb 04 22:54:14 2009 +0900
+++ b/TaskManager/Test/test_render/Makefile.def	Mon Feb 09 00:12:40 2009 +0900
@@ -3,10 +3,10 @@
 # include/library path
 # ex: macosx
 #CERIUM = /Users/gongo/Source/Concurrency/Game_project/Cerium
-#CERIUM = /Users/gongo/Source/hg/Cerium
+CERIUM = /Users/gongo/Source/hg/Cerium
 
 # ex: linux/ps3
-CERIUM = /home/gongo/Cerium
+#CERIUM = /home/gongo/Cerium
 #CERIUM = /Users/tkaito/hg/Game/Cerium
 
 #CERIUM = ../../..
--- a/TaskManager/Test/test_render/SceneGraph.cpp	Wed Feb 04 22:54:14 2009 +0900
+++ b/TaskManager/Test/test_render/SceneGraph.cpp	Mon Feb 09 00:12:40 2009 +0900
@@ -103,6 +103,8 @@
 {
     init();
     finalize = &SceneGraph::finalize_copy;
+
+    this->name = "NULLPO";
 }
 
 /**
@@ -111,13 +113,23 @@
 SceneGraph::SceneGraph(SceneGraphPtr orig)
 {
     init();
-    finalize = &SceneGraph::finalize_copy;
-
     memcpy(this, orig, sizeof(SceneGraph));
 
     // コピーしない
-    flag_remove = 0;
-    flag_drawable = 1;
+    //flag_remove = 0;
+    //flag_drawable = 1;
+    next = NULL;
+    prev = NULL;
+    last = NULL;
+
+    parent = NULL;
+    brother = NULL;
+    children = NULL;
+    lastChild = NULL;
+
+    finalize = &SceneGraph::finalize_copy;
+
+
     frame = 0;    
 }
 
@@ -662,7 +674,6 @@
 	ret = NULL;
     }
 
-    delete node;
     return ret;
 }
 
--- a/TaskManager/Test/test_render/SceneGraphRoot.cpp	Wed Feb 04 22:54:14 2009 +0900
+++ b/TaskManager/Test/test_render/SceneGraphRoot.cpp	Mon Feb 09 00:12:40 2009 +0900
@@ -8,21 +8,23 @@
 #include "texture.h"
 #include "SGList.h"
 
+int cnt = 0;
+
 SceneGraphRoot::SceneGraphRoot(void)
 {
     sg_src = new SceneGraphPtr[SGLIST_LENGTH];
     camera = new Camera;
     iterator = new SceneGraphIterator;
 
-    sg_exec_list = NULL;
-    sg_draw_list = NULL;
+    sg_exec_tree = NULL;
+    sg_draw_tree = NULL;
     sg_available_list = NULL;
+    sg_remove_list = NULL;
 
     // TODO
     //   今はとりあえず camera を Root にしています
-    sg_exec_list = camera;
-
-    addNext(camera);
+    //   今はそれすらもしてません
+    //sg_exec_tree = camera;
 }
 
 SceneGraphRoot::~SceneGraphRoot(void)
@@ -33,6 +35,16 @@
 	SceneGraphPtr tmp = p->next;
 	delete p;
 	p = tmp;
+	cnt--;
+    }
+
+    p = sg_remove_list;
+
+    while (p) {
+	SceneGraphPtr tmp = p->next;
+	delete p;
+	p = tmp;
+	cnt--;
     }
 
     delete [] sg_src;
@@ -40,6 +52,11 @@
     delete iterator;
 }
 
+/**
+ * xml ファイルから生成された SceneGraph を sg_src に登録する。
+ *
+ * @param sg SceneGraph created by xmlfile
+ */
 void
 SceneGraphRoot::registSceneGraph(SceneGraphPtr sg)
 {
@@ -69,6 +86,8 @@
 	last->next = sg;
 	sg->prev = last;
     }
+
+    cnt++;
 }
 
 /* XMLファイルからポリゴンを作成  */
@@ -141,34 +160,60 @@
 void
 SceneGraphRoot::allExecute(int screen_w, int screen_h)
 {
-    SceneGraphPtr top = sg_exec_list;
-    SceneGraphPtr t = top; /* top = Camera (090128 現在) */
-    CameraPtr camera = (CameraPtr)t;
-    
-    camera->move_execute(screen_w, 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);
-    
-    t = camera->children;
+
+    camera->children = NULL;
+    camera->lastChild = NULL;
 
     while (t) {
-	t->move_execute(screen_w, screen_h);
-	t->collision_check(screen_w, screen_h, top);
+	SceneGraphPtr c = t->clone();
 
-	t->frame++;
+	addNext(c);
+	cur_parent->addChild(c);
+	c->frame = t->frame;
+
+	c->move_execute(screen_w, screen_h);
+	c->collision_check(screen_w, screen_h, list);
 
-	//if (t->parent != NULL) {
-	get_matrix(t->matrix, t->angle, t->xyz, t->parent->matrix);
-	//} else {
-	//get_matrix(t->matrix, t->angle, t->xyz, NULL);
-	//}
+	if (c->isRemoved()) {
+	    sg_exec_tree = c->realRemoveFromTree(cur_parent);
+	    sg_available_list = c->realRemoveFromList(sg_available_list);
+	    delete c;
+	    cnt--;
+	    t->children = NULL;
+	    t->parent = cur_parent;
+	} else {
+	    c->frame++;
+	    get_matrix(c->matrix, c->angle, c->xyz, c->parent->matrix);
+	}
 
 	if (t->children != NULL) {
+	    cur_parent = c;
 	    t = t->children;
 	} else if (t->brother != NULL) {
+	    cur_parent = c->parent;
 	    t = t->brother;
 	} else {
 	    while (t) {
 		if (t->brother != NULL) {
+		    cur_parent = t->parent;
 		    t = t->brother;
 		    break;
 		} else {
@@ -182,6 +227,23 @@
 	    }
 	}
     }
+
+    // 現在、allExecute が終わった時点では
+    // camera->children が User SceneGraph の root になる
+    sg_exec_tree = camera->children;
+}
+
+void
+SceneGraphRoot::allRemove(SceneGraphPtr list)
+{
+    SceneGraphPtr p = list;
+
+    while (p) {
+	SceneGraphPtr p1 = p->next;
+	delete p;
+	p = p1;
+	cnt--;
+    }
 }
 
 void
@@ -193,26 +255,24 @@
     while (p) {
 	p1 = p->next;
 	if (p->isRemoved()) {
-	    sg_exec_list = p->realRemoveFromTree(sg_exec_list);
+	    sg_exec_tree = p->realRemoveFromTree(sg_exec_tree);
 	    sg_available_list = p->realRemoveFromList(sg_available_list);
 	}
+	delete p;
 	p = p1;
     }
-
-    // 現在、exec と draw は別で処理できてないので、一緒にする
-    sg_draw_list = sg_exec_list;
 }
 
 SceneGraphPtr
 SceneGraphRoot::getExecuteSceneGraph(void)
 {
-    return sg_exec_list;
+    return sg_exec_tree;
 }
 
 SceneGraphPtr
 SceneGraphRoot::getDrawSceneGraph(void)
 {
-    return sg_draw_list;
+    return sg_draw_tree;
 }
 
 void
@@ -224,9 +284,7 @@
 void
 SceneGraphRoot::setSceneData(SceneGraphPtr sg)
 {
-    //sg_draw_list = sg_exec_list = sg;
-    sg_exec_list->addChild(sg);
-    sg_draw_list = sg_exec_list;
+    sg_exec_tree = sg;
 }
 
 Pad*
@@ -248,3 +306,9 @@
     iterator->set(list);
     return iterator;
 }
+
+CameraPtr
+SceneGraphRoot::getCamera(void)
+{
+    return camera;
+}
--- a/TaskManager/Test/test_render/SceneGraphRoot.h	Wed Feb 04 22:54:14 2009 +0900
+++ b/TaskManager/Test/test_render/SceneGraphRoot.h	Mon Feb 09 00:12:40 2009 +0900
@@ -24,14 +24,18 @@
     SceneGraphPtr *sg_src;
 
     // move, collision 用の SceneGraph (tree)
-    SceneGraphPtr sg_exec_list;
+    SceneGraphPtr sg_exec_tree;
 
     // 描画用の SceneGraph List (tree)
-    SceneGraphPtr sg_draw_list;
+    SceneGraphPtr sg_draw_tree;
 
-    // 現在存在する SceneGraph (double linked list)
+    // sg_exec_tree に対応する list
     SceneGraphPtr sg_available_list;
 
+    // sg_draw_tree に対応する list
+    // draw_tree は描画後削除される
+    SceneGraphPtr sg_remove_list;
+
     // コントローラーオブジェクト (Keyboard, Joystick, ..)
     Pad *controller;
 
@@ -52,6 +56,7 @@
     Pad *getController(void);
     SceneGraphIteratorPtr getIterator(void);
     SceneGraphIteratorPtr getIterator(SceneGraphPtr list);
+    CameraPtr getCamera(void);
 
     /* Other System API */
     void allExecute(int screen_w, int screen_h);
@@ -63,6 +68,7 @@
     /* System API */
     void registSceneGraph(SceneGraphPtr sg);
     void addNext(SceneGraphPtr sg);
+    void allRemove(SceneGraphPtr list);
 };
 
 typedef SceneGraphRoot *SceneGraphRootPtr;
--- a/TaskManager/Test/test_render/cube_action.cpp	Wed Feb 04 22:54:14 2009 +0900
+++ b/TaskManager/Test/test_render/cube_action.cpp	Mon Feb 09 00:12:40 2009 +0900
@@ -1,3 +1,4 @@
+#include <math.h>
 #include "SceneGraphRoot.h"
 #include "SGList.h"
 
@@ -27,6 +28,10 @@
     node->angle[0] += 2.0f;
     node->angle[1] += 2.0f * node->stack_xyz[1];
     node->angle[2] += 2.0f * node->stack_xyz[2];
+
+    node->angle[0] = fmodf(node->angle[0], 360.0f);
+    node->angle[1] = fmodf(node->angle[1], 360.0f);
+    node->angle[2] = fmodf(node->angle[2], 360.0f);
     
     if (node->frame > 10 && sgroot->controller->circle.isPush()) {
 	cube_split(node);
@@ -51,7 +56,11 @@
     node->angle[0] += 2.0f;
     node->angle[1] += 2.0f * node->stack_xyz[1];
     node->angle[2] += 2.0f * node->stack_xyz[2];
-    
+
+    node->angle[0] = fmodf(node->angle[0], 360.0f);
+    node->angle[1] = fmodf(node->angle[1], 360.0f);
+    node->angle[2] = fmodf(node->angle[2], 360.0f);
+
     if (node->frame > 10 && sgroot->controller->circle.isPush()) {
 	cube_split(node);
     }
@@ -63,15 +72,9 @@
     SceneGraphPtr p = root->clone();
     root->addBrother(p);
 
-    printf("%d %d\n", root->frame, p->frame);
-    // TODO
-    // 木の作り方変えたらここ消す
-    p->frame = 0;
-    root->frame = 0;
-
     root->set_move_collision(cube_move_left, cube_collision);
     p->set_move_collision(cube_move_right, cube_collision);
-    
+ 
     p->xyz[0] = root->xyz[0] + 2;
     p->xyz[1] = root->xyz[1];
     p->xyz[2] = root->xyz[2];
@@ -109,19 +112,21 @@
 create_cube_split(int number)
 {
     SceneGraphPtr cube;
+    SceneGraphPtr back;
 
-    //sgroot->createFromXMLfile("xml_file/cube_split.xml");
     sgroot->createFromXMLfile("xml_file/cube.xml");
 
-    //if (number == 0) {
-    //cube = sgroot->createSceneGraph(SmallCube);
-//} else {
+    // 何もしない親
+    // cube は brother として繋がっていくので
+    // 親が居ないとだめ。
+    back = sgroot->createSceneGraph();
+
     cube = sgroot->createSceneGraph(Cube);
     cube->xyz[0] = 960.0f;
     cube->xyz[1] = 540.0f;
-//}
-
     cube->set_move_collision(cube_move_idle, cube_collision);
 
-    sgroot->setSceneData(cube);
+    back->addChild(cube);
+
+    sgroot->setSceneData(back);
 }
--- a/TaskManager/Test/test_render/init_position.cpp	Wed Feb 04 22:54:14 2009 +0900
+++ b/TaskManager/Test/test_render/init_position.cpp	Mon Feb 09 00:12:40 2009 +0900
@@ -24,7 +24,7 @@
 
     back->addChild(player);
 
-    for (int i = 0; i < 15; i++) {
+    for (int i = 0; i < 1; i++) {
       enemy  = sgroot->createSceneGraph(E_PLANE);
       enemy->set_move_collision(enemy_move, enemy_collision);
       enemy->xyz[0] = 50.0*i;
--- a/TaskManager/Test/test_render/sys.cpp	Wed Feb 04 22:54:14 2009 +0900
+++ b/TaskManager/Test/test_render/sys.cpp	Mon Feb 09 00:12:40 2009 +0900
@@ -10,6 +10,62 @@
   exit(1);
 }
 
+void
+transMatrix(float *m0, float *m1, float *v)
+{
+    memcpy(m0, m1, sizeof(float)*16);
+
+    m0[12] = m1[12] + v[0];
+    m0[13] = m1[13] + v[1];
+    m0[14] = m1[14] + v[2];
+    m0[15] = m1[15] + v[3];
+}
+
+void
+unitMatrix(float *m)
+{
+    bzero(m, sizeof(float)*16);
+
+    m[0] = 1.0f;
+    m[5] = 1.0f;
+    m[10] = 1.0f;
+    m[15] = 1.0f;
+}
+
+void
+inversMatrix(float *m0, float *m1)
+{
+    float m[16];
+
+    for (int i = 0; i < 4; i++) {
+	for (int j = 0; j < 4; j++) {
+	    m[i*4+j] = m1[j*4+i];
+	}
+    }
+
+    m[12] = -(m1[12]*m[0] + m1[13]*m[1] + m1[14]*m[2]);
+    m[13] = -(m1[12]*m[4] + m1[13]*m[5] + m1[14]*m[6]);
+    m[14] = -(m1[12]*m[8] + m1[13]*m[9] + m1[14]*m[10]);
+    m[3] = m[7] = m[11] = 0.0f;
+    m[15] = 1.0f;
+
+    memcpy(m0, m, sizeof(float)*16);
+}
+
+/**
+ * マトリックス m にベクトル v1 を右から乗算して、v0に与える
+ * @param[out] v0 output vector (float[4])
+ * @param[in] v1 input vector (float[4])
+ * @param[in] m matrix (float[16])
+ */
+void
+applyMatrix(float *v0, float *m, float *v1)
+{
+    for (int i = 0; i < 4; i++) {
+	v0[i] = v1[0]*m[i] + v1[1]*m[i+4] + v1[2]*m[i+8] + v1[3]*m[i+12];
+    }
+}
+
 /**
  * ベクトルの正規化
  *
@@ -55,6 +111,20 @@
     v0[3] = 0;
 }
 
+void
+transposeMatrix(float *m0, float *m1)
+{
+    float t[16];
+
+    for (int i = 0; i < 4; i++) {
+	for (int j = 0; j < 4; j++) {
+	    t[i*4+j] = m1[j*4+i];
+	}
+    }
+
+    memcpy(m0, t, sizeof(float)*16);
+}
+
 /**
  * ベクトルの内積 f = v0 * v1
  */
--- a/TaskManager/Test/test_render/sys.h	Wed Feb 04 22:54:14 2009 +0900
+++ b/TaskManager/Test/test_render/sys.h	Mon Feb 09 00:12:40 2009 +0900
@@ -12,3 +12,8 @@
 void subVector(float *v0, float *v1, float *v2);
 void outerProduct(float *v0, float *v1, float *v2);
 float innerProduct(float *v0, float *v1);
+void applyMatrix(float *v0, float *m, float *v1);
+void inversMatrix(float *m0, float *m1);
+void transposeMatrix(float *m0, float *m1);
+void unitMatrix(float *m);
+void transMatrix(float *m0, float *m1, float *v);
--- a/TaskManager/Test/test_render/task/CreatePolygonFromSceneGraph.cpp	Wed Feb 04 22:54:14 2009 +0900
+++ b/TaskManager/Test/test_render/task/CreatePolygonFromSceneGraph.cpp	Mon Feb 09 00:12:40 2009 +0900
@@ -123,7 +123,7 @@
 		ApplyMatrix(xyz2, sg->matrix);
 		ApplyMatrix(xyz3, sg->matrix);
 
-#if 1
+#if 0
 		xyz1[0] /= xyz1[2];
 		xyz1[1] /= xyz1[2];
 		xyz2[0] /= xyz2[2];
--- a/TaskManager/Test/test_render/task/CreateSpan.cpp	Wed Feb 04 22:54:14 2009 +0900
+++ b/TaskManager/Test/test_render/task/CreateSpan.cpp	Mon Feb 09 00:12:40 2009 +0900
@@ -168,7 +168,6 @@
     }
 
     return (scale > scale_max) ? scale_max : scale;
-    //return scale_max;
 }
 
 /**
@@ -374,7 +373,6 @@
 	span->tex_y1     = start_tex_y;
 	span->tex_y2     = end_tex_y;
 
-
 	float tex_x_len = span->tex_x2 - span->tex_x1;
 
 	/**
--- a/TaskManager/Test/test_render/task/DrawSpan.cpp	Wed Feb 04 22:54:14 2009 +0900
+++ b/TaskManager/Test/test_render/task/DrawSpan.cpp	Mon Feb 09 00:12:40 2009 +0900
@@ -315,6 +315,7 @@
     tex_xpos = (int)((span->tex_width-1) * tex);
     tex_ypos = (int)((span->tex_height-1) * tey);
 
+    //if (0 < zpos && zpos < zRow[localx + (rangex*localy)]) {
     if (zpos < zRow[localx + (rangex*localy)]) {
 	tex_addr = getTile(tex_xpos, tex_ypos,
 			   span->tex_width, span->tex_addr);
@@ -377,6 +378,7 @@
 	localx = getLocalX(x-1+j);
 	tex_z = zpos1*(x_len-1-j)/(x_len-1) + zpos2*j/(x_len-1);
 		    
+	//if (0 < tex_z && tex_z < zRow[localx + (rangex*localy)]) {
 	if (tex_z < zRow[localx + (rangex*localy)]) {
 	    // (tex_xpos, tex_ypos) の、Tile 内(上の図参照)での座標と
 	    // そのブロックのアドレス(MainMemory)
@@ -482,6 +484,7 @@
 	tex_xpos = (int)((span->tex_width-1) * tex_x);
 	tex_ypos = (int)((span->tex_height-1) * tex_y);
 
+	//if (0 < tex_z && tex_z < zRow[localx + (rangex*localy)]) {
 	if (tex_z < zRow[localx + (rangex*localy)]) {
 	    tex_addr = getTile(tex_xpos, tex_ypos,
 			       span->tex_width, span->tex_addr);
--- a/TaskManager/Test/test_render/viewer.cpp	Wed Feb 04 22:54:14 2009 +0900
+++ b/TaskManager/Test/test_render/viewer.cpp	Mon Feb 09 00:12:40 2009 +0900
@@ -259,7 +259,7 @@
 #else
     sgroot->updateControllerState();
     sgroot->allExecute(width, height);
-    sgroot->checkRemove();
+    //sgroot->checkRemove();
 #endif
 
 #if 0
@@ -397,5 +397,7 @@
     //scene_graph->controller->close();
     //delete scene_graph;
 
+    delete sgroot;
+
     quit();
 }