changeset 137:6cf991f28c6c

SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
author gongo@gendarme.cr.ie.u-ryukyu.ac.jp
date Fri, 28 Nov 2008 10:07:48 +0900
parents 802e6e75c052
children 3fd24be89d02
files TaskManager/Test/test_render/Func.h TaskManager/Test/test_render/Makefile.def TaskManager/Test/test_render/SceneGraph.cpp TaskManager/Test/test_render/SceneGraph.h TaskManager/Test/test_render/node.cpp TaskManager/Test/test_render/polygon.cpp TaskManager/Test/test_render/polygon.h TaskManager/Test/test_render/scene_graph_pack.h TaskManager/Test/test_render/spe/CreateSpan.cpp TaskManager/Test/test_render/task/CreatePolygonFromSceneGraph.cpp TaskManager/Test/test_render/task/CreatePolygonFromSceneGraph.h TaskManager/Test/test_render/task/CreateSpan.cpp TaskManager/Test/test_render/task/create_sgp.cpp TaskManager/Test/test_render/task/task_init.cpp TaskManager/Test/test_render/task/update_sgp.cpp TaskManager/Test/test_render/viewer.cpp
diffstat 16 files changed, 922 insertions(+), 721 deletions(-) [+]
line wrap: on
line diff
--- a/TaskManager/Test/test_render/Func.h	Thu Nov 27 16:20:11 2008 +0900
+++ b/TaskManager/Test/test_render/Func.h	Fri Nov 28 10:07:48 2008 +0900
@@ -11,6 +11,7 @@
      TASK_CREATE_SGP,
      TASK_UPDATE_SGP,
      TASK_CREATE_PP,
+     TASK_CREATE_PP2,
      TASK_CREATE_SPAN,
      TASK_CS_START,
      TASK_CS_RUN,
--- a/TaskManager/Test/test_render/Makefile.def	Thu Nov 27 16:20:11 2008 +0900
+++ b/TaskManager/Test/test_render/Makefile.def	Fri Nov 28 10:07:48 2008 +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 = ../../..
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TaskManager/Test/test_render/SceneGraph.cpp	Fri Nov 28 10:07:48 2008 +0900
@@ -0,0 +1,371 @@
+#include <iostream>
+#include <SDL.h>
+#include <SDL_opengl.h>
+#include <SDL_image.h>
+#include <libxml/parser.h>
+#include "SceneGraph.h"
+#include "xml.h"
+#include "sys.h"
+
+using namespace std;
+
+extern int decode(char *cont, FILE *outfile);
+
+static void
+no_move(SceneGraphPtr self) {}
+
+static void
+no_collision(SceneGraphPtr self, SceneGraphPtr tree) {}
+
+SceneGraph::SceneGraph(void)
+{
+    next = NULL;
+    last = NULL;
+
+    parent = NULL;
+    brother = NULL;
+    children = NULL;
+    lastChild = NULL;
+    move = no_move;
+    collision = no_collision;
+}
+
+
+/* construct polygon from xmlNode.  */
+SceneGraph::SceneGraph(xmlNodePtr surface)
+{
+#if 1
+    next = NULL;
+    last = NULL;
+    parent = NULL;
+    brother = NULL;
+    children = NULL;
+    lastChild = NULL;
+    move = no_move;
+    collision = no_collision;
+#else
+    // こうしたいんだけどなー
+    this->SceneGraph();
+#endif
+
+    size = atoi((char *)xmlGetProp(surface,(xmlChar *)"size"));
+    name = (char *)xmlGetProp(surface,(xmlChar *)"name");
+    parent_name = (char *)xmlGetProp(surface,(xmlChar *)"parent");
+
+    data = new float[size*3*3];
+
+    get_data(surface->children);
+}
+
+
+/* XMLファイルからポリゴンを作成  */
+SceneGraph*
+SceneGraph::createFromXMLfile(char *xmlfile)
+{
+    xmlDocPtr doc;
+    xmlNodePtr cur;
+    SceneGraph *root = NULL, *tmp, *parent;
+
+    /* パース DOM生成 */
+    doc = xmlParseFile(xmlfile);
+    cur = xmlDocGetRootElement(doc);
+
+    /* ??  */
+    xmlStrcmp(cur->name,(xmlChar*)"OBJECT-3D");
+
+    /* XMLのノードを一つずつ解析  */
+    for (cur=cur->children; cur; cur=cur->next) {
+	/* 扱うのはsurfaceオンリー  */
+	if (xmlStrcmp(cur->name,(xmlChar*)"surface") != 0) {
+	    continue;
+	}
+
+	/* ポリゴン(SceneGraph)生成  */
+	tmp = new SceneGraph(cur);
+	if ( tmp->parent_name==NULL || 0==strcmp(tmp->parent_name, "NULL")) {
+	    /* このsurfaceがroot  */
+	    root = tmp;
+	} else {
+	    /* 親はこのsurfaceより前に定義されているものとする (していい?)  */
+	    //  ここで parent_name を用いるのは間違っていて、
+	    //   *cur->properties->children から探すべきらしい kono
+	    parent = root->searchSceneGraph(tmp->parent_name);
+	    if (parent==NULL) {
+		fprintf(stderr, "[%s] No such parent %s\n",
+			tmp->name, tmp->parent_name);
+		root->addChild(tmp);
+	    } else {
+		parent->addChild(tmp);
+	    }
+	    root->add_next(tmp);
+	}
+    }
+  
+    xmlFreeDoc(doc);
+    return root;
+}
+
+/* 子供を追加  */
+SceneGraph*
+SceneGraph::addChild(SceneGraph *child)
+{
+    SceneGraph *tmp;
+
+    /* childrenのリストの最後に加える */
+    if (this->lastChild != NULL) {
+	tmp = this->lastChild;
+	tmp->children = child;
+    }
+
+    this->lastChild = child;
+
+    if (this->children == NULL) {
+	this->children = child;
+    }
+
+    child->parent = this;
+
+    return child;
+}
+
+/* thisの子や子孫にnameのものが存在すればそいつを返す なければNULL.  */
+SceneGraph*
+SceneGraph::searchSceneGraph(char *name)
+{
+    SceneGraph* tmp;
+    SceneGraph* result;
+
+    /* 本人か  */
+    if( 0==strcmp(this->name, name) ) return this;
+
+    /* 子供から再帰的に探す  */
+    for(tmp = this->children; tmp; tmp = tmp->next) {
+	if ((result=tmp->searchSceneGraph(name)) != NULL)
+	    return result;
+    }
+
+    /* 無かったら NULL.  */
+    return NULL;
+}
+
+void
+SceneGraph::tree_check(void)
+{
+    SceneGraph *t = this;
+
+    while(t)
+    {
+	cout << "my_name : " << t->name << endl;
+	if(t->children != NULL)
+	{
+	    cout << "--move children : " << t->children->name << endl;
+	    t = t->children;
+	}
+	else if(t->brother != NULL)
+	{
+	    cout << "--move brother : " << t->brother->name << endl;
+	    t = t->brother;
+	}
+	else
+	{
+	    while(t)
+	    {
+		if(t->brother != NULL)
+		{
+		    cout << "--move brother : " << t->brother->name << endl;
+		    t = t->brother;
+		    break;
+		}
+		else
+		{
+		    if(t->parent)
+		    {
+			cout << "--move parent : " << t->parent->name << endl;
+		    }
+		    t = t->parent;
+		}
+	    }
+	}
+    }
+}
+
+
+void
+SceneGraph::print_member(void)
+{
+    cout << "size = " << size << endl;
+    cout << "name = " << name << endl;
+    cout << "parent_name = " << parent_name << endl;
+
+    if (parent != NULL) {
+	cout << "parent->name = " << parent->name << endl;
+    }
+
+    if (children != NULL) {
+	cout << "children->name = " << children->name << endl;
+    }
+}
+
+
+/*
+ * surface nodeからポリゴンの情報を読み出す 再帰しない
+ */
+void
+SceneGraph::get_data(xmlNodePtr cur)
+{
+    char *cont;
+    //char *image_name;
+
+    for(;cur;cur=cur->next)
+    {
+	if(!xmlStrcmp(cur->name,(xmlChar*)"coordinate"))
+        {
+	    cont = (char *)xmlNodeGetContent(cur);
+	    pickup_coordinate(cont);
+        }
+	else if(!xmlStrcmp(cur->name,(xmlChar*)"normal"))
+        {
+	    cont = (char *)xmlNodeGetContent(cur);
+	    pickup_normal(cont);
+        }
+	else if(!xmlStrcmp(cur->name,(xmlChar*)"model"))
+        {
+	    cont = (char *)xmlNodeGetContent(cur);
+	    pickup_model(cont);
+        }
+	else if(!xmlStrcmp(cur->name,(xmlChar*)"texture"))
+        {
+	    cont = (char *)xmlNodeGetContent(cur);
+	    pickup_texture(cont);
+	}
+	else if(!xmlStrcmp(cur->name,(xmlChar*)"image"))
+        {
+	    char image_name[20] = "/tmp/image_XXXXXX";
+	    int fd = mkstemp(image_name);
+	    FILE *outfile = fdopen(fd, "wb");
+	    if(NULL == outfile)
+	    {
+		cout << "error open file\n";
+	    }
+	    cont = (char *)xmlNodeGetContent(cur);
+	    //decode(cont, image_name);
+	    decode(cont, outfile);
+	    fclose(outfile);
+
+	    texture_image = IMG_Load(image_name);
+
+	    /**
+	     * image を 32bit(RGBA) に変換する
+	     */
+	    SDL_Surface *tmpImage
+		= SDL_CreateRGBSurface(SDL_HWSURFACE, texture_image->w,
+				       texture_image->h, 32,
+				       redMask, greenMask, blueMask, alphaMask);
+	    SDL_Surface *converted;
+	    converted = SDL_ConvertSurface(texture_image,
+					   tmpImage->format, SDL_HWSURFACE);
+	    if( converted != NULL){
+		SDL_FreeSurface(texture_image);
+		texture_image = converted;
+	    }
+
+	    //load_texture(image_name);
+	    if(unlink(image_name))
+	    {
+		cout << "unlink error\n";
+	    }
+        }
+    }
+}
+
+
+void
+SceneGraph::delete_data(void)
+{
+    SceneGraph *n,*m;
+
+    n = this;
+    delete [] n->data;
+
+    if (next)
+    {
+	for(n = this->next; n; n=m)
+	{
+	    m = n->next;
+	    delete [] n->data;
+	    delete n;
+	}
+    }
+}
+
+void
+SceneGraph::move_execute(void)
+{
+    (*move)(this);
+}
+
+void
+SceneGraph::collision_check(SceneGraph *tree)
+{
+    (*collision)(this, tree);
+}
+
+void
+SceneGraph::all_execute(void)
+{
+    SceneGraphPtr top = this;
+    SceneGraphPtr t = top;
+
+    while (t) {
+	t->move_execute();
+	t->collision_check(top);
+
+	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 (t->children != NULL) {
+	    t = t->children;
+	} else if (t->brother != NULL) {
+	    t = t->brother;
+	} else {
+	    while (t) {
+		if (t->brother != NULL) {
+		    t = t->brother;
+		    break;
+		} else {
+		    if (t->parent == NULL) {
+			t = NULL;
+			break;
+		    } else {
+			t = t->parent;
+		    }
+		}
+	    }
+	}
+    }
+}
+
+void
+SceneGraph::set_move_collision(SceneGraphPtr node, move_func new_move,
+			       collision_func new_collision)
+{
+    node->move = new_move;
+    node->collision = new_collision;
+}
+
+void
+SceneGraph::add_next(SceneGraphPtr next)
+{
+    /* next のリストの最後に加える */
+    if (this->next != NULL) {
+	SceneGraphPtr tmp = this->last;
+	tmp->next = next;
+    } else {
+	this->next = next;
+    }
+
+    this->last = next;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TaskManager/Test/test_render/SceneGraph.h	Fri Nov 28 10:07:48 2008 +0900
@@ -0,0 +1,54 @@
+#ifndef INCLUDED_SCENE_GRAPH
+#define INCLUDED_SCENE_GRAPH
+
+#ifndef INCLUDED_POLYGON
+#  include "polygon.h"
+#endif
+
+class SceneGraph : public Polygon {
+public:
+    SceneGraph(void);
+    SceneGraph(xmlNodePtr surface);
+
+    // xml ファイルから生成した時のオブジェクトリスト
+    SceneGraph* next;
+    SceneGraph* last;
+
+    // Tree Node
+    SceneGraph *parent;
+    SceneGraph *brother;
+    SceneGraph *children;
+    SceneGraph *lastChild;
+
+    // 関数ポインタ
+    void (*move)(SceneGraph *node);
+    void (*collision)(SceneGraph *node, SceneGraph* tree);
+
+    void move_execute(void);
+    void collision_check(SceneGraph *tree);
+    void all_execute(void);
+
+    void add_next(SceneGraph *next);
+    SceneGraph* addChild(SceneGraph *child);
+    SceneGraph* searchSceneGraph(char *name);
+    void set_move_collision(SceneGraph *node,
+			    void (*new_move)(SceneGraph *node),
+			    void (*new_collision)(SceneGraph *node,
+						  SceneGraph *collision));
+
+    static SceneGraph* createFromXMLfile(char *);
+
+    void tree_check(void);
+    void print_member(void);
+    void get_data(xmlNodePtr cur);
+    void delete_data(void);
+};
+
+
+typedef void (*move_func)(SceneGraph* node);
+typedef void (*collision_func)(SceneGraph* node, SceneGraph* tree);
+typedef SceneGraph* SceneGraphPtr;
+
+#endif
+
+extern SceneGraphPtr scene_graph;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TaskManager/Test/test_render/node.cpp	Fri Nov 28 10:07:48 2008 +0900
@@ -0,0 +1,57 @@
+#include "SceneGraph.h"
+#include "xml_file/universe.h"
+#include "xml_file/cube.h"
+
+
+static void
+earth_move(SceneGraphPtr node)
+{
+    node->xyz[0] += 3;
+    node->xyz[1] += 3;
+}
+
+static void
+moon_move(SceneGraphPtr node)
+{
+}
+
+static void
+earth_collision(SceneGraphPtr node, SceneGraphPtr tree)
+{
+}
+
+static void
+moon_collision(SceneGraphPtr node, SceneGraphPtr tree)
+{
+}
+
+static void
+cube_move(SceneGraphPtr node)
+{
+    static float dest_x = 0.3f;
+    static float dest_y = 0.5f;
+
+    node->angle[1] += 1.0f;
+    if (node->angle[1] > 360.0f) {
+	node->angle[1] = 0.0f;
+    }
+
+    node->xyz[0] += dest_x;
+    node->xyz[1] += dest_y;
+}
+
+static void
+cube_collision(SceneGraphPtr node, SceneGraphPtr tree)
+{
+}
+
+void
+node_init(void)
+{
+#if 1
+    scene_graph->set_move_collision(Earth, earth_move, earth_collision);
+    scene_graph->set_move_collision(Moon, moon_move, moon_collision);
+#else
+    scene_graph->set_move_collision(Cube, cube_move, cube_collision);
+#endif
+}
--- a/TaskManager/Test/test_render/polygon.cpp	Thu Nov 27 16:20:11 2008 +0900
+++ b/TaskManager/Test/test_render/polygon.cpp	Fri Nov 28 10:07:48 2008 +0900
@@ -22,181 +22,93 @@
 
 SDL_Surface* Polygon::texture_image;
 
-Polygon::Polygon()
+Polygon::Polygon(void)
 {
-  xyz[0] = 0;
-  xyz[1] = 0;
-  xyz[2] = 0;
-  xyz[3] = 1;
-  c_xyz[0] = 0;
-  c_xyz[1] = 0;
-  c_xyz[2] = 0;
-  c_xyz[3] = 1;
-  angle[0] = 0;
-  angle[1] = 0;
-  angle[2] = 0;
-  angle[3] = 1;
-  next = NULL;
-  parent = NULL;
-  brother = NULL;
-  children = NULL;
-  lastChild = NULL;
-}
-
-
-
-void Polygon::tree_check()
-{
-  Polygon *t;
-  t = this;
+    xyz[0] = 0;
+    xyz[1] = 0;
+    xyz[2] = 0;
+    xyz[3] = 1;
+    c_xyz[0] = 0;
+    c_xyz[1] = 0;
+    c_xyz[2] = 0;
+    c_xyz[3] = 1;
+    angle[0] = 0;
+    angle[1] = 0;
+    angle[2] = 0;
+    angle[3] = 1;
 
-  while(t)
-    {
-      cout << "my_name : " << t->name << endl;
-      if(t->children != NULL)
-	{
-	  cout << "--move children : " << t->children->name << endl;
-	  t = t->children;
-	}
-      else if(t->brother != NULL)
-	{
-	  cout << "--move brother : " << t->brother->name << endl;
-	  t = t->brother;
-	}
-      else
-	{
-	  while(t)
-	    {
-	      if(t->brother != NULL)
-		{
-		  cout << "--move brother : " << t->brother->name << endl;
-		  t = t->brother;
-		  break;
-		}
-	      else
-		{
-		  if(t->parent)
-		    {
-		      cout << "--move parent : " << t->parent->name << endl;
-		    }
-		  t = t->parent;
-		}
-	    }
-	}
+    for (int i = 0; i < 16; i++) {
+	matrix[i] = 0;
     }
 }
 
-void Polygon::print_member()
-{
-  //int n;
-
-  cout << "size = " << size << endl;
-  cout << "name = " << name << endl;
-  cout << "parent_name = " << parent_name << endl;
-  /*
-  for(n=0; n<size*3; n+=3)
-    {
-      cout<<"coordinate = "<<data[n]<<" "<<data[n+1]<<" "<< data[n+2]<<endl;
-    }
-  */
-  /*
-  for(n=size*3; n<size*6; n+=3)
-    {
-      cout<<"narmal = "<<data[n]<<" "<<data[n+1]<<" "<<data[n+2]<<endl;
-    }
-  */
-  cout<<"c_xyz = "<<c_xyz[0]<<" "<<c_xyz[1]<<" "<<c_xyz[2]<<endl;
-  /*
-  for(n=size*6; n<size*9; n+=3)
-    {
-      cout<<"texture = "<<data[n]<<" "<<data[n+1]<<" "<<data[n+2]<<endl;
-    }
-  */
-  /*
-  for(n=0; n<size*3; n+=3)
-    {
-      cout<<"coordinate = "<<data[n]<<" "<<data[n+1]<<" "<<data[n+2]<<endl;
-      cout<<"normal = "<<data[n+size*3]<<" "<<data[n+size*3+1]<<" "<<data[n+size*3+2]<<endl;
-      cout<<"texture = "<<data[n+size*6]<<" "<<1-data[n+size*6+1]<<endl;
-    }
-  */
-  //cout << "image_name = " << image_name << endl;
-  if(parent != NULL)
-    {
-      cout << "parent->name = " << parent->name << endl;
-    }
-  if(children != NULL)
-    {
-      cout << "children->name = " << children->name << endl;
-    }
-}
-
+#if 0
 void Polygon::draw(SceneGraphPack *sgp)
 {
-  float xyz1[4],xyz2[4],xyz3[4];
+    float xyz1[4],xyz2[4],xyz3[4];
 
-  /***SceneGraphUpdate***/
-  //sgp_update();
-  for (int i = 0; i < sgp->info.size; i++) {
-    SceneGraphNode node = sgp->node[i];
+    /***SceneGraphUpdate***/
+    //sgp_update();
+    for (int i = 0; i < sgp->info.size; i++) {
+	SceneGraphNode node = sgp->node[i];
 
-    /***draw***/
-    int n,nt;
-    for(n=0,nt=0; n<node.size*3; n+=9,nt+=6) {
-      xyz1[0] = node.vertex[n];
-      xyz1[1] = node.vertex[n+1];
-      xyz1[2] = node.vertex[n+2]*-1;
-      xyz1[3] = 1;
-      xyz2[0] = node.vertex[n+3];
-      xyz2[1] = node.vertex[n+3+1];
-      xyz2[2] = node.vertex[n+3+2]*-1;
-      xyz2[3] = 1;
-      xyz3[0] = node.vertex[n+6];
-      xyz3[1] = node.vertex[n+6+1];
-      xyz3[2] = node.vertex[n+6+2]*-1;
-      xyz3[3] = 1;
+	/***draw***/
+	int n,nt;
+	for(n=0,nt=0; n<node.size*3; n+=9,nt+=6) {
+	    xyz1[0] = node.vertex[n];
+	    xyz1[1] = node.vertex[n+1];
+	    xyz1[2] = node.vertex[n+2]*-1;
+	    xyz1[3] = 1;
+	    xyz2[0] = node.vertex[n+3];
+	    xyz2[1] = node.vertex[n+3+1];
+	    xyz2[2] = node.vertex[n+3+2]*-1;
+	    xyz2[3] = 1;
+	    xyz3[0] = node.vertex[n+6];
+	    xyz3[1] = node.vertex[n+6+1];
+	    xyz3[2] = node.vertex[n+6+2]*-1;
+	    xyz3[3] = 1;
 
-      rotate(xyz1, node.translation);
-      rotate(xyz2, node.translation);
-      rotate(xyz3, node.translation);
+	    rotate(xyz1, node.translation);
+	    rotate(xyz2, node.translation);
+	    rotate(xyz3, node.translation);
 
-      Vertex *ver1 = new Vertex(xyz1[0],xyz1[1],xyz1[2],node.texture[nt],node.texture[nt+1]);
-      Vertex *ver2 = new Vertex(xyz2[0],xyz2[1],xyz2[2],node.texture[nt+2],node.texture[nt+2+1]);
-      Vertex *ver3 = new Vertex(xyz3[0],xyz3[1],xyz3[2],node.texture[nt+4],node.texture[nt+4+1]);
+	    Vertex *ver1 = new Vertex(xyz1[0],xyz1[1],xyz1[2],node.texture[nt],node.texture[nt+1]);
+	    Vertex *ver2 = new Vertex(xyz2[0],xyz2[1],xyz2[2],node.texture[nt+2],node.texture[nt+2+1]);
+	    Vertex *ver3 = new Vertex(xyz3[0],xyz3[1],xyz3[2],node.texture[nt+4],node.texture[nt+4+1]);
 
-      Triangle *tri = new Triangle(ver1,ver2,ver3);
-      Span_c *span = new Span_c();
-      span->viewer = viewer;
-      span->p = this;
-      span->create_span(tri,texture_image);
-      delete ver1;
-      delete ver2;
-      delete ver3;
-      delete tri;
-      delete span;
+	    Triangle *tri = new Triangle(ver1,ver2,ver3);
+	    Span_c *span = new Span_c();
+	    span->viewer = viewer;
+	    span->p = this;
+	    span->create_span(tri,texture_image);
+	    delete ver1;
+	    delete ver2;
+	    delete ver3;
+	    delete tri;
+	    delete span;
+	}
     }
-  }
 }
 
 
 void Polygon::draw(PolygonPack *pp)
 {
-  for(int n=0; n<pp->info.size; n++)
+    for(int n=0; n<pp->info.size; n++)
     {
-      Vertex *ver1 = new Vertex(pp->tri[n].ver1.x,pp->tri[n].ver1.y,pp->tri[n].ver1.z,pp->tri[n].ver1.tex_x,pp->tri[n].ver1.tex_y);
-      Vertex *ver2 = new Vertex(pp->tri[n].ver2.x,pp->tri[n].ver2.y,pp->tri[n].ver2.z,pp->tri[n].ver2.tex_x,pp->tri[n].ver2.tex_y);
-      Vertex *ver3 = new Vertex(pp->tri[n].ver3.x,pp->tri[n].ver3.y,pp->tri[n].ver3.z,pp->tri[n].ver3.tex_x,pp->tri[n].ver3.tex_y);
+	Vertex *ver1 = new Vertex(pp->tri[n].ver1.x,pp->tri[n].ver1.y,pp->tri[n].ver1.z,pp->tri[n].ver1.tex_x,pp->tri[n].ver1.tex_y);
+	Vertex *ver2 = new Vertex(pp->tri[n].ver2.x,pp->tri[n].ver2.y,pp->tri[n].ver2.z,pp->tri[n].ver2.tex_x,pp->tri[n].ver2.tex_y);
+	Vertex *ver3 = new Vertex(pp->tri[n].ver3.x,pp->tri[n].ver3.y,pp->tri[n].ver3.z,pp->tri[n].ver3.tex_x,pp->tri[n].ver3.tex_y);
 
-      Triangle *tri = new Triangle(ver1,ver2,ver3);
-      Span_c *span = new Span_c();
-      span->viewer = viewer;
-      span->p = this;
-      span->create_span(tri,texture_image);
-      delete ver1;
-      delete ver2;
-      delete ver3;
-      delete tri;
-      delete span;
+	Triangle *tri = new Triangle(ver1,ver2,ver3);
+	Span_c *span = new Span_c();
+	span->viewer = viewer;
+	span->p = this;
+	span->create_span(tri,texture_image);
+	delete ver1;
+	delete ver2;
+	delete ver3;
+	delete tri;
+	delete span;
     }
 }
 
@@ -244,503 +156,135 @@
     }
 }
 
-void Polygon::add_next()
-{
-  Polygon *p;
-  p = new Polygon;
-
-  next = p;
-}
-
-
-void Polygon::create_tree()
-{
-  Polygon *list;
-  Polygon *check_list;
-  Polygon *p;
-  Polygon *bros;
-
-  check_list = this;
-
-  for (list=this; list; list=list->next) {
-      if (xmlStrcmp((xmlChar *)list->parent_name, (xmlChar *)"NULL")) {
-	  p = this;
-
-	  while (p) {
-	      if (!xmlStrcmp((xmlChar *)p->name,(xmlChar *)list->parent_name))
-	      {
-		  list->parent = p;
-		  if(p->children == NULL)
-		  {
-		      p->children = list;
-		  }
-		  else
-		  {
-		      bros = p->children;
-		      while(bros->brother != NULL)
-		      {
-			  bros = bros->brother;
-		      }
-		      bros->brother = list;
-		  }		  
-		  break;
-	      }
-	      p = p->next;
-	  }
-      }
-  }
-}
+#endif
 
 void Polygon::pickup_coordinate(char *cont)
 {
-  for(int n=0; n<size*3; n+=3)
+    for(int n=0; n<size*3; n+=3)
     {
-      cont = pickup_float(cont, data+n);
-      cont = pickup_float(cont, data+n+1);
-      cont = pickup_float(cont, data+n+2);
+	cont = pickup_float(cont, data+n);
+	cont = pickup_float(cont, data+n+1);
+	cont = pickup_float(cont, data+n+2);
       
-      if (cont == NULL)
+	if (cont == NULL)
 	{
-	  cout << "Analyzing obj data failed coordinate\n";
+	    cout << "Analyzing obj data failed coordinate\n";
 	}
     }
 }
 
 void Polygon::pickup_normal(char *cont)
 {
-  for(int n=size*3;n<size*6;n+=3)
+    for(int n=size*3;n<size*6;n+=3)
     {
-      cont = pickup_float(cont,data+n);
-      cont = pickup_float(cont,data+n+1);
-      cont = pickup_float(cont,data+n+2);
+	cont = pickup_float(cont,data+n);
+	cont = pickup_float(cont,data+n+1);
+	cont = pickup_float(cont,data+n+2);
       
-      if (cont == NULL)
+	if (cont == NULL)
 	{
-	  cout << "Analyzing obj data failed normal\n";
+	    cout << "Analyzing obj data failed normal\n";
 	}
     }
 }
 
 void Polygon::pickup_model(char *cont)
 {
-  cont = pickup_float(cont,c_xyz);
-  cont = pickup_float(cont,c_xyz+1);
-  cont = pickup_float(cont,c_xyz+2);
+    cont = pickup_float(cont,c_xyz);
+    cont = pickup_float(cont,c_xyz+1);
+    cont = pickup_float(cont,c_xyz+2);
   
-  if (cont == NULL)
+    if (cont == NULL)
     {
-      cout << "Analyzing obj data failed model\n";
+	cout << "Analyzing obj data failed model\n";
     }
 }
 
 void Polygon::pickup_texture(char *cont)
 {
-  for(int n=size*6; n<size*9; n+=3)
+    for(int n=size*6; n<size*9; n+=3)
     {
-      cont = pickup_float(cont,data+n);
-      cont = pickup_float(cont,data+n+1);
-      data[n+2] = 1.0;
+	cont = pickup_float(cont,data+n);
+	cont = pickup_float(cont,data+n+1);
+	data[n+2] = 1.0;
       
-      if (cont == NULL)
+	if (cont == NULL)
 	{
-	  cout << "Analyzing obj data failed texture\n";
+	    cout << "Analyzing obj data failed texture\n";
 	}
     }
 }
 
 char *get_pixel(int tx, int ty, SDL_Surface *texture_image)
 {
-  return (char*)texture_image->pixels+(texture_image->format->BytesPerPixel*((texture_image->w)*ty+tx));
+    return (char*)texture_image->pixels+(texture_image->format->BytesPerPixel*((texture_image->w)*ty+tx));
 }
 
 unsigned my_ntohl(unsigned u) {
-  //     rr gg bb 00
-  //           rr
-  //     bb gg rr
-  //unsigned u1 =   ((u&0xff)<<24) +
-  //         ((u&0xff00)<<8) +
-  //         ((u&0xff0000)>>8) +
-  //         ((u&0xff000000)>>24);
-  unsigned u1;
-  unsigned b = (u&0xff000000)>>24;
-  unsigned g = (u&0xff0000)>>16;
-  unsigned r = (u&0xff00)>>8;
-  u1 = r + (g<<8) + (b<<16);
-  //printf("pixel %x->%x\n",u,u1);
-  return u1;
+    //     rr gg bb 00
+    //           rr
+    //     bb gg rr
+    //unsigned u1 =   ((u&0xff)<<24) +
+    //         ((u&0xff00)<<8) +
+    //         ((u&0xff0000)>>8) +
+    //         ((u&0xff000000)>>24);
+    unsigned u1;
+    unsigned b = (u&0xff000000)>>24;
+    unsigned g = (u&0xff0000)>>16;
+    unsigned r = (u&0xff00)>>8;
+    u1 = r + (g<<8) + (b<<16);
+    //printf("pixel %x->%x\n",u,u1);
+    return u1;
 }
 
 Uint32 Polygon::get_rgb(int tx, int ty)
 {
-  SDL_PixelFormat *fmt;
-  //Uint32 temp, pixel;
-  Uint8 red, green, blue;
+    SDL_PixelFormat *fmt;
+    //Uint32 temp, pixel;
+    Uint8 red, green, blue;
   
-  fmt = texture_image->format;
+    fmt = texture_image->format;
 
-  if (tx<0) tx = 0;
-  if (texture_image->w-1< tx) tx = texture_image->w-1 ;
-  if (ty<0) ty = 0;
-  if (texture_image->h-1< ty) ty = texture_image->h-1 ;
+    if (tx<0) tx = 0;
+    if (texture_image->w-1< tx) tx = texture_image->w-1 ;
+    if (ty<0) ty = 0;
+    if (texture_image->h-1< ty) ty = texture_image->h-1 ;
 
 
 
-  //SDL_LockSurface(texture_image);
-  char *p = get_pixel(tx,ty,texture_image);
+    //SDL_LockSurface(texture_image);
+    char *p = get_pixel(tx,ty,texture_image);
 #if 0
-  pixel = my_ntohl(*(Uint32*)p);
-  //printf("pixel = %d\n", pixel);
-  //printf("pixel %x bpp = %d ",p, fmt->BytesPerPixel);
-  //SDL_UnlockSurface(texture_image);
+    pixel = my_ntohl(*(Uint32*)p);
+    //printf("pixel = %d\n", pixel);
+    //printf("pixel %x bpp = %d ",p, fmt->BytesPerPixel);
+    //SDL_UnlockSurface(texture_image);
   
-  temp = pixel&fmt->Rmask;
-  temp = temp>>fmt->Rshift;
-  temp = temp<<fmt->Rloss;
-  red = (Uint8)temp;
+    temp = pixel&fmt->Rmask;
+    temp = temp>>fmt->Rshift;
+    temp = temp<<fmt->Rloss;
+    red = (Uint8)temp;
   
-  temp = pixel&fmt->Gmask;
-  temp = temp>>fmt->Gshift;
-  temp = temp<<fmt->Gloss;
-  green = (Uint8)temp;
+    temp = pixel&fmt->Gmask;
+    temp = temp>>fmt->Gshift;
+    temp = temp<<fmt->Gloss;
+    green = (Uint8)temp;
   
-  temp = pixel&fmt->Bmask;
-  temp = temp>>fmt->Bshift;
-  temp = temp<<fmt->Bloss;
-  blue = (Uint8)temp;
+    temp = pixel&fmt->Bmask;
+    temp = temp>>fmt->Bshift;
+    temp = temp<<fmt->Bloss;
+    blue = (Uint8)temp;
 #endif
-  blue  = (Uint8) p[0];
-  green = (Uint8) p[1];
-  red   = (Uint8) p[2];
+    blue  = (Uint8) p[0];
+    green = (Uint8) p[1];
+    red   = (Uint8) p[2];
 	  
-  //printf("tx = %d ty = %d ", tx,ty); 
-  //printf("pixel color =>  R: %d,  G: %d,  B: %d\n", red, green, blue);
-
-  SDL_PixelFormat *pf;
-  //pf = viewer->screen->format;
-
-  //cout << SDL_MapRGB(pf, red, green, blue) << endl;
-  return SDL_MapRGB(pf, red, green, blue);
-}
-
-
-/*
- * surface nodeからポリゴンの情報を読み出す 再帰しない
- */
-void Polygon::get_data(xmlNodePtr cur)
-{
-  char *cont;
-  //char *image_name;
-
-  for(;cur;cur=cur->next)
-    {
-      if(!xmlStrcmp(cur->name,(xmlChar*)"coordinate"))
-        {
-          cont = (char *)xmlNodeGetContent(cur);
-	  pickup_coordinate(cont);
-        }
-      else if(!xmlStrcmp(cur->name,(xmlChar*)"normal"))
-        {
-          cont = (char *)xmlNodeGetContent(cur);
-	  pickup_normal(cont);
-        }
-      else if(!xmlStrcmp(cur->name,(xmlChar*)"model"))
-        {
-          cont = (char *)xmlNodeGetContent(cur);
-	  pickup_model(cont);
-        }
-      else if(!xmlStrcmp(cur->name,(xmlChar*)"texture"))
-        {
-          cont = (char *)xmlNodeGetContent(cur);
-	  pickup_texture(cont);
-	}
-      else if(!xmlStrcmp(cur->name,(xmlChar*)"image"))
-        {
-	  char image_name[20] = "/tmp/image_XXXXXX";
-	  int fd = mkstemp(image_name);
-	  FILE *outfile = fdopen(fd, "wb");
-	  if(NULL == outfile)
-	    {
-	      cout << "error open file\n";
-	    }
-          cont = (char *)xmlNodeGetContent(cur);
-          //decode(cont, image_name);
-	  decode(cont, outfile);
-	  fclose(outfile);
-
-	  texture_image = IMG_Load(image_name);
+    //printf("tx = %d ty = %d ", tx,ty); 
+    //printf("pixel color =>  R: %d,  G: %d,  B: %d\n", red, green, blue);
 
-	  /**
-	   * image を 32bit(RGBA) に変換する
-	   */
-	  SDL_Surface *tmpImage
-	      = SDL_CreateRGBSurface(SDL_HWSURFACE, texture_image->w,
-				     texture_image->h, 32,
-				     redMask, greenMask, blueMask, alphaMask);
-	  SDL_Surface *converted;
-	  converted = SDL_ConvertSurface(texture_image,
-					 tmpImage->format, SDL_HWSURFACE);
-	  if( converted != NULL){
-	      SDL_FreeSurface(texture_image);
-	      texture_image = converted;
-	  }
-
-	  //load_texture(image_name);
-	  if(unlink(image_name))
-	    {
-	      cout << "unlink error\n";
-	    }
-        }
-    }
-}
-
-
-/*
- * ノードを受け取って、そこからポリゴンを生成
- * リークしてない? data上書きしちゃだめ
- */
-void Polygon::create_data(xmlNodePtr cur)
-{
-    char *p = (char *)xmlGetProp(cur,(xmlChar *)"size");
-    //error 出力?
-
-#ifndef _DEBUG
-    if(strlen(p)>8){     
-	__debug("Polygon size is too large.\n");
-	exit(1);
-    }
-#endif
-  
-    size = atoi((char *)xmlGetProp(cur,(xmlChar *)"size"));    
-    name = (char *)xmlGetProp(cur,(xmlChar *)"name");
-    parent_name = (char *)xmlGetProp(cur,(xmlChar *)"parent");
-    next = NULL;
-    
-    data = new float[size*3*3];
+    SDL_PixelFormat *pf;
+    //pf = viewer->screen->format;
 
-    get_data(cur->children);
-}
-
-/*
- * xmlをオープンして、Surfaceノードからポリゴンを作る
- *
- */
-void Polygon::set_data(char *file_name)
-{
-  xmlDocPtr doc;
-  xmlNodePtr cur;
-  Polygon *tmp;
-
-  doc = xmlParseFile(file_name);
-
-  cur = xmlDocGetRootElement(doc);
-
-  xmlStrcmp(cur->name,(xmlChar*)"OBJECT-3D");
-
-  tmp = this;
-
-  for (cur=cur->children; cur; cur=cur->next)
-    {
-      if (!xmlStrcmp(cur->name,(xmlChar*)"surface"))
-        {
-	  tmp->create_data(cur);
-	  if(cur->next->next)
-	    {
-	      tmp->add_next();
-	      tmp = tmp->next;
-	    }
-        }
-    }
-
-  create_tree();
-  //tree_check();
-  //create_scene_graph_pack();
-
-  xmlFreeDoc(doc);
-
-  /*
-  for(int s=0; s<sgp->info.size; s++)
-    {
-      printf("sgp->node[%d].pn = %d\n",s,sgp->node[s].pn);
-    }
-  */
-  //delete sgp;
+    //cout << SDL_MapRGB(pf, red, green, blue) << endl;
+    return SDL_MapRGB(pf, red, green, blue);
 }
-
-void Polygon::delete_data()
-{
-  Polygon *n,*m;
-
-  n = this;
-  delete [] n->data;
-
-  if(next)
-    {
-      for(n = this->next; n; n=m)
-	{
-	  m = n->next;
-	  delete [] n->data;
-	  delete n;
-	}
-    }
-}
-
-
-
-/* construct polygon from xml.  */
-/*
-Polygon::Polygon(char *xmlfile)
-{
-  Polygon();
-  xmlDocPtr doc;
-  xmlNodePtr cur;
-  Polygon *tmp;
-
-  doc = xmlParseFile(file_name);
-
-  cur = xmlDocGetRootElement(doc);
-
-  xmlStrcmp(cur->name,(xmlChar*)"OBJECT-3D");
-
-  tmp = this;
-
-  for (cur=cur->children; cur; cur=cur->next)
-    {
-      if ( xmlStrcmp(cur->name,(xmlChar*)"surface")!=0 )
-	  continue;
-
-      if ( xmlStrcmp(cur->parent ))
-      tmp->create_data(cur);
-      if(cur->next->next)
-        {
-	  tmp->add_next();
-	  tmp = tmp->next;
-	}
-    }
-
-  create_tree();
-  //tree_check();
-  //create_scene_graph_pack();
-
-  xmlFreeDoc(doc);
-}
-*/
-
-/* construct polygon from xmlNode.  */
-Polygon::Polygon(xmlNodePtr surface)
-{
-#if 1
-  xyz[0] = 0;
-  xyz[1] = 0;
-  xyz[2] = 0;
-  xyz[3] = 1;
-  c_xyz[0] = 0;
-  c_xyz[1] = 0;
-  c_xyz[2] = 0;
-  c_xyz[3] = 1;
-  angle[0] = 0;
-  angle[1] = 0;
-  angle[2] = 0;
-  angle[3] = 1;
-  next = NULL;
-  parent = NULL;
-  brother = NULL;
-  children = NULL;
-  lastChild = NULL;
-#else
-  /* これ使うにはどうすればいいの?  */
-  this->Polygon();
-#endif
-  size = atoi((char *)xmlGetProp(surface,(xmlChar *)"size"));
-  name = (char *)xmlGetProp(surface,(xmlChar *)"name");
-  parent_name = (char *)xmlGetProp(surface,(xmlChar *)"parent");
-  next = NULL;
-
-  data = new float[size*3*3];
-
-  get_data(surface->children);
-}
-
-/* XMLファイルからポリゴンを作成  */
-Polygon *Polygon::createFromXMLfile(char *xmlfile)
-{
-    xmlDocPtr doc;
-    xmlNodePtr cur;
-    Polygon *root=NULL, *tmp, *parent;
-
-    /* パース DOM生成 */
-    doc = xmlParseFile(xmlfile);
-    cur = xmlDocGetRootElement(doc);
-
-    /* ??  */
-    xmlStrcmp(cur->name,(xmlChar*)"OBJECT-3D");
-
-    /* XMLのノードを一つずつ解析  */
-    for (cur=cur->children; cur; cur=cur->next)
-    {
-	/* 扱うのはsurfaceオンリー  */
-	if ( xmlStrcmp(cur->name,(xmlChar*)"surface")!=0 )
-	    continue;
-
-	/* ポリゴン生成  */
-	tmp = new Polygon(cur);
-	if ( tmp->parent_name==NULL || 0==strcmp(tmp->parent_name, "NULL")) {
-	    /* このsurfaceがroot  */
-	    root = tmp;
-	} else {
-	    /* 親はこのsurfaceより前に定義されているものとする (していい?)  */
-	    //  ここで parent_name を用いるのは間違っていて、
-	    //   *cur->properties->children から探すべきらしい kono
-	    parent = root->searchPolygon(tmp->parent_name);
-	    if (parent==NULL) {
-		fprintf(stderr, "[%s] No such parent %s\n",
-			tmp->name, tmp->parent_name);
-		root->addChild(tmp);
-	    } else {
-		parent->addChild(tmp);
-	    }
-	}
-    }
-  
-    xmlFreeDoc(doc);
-    return root;
-}
-
-/* 子供を追加  */
-Polygon *Polygon::addChild(Polygon *child)
-{
-  Polygon *tmp;
-
-  /* childrenのリストの最後に加える */
-  if (this->lastChild != NULL) {
-      tmp = this->lastChild;
-      tmp->children = child;
-  }
-
-  this->lastChild = child;
-
-  if (this->children == NULL) {
-      this->children = child;
-  }
-
-  return child;
-}
-
-/* thisの子や子孫にnameのものが存在すればそいつを返す なければNULL.  */
-Polygon *Polygon::searchPolygon(char *name)
-{
-  Polygon *tmp, *result;
-
-  /* 本人か  */
-  if( 0==strcmp(this->name, name) ) return this;
-
-  /* 子供から再帰的に探す  */
-  for( tmp=this->children; tmp; tmp=tmp->next )
-    {
-      if( (result=tmp->searchPolygon(name))!=NULL )
-	return result;
-    }
-
-  /* 無かったら NULL.  */
-  return NULL;
-}
-
--- a/TaskManager/Test/test_render/polygon.h	Thu Nov 27 16:20:11 2008 +0900
+++ b/TaskManager/Test/test_render/polygon.h	Fri Nov 28 10:07:48 2008 +0900
@@ -4,30 +4,23 @@
 #define INCLUDED_POLYGON
 
 #ifndef INCLUDED_VIEWER
-#include "viewer.h"
-#endif
-
-#ifndef INCLUDED_SCENE_GRAPH_PACK
-#include "scene_graph_pack.h"
+#  include "viewer.h"
 #endif
 
 #ifndef INCLUDED_POLYGON_PACK
-#include "polygon_pack.h"
+#  include "polygon_pack.h"
 #endif
 
 #ifndef INCLUDED_SPAN_PACK
-#include "SpanPack.h"
+#  include "SpanPack.h"
 #endif
 
-class Polygon{
+class Polygon {
 public:
     long long size;
     char *name;
     char *parent_name;
 
-    //int texture_id;
-    //int texture_px, texture_py; // texture の分割数
-    
     float *data;        //"vertex" and "normal" and "texture"
     float xyz[4];          // position
     float angle[4];        // angle
@@ -37,45 +30,23 @@
     int frame;         // anime frame num
     //int *texture;         // pointer of this surface's texture
     static SDL_Surface* texture_image;      // pointer of this surface's texture
-    //SDL_Surface *screen;
-    //char image_name[20];     // texture image name
-    Polygon *next;
-    Polygon *parent;
-    Polygon *brother;
-    Viewer *viewer;
-    //SceneGraphPack *sgp;
 
-    Polygon();
-    void tree_check();
-    void print_member();
+    Polygon(void);
+    Polygon(xmlNodePtr);
+
     void parameter_change(char *name, float x, float y, float z, float ax, float ay, float az);
     //void load_texture(char *image_name);
-    void draw(float *stack);
-    void draw(SceneGraphPack *sgp);
-    void draw(PolygonPack *pp);
-    void draw(SpanPack *sp);
-    void delete_data();
+    //void draw(float *stack);
+    //void draw(SceneGraphPack *sgp);
+    //void draw(PolygonPack *pp);
+    //void draw(SpanPack *sp);
+    Uint32 get_rgb(int tx, int ty);
+
     void tree_draw();
-    void get_data(xmlNodePtr cur);
     void pickup_coordinate(char *cont);
     void pickup_normal(char *cont);
     void pickup_model(char *cont);
     void pickup_texture(char *cont);
-    Uint32 get_rgb(int tx, int ty);
-    //void sgp_update();
-    //void sgp_draw();
-    //void create_scene_graph_pack();
-    void create_data(xmlNodePtr doc);
-    void set_data(char *file_name);
-    void add_next();
-    void create_tree();
+};
 
-    /* added by kent. */
-    Polygon(xmlNodePtr);
-    Polygon *addChild(Polygon *);
-    Polygon *children;
-    Polygon *lastChild;
-    Polygon *searchPolygon(char *);
-    static Polygon *createFromXMLfile(char *);
-};
 #endif
--- a/TaskManager/Test/test_render/scene_graph_pack.h	Thu Nov 27 16:20:11 2008 +0900
+++ b/TaskManager/Test/test_render/scene_graph_pack.h	Fri Nov 28 10:07:48 2008 +0900
@@ -1,6 +1,10 @@
 #ifndef INCLUDED_SCENE_GRAPH_PACK
 #define INCLUDED_SCENE_GRAPH_PACK
 
+#ifndef INCLUDED_SCENE_GRAPH
+#  include "SceneGraph.h"
+#endif
+
 #define MAX_NODE 16
 #define MAX_POLYGON 36
 
@@ -17,11 +21,23 @@
     int pn; // parent number?
     SceneGraphNode *next;
     int pad[3];
+    SceneGraphPtr self;
+    SceneGraphPtr tree;
 
     void init(void) {
 	size = 0;
 	next = 0;
     }
+
+    void finish(void) {
+	SceneGraphNode *p = this->next, *p1;
+
+	while (p) {
+	    p1 = p->next;
+	    free(p);
+	    p = p1;
+	}
+    }
 }SceneGraphNode, *SceneGraphNodePtr;
 
 typedef struct SceneGraphInfo {
@@ -42,6 +58,15 @@
 	    node[i].size = 0;
 	}
     }
+
+    void finish(void) {
+	for (int i = 0; i < info.size; i++) {
+	    node[i].finish();
+	}
+
+	next = 0;
+	info.size = 0;
+    }
 } SceneGraphPack, *SceneGraphPackPtr;
 
 #endif
--- a/TaskManager/Test/test_render/spe/CreateSpan.cpp	Thu Nov 27 16:20:11 2008 +0900
+++ b/TaskManager/Test/test_render/spe/CreateSpan.cpp	Fri Nov 28 10:07:48 2008 +0900
@@ -94,6 +94,22 @@
     float start_tex_x, end_tex_x, start_tex_y, end_tex_y;
     int x, y, length;
 
+#if 1
+    // これじゃないと
+    // テクスチャの貼りに微妙に隙間が。謎だ
+    int start_y = (int)vMid->y;
+    int end_y   = (int)vMin->y;
+#else
+    float start_y = vMid->y;
+    float end_y   = vMin->y;
+#endif
+    float div_y = start_y - end_y;
+    int k = 0;
+    int l = 1;
+
+    SpanPackPtr tmp_spack;
+
+
     /**
      * 三角形ポリゴンをx軸に水平に二つに分けようとして
      * ある一辺がすでに水平だった場合、つまり
@@ -115,24 +131,15 @@
      * てかこんなんでいいのかよ。。。
      *
      */
+#if 1
+    if ((int)div_y == 0) {
+	return;
+    }
+#else
     if (vMid10->x == vMin->x && vMid10->y == vMin->y) {
 	return;
     }
-
-#if 1
-    // これじゃないと
-    // テクスチャの貼りに微妙に隙間が。謎だ
-    int start_y = (int)vMid->y;
-    int end_y   = (int)vMin->y;
-#else
-    float start_y = vMid->y;
-    float end_y   = vMin->y;
 #endif
-    float div_y = start_y - end_y;
-    int k = 0;
-    int l = 1;
-
-    SpanPackPtr tmp_spack;
 
     if (div_y < 0) {
 	div_y = -div_y;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TaskManager/Test/test_render/task/CreatePolygonFromSceneGraph.cpp	Fri Nov 28 10:07:48 2008 +0900
@@ -0,0 +1,156 @@
+/**
+ * SceneGraph が増えてくると動かなくなるかもしれない。
+ * 一応 mainMem とかで動くようになるとは思うけど。
+ * だめだったら、そこら辺が怪しいと思うべき
+ */
+
+#include "CreatePolygonFromSceneGraph.h"
+#include "polygon_pack.h"
+#include "scene_graph_pack.h"
+
+SchedDefineTask(CreatePolygonFromSceneGraph);
+
+#define SG_PACK_LOAD 10
+#define SG_NODE_LOAD 11
+#define PP_LOAD 12
+#define PP_STORE 13
+
+/**
+ * あとで直す
+ */
+static void
+rotate(float *xyz, float *matrix)
+{
+    float abc[4];
+
+    abc[0] = xyz[0];
+    abc[1] = xyz[1];
+    abc[2] = xyz[2];
+    abc[3] = xyz[3];
+
+    for(int i=0; i<4; i++)
+    {
+	xyz[i] = abc[0]*matrix[i] + abc[1]*matrix[i+4] + abc[2]*matrix[i+8] + abc[3]*matrix[i+12];
+    }
+}
+
+int 
+CreatePolygonFromSceneGraph::run(void *rbuf, void *wbuf)
+{
+    float xyz1[4], xyz2[4], xyz3[4];
+
+    SceneGraphPtr sg_top = (SceneGraphPtr)smanager->get_param(0);
+    SceneGraphPtr sg = sg_top;
+
+    PolygonPackPtr pp
+	= (PolygonPackPtr)smanager->allocate(sizeof(PolygonPack));
+    PolygonPackPtr send_pp
+	= (PolygonPackPtr)smanager->allocate(sizeof(PolygonPack));
+    PolygonPackPtr pp_addr = (PolygonPackPtr)smanager->get_param(1);
+    PolygonPackPtr tmp_pp;
+    
+    pp->init();
+    send_pp->init();
+
+    while (sg) {
+	for (int i = 0; i < sg->size; i += 3) {
+	    if (pp->info.size >= MAX_SIZE_TRIANGLE) {
+		PolygonPackPtr next;
+	    
+		smanager->mainMem_alloc(0, sizeof(PolygonPack));
+		smanager->mainMem_wait();
+		next = (PolygonPackPtr)smanager->mainMem_get(0);
+	    
+		pp->next = next;
+	    
+		tmp_pp = pp;
+		pp = send_pp;
+		send_pp = tmp_pp;
+	    
+		smanager->dma_wait(PP_STORE);
+		smanager->dma_store(send_pp, (uint32)pp_addr,
+				    sizeof(PolygonPack), PP_STORE);
+	    
+		pp_addr = next;
+	    
+		smanager->dma_wait(PP_LOAD);
+		smanager->dma_load(pp, (uint32)pp_addr,
+				   sizeof(PolygonPack), PP_LOAD);
+		smanager->dma_wait(PP_LOAD);
+		pp->init();
+	    }
+
+	    TrianglePack *triangle = &pp->tri[pp->info.size++];
+	    
+	    xyz1[0] = sg->data[(i+0)*3];
+	    xyz1[1] = sg->data[(i+0)*3+1];
+	    xyz1[2] = sg->data[(i+0)*3+2]*-1;
+	    xyz1[3] = 1;
+	    xyz2[0] = sg->data[(i+1)*3];
+	    xyz2[1] = sg->data[(i+1)*3+1];
+	    xyz2[2] = sg->data[(i+1)*3+2]*-1;
+	    xyz2[3] = 1;
+	    xyz3[0] = sg->data[(i+2)*3];
+	    xyz3[1] = sg->data[(i+2)*3+1];
+	    xyz3[2] = sg->data[(i+2)*3+2]*-1;
+	    xyz3[3] = 1;
+
+	    rotate(xyz1, sg->matrix);
+	    rotate(xyz2, sg->matrix);
+	    rotate(xyz3, sg->matrix);
+		
+	    triangle->ver1.x = xyz1[0];
+	    triangle->ver1.y = xyz1[1];
+	    triangle->ver1.z = xyz1[2];
+	    triangle->ver1.tex_x = sg->data[(i+0)*3 + sg->size*6];
+	    triangle->ver1.tex_y = sg->data[(i+0)*3 + sg->size*6+1];
+		
+	    triangle->ver2.x = xyz2[0];
+	    triangle->ver2.y = xyz2[1];
+	    triangle->ver2.z = xyz2[2];
+	    triangle->ver2.tex_x = sg->data[(i+1)*3 + sg->size*6];
+	    triangle->ver2.tex_y = sg->data[(i+1)*3 + sg->size*6+1];
+		
+	    triangle->ver3.x = xyz3[0];
+	    triangle->ver3.y = xyz3[1];
+	    triangle->ver3.z = xyz3[2];
+	    triangle->ver3.tex_x = sg->data[(i+2)*3 + sg->size*6];
+	    triangle->ver3.tex_y = sg->data[(i+2)*3 + sg->size*6+1];
+	
+	    //triangle->tex_addr = sg->texture_image->pixels;
+	    triangle->tex_width = sg->texture_image->w;
+	    triangle->tex_height = sg->texture_image->h;
+	}
+
+
+	if (sg->children != NULL) {
+	    sg = sg->children;
+	} else if (sg->brother != NULL) {
+	    sg = sg->brother;
+	} else {
+	    while (sg) {
+		if (sg->brother != NULL) {
+		    sg = sg->brother;
+		    break;
+		} else {
+		    if (sg->parent == NULL) {
+			sg = NULL;
+			break;
+		    } else {
+			sg = sg->parent;
+		    }
+		}
+	    }
+	}
+    }
+    
+    smanager->dma_wait(PP_STORE);
+    smanager->dma_store(pp, (uint32)pp_addr,
+			sizeof(PolygonPack), PP_STORE);
+    smanager->dma_wait(PP_STORE);
+
+    free(pp);
+    free(send_pp);
+
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TaskManager/Test/test_render/task/CreatePolygonFromSceneGraph.h	Fri Nov 28 10:07:48 2008 +0900
@@ -0,0 +1,15 @@
+#ifndef INCLUDED_CREATE_POLYGON
+#define INCLUDED_CREATE_POLYGON
+
+#ifndef INCLUDED_SCHED_TASK
+#  include "SchedTask.h"
+#endif
+
+class CreatePolygonFromSceneGraph : public SchedTask {
+public:
+    SchedConstructor(CreatePolygonFromSceneGraph);
+
+    int run(void *rbuf, void *wbuf);
+};
+
+#endif
--- a/TaskManager/Test/test_render/task/CreateSpan.cpp	Thu Nov 27 16:20:11 2008 +0900
+++ b/TaskManager/Test/test_render/task/CreateSpan.cpp	Fri Nov 28 10:07:48 2008 +0900
@@ -94,6 +94,22 @@
     float start_tex_x, end_tex_x, start_tex_y, end_tex_y;
     int x, y, length;
 
+#if 1
+    // これじゃないと
+    // テクスチャの貼りに微妙に隙間が。謎だ
+    int start_y = (int)vMid->y;
+    int end_y   = (int)vMin->y;
+#else
+    float start_y = vMid->y;
+    float end_y   = vMin->y;
+#endif
+    float div_y = start_y - end_y;
+    int k = 0;
+    int l = 1;
+
+    SpanPackPtr tmp_spack;
+
+
     /**
      * 三角形ポリゴンをx軸に水平に二つに分けようとして
      * ある一辺がすでに水平だった場合、つまり
@@ -115,24 +131,15 @@
      * てかこんなんでいいのかよ。。。
      *
      */
+#if 1
+    if ((int)div_y == 0) {
+	return;
+    }
+#else
     if (vMid10->x == vMin->x && vMid10->y == vMin->y) {
 	return;
     }
-
-#if 1
-    // これじゃないと
-    // テクスチャの貼りに微妙に隙間が。謎だ
-    int start_y = (int)vMid->y;
-    int end_y   = (int)vMin->y;
-#else
-    float start_y = vMid->y;
-    float end_y   = vMin->y;
 #endif
-    float div_y = start_y - end_y;
-    int k = 0;
-    int l = 1;
-
-    SpanPackPtr tmp_spack;
 
     if (div_y < 0) {
 	div_y = -div_y;
--- a/TaskManager/Test/test_render/task/create_sgp.cpp	Thu Nov 27 16:20:11 2008 +0900
+++ b/TaskManager/Test/test_render/task/create_sgp.cpp	Fri Nov 28 10:07:48 2008 +0900
@@ -1,6 +1,5 @@
-#include <iostream>
 #include "scene_graph_pack.h"
-#include "polygon.h"
+#include "SceneGraph.h"
 #include "create_sgp.hpp"
 #include "TaskManager.h"
 using namespace std;
@@ -18,16 +17,16 @@
 //create_sgp(Polygon *sg, SceneGraphPack *sgp)
 Create_SGP::run(void *rbuf, void *wbuf)
 {
-    Polygon *sg = (Polygon*)get_input(rbuf, 0);
-    //SceneGraphPack *sgp = (SceneGraphPack*)get_output(wbuf, 0);
-    SceneGraphPack *sgp = (SceneGraphPack*)get_param(0);
+    //SceneGraph *sg = (SceneGraph*)smanager->get_input(rbuf, 0);
+    SceneGraph *sg = (SceneGraph*)smanager->get_param(0);
+    SceneGraphPack *sgp = (SceneGraphPack*)smanager->get_param(0);
     sgp->init();
 
     int curNumber = 0;
     int nnpn = -1;
     SceneGraphNodePtr node;
 
-    Polygon *t = sg;
+    SceneGraph *t = sg;
     
     while(t) {
 	// blocking はこれでいいのかな?
@@ -91,7 +90,9 @@
 	    p->id = 0;
 	    p->move = 0;
 	    p->interaction = 0;
-	    
+	    p->self = t;
+	    p->tree = scene_graph;
+
 	    p->pn = nnpn;
 	    //node->tex_addr = t->texture_image->pixels;
 	    p->tex_width = t->texture_image->w;
@@ -124,7 +125,5 @@
     }
     sgp->info.size = curNumber;
 
-    
-
     return 0;
 }
--- a/TaskManager/Test/test_render/task/task_init.cpp	Thu Nov 27 16:20:11 2008 +0900
+++ b/TaskManager/Test/test_render/task/task_init.cpp	Fri Nov 28 10:07:48 2008 +0900
@@ -8,6 +8,7 @@
 SchedExternTask(Create_SGP);
 SchedExternTask(Update_SGP);
 SchedExternTask(CreatePolygon);
+SchedExternTask(CreatePolygonFromSceneGraph);
 SchedExternTask(CreateSpan);
 
 SchedExternTask(DrawSpan);
@@ -27,6 +28,7 @@
     SchedRegisterTask(TASK_CREATE_SGP, Create_SGP);
     SchedRegisterTask(TASK_UPDATE_SGP, Update_SGP);
     SchedRegisterTask(TASK_CREATE_PP,  CreatePolygon);
+    SchedRegisterTask(TASK_CREATE_PP2,  CreatePolygonFromSceneGraph);
     SchedRegisterTask(TASK_CREATE_SPAN, CreateSpan);
 
     SchedRegisterTask(TASK_DRAW_SPAN, DrawSpan);
--- a/TaskManager/Test/test_render/task/update_sgp.cpp	Thu Nov 27 16:20:11 2008 +0900
+++ b/TaskManager/Test/test_render/task/update_sgp.cpp	Fri Nov 28 10:07:48 2008 +0900
@@ -8,12 +8,6 @@
 
 SchedDefineTask(Update_SGP);
 
-typedef void (*moveFunc)(SceneGraphNodePtr, int, int);
-typedef void (*collFunc)(SceneGraphNodePtr, int, int);
-
-static moveFunc moveList[3];
-static collFunc collList[3];
-
 static void
 move0(SceneGraphNodePtr node, int w, int h)
 {
@@ -97,19 +91,6 @@
 {
 }
 
-static void
-init(void)
-{
-    //moveList[0] = no_move;
-    moveList[0] = move2;
-    moveList[1] = move3;
-    moveList[2] = move2;
-
-    collList[0] = coll;
-    collList[1] = coll;
-    collList[2] = coll;
-}
-
 int
 Update_SGP::run(void *rbuf, void *wbuf)
 {
@@ -119,16 +100,11 @@
     int screen_width = get_param(0);
     int screen_height = get_param(1);
 
-    init();
-
     // ϤǤ󤸤ʤ
     for (int i = 0; i < sgp->info.size && i < 3; i++) {
 	node = &sgp->node[i];
 
 	do {
-	    moveList[i](node, screen_width, screen_height);
-	    collList[i](node, screen_width, screen_height);
-
 	    if (node->pn != -1) {
 		get_matrix(node->translation,
 			   node->angle, node->obj_pos,
--- a/TaskManager/Test/test_render/viewer.cpp	Thu Nov 27 16:20:11 2008 +0900
+++ b/TaskManager/Test/test_render/viewer.cpp	Fri Nov 28 10:07:48 2008 +0900
@@ -1,6 +1,7 @@
 #include "viewer.h"
 #include "viewer_types.h"
-#include "polygon.h"
+#include "SceneGraph.h"
+#include "scene_graph_pack.h"
 #include "sys.h"
 #include "Func.h"
 #include "error.h"
@@ -14,7 +15,7 @@
 int this_time;
 int frames;
 
-Polygon *polygon;
+SceneGraph *scene_graph;
 
 /* Data Pack */
 SceneGraphPack *sgpack;
@@ -74,19 +75,22 @@
     SDL_GL_SwapBuffers();
 }
 
+extern void node_init(void);
+
 void
 Viewer::run_init(char *xml)
 {
     HTaskPtr task_next;
-    HTaskPtr task_sgp;
     HTaskPtr task_init_tex;
 
     start_time = get_ticks();
     this_time  = 0;
     frames     = 0;
 
-    polygon = Polygon::createFromXMLfile(xml);
-    polygon->viewer  = this;
+    scene_graph = SceneGraph::createFromXMLfile(xml);
+    //polygon->viewer  = this;
+	
+    node_init();
 
     sgpack = (SceneGraphPack*)manager->malloc(sizeof(SceneGraphPack));
     sgpack->init();
@@ -114,21 +118,25 @@
     task_next = manager->create_task(TASK_DUMMY);
     task_next->set_post(&post2runLoop, NULL);
 
+#if 0
+    // 諸事情で、今は SceneGraphPack を作らずに
+    // そのまま SceneGraph でやっています
+    HTaskPtr task_sgp;
     task_sgp = manager->create_task(TASK_CREATE_SGP);
-    task_sgp->add_inData(polygon, sizeof(Polygon));
-    //task_sgp->add_outData(sgpack, sizeof(SceneGraphPack));
+    task_sgp->add_param((uint32)scene_graph);
     task_sgp->add_param((uint32)sgpack);
     task_next->wait_for(task_sgp);
     task_sgp->spawn();
+#endif
 
-    int tex_width = polygon->texture_image->w;
-    int tex_height = polygon->texture_image->h;
+    int tex_width = scene_graph->texture_image->w;
+    int tex_height = scene_graph->texture_image->h;
     int tex_blocksize = tex_width*tex_height*4;
 
     __texture = (void*)manager->malloc(tex_blocksize);
-    memcpy(__texture, polygon->texture_image->pixels, tex_blocksize);
+    memcpy(__texture, scene_graph->texture_image->pixels, tex_blocksize);
 
-    uint32 *tex_src = (uint32*)polygon->texture_image->pixels;
+    uint32 *tex_src = (uint32*)scene_graph->texture_image->pixels;
     uint32 *tex_dest = (uint32*)manager->malloc(tex_blocksize);
     int tile_size = TEXTURE_SPLIT_PIXEL*TEXTURE_SPLIT_PIXEL;
     int tile_num = tex_width*tex_height/tile_size;
@@ -170,7 +178,6 @@
 void
 Viewer::run_loop(void)
 {
-    HTaskPtr task_update_sgp = NULL;
     HTaskPtr task_create_pp  = NULL;
     HTaskPtr task_create_sp  = NULL;
     HTaskPtr task_next;
@@ -193,17 +200,28 @@
     task_next = manager->create_task(TASK_DUMMY);
     task_next->set_post(post2runDraw, NULL);
 
+#if 0
+    HTaskPtr task_update_sgp = NULL;
     task_update_sgp = manager->create_task(TASK_UPDATE_SGP);
     task_update_sgp->add_inData(sgpack, sizeof(SceneGraphPack));
     task_update_sgp->add_outData(sgpack, sizeof(SceneGraphPack));
     task_update_sgp->add_param(width);
     task_update_sgp->add_param(height);
     task_next->wait_for(task_update_sgp);
+    task_update_sgp->spawn();
+#else
+    scene_graph->all_execute();
+#endif
 
+#if 0
     task_create_pp = manager->create_task(TASK_CREATE_PP);
     task_create_pp->add_inData(sgpack, sizeof(SceneGraphPack));
     task_create_pp->add_param((uint32)ppack);
-    //task_create_pp->set_cpu(SPE_ANY);
+#else
+    task_create_pp = manager->create_task(TASK_CREATE_PP2);
+    task_create_pp->add_param((uint32)scene_graph);
+    task_create_pp->add_param((uint32)ppack);
+#endif
     task_next->wait_for(task_create_pp);
 
     int range_base = spe_num;
@@ -242,7 +260,6 @@
 	task_create_sp->spawn();
     }
 
-    task_update_sgp->spawn();
     task_create_pp->spawn();
     task_next->spawn();
 }
@@ -258,14 +275,13 @@
     
     ppack->clear();
 
-    unsigned int diff = 0;
     for (int i = 0; i < spackList_length; i++) {
 	SpanPack *spack = &spackList[i];
 	int startx = 1;
 	int endx = split_screen_w;
 
 	int start_y = spack->info.y_top - split_screen_h + 1;
-	int end_y = spack->info.y_top;
+	//int end_y = spack->info.y_top;
 	int rangey = (start_y + split_screen_h - 1 > this->height)
 	    ? this->height - start_y + 1 : split_screen_h;
 
@@ -314,8 +330,8 @@
 	printf("%f FPS\n", (((float)frames)/(this_time-start_time))*1000.0);
     }
 
-    polygon->delete_data();
-    delete polygon;
+    scene_graph->delete_data();
+    delete scene_graph;
 
     free(__texture);
     quit();