Mercurial > hg > Game > Cerium
changeset 39:b6858e9fe2b4
*** empty log message ***
author | gongo |
---|---|
date | Wed, 13 Feb 2008 15:10:47 +0900 |
parents | babf9a330418 |
children | 0024a5259363 |
files | TaskManager/Test/simple_render/Makefile TaskManager/Test/simple_render/demonstration.cpp TaskManager/Test/simple_render/mygl.cpp TaskManager/Test/simple_render/pad.cpp TaskManager/Test/simple_render/scene.cpp TaskManager/Test/simple_render/scene_graph_to_polygon_pack.cpp TaskManager/Test/simple_render/scene_graph_update.cpp TaskManager/Test/simple_render/trash/demonstration.cpp TaskManager/Test/simple_render/trash/mygl.cpp TaskManager/Test/simple_render/trash/pad.cpp TaskManager/Test/simple_render/trash/scene.cpp TaskManager/Test/simple_render/trash/scene_graph_to_polygon_pack.cpp TaskManager/Test/simple_render/trash/scene_graph_update.cpp |
diffstat | 13 files changed, 274 insertions(+), 259 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/Test/simple_render/Makefile Wed Feb 13 10:29:00 2008 +0900 +++ b/TaskManager/Test/simple_render/Makefile Wed Feb 13 15:10:47 2008 +0900 @@ -1,21 +1,36 @@ -CC = g++ -CFLAGS = -O9 -g -Wall `sdl-config --cflags` `xml2-config --cflags`\ - -I../../../include/TaskManager -I. -LIBS = `sdl-config --libs` -lSDL_image -Wl,-framework,OpenGL `xml2-config --libs`\ - -L../../ -lmanager TARGET = test_nogl + +SRCS = $(wildcard *.cpp) +OBJS = $(SRCS:.cpp=.o) + +TASK_DIR = task +TASK_SRCS = $(wildcard $(TASK_DIR)/*.cpp) +TASK_OBJS = $(TASK_SRCS:.cpp=.o) + +CC = g++ +CFLAGS = -O9 -g -Wall +INCLUDE = -I../../../include/TaskManager -I. + +EXTRA_CFLAGS = `sdl-config --cflags` `xml2-config --cflags`\ + +LIBS = `sdl-config --libs` -lSDL_image -Wl,-framework,OpenGL \ + `xml2-config --libs`\ + -L../../ -lmanager + #OBJS = scene.o demonstration.o sys.o base64_de.o pad.o texture.o xml.o polygon.o viewer.o main.o -OBJS = task/task_init.o task/create_pp.o task/update_sgp.o task/create_sgp.o triangle.o vertex.o span.o sys.o base64_de.o pad.o texture.o xml.o polygon.o viewer.o main.o +#OBJS = task/task_init.o task/create_pp.o task/update_sgp.o task/create_sgp.o triangle.o vertex.o span.o sys.o base64_de.o pad.o texture.o xml.o polygon.o viewer.o main.o -all:$(TARGET) - -$(TARGET): $(OBJS) - $(CC) -o $@ $(OBJS) $(LIBS) +.SUFFIXES: .cpp .o .cpp.o: - $(CC) $(CFLAGS) -o $@ -c $< + $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(INCLUDE) -c $< -o $@ + +all: $(TARGET) + +$(TARGET): $(OBJS) $(TASK_OBJS) + $(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS) clean: - rm -f $(TARGET) $(OBJS) - rm -f *~ + rm -f $(TARGET) $(OBJS) $(TASK_OBJS) + rm -f *~ \#*
--- a/TaskManager/Test/simple_render/demonstration.cpp Wed Feb 13 10:29:00 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -#include <iostream> -#include "polygon.h" -#include "xml.h" -#include "texture.h" -#include "demonstration.h" -#include "pad.h" -using namespace std; - -Demonstration::Demonstration() -{ - action_demo = &Demonstration::test_play; -} - -void Demonstration::test_play() -{ - list->draw(); - if(pad(RIGHT)) - { - //action_demo = &Demonstration::test_end; - action_demo = NULL; - } -}
--- a/TaskManager/Test/simple_render/mygl.cpp Wed Feb 13 10:29:00 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -#include <iostream> -#include <SDL.h> -using namespace std; - -void write_pixel(int x, int y) -{ - int i; - for (i=0; i<height; i++) - { - pixels[i*width] = 0xff; - } - -}
--- a/TaskManager/Test/simple_render/pad.cpp Wed Feb 13 10:29:00 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -#include <iostream> -#include <SDL.h> -#include <SDL_opengl.h> -#include "pad.h" -using namespace std; - -int pad(int button) -{ - Uint8 *keys=SDL_GetKeyState(NULL); - - if(button==UP && keys[SDLK_UP]==SDL_PRESSED) - { - return 1; - } - if(button==DOWN && keys[SDLK_DOWN]==SDL_PRESSED) - { - return 1; - } - if(button==RIGHT && keys[SDLK_RIGHT]==SDL_PRESSED) - { - return 1; - } - if(button==LEFT && keys[SDLK_LEFT]==SDL_PRESSED) - { - return 1; - } - return 0; -}
--- a/TaskManager/Test/simple_render/scene.cpp Wed Feb 13 10:29:00 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -#include <iostream> -#include "polygon.h" -#include "xml.h" -#include "texture.h" -#include "demonstration.h" -#include "scene.h" -#include "pad.h" -using namespace std; - -Scene::Scene() -{ - action_scene = &Scene::title_init; -} - -void Scene::title_init() -{ - demo = new Demonstration; - demo->list = new Polygon; - demo->list->set_data("xml/title.xml"); - - action_scene = &Scene::title; -} - -void Scene::title() -{ - (demo->*demo->action_demo)(); - - if(demo->action_demo == NULL) - { - action_scene = &Scene::title_end; - } -} - -void Scene::title_end() -{ - delete demo->list; - delete demo; - action_scene = NULL; -}
--- a/TaskManager/Test/simple_render/scene_graph_to_polygon_pack.cpp Wed Feb 13 10:29:00 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -typedef struct Triangle { - long tex_addr, tex_width, tex_height; - float x1, y1, z1, tex_x1, tex_y1; - float x2, y2, z2, tex_x2, tex_y2; - float x3, y3, z3, tex_x3, tex_y3; -} TRIANGLEPACK, *TRIANGLEPACK_PTR; - - -typedef struct PolygonPack { - PORIGON_INFO info { - int size - light_pos[3] - light_rgb[3] - }; - TrianglePack tri[1]; // Variable length array -} POLYGONPACK, POLYGONPACK_PTR; - - -class SceneGraph2PolygonPack : SpeTask { - - SceneGraph2PolygonPack() { - rbuf = _rbuf; - wbuf = _wbuf; - } - - int - SceneGraph2PlygonPack::run() { - SceneGraphPack *sgp = (SceneGraphPack*)rbuf; - PolygonPack *pp = (PolygonPack*)wbuf;; - for (int i = 0; i < sgp->size; i++) { - SceneGraphNode *node = sgp->node[i]; - - int n,tex; - for(n=0,tex=0; n<node->size*3; n+=9,tex+=6) { - pp->tri[].x1 = node.vertex[n]; - pp->tri[].y1 = node.vertex[n+1]; - pp->tri[].z1 = node.vertex[n+2]; - pp->tri[].tex_x1 = node.texture[tex]; - pp->tri[].tex_y1 = node.texture[tex+1]; - - pp->tri[].x2 = node.vertex[n+3]; - pp->tri[].y2 = node.vertex[n+3+1]; - pp->tri[].z2 = node.vertex[n+3+2]; - pp->tri[].tex_x2 = node.texture[tex+2]; - pp->tri[].tex_y2 = node.texture[tex+2+1]; - - pp->tri[].x3 = node.vertex[n+6]; - pp->tri[].y3 = node.vertex[n+6+1]; - pp->tri[].z3 = node.vertex[n+6+2]; - pp->tri[].tex_x3 = node.texture[tex+4]; - pp->tri[].tex_y3 = node.texture[tex+4+1]; - } - - copy(pp, wbuf, pp->size()); - } - } - -};
--- a/TaskManager/Test/simple_render/scene_graph_update.cpp Wed Feb 13 10:29:00 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ -#include "scene_graph_update.h" - -class SceneGraphUpdate : SpeTask { - - SceneGraphUpdate() { - rbuf = _rbuf; - wbuf = _wbuf; - } - - void - SceneGraphUpdate::matrix4x4(float *xyz, float *xyz1, float *xyz2) { - for(int t=0; t<16; t+=4) { - for(int i=0; i<4; i++) { - xyz[t+i] = xyz1[t]*xyz2[i] + xyz1[t+1]*xyz2[4+i] + xyz1[t+2]*xyz2[8+i]+ xyz1[t+3]*xyz2[12+i]; - } - } - } - - void - SceneGraphUpdate::get_matrix( float *matrix, float *rxyz, float *txyz, float *stack) { - float radx,rady,radz; - radx = rxyz[0]*3.14/180; - rady = rxyz[1]*3.14/180; - radz = rxyz[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); - - matrix[0] = cosz*cosy+sinz*sinx*siny; - matrix[1] =sinz*cosx; - matrix[2] = -cosz*siny+sinz*sinx*cosy; - matrix[3] = 0; - matrix[4] = -sinz*cosy+cosz*sinx*siny; - matrix[5] = cosz*cosx; - matrix[6] = sinz*siny+cosz*sinx*cosy; - matrix[7] = 0; - matrix[8] = cosx*siny; - matrix[9] = -sinx; - matrix[10] = cosx*cosy; - matrix[11] = 0; - matrix[12] = txyz[0]; - matrix[13] = txyz[1]; - matrix[14] = txyz[2]; - matrix[15] = 1; - - float m[16]; - for(int i=0; i<16; i++) { - m[i] = matrix[i]; - } - - if(stack) { - matrix4x4(matrix, m, stack); - } - } - - - int - SceneGraphUpdate::run() { - SceneGraphPack *sgp = (SceneGraphPack*)rbuf; - for (int i = 0; i < sgp->size; i++) { - //SceneGraphNode *node = sgp->node[i]; - (*my_func[sgp->node[i].move])(node); - (*my_func[sgp->node[i].interaction])(sgp->node[i], sgp); - if(sgp->node[i].pn != -1) { - get_matrix(sgp->node[i].translation, sgp->node[i].angle, sgp->node[i].obj_pos, sgp->node[sgp->node[i].pn].translation); - } - else { - get_matrix(sgp->node[i].translation, sgp->node[i].angle, sgp->node[i].obj_pos, NULL); - } - - copy(sgp->node, wbuf, sgp->node->size()); - } - } - - - void - Boss::move(SceneGraphNode *node) { - x = x+1; - } - - -};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/simple_render/trash/demonstration.cpp Wed Feb 13 15:10:47 2008 +0900 @@ -0,0 +1,22 @@ +#include <iostream> +#include "polygon.h" +#include "xml.h" +#include "texture.h" +#include "demonstration.h" +#include "pad.h" +using namespace std; + +Demonstration::Demonstration() +{ + action_demo = &Demonstration::test_play; +} + +void Demonstration::test_play() +{ + list->draw(); + if(pad(RIGHT)) + { + //action_demo = &Demonstration::test_end; + action_demo = NULL; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/simple_render/trash/mygl.cpp Wed Feb 13 15:10:47 2008 +0900 @@ -0,0 +1,13 @@ +#include <iostream> +#include <SDL.h> +using namespace std; + +void write_pixel(int x, int y) +{ + int i; + for (i=0; i<height; i++) + { + pixels[i*width] = 0xff; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/simple_render/trash/pad.cpp Wed Feb 13 15:10:47 2008 +0900 @@ -0,0 +1,28 @@ +#include <iostream> +#include <SDL.h> +#include <SDL_opengl.h> +#include "pad.h" +using namespace std; + +int pad(int button) +{ + Uint8 *keys=SDL_GetKeyState(NULL); + + if(button==UP && keys[SDLK_UP]==SDL_PRESSED) + { + return 1; + } + if(button==DOWN && keys[SDLK_DOWN]==SDL_PRESSED) + { + return 1; + } + if(button==RIGHT && keys[SDLK_RIGHT]==SDL_PRESSED) + { + return 1; + } + if(button==LEFT && keys[SDLK_LEFT]==SDL_PRESSED) + { + return 1; + } + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/simple_render/trash/scene.cpp Wed Feb 13 15:10:47 2008 +0900 @@ -0,0 +1,39 @@ +#include <iostream> +#include "polygon.h" +#include "xml.h" +#include "texture.h" +#include "demonstration.h" +#include "scene.h" +#include "pad.h" +using namespace std; + +Scene::Scene() +{ + action_scene = &Scene::title_init; +} + +void Scene::title_init() +{ + demo = new Demonstration; + demo->list = new Polygon; + demo->list->set_data("xml/title.xml"); + + action_scene = &Scene::title; +} + +void Scene::title() +{ + (demo->*demo->action_demo)(); + + if(demo->action_demo == NULL) + { + action_scene = &Scene::title_end; + } +} + +void Scene::title_end() +{ + delete demo->list; + delete demo; + action_scene = NULL; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/simple_render/trash/scene_graph_to_polygon_pack.cpp Wed Feb 13 15:10:47 2008 +0900 @@ -0,0 +1,58 @@ +typedef struct Triangle { + long tex_addr, tex_width, tex_height; + float x1, y1, z1, tex_x1, tex_y1; + float x2, y2, z2, tex_x2, tex_y2; + float x3, y3, z3, tex_x3, tex_y3; +} TRIANGLEPACK, *TRIANGLEPACK_PTR; + + +typedef struct PolygonPack { + PORIGON_INFO info { + int size + light_pos[3] + light_rgb[3] + }; + TrianglePack tri[1]; // Variable length array +} POLYGONPACK, POLYGONPACK_PTR; + + +class SceneGraph2PolygonPack : SpeTask { + + SceneGraph2PolygonPack() { + rbuf = _rbuf; + wbuf = _wbuf; + } + + int + SceneGraph2PlygonPack::run() { + SceneGraphPack *sgp = (SceneGraphPack*)rbuf; + PolygonPack *pp = (PolygonPack*)wbuf;; + for (int i = 0; i < sgp->size; i++) { + SceneGraphNode *node = sgp->node[i]; + + int n,tex; + for(n=0,tex=0; n<node->size*3; n+=9,tex+=6) { + pp->tri[].x1 = node.vertex[n]; + pp->tri[].y1 = node.vertex[n+1]; + pp->tri[].z1 = node.vertex[n+2]; + pp->tri[].tex_x1 = node.texture[tex]; + pp->tri[].tex_y1 = node.texture[tex+1]; + + pp->tri[].x2 = node.vertex[n+3]; + pp->tri[].y2 = node.vertex[n+3+1]; + pp->tri[].z2 = node.vertex[n+3+2]; + pp->tri[].tex_x2 = node.texture[tex+2]; + pp->tri[].tex_y2 = node.texture[tex+2+1]; + + pp->tri[].x3 = node.vertex[n+6]; + pp->tri[].y3 = node.vertex[n+6+1]; + pp->tri[].z3 = node.vertex[n+6+2]; + pp->tri[].tex_x3 = node.texture[tex+4]; + pp->tri[].tex_y3 = node.texture[tex+4+1]; + } + + copy(pp, wbuf, pp->size()); + } + } + +};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/simple_render/trash/scene_graph_update.cpp Wed Feb 13 15:10:47 2008 +0900 @@ -0,0 +1,86 @@ +#include "scene_graph_update.h" + +class SceneGraphUpdate : SpeTask { + + SceneGraphUpdate() { + rbuf = _rbuf; + wbuf = _wbuf; + } + + void + SceneGraphUpdate::matrix4x4(float *xyz, float *xyz1, float *xyz2) { + for(int t=0; t<16; t+=4) { + for(int i=0; i<4; i++) { + xyz[t+i] = xyz1[t]*xyz2[i] + xyz1[t+1]*xyz2[4+i] + xyz1[t+2]*xyz2[8+i]+ xyz1[t+3]*xyz2[12+i]; + } + } + } + + void + SceneGraphUpdate::get_matrix( float *matrix, float *rxyz, float *txyz, float *stack) { + float radx,rady,radz; + radx = rxyz[0]*3.14/180; + rady = rxyz[1]*3.14/180; + radz = rxyz[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); + + matrix[0] = cosz*cosy+sinz*sinx*siny; + matrix[1] =sinz*cosx; + matrix[2] = -cosz*siny+sinz*sinx*cosy; + matrix[3] = 0; + matrix[4] = -sinz*cosy+cosz*sinx*siny; + matrix[5] = cosz*cosx; + matrix[6] = sinz*siny+cosz*sinx*cosy; + matrix[7] = 0; + matrix[8] = cosx*siny; + matrix[9] = -sinx; + matrix[10] = cosx*cosy; + matrix[11] = 0; + matrix[12] = txyz[0]; + matrix[13] = txyz[1]; + matrix[14] = txyz[2]; + matrix[15] = 1; + + float m[16]; + for(int i=0; i<16; i++) { + m[i] = matrix[i]; + } + + if(stack) { + matrix4x4(matrix, m, stack); + } + } + + + int + SceneGraphUpdate::run() { + SceneGraphPack *sgp = (SceneGraphPack*)rbuf; + for (int i = 0; i < sgp->size; i++) { + //SceneGraphNode *node = sgp->node[i]; + (*my_func[sgp->node[i].move])(node); + (*my_func[sgp->node[i].interaction])(sgp->node[i], sgp); + if(sgp->node[i].pn != -1) { + get_matrix(sgp->node[i].translation, sgp->node[i].angle, sgp->node[i].obj_pos, sgp->node[sgp->node[i].pn].translation); + } + else { + get_matrix(sgp->node[i].translation, sgp->node[i].angle, sgp->node[i].obj_pos, NULL); + } + + copy(sgp->node, wbuf, sgp->node->size()); + } + } + + + void + Boss::move(SceneGraphNode *node) { + x = x+1; + } + + +};