Mercurial > hg > Members > kono > Cerium
changeset 138:3fd24be89d02
オブジェクトを増やして複数の表示に成功。
TODO:オブジェクトの削除
author | gongo@charles.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Fri, 28 Nov 2008 12:16:24 +0900 |
parents | 6cf991f28c6c |
children | c948f4ebde62 |
files | 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/spe/Makefile TaskManager/Test/test_render/spe/spe-main.cpp TaskManager/Test/test_render/task/update_sgp.cpp TaskManager/Test/test_render/viewer.cpp |
diffstat | 10 files changed, 199 insertions(+), 140 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/Test/test_render/Makefile.def Fri Nov 28 10:07:48 2008 +0900 +++ b/TaskManager/Test/test_render/Makefile.def Fri Nov 28 12:16:24 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 = ../../..
--- a/TaskManager/Test/test_render/SceneGraph.cpp Fri Nov 28 10:07:48 2008 +0900 +++ b/TaskManager/Test/test_render/SceneGraph.cpp Fri Nov 28 12:16:24 2008 +0900 @@ -12,10 +12,11 @@ extern int decode(char *cont, FILE *outfile); static void -no_move(SceneGraphPtr self) {} +no_move(SceneGraphPtr self, int screen_w, int screen_h) {} static void -no_collision(SceneGraphPtr self, SceneGraphPtr tree) {} +no_collision(SceneGraphPtr self, int screen_w, int screen_h, + SceneGraphPtr tree) {} SceneGraph::SceneGraph(void) { @@ -26,6 +27,14 @@ brother = NULL; children = NULL; lastChild = NULL; + + stack_xyz[0] = 0.0f; + stack_xyz[2] = 0.0f; + stack_xyz[1] = 0.0f; + stack_angle[0] = 0.0f; + stack_angle[1] = 0.0f; + stack_angle[2] = 0.0f; + move = no_move; collision = no_collision; } @@ -128,6 +137,24 @@ return child; } +/* 兄弟を追加 */ +SceneGraph* +SceneGraph::addBrother(SceneGraph *bro) +{ + SceneGraphPtr sg = this->brother; + + if (sg != NULL) { + while (sg->brother) { + sg = sg->brother; + } + sg->brother = bro; + } else { + this->brother = bro; + } + + return bro; +} + /* thisの子や子孫にnameのものが存在すればそいつを返す なければNULL. */ SceneGraph* SceneGraph::searchSceneGraph(char *name) @@ -299,26 +326,26 @@ } void -SceneGraph::move_execute(void) +SceneGraph::move_execute(int w, int h) { - (*move)(this); + (*move)(this, w, h); } void -SceneGraph::collision_check(SceneGraph *tree) +SceneGraph::collision_check(int w, int h, SceneGraph *tree) { - (*collision)(this, tree); + (*collision)(this, w, h, tree); } void -SceneGraph::all_execute(void) +SceneGraph::all_execute(int screen_w, int screen_h) { SceneGraphPtr top = this; SceneGraphPtr t = top; while (t) { - t->move_execute(); - t->collision_check(top); + t->move_execute(screen_w, screen_h); + t->collision_check(screen_w, screen_h, top); if (t->parent != NULL) { get_matrix(t->matrix, t->angle, t->xyz, t->parent->matrix); @@ -369,3 +396,30 @@ this->last = next; } + +SceneGraph* +SceneGraph::clone(void) { + SceneGraphPtr p = new SceneGraph; + memcpy(p, this, sizeof(SceneGraph)); + + + // どっかで関数にまとめるか + p->next = NULL; + p->last = NULL; + + p->parent = NULL; + p->brother = NULL; + p->children = NULL; + p->lastChild = NULL; + p->move = no_move; + p->collision = no_collision; + + p->stack_xyz[0] = 0.0f; + p->stack_xyz[2] = 0.0f; + p->stack_xyz[1] = 0.0f; + p->stack_angle[0] = 0.0f; + p->stack_angle[1] = 0.0f; + p->stack_angle[2] = 0.0f; + + return p; +}
--- a/TaskManager/Test/test_render/SceneGraph.h Fri Nov 28 10:07:48 2008 +0900 +++ b/TaskManager/Test/test_render/SceneGraph.h Fri Nov 28 12:16:24 2008 +0900 @@ -5,36 +5,49 @@ # include "polygon.h" #endif +class SceneGraph; + +typedef void (*move_func)(SceneGraph* node, int screen_w, int screen_h); +typedef void (*collision_func)(SceneGraph* node, int screen_w, int screen_h, + SceneGraph* tree); +typedef SceneGraph* SceneGraphPtr; + class SceneGraph : public Polygon { public: SceneGraph(void); SceneGraph(xmlNodePtr surface); + // Node がもつ状態変数(というべきか否か + // xyz,angle ぐらいあればおk? + float stack_xyz[3]; + float stack_angle[3]; + // xml ファイルから生成した時のオブジェクトリスト SceneGraph* next; SceneGraph* last; - // Tree Node + // Tree Structure SceneGraph *parent; SceneGraph *brother; SceneGraph *children; SceneGraph *lastChild; // 関数ポインタ - void (*move)(SceneGraph *node); - void (*collision)(SceneGraph *node, SceneGraph* tree); + move_func move; + collision_func collision; - void move_execute(void); - void collision_check(SceneGraph *tree); - void all_execute(void); + void move_execute(int screen_w, int screen_h); + void collision_check(int screen_w, int screen_h, SceneGraph *tree); + void all_execute(int screen_w, int screen_h); void add_next(SceneGraph *next); SceneGraph* addChild(SceneGraph *child); + SceneGraph* addBrother(SceneGraph *bro); + SceneGraph* clone(void); SceneGraph* searchSceneGraph(char *name); void set_move_collision(SceneGraph *node, - void (*new_move)(SceneGraph *node), - void (*new_collision)(SceneGraph *node, - SceneGraph *collision)); + move_func new_move, collision_func new_collision); + static SceneGraph* createFromXMLfile(char *); @@ -44,11 +57,6 @@ 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;
--- a/TaskManager/Test/test_render/node.cpp Fri Nov 28 10:07:48 2008 +0900 +++ b/TaskManager/Test/test_render/node.cpp Fri Nov 28 12:16:24 2008 +0900 @@ -4,29 +4,7 @@ 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) +earth_move(SceneGraphPtr node, int screen_w, int screen_h) { static float dest_x = 0.3f; static float dest_y = 0.5f; @@ -37,21 +15,100 @@ } node->xyz[0] += dest_x; + if ((int)node->xyz[0] > screen_w || (int)node->xyz[0] < 0) { + dest_x = -dest_x; + } + node->xyz[1] += dest_y; + if ((int)node->xyz[1] > screen_h || (int)node->xyz[1] < 0) { + dest_y = -dest_y; + } +} + +static void +moon_move(SceneGraphPtr node, int screen_w, int screen_h) +{ + node->angle[0] += 1.0f; + if (node->angle[1] > 360.0f) { + node->angle[1] = 0.0f; + } +} + +static void +earth_collision(SceneGraphPtr node, int screen_w, int screen_h, + SceneGraphPtr tree) +{ +} + +static void +moon_collision(SceneGraphPtr node, int screen_w, int screen_h, + SceneGraphPtr tree) +{ +} + +static void +cube_collision(SceneGraphPtr node, int screen_w, int screen_h, + SceneGraphPtr tree) +{ } static void -cube_collision(SceneGraphPtr node, SceneGraphPtr tree) +cube_move2(SceneGraphPtr node, int screen_w, int screen_h) +{ + node->angle[1] += 1.0f; + if (node->angle[1] > 360.0f) { + node->angle[1] = 0.0f; + } + + node->xyz[0] += node->stack_xyz[0]; + if ((int)node->xyz[0] > screen_w || (int)node->xyz[0] < 0) { + node->stack_xyz[0] = -node->stack_xyz[0]; + } + + node->xyz[1] += node->stack_xyz[1]; + if ((int)node->xyz[1] > screen_h || (int)node->xyz[1] < 0) { + node->stack_xyz[1] = -node->stack_xyz[1]; + } +} + +static void +cube_move(SceneGraphPtr node, int screen_w, int screen_h) { + node->angle[1] += 1.0f; + if (node->angle[1] > 360.0f) { + node->angle[1] = 0.0f; + } + + node->xyz[0] += node->stack_xyz[0]; + if ((int)node->xyz[0] > screen_w || (int)node->xyz[0] < 0) { + node->stack_xyz[0] = -node->stack_xyz[0]; + } + + node->xyz[1] += node->stack_xyz[1]; + if ((int)node->xyz[1] > screen_h || (int)node->xyz[1] < 0) { + + SceneGraphPtr p = node->clone(); + p->position_init(); + node->addBrother(p); + scene_graph->set_move_collision(p, cube_move2, cube_collision); + p->stack_xyz[0] = 0.5f; + p->stack_xyz[1] = 0.5f; + //p->xyz[0] = screen_w/2; + //p->xyz[1] = screen_h/2; + + node->stack_xyz[1] = -node->stack_xyz[1]; + } } void node_init(void) { -#if 1 +#if 0 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); + Cube->stack_xyz[0] = 0.5f; + Cube->stack_xyz[1] = 0.5f; #endif }
--- a/TaskManager/Test/test_render/polygon.cpp Fri Nov 28 10:07:48 2008 +0900 +++ b/TaskManager/Test/test_render/polygon.cpp Fri Nov 28 12:16:24 2008 +0900 @@ -2,7 +2,6 @@ #include <SDL.h> #include <SDL_opengl.h> #include <SDL_image.h> -#include <libxml/parser.h> #include "polygon.h" #include "xml.h" #include "texture.h" @@ -42,6 +41,27 @@ } } +void +Polygon::position_init(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; + + for (int i = 0; i < 16; i++) { + matrix[i] = 0; + } +} + #if 0 void Polygon::draw(SceneGraphPack *sgp) {
--- a/TaskManager/Test/test_render/polygon.h Fri Nov 28 10:07:48 2008 +0900 +++ b/TaskManager/Test/test_render/polygon.h Fri Nov 28 12:16:24 2008 +0900 @@ -1,5 +1,3 @@ -#include <libxml/parser.h> - #ifndef INCLUDED_POLYGON #define INCLUDED_POLYGON @@ -7,6 +5,8 @@ # include "viewer.h" #endif +#include <libxml/parser.h> + #ifndef INCLUDED_POLYGON_PACK # include "polygon_pack.h" #endif @@ -32,7 +32,6 @@ static SDL_Surface* texture_image; // pointer of this surface's texture 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); @@ -42,6 +41,9 @@ //void draw(SpanPack *sp); Uint32 get_rgb(int tx, int ty); +public: + void position_init(void); + void tree_draw(); void pickup_coordinate(char *cont); void pickup_normal(char *cont);
--- a/TaskManager/Test/test_render/spe/Makefile Fri Nov 28 10:07:48 2008 +0900 +++ b/TaskManager/Test/test_render/spe/Makefile Fri Nov 28 12:16:24 2008 +0900 @@ -3,6 +3,7 @@ TARGET = ../spe-main SRCS_TMP = $(wildcard *.cpp) +SRCS_EXCLUDE = CreatePolygon.cpp SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP)) OBJS = $(SRCS:.cpp=.o)
--- a/TaskManager/Test/test_render/spe/spe-main.cpp Fri Nov 28 10:07:48 2008 +0900 +++ b/TaskManager/Test/test_render/spe/spe-main.cpp Fri Nov 28 12:16:24 2008 +0900 @@ -7,7 +7,7 @@ SchedExternTask(DrawBack); SchedExternTask(CreateSpan); -SchedExternTask(CreatePolygon); +//SchedExternTask(CreatePolygon); void task_init(void) @@ -18,5 +18,5 @@ SchedRegisterTask(TASK_DRAW_BACK, DrawBack); SchedRegisterTask(TASK_CREATE_SPAN, CreateSpan); - SchedRegisterTask(TASK_CREATE_PP, CreatePolygon); + //SchedRegisterTask(TASK_CREATE_PP, CreatePolygon); }
--- a/TaskManager/Test/test_render/task/update_sgp.cpp Fri Nov 28 10:07:48 2008 +0900 +++ b/TaskManager/Test/test_render/task/update_sgp.cpp Fri Nov 28 12:16:24 2008 +0900 @@ -8,89 +8,6 @@ SchedDefineTask(Update_SGP); -static void -move0(SceneGraphNodePtr node, int w, int h) -{ - 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->obj_pos[0] += dest_x; - if ((int)node->obj_pos[0] > w || (int)node->obj_pos[0] < 0) { - dest_x = -dest_x; - } - - node->obj_pos[1] += dest_y; - if ((int)node->obj_pos[1] > h || (int)node->obj_pos[1] < 0) { - dest_y = -dest_y; - } -} - -static void -move3(SceneGraphNodePtr node, int w, int h) -{ - node->angle[1] += 1.0f; - if (node->angle[1] > 360.0f) { - node->angle[1] = 0.0f; - } -} - -static void -no_move(SceneGraphNodePtr node, int w, int h) -{ - node->obj_pos[0] = 0; - node->obj_pos[1] = 0; -} - -static void -move1(SceneGraphNodePtr node, int w, int h) -{ - node->angle[1] += 1.0f; - if (node->angle[1] > 360.0f) { - node->angle[1] = 0.0f; - } - - static float dest_x = 0.5f; - static float dest_y = 1.3f; - - node->obj_pos[0] += dest_x; - if ((int)node->obj_pos[0] > w || (int)node->obj_pos[0] < 0) { - dest_x = -dest_x; - } - - node->obj_pos[1] += dest_y; - if ((int)node->obj_pos[1] > h || (int)node->obj_pos[1] < 0) { - dest_y = -dest_y; - } -} - -static void -move2(SceneGraphNodePtr node, int w, int h) -{ - static float dest_x = 1.0f; - static float dest_y = 0.8f; - - node->obj_pos[0] += dest_x; - if ((int)node->obj_pos[0] > w || (int)node->obj_pos[0] < 0) { - dest_x = -dest_x; - } - - node->obj_pos[1] += dest_y; - if ((int)node->obj_pos[1] > h || (int)node->obj_pos[1] < 0) { - dest_y = -dest_y; - } -} - - -static void -coll(SceneGraphNodePtr node, int w, int h) -{ -} - int Update_SGP::run(void *rbuf, void *wbuf) {
--- a/TaskManager/Test/test_render/viewer.cpp Fri Nov 28 10:07:48 2008 +0900 +++ b/TaskManager/Test/test_render/viewer.cpp Fri Nov 28 12:16:24 2008 +0900 @@ -210,7 +210,7 @@ task_next->wait_for(task_update_sgp); task_update_sgp->spawn(); #else - scene_graph->all_execute(); + scene_graph->all_execute(width, height); #endif #if 0