Mercurial > hg > Game > Cerium
changeset 206:f5784443dd50 draft
add Camera
author | gongo@gendarme.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Thu, 29 Jan 2009 13:52:47 +0900 |
parents | de235e3ef9d3 |
children | e1746a2d1343 |
files | TaskManager/Test/test_render/Camera.h TaskManager/Test/test_render/Makefile.def TaskManager/Test/test_render/SceneGraphRoot.cpp TaskManager/Test/test_render/ieshoot.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 |
diffstat | 8 files changed, 85 insertions(+), 67 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/Test/test_render/Camera.h Tue Jan 27 18:21:12 2009 +0900 +++ b/TaskManager/Test/test_render/Camera.h Thu Jan 29 13:52:47 2009 +0900 @@ -1,9 +1,21 @@ #ifndef INCLUDED_CAMERA #define INCLUDED_CAMERA +#ifndef INCLUDED_SCENE_GRAPH +# include "SceneGraph.h" +#endif + class Camera : public SceneGraph { public: - Camera(void) {name = (const char*)"Camera";} + Camera(void); + + float fov; // 視野角 + float near; // 近平面 + float far; // 遠平面 + + //void updatePerspectiveMatrix(float *m, float z0, float z1); + void updatePerspectiveMatrix(float *m, float s, float r); + void update(int screen_w, int screen_h); }; typedef Camera *CameraPtr;
--- a/TaskManager/Test/test_render/Makefile.def Tue Jan 27 18:21:12 2009 +0900 +++ b/TaskManager/Test/test_render/Makefile.def Thu Jan 29 13:52:47 2009 +0900 @@ -3,16 +3,16 @@ # 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 = ../../.. CC = g++ -CFLAGS = -O9 -g -Wall# -DDEBUG +CFLAGS = -O0 -g -Wall# -DDEBUG INCLUDE = -I$(CERIUM)/include/TaskManager -I. LIBS = -L$(CERIUM)/TaskManager \ No newline at end of file
--- a/TaskManager/Test/test_render/SceneGraphRoot.cpp Tue Jan 27 18:21:12 2009 +0900 +++ b/TaskManager/Test/test_render/SceneGraphRoot.cpp Thu Jan 29 13:52:47 2009 +0900 @@ -140,7 +140,13 @@ SceneGraphRoot::allExecute(int screen_w, int screen_h) { SceneGraphPtr top = sg_exec_list; - SceneGraphPtr t = top; + SceneGraphPtr t = top; /* top = Camera (090128 現在) */ + CameraPtr camera = (CameraPtr)t; + + //camera->move_execute(screen_w, screen_h); + camera->update(screen_w, screen_h); + + t = camera->children; while (t) { t->move_execute(screen_w, screen_h); @@ -148,11 +154,11 @@ t->frame++; - 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->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;
--- a/TaskManager/Test/test_render/ieshoot.cpp Tue Jan 27 18:21:12 2009 +0900 +++ b/TaskManager/Test/test_render/ieshoot.cpp Thu Jan 29 13:52:47 2009 +0900 @@ -56,7 +56,7 @@ iebosstama->set_move_collision(iebosstama_move, ietama_collision); iebosstama->xyz[0] = node->xyz[0]; iebosstama->xyz[1] = node->xyz[1] + boss_radius_y; - iebosstama->xyz[2] = 30000.0f; + //iebosstama->xyz[2] = 50.0f; node->addBrother(iebosstama); damage++; @@ -76,6 +76,7 @@ * Boss が複数居た場合、これじゃ駄目 */ static int x_speed = 5.0f; + static int z_speed = 5.0f; node->xyz[0] += x_speed; @@ -86,6 +87,15 @@ x_speed = -x_speed; node->xyz[0] = screen_w - boss_radius_x; } + + //node->xyz[2] += z_speed; + if (node->xyz[2] >= 100.0f) { + node->xyz[2] = 99.99f; + z_speed = -z_speed; + } else if (node->xyz[2] <= -100.0f) { + node->xyz[2] = -99.99f; + z_speed = -z_speed; + } } static void @@ -194,6 +204,7 @@ iejiki = sgroot->createSceneGraph(IEJIKI); iejiki->set_move_collision(iejiki_move, iejiki_collision); + iejiki->xyz[2] = 20; back->addChild(iejiki); enemy = sgroot->createSceneGraph(IEBOSS);
--- a/TaskManager/Test/test_render/sys.cpp Tue Jan 27 18:21:12 2009 +0900 +++ b/TaskManager/Test/test_render/sys.cpp Thu Jan 29 13:52:47 2009 +0900 @@ -35,6 +35,7 @@ float sinz = sin(radz); float cosz = cos(radz); + /* View Transform */ matrix[0] = cosz*cosy+sinz*sinx*siny; matrix[1] = sinz*cosx; matrix[2] = -cosz*siny+sinz*sinx*cosy; @@ -52,6 +53,17 @@ matrix[14] = txyz[2]; matrix[15] = 1; + /* Perspective Transform */ +#if 0 + float n = 0.0f; + float f = 1000.0f; + float a = 0.995f / (n-f); + float b = 1-((0.995*n)/(n-f)); + + matrix[0] *= a*txyz[2]+b; + matrix[5] *= a*txyz[2]+b; +#endif + float m[16]; for(int i=0; i<16; i++)
--- a/TaskManager/Test/test_render/sys.h Tue Jan 27 18:21:12 2009 +0900 +++ b/TaskManager/Test/test_render/sys.h Thu Jan 29 13:52:47 2009 +0900 @@ -6,3 +6,4 @@ //void rotate(float *xyz, float *matrix, float *rxyz, float *txyz, float *stack[]); void rotate(float *xyz, float *matrix); void translate(float *xyz, float x, float y, float z); +void matrix4x4(float *, float *, float *);
--- a/TaskManager/Test/test_render/task/CreatePolygonFromSceneGraph.cpp Tue Jan 27 18:21:12 2009 +0900 +++ b/TaskManager/Test/test_render/task/CreatePolygonFromSceneGraph.cpp Thu Jan 29 13:52:47 2009 +0900 @@ -16,45 +16,44 @@ #define PP_STORE 13 /** - * あとで直す + * ベクトルに行列を乗算する + * @param[out] v vector (float[4]) + * @param[in] m matrix (float[16]) */ static void -rotate(float *xyz, float *matrix) +ApplyMatrix(float *v, float *m) { - float abc[4]; + float t[4]; - abc[0] = xyz[0]; - abc[1] = xyz[1]; - abc[2] = xyz[2]; - abc[3] = xyz[3]; + t[0] = v[0]; + t[1] = v[1]; + t[2] = v[2]; + t[3] = v[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]; + for (int i = 0; i < 4; i++) { + v[i] = t[0]*m[i] + t[1]*m[i+4] + t[2]*m[i+8] + t[3]*m[i+12]; } } +/** + * 行列の積 + * + * @param[out] m0 output matrix + * @param[in] m1 input left matrix + * @param[in] m2 input right matrix + */ static void -apply_matrix(float *xyz, float *mat) +MulMatrix(float *m0, float *m1, float *m2) //xyz[16] { - float tmp[4]; - - tmp[0] = xyz[0]; - tmp[1] = xyz[1]; - tmp[2] = xyz[2]; - tmp[3] = xyz[3]; - - for (int i = 0; i < 4; i++) { - xyz[i] = tmp[0]*mat[i*4+0] + tmp[1]*mat[i*4+1] - + tmp[2]*mat[i*4+2] + tmp[3]*mat[i*4+3]; + for(int t = 0; t < 16; t += 4) { + for (int i = 0; i < 4; i++) { + m0[t+i] = + m1[t+0]*m2[ i ] + m1[t+1]*m2[i+ 4] + + m1[t+2]*m2[i+8] + m1[t+3]*m2[i+12]; + } } } -float fx = 1.0f; -float fy = 1.0f; -float fz = 0.9f; -float fd = 0.05f; - int CreatePolygonFromSceneGraph::run(void *rbuf, void *wbuf) { @@ -70,21 +69,6 @@ PolygonPackPtr pp_addr = (PolygonPackPtr)smanager->get_param(1); PolygonPackPtr tmp_pp; - float n = 10.0f; - float f = 1000.0f; - float t = 30.0f; - float b = -30.0f; - float r = 30.0f; - float l = -30.0f; - - float mat[16] = { - 2*n/(r-l), 0, (r+l)/(r-l), 0, - 0, 2*n/(t-b), (t+b)/(t-b), 0, - 0, 0, -(f+n)/(f-n), -2*n*f/(f-n), - 0, 0, -1, 0 - }; - - pp->init(); send_pp->init(); @@ -123,23 +107,22 @@ 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); - //apply_matrix(xyz1, mat); - //apply_matrix(xyz2, mat); - //apply_matrix(xyz3, mat); - + // sg->matrix = 回転行列*透視変換行列 + ApplyMatrix(xyz1, sg->matrix); + ApplyMatrix(xyz2, sg->matrix); + ApplyMatrix(xyz3, sg->matrix); + triangle->ver1.x = xyz1[0]; triangle->ver1.y = xyz1[1]; triangle->ver1.z = xyz1[2];
--- a/TaskManager/Test/test_render/task/CreateSpan.cpp Tue Jan 27 18:21:12 2009 +0900 +++ b/TaskManager/Test/test_render/task/CreateSpan.cpp Thu Jan 29 13:52:47 2009 +0900 @@ -498,17 +498,10 @@ triPack->tex_info.scale_max, vMin, vMid, vMid10, (int)(vMax->y - vMin->y), vMax->tex_y - vMin->tex_y); half_triangle(spackList, charge_y_top, charge_y_end, -#if 0 - pp->tri[0].tex_info.addr, - pp->tri[0].tex_info.width, - pp->tri[0].tex_info.height, - pp->tri[0].tex_info.scale_max, vMax, vMid, vMid10, -#else triPack->tex_info.addr, triPack->tex_info.width, triPack->tex_info.height, triPack->tex_info.scale_max, vMax, vMid, vMid10, -#endif (int)(vMax->y - vMin->y), vMax->tex_y - vMin->tex_y); }