Mercurial > hg > Game > Cerium
changeset 404:0d2dc1869cbe draft
rename cpp to cc
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 23 Sep 2009 12:23:01 +0900 |
parents | e2f29e912d0b |
children | 2c592936bbdf |
files | TaskManager/Test/test_render/Button.cc TaskManager/Test/test_render/Button.cpp TaskManager/Test/test_render/Camera.cc TaskManager/Test/test_render/Camera.cpp TaskManager/Test/test_render/Joystick.cc TaskManager/Test/test_render/Joystick.cpp TaskManager/Test/test_render/Keyboard.cc TaskManager/Test/test_render/Keyboard.cpp TaskManager/Test/test_render/Makefile.cell TaskManager/Test/test_render/Makefile.macosx TaskManager/Test/test_render/Pad.cc TaskManager/Test/test_render/Pad.cpp TaskManager/Test/test_render/SceneGraph.cc TaskManager/Test/test_render/SceneGraph.cpp TaskManager/Test/test_render/SceneGraphIterator.cc TaskManager/Test/test_render/SceneGraphIterator.cpp TaskManager/Test/test_render/SceneGraphRoot.cc TaskManager/Test/test_render/SceneGraphRoot.cpp TaskManager/Test/test_render/SpanC.cc TaskManager/Test/test_render/SpanC.cpp TaskManager/Test/test_render/TextureHash.cc TaskManager/Test/test_render/TextureHash.cpp TaskManager/Test/test_render/back_action.cc TaskManager/Test/test_render/back_action.cpp TaskManager/Test/test_render/ball_action.cc TaskManager/Test/test_render/ball_action.cpp TaskManager/Test/test_render/ball_bound.cc TaskManager/Test/test_render/ball_bound.cpp TaskManager/Test/test_render/base64_de.cc TaskManager/Test/test_render/base64_de.cpp TaskManager/Test/test_render/boss1_action.cc TaskManager/Test/test_render/boss1_action.cpp TaskManager/Test/test_render/bullet_action.cc TaskManager/Test/test_render/bullet_action.cpp TaskManager/Test/test_render/camera_action.cc TaskManager/Test/test_render/camera_action.cpp TaskManager/Test/test_render/chain.cc TaskManager/Test/test_render/chain.cpp TaskManager/Test/test_render/cube.cc TaskManager/Test/test_render/cube.cpp TaskManager/Test/test_render/cube_action.cc TaskManager/Test/test_render/cube_action.cpp TaskManager/Test/test_render/direction.cc TaskManager/Test/test_render/direction.cpp TaskManager/Test/test_render/enemy_action.cc TaskManager/Test/test_render/enemy_action.cpp TaskManager/Test/test_render/game_over.cc TaskManager/Test/test_render/game_over.cpp TaskManager/Test/test_render/gaplant.cc TaskManager/Test/test_render/gaplant.cpp TaskManager/Test/test_render/gaplant_action.cc TaskManager/Test/test_render/gaplant_action.cpp TaskManager/Test/test_render/hit_judge.cc TaskManager/Test/test_render/hit_judge.cpp TaskManager/Test/test_render/ieshoot.cc TaskManager/Test/test_render/ieshoot.cpp TaskManager/Test/test_render/init_position.cc TaskManager/Test/test_render/init_position.cpp TaskManager/Test/test_render/lindaapi.cc TaskManager/Test/test_render/lindaapi.cpp TaskManager/Test/test_render/long_cube.cc TaskManager/Test/test_render/long_cube.cpp TaskManager/Test/test_render/main.cc TaskManager/Test/test_render/main.cpp TaskManager/Test/test_render/node.cc TaskManager/Test/test_render/node.cpp TaskManager/Test/test_render/panel.cc TaskManager/Test/test_render/panel.cpp TaskManager/Test/test_render/player_action.cc TaskManager/Test/test_render/player_action.cpp TaskManager/Test/test_render/polygon.cc TaskManager/Test/test_render/polygon.cpp TaskManager/Test/test_render/post.cc TaskManager/Test/test_render/post.cpp TaskManager/Test/test_render/show_time.cc TaskManager/Test/test_render/show_time.cpp TaskManager/Test/test_render/sys.cc TaskManager/Test/test_render/sys.cpp TaskManager/Test/test_render/task/CreatePolygon.cc TaskManager/Test/test_render/task/CreatePolygon.cpp TaskManager/Test/test_render/task/CreatePolygonFromSceneGraph.cc TaskManager/Test/test_render/task/CreatePolygonFromSceneGraph.cpp TaskManager/Test/test_render/task/CreateSpan.cc TaskManager/Test/test_render/task/CreateSpan.cpp TaskManager/Test/test_render/task/DrawBack.cc TaskManager/Test/test_render/task/DrawBack.cpp TaskManager/Test/test_render/task/DrawSpan.cc TaskManager/Test/test_render/task/DrawSpan.cpp TaskManager/Test/test_render/task/DrawSpanRenew.cc TaskManager/Test/test_render/task/DrawSpanRenew.cpp TaskManager/Test/test_render/task/Load_Texture.cc TaskManager/Test/test_render/task/Load_Texture.cpp TaskManager/Test/test_render/task/Set_Texture.cc TaskManager/Test/test_render/task/Set_Texture.cpp TaskManager/Test/test_render/task/ShowTime.cc TaskManager/Test/test_render/task/ShowTime.cpp TaskManager/Test/test_render/task/TileHash.cc TaskManager/Test/test_render/task/TileHash.cpp TaskManager/Test/test_render/task/create_sgp.cc TaskManager/Test/test_render/task/create_sgp.cpp TaskManager/Test/test_render/task/dummy.cc TaskManager/Test/test_render/task/dummy.cpp TaskManager/Test/test_render/task/dummy.h TaskManager/Test/test_render/task/dummy.hpp TaskManager/Test/test_render/task/task_init.cc TaskManager/Test/test_render/task/task_init.cpp TaskManager/Test/test_render/task/update_sgp.cc TaskManager/Test/test_render/task/update_sgp.cpp TaskManager/Test/test_render/task/update_sgp.h TaskManager/Test/test_render/task/update_sgp.hpp TaskManager/Test/test_render/texture.cc TaskManager/Test/test_render/texture.cpp TaskManager/Test/test_render/title.cc TaskManager/Test/test_render/title.cpp TaskManager/Test/test_render/tools/create_sglist.pl TaskManager/Test/test_render/triangle.cc TaskManager/Test/test_render/triangle.cpp TaskManager/Test/test_render/universe.cc TaskManager/Test/test_render/universe.cpp TaskManager/Test/test_render/untitled.cc TaskManager/Test/test_render/untitled.cpp TaskManager/Test/test_render/vacuum.cc TaskManager/Test/test_render/vacuum.cpp TaskManager/Test/test_render/vertex.cc TaskManager/Test/test_render/vertex.cpp TaskManager/Test/test_render/viewer.cc TaskManager/Test/test_render/viewer.cpp TaskManager/Test/test_render/viewerFB.cc TaskManager/Test/test_render/viewerFB.cpp TaskManager/Test/test_render/viewerSDL.cc TaskManager/Test/test_render/viewerSDL.cpp TaskManager/Test/test_render/viewer_types.cc TaskManager/Test/test_render/viewer_types.cpp TaskManager/Test/test_render/xml.cc TaskManager/Test/test_render/xml.cpp |
diffstat | 135 files changed, 9068 insertions(+), 9068 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/Button.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,55 @@ +#include "Button.h" + +/** + * ボタン押下時に push, hold, release の状態を変更する + * push は押した瞬間にだけ 1 を持つ + * hold の状態では 0 を持つ + */ +void +Button::push_work(void) +{ + push = (!hold); + hold = 1; + release = 0; +} + +/** + * ボタンを離した時に push, hold, release の状態を変更する + */ +void +Button::release_work(void) +{ + push = 0; + hold = 0; + release = 1; +} + +/** + * @retval 1 ボタンが押された(このフレームのみ) + * @retval 0 押されていない + */ +int +Button::isPush(void) +{ + return push; +} + +/** + * @retval 1 ボタンは押され続けている + * @retval 0 ボタンは押されていない + */ +int +Button::isHold(void) +{ + return hold; +} + +/** + * @retval 1 ボタンは押されていない + * @retval 0 ボタンが押されている + */ +int +Button::isRelease(void) +{ + return release; +}
--- a/TaskManager/Test/test_render/Button.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -#include "Button.h" - -/** - * ボタン押下時に push, hold, release の状態を変更する - * push は押した瞬間にだけ 1 を持つ - * hold の状態では 0 を持つ - */ -void -Button::push_work(void) -{ - push = (!hold); - hold = 1; - release = 0; -} - -/** - * ボタンを離した時に push, hold, release の状態を変更する - */ -void -Button::release_work(void) -{ - push = 0; - hold = 0; - release = 1; -} - -/** - * @retval 1 ボタンが押された(このフレームのみ) - * @retval 0 押されていない - */ -int -Button::isPush(void) -{ - return push; -} - -/** - * @retval 1 ボタンは押され続けている - * @retval 0 ボタンは押されていない - */ -int -Button::isHold(void) -{ - return hold; -} - -/** - * @retval 1 ボタンは押されていない - * @retval 0 ボタンが押されている - */ -int -Button::isRelease(void) -{ - return release; -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/Camera.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,263 @@ +#include <math.h> +#include "SceneGraphRoot.h" +#include "Camera.h" +#include "sys.h" +#include "Scheduler.h" +#include "show_time.h" +#include "TaskManager.h" + +static void +camera_move(SceneGraphPtr _node, int screen_w, int screen_h) +{ + Pad *pad = sgroot->getController(); + CameraPtr node = (CameraPtr)_node; + +#if 0 + if (pad->right.isHold()) { + node->xyz[0] += 10.0f; + } else if (pad->left.isHold()) { + node->xyz[0] -= 10.0f; + } + + if (pad->up.isPush() || pad->up.isHold()) { + node->xyz[1] -= 2.0f; + } else if (pad->down.isPush() || pad->down.isHold()) { + node->xyz[1] += 2.0f; + } +#endif + + /* + * ここに show_dma_wait 表示をいれようか + */ + + /* + if (pad->r1.isPush()) { + show_time(manager); + } + */ + + if (pad->r1.isPush() || pad->r1.isHold()) { + node->xyz[2] += 10.0f; + } else if (pad->l1.isPush() || pad->l1.isHold()) { + node->xyz[2] -= 10.0f; + } + + if (pad->r2.isHold()) { + if (node->zd[0] <= 1.0f) { + node->zd[0] += 0.02f; + } + if (node->zd[2] >= 0.0f) { + node->zd[2] -= 0.02f; + } + } else if (pad->l2.isHold()) { + if (node->zd[0] > -1.0f) { + node->zd[0] -= -0.02f; + } + if (node->zd[2] >= 0.0f) { + node->zd[2] -= 0.02f; + } + } else { + node->zd[0] = 0.0f; + node->zd[2] = 1.0f; + } + +} + +static void +camera_collision(SceneGraphPtr node, int screen_w, int screen_h, + SceneGraphPtr tree) +{ +} + +/** + * @param w Width of screen + * @param h Height of screen + */ +Camera::Camera(float w, float h) +{ + name = (char*)"Camera"; + + + fov = 60.0f; + near = 0.0f; + far = 1000.0f; + + zd[0] = 0.0f; + zd[1] = 0.0f; + zd[2] = 1.0f; + zd[3] = 1.0f; + + yd[0] = 0.0f; + yd[1] = 1.0f; + yd[2] = 0.0f; + yd[3] = 1.0f; + + // Screen の真ん中を初期値とする + xyz[0] = w/2.0f; + xyz[1] = h/2.0f; + + // min(w, h) がちょうど一杯見えるような z の位置の計算 + xyz[2] = -(((xyz[1] < xyz[0]) ? xyz[1] : xyz[0])/tanf((fov/2.0f)*M_PI/180.0f)); + //xyz[2] = -200.0f; + xyz[3] = 1.0f; + + m_view = new float[16]; + m_pers = new float[16]; + m_screen = new float[16]; + + this->set_move_collision(camera_move, camera_collision); +} + +Camera::~Camera(void) +{ + delete [] m_view; + delete [] m_pers; + delete [] m_screen; +} + +void +Camera::updateView(void) +{ + float radx,rady,radz; + float cx[4], cy[4], cz[4], p[4]; + float tm[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); + + /* View Transform */ + tm[0] = cosz*cosy+sinz*sinx*siny; + tm[1] = sinz*cosx; + tm[2] = -cosz*siny+sinz*sinx*cosy; + tm[3] = 0.0f; + tm[4] = -sinz*cosy+cosz*sinx*siny; + tm[5] = cosz*cosx; + tm[6] = sinz*siny+cosz*sinx*cosy; + tm[7] = 0.0f; + tm[8] = cosx*siny; + tm[9] = -sinx; + tm[10] = cosx*cosy; + tm[11] = 0.0f; + tm[12] = 0.0f; + tm[13] = 0.0f; + tm[14] = 0.0f; + tm[15] = 1.0f; + + applyMatrix(cz, tm, zd); + applyMatrix(cy, tm, yd); + applyMatrix(p, tm, xyz); + + outerProduct(cx, cy, cz); + normalize(cx, cx); + normalize(cz, cz); + outerProduct(cy, cz, cx); + + m_view[ 0] = cx[0]; + m_view[ 1] = cy[0]; + m_view[ 2] = cz[0]; + m_view[ 3] = 0.0f; + + m_view[ 4] = cx[1]; + m_view[ 5] = cy[1]; + m_view[ 6] = cz[1]; + m_view[ 7] = 0.0f; + m_view[ 8] = cx[2]; + m_view[ 9] = cy[2]; + m_view[10] = cz[2]; + m_view[11] = 0.0f; + + m_view[12] = innerProduct(xyz, cx)*(-1); + m_view[13] = innerProduct(xyz, cy)*(-1); + m_view[14] = innerProduct(xyz, cz)*(-1); + m_view[15] = 1.0f; +} + +void +Camera::updatePerspective(float w, float h) +{ + float sx, sy, sz; + float aspect = w/h; + + sy = (1.0f/tanf((fov/2.0f)*M_PI/180.0f)); + sx = sy/aspect; + //sz = far/(far+near); + sz = far/(far-near); + + m_pers[ 0] = sx; + m_pers[ 1] = 0.0f; + m_pers[ 2] = 0.0f; + m_pers[ 3] = 0.0f; + + m_pers[ 4] = 0.0f; + m_pers[ 5] = sy; + m_pers[ 6] = 0.0f; + m_pers[ 7] = 0.0f; + + m_pers[ 8] = 0.0f; + m_pers[ 9] = 0.0f; + m_pers[10] = sz; + m_pers[11] = 1.0f; + + m_pers[12] = 0.0f; + m_pers[13] = 0.0f; + m_pers[14] = -near*sz; + m_pers[15] = 0.0f; +} + +void +Camera::updateScreen(float _w, float _h) +{ + float w = _w/2.0f; + float h = _h/2.0f; + + m_screen[ 0] = w; + m_screen[ 1] = 0.0f; + m_screen[ 2] = 0.0f; + m_screen[ 3] = 0.0f; + + m_screen[ 4] = 0.0f; + m_screen[ 5] = h; + m_screen[ 6] = 0.0f; + m_screen[ 7] = 0.0f; + + m_screen[ 8] = 0.0f; + m_screen[ 9] = 0.0f; + m_screen[10] = 1.0f; + m_screen[11] = 0.0f; + + m_screen[12] = w; + m_screen[13] = h; + m_screen[14] = 0.0f; + m_screen[15] = 1.0f; +} + +void +Camera::setCamera(float *pose) +{ + //memcpy(xyz, &pose[12], sizeof(float)*4); +} + +void +Camera::update(float w, float h) +{ +#if 1 + float tmp[16]; + + updateView(); + updatePerspective(w, h); + updateScreen(w, h); + + matrix4x4(tmp, this->m_pers, this->m_screen); + matrix4x4(this->matrix, this->m_view, tmp); +#else + get_matrix(matrix, angle, xyz, NULL); +#endif +}
--- a/TaskManager/Test/test_render/Camera.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,263 +0,0 @@ -#include <math.h> -#include "SceneGraphRoot.h" -#include "Camera.h" -#include "sys.h" -#include "Scheduler.h" -#include "show_time.h" -#include "TaskManager.h" - -static void -camera_move(SceneGraphPtr _node, int screen_w, int screen_h) -{ - Pad *pad = sgroot->getController(); - CameraPtr node = (CameraPtr)_node; - -#if 0 - if (pad->right.isHold()) { - node->xyz[0] += 10.0f; - } else if (pad->left.isHold()) { - node->xyz[0] -= 10.0f; - } - - if (pad->up.isPush() || pad->up.isHold()) { - node->xyz[1] -= 2.0f; - } else if (pad->down.isPush() || pad->down.isHold()) { - node->xyz[1] += 2.0f; - } -#endif - - /* - * ここに show_dma_wait 表示をいれようか - */ - - /* - if (pad->r1.isPush()) { - show_time(manager); - } - */ - - if (pad->r1.isPush() || pad->r1.isHold()) { - node->xyz[2] += 10.0f; - } else if (pad->l1.isPush() || pad->l1.isHold()) { - node->xyz[2] -= 10.0f; - } - - if (pad->r2.isHold()) { - if (node->zd[0] <= 1.0f) { - node->zd[0] += 0.02f; - } - if (node->zd[2] >= 0.0f) { - node->zd[2] -= 0.02f; - } - } else if (pad->l2.isHold()) { - if (node->zd[0] > -1.0f) { - node->zd[0] -= -0.02f; - } - if (node->zd[2] >= 0.0f) { - node->zd[2] -= 0.02f; - } - } else { - node->zd[0] = 0.0f; - node->zd[2] = 1.0f; - } - -} - -static void -camera_collision(SceneGraphPtr node, int screen_w, int screen_h, - SceneGraphPtr tree) -{ -} - -/** - * @param w Width of screen - * @param h Height of screen - */ -Camera::Camera(float w, float h) -{ - name = (char*)"Camera"; - - - fov = 60.0f; - near = 0.0f; - far = 1000.0f; - - zd[0] = 0.0f; - zd[1] = 0.0f; - zd[2] = 1.0f; - zd[3] = 1.0f; - - yd[0] = 0.0f; - yd[1] = 1.0f; - yd[2] = 0.0f; - yd[3] = 1.0f; - - // Screen の真ん中を初期値とする - xyz[0] = w/2.0f; - xyz[1] = h/2.0f; - - // min(w, h) がちょうど一杯見えるような z の位置の計算 - xyz[2] = -(((xyz[1] < xyz[0]) ? xyz[1] : xyz[0])/tanf((fov/2.0f)*M_PI/180.0f)); - //xyz[2] = -200.0f; - xyz[3] = 1.0f; - - m_view = new float[16]; - m_pers = new float[16]; - m_screen = new float[16]; - - this->set_move_collision(camera_move, camera_collision); -} - -Camera::~Camera(void) -{ - delete [] m_view; - delete [] m_pers; - delete [] m_screen; -} - -void -Camera::updateView(void) -{ - float radx,rady,radz; - float cx[4], cy[4], cz[4], p[4]; - float tm[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); - - /* View Transform */ - tm[0] = cosz*cosy+sinz*sinx*siny; - tm[1] = sinz*cosx; - tm[2] = -cosz*siny+sinz*sinx*cosy; - tm[3] = 0.0f; - tm[4] = -sinz*cosy+cosz*sinx*siny; - tm[5] = cosz*cosx; - tm[6] = sinz*siny+cosz*sinx*cosy; - tm[7] = 0.0f; - tm[8] = cosx*siny; - tm[9] = -sinx; - tm[10] = cosx*cosy; - tm[11] = 0.0f; - tm[12] = 0.0f; - tm[13] = 0.0f; - tm[14] = 0.0f; - tm[15] = 1.0f; - - applyMatrix(cz, tm, zd); - applyMatrix(cy, tm, yd); - applyMatrix(p, tm, xyz); - - outerProduct(cx, cy, cz); - normalize(cx, cx); - normalize(cz, cz); - outerProduct(cy, cz, cx); - - m_view[ 0] = cx[0]; - m_view[ 1] = cy[0]; - m_view[ 2] = cz[0]; - m_view[ 3] = 0.0f; - - m_view[ 4] = cx[1]; - m_view[ 5] = cy[1]; - m_view[ 6] = cz[1]; - m_view[ 7] = 0.0f; - m_view[ 8] = cx[2]; - m_view[ 9] = cy[2]; - m_view[10] = cz[2]; - m_view[11] = 0.0f; - - m_view[12] = innerProduct(xyz, cx)*(-1); - m_view[13] = innerProduct(xyz, cy)*(-1); - m_view[14] = innerProduct(xyz, cz)*(-1); - m_view[15] = 1.0f; -} - -void -Camera::updatePerspective(float w, float h) -{ - float sx, sy, sz; - float aspect = w/h; - - sy = (1.0f/tanf((fov/2.0f)*M_PI/180.0f)); - sx = sy/aspect; - //sz = far/(far+near); - sz = far/(far-near); - - m_pers[ 0] = sx; - m_pers[ 1] = 0.0f; - m_pers[ 2] = 0.0f; - m_pers[ 3] = 0.0f; - - m_pers[ 4] = 0.0f; - m_pers[ 5] = sy; - m_pers[ 6] = 0.0f; - m_pers[ 7] = 0.0f; - - m_pers[ 8] = 0.0f; - m_pers[ 9] = 0.0f; - m_pers[10] = sz; - m_pers[11] = 1.0f; - - m_pers[12] = 0.0f; - m_pers[13] = 0.0f; - m_pers[14] = -near*sz; - m_pers[15] = 0.0f; -} - -void -Camera::updateScreen(float _w, float _h) -{ - float w = _w/2.0f; - float h = _h/2.0f; - - m_screen[ 0] = w; - m_screen[ 1] = 0.0f; - m_screen[ 2] = 0.0f; - m_screen[ 3] = 0.0f; - - m_screen[ 4] = 0.0f; - m_screen[ 5] = h; - m_screen[ 6] = 0.0f; - m_screen[ 7] = 0.0f; - - m_screen[ 8] = 0.0f; - m_screen[ 9] = 0.0f; - m_screen[10] = 1.0f; - m_screen[11] = 0.0f; - - m_screen[12] = w; - m_screen[13] = h; - m_screen[14] = 0.0f; - m_screen[15] = 1.0f; -} - -void -Camera::setCamera(float *pose) -{ - //memcpy(xyz, &pose[12], sizeof(float)*4); -} - -void -Camera::update(float w, float h) -{ -#if 1 - float tmp[16]; - - updateView(); - updatePerspective(w, h); - updateScreen(w, h); - - matrix4x4(tmp, this->m_pers, this->m_screen); - matrix4x4(this->matrix, this->m_view, tmp); -#else - get_matrix(matrix, angle, xyz, NULL); -#endif -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/Joystick.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,178 @@ +#include <SDL.h> +#include "Joystick.h" + +/** + * PS3 コントローラの配置 + */ +static const int SELECT = 0; +static const int L3 = 1; +static const int R3 = 2; +static const int START = 3; +static const int UP = 4; +static const int RIGHT = 5; +static const int DOWN = 6; +static const int LEFT = 7; +static const int L2 = 8; +static const int R2 = 9; +static const int L1 = 10; +static const int R1 = 11; +static const int TRIANGLE = 12; +static const int CIRCLE = 13; +static const int CROSS = 14; +static const int SQUARE = 15; +static const int PS = 16; + +#if 0 // PS2 コントローラ +static const int CROSS = 0; +static const int CIRCLE = 1; +static const int SQUARE = 2; +static const int TRIANGLE = 3; +static const int L1 = 4; +static const int R1 = 5; +static const int L2 = 6; +static const int R2 = 7; +static const int START = 8; +static const int SELECT = 9; +static const int L3 = 10; +static const int R3 = 11; +static const int UP = 12; +static const int DOWN = 13; +static const int RIGHT = 14; +static const int LEFT = 15; +static const int ESCAPE = 16; +static const int SPACE = 17; +#endif + +Joystick::Joystick(SDL_Joystick *j) +{ + joy = j; +} + +Joystick::~Joystick(void) +{ + SDL_JoystickClose(joy); +} + +void +Joystick::check(void) +{ + SDL_JoystickUpdate(); + + if (SDL_JoystickGetButton(joy,CROSS)==SDL_PRESSED) { + cross.push_work(); + } else { + cross.release_work(); + } + + if (SDL_JoystickGetButton(joy,CIRCLE)==SDL_PRESSED) { + circle.push_work(); + } else { + circle.release_work(); + } + + if (SDL_JoystickGetButton(joy,SQUARE)==SDL_PRESSED) { + square.push_work(); + } else { + square.release_work(); + } + + if (SDL_JoystickGetButton(joy,TRIANGLE)==SDL_PRESSED) { + triangle.push_work(); + } else { + triangle.release_work(); + } + + if (SDL_JoystickGetButton(joy,L1)==SDL_PRESSED) { + l1.push_work(); + } else { + l1.release_work(); + } + + if (SDL_JoystickGetButton(joy,R1)==SDL_PRESSED) { + r1.push_work(); + } else { + r1.release_work(); + } + + if (SDL_JoystickGetButton(joy,L2)==SDL_PRESSED) { + l2.push_work(); + } else { + l2.release_work(); + } + + if (SDL_JoystickGetButton(joy,R2)==SDL_PRESSED) { + r2.push_work(); + } else { + r2.release_work(); + } + + if (SDL_JoystickGetButton(joy,START)==SDL_PRESSED) { + start.push_work(); + } else { + start.release_work(); + } + + if (SDL_JoystickGetButton(joy,SELECT)==SDL_PRESSED) { + select.push_work(); + } else { + select.release_work(); + } + + if (SDL_JoystickGetButton(joy,L3)==SDL_PRESSED) { + l3.push_work(); + } else { + l3.release_work(); + } + + if (SDL_JoystickGetButton(joy,R3)==SDL_PRESSED) { + r3.push_work(); + } else { + r3.release_work(); + } + + if (SDL_JoystickGetButton(joy,UP)==SDL_PRESSED) { + up.push_work(); + } else { + up.release_work(); + } + + if (SDL_JoystickGetButton(joy,DOWN)==SDL_PRESSED) { + down.push_work(); + } else { + down.release_work(); + } + if (SDL_JoystickGetButton(joy,RIGHT)==SDL_PRESSED) { + right.push_work(); + } else { + right.release_work(); + } + if (SDL_JoystickGetButton(joy,LEFT)==SDL_PRESSED) { + left.push_work(); + } else { + left.release_work(); + } + + axis = SDL_JoystickGetAxis(joy,0); + if (axis >= 3200) { + left.release_work(); + right.push_work(); + } else if (axis <= -3200) { + right.release_work(); + left.push_work(); + } else { + left.release_work(); + right.release_work(); + } + + axis = SDL_JoystickGetAxis(joy,1); + if (axis>=3200) { + up.release_work(); + down.push_work(); + } else if (axis<=-3200) { + down.release_work(); + up.push_work(); + } else { + up.release_work(); + down.release_work(); + } +}
--- a/TaskManager/Test/test_render/Joystick.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,178 +0,0 @@ -#include <SDL.h> -#include "Joystick.h" - -/** - * PS3 コントローラの配置 - */ -static const int SELECT = 0; -static const int L3 = 1; -static const int R3 = 2; -static const int START = 3; -static const int UP = 4; -static const int RIGHT = 5; -static const int DOWN = 6; -static const int LEFT = 7; -static const int L2 = 8; -static const int R2 = 9; -static const int L1 = 10; -static const int R1 = 11; -static const int TRIANGLE = 12; -static const int CIRCLE = 13; -static const int CROSS = 14; -static const int SQUARE = 15; -static const int PS = 16; - -#if 0 // PS2 コントローラ -static const int CROSS = 0; -static const int CIRCLE = 1; -static const int SQUARE = 2; -static const int TRIANGLE = 3; -static const int L1 = 4; -static const int R1 = 5; -static const int L2 = 6; -static const int R2 = 7; -static const int START = 8; -static const int SELECT = 9; -static const int L3 = 10; -static const int R3 = 11; -static const int UP = 12; -static const int DOWN = 13; -static const int RIGHT = 14; -static const int LEFT = 15; -static const int ESCAPE = 16; -static const int SPACE = 17; -#endif - -Joystick::Joystick(SDL_Joystick *j) -{ - joy = j; -} - -Joystick::~Joystick(void) -{ - SDL_JoystickClose(joy); -} - -void -Joystick::check(void) -{ - SDL_JoystickUpdate(); - - if (SDL_JoystickGetButton(joy,CROSS)==SDL_PRESSED) { - cross.push_work(); - } else { - cross.release_work(); - } - - if (SDL_JoystickGetButton(joy,CIRCLE)==SDL_PRESSED) { - circle.push_work(); - } else { - circle.release_work(); - } - - if (SDL_JoystickGetButton(joy,SQUARE)==SDL_PRESSED) { - square.push_work(); - } else { - square.release_work(); - } - - if (SDL_JoystickGetButton(joy,TRIANGLE)==SDL_PRESSED) { - triangle.push_work(); - } else { - triangle.release_work(); - } - - if (SDL_JoystickGetButton(joy,L1)==SDL_PRESSED) { - l1.push_work(); - } else { - l1.release_work(); - } - - if (SDL_JoystickGetButton(joy,R1)==SDL_PRESSED) { - r1.push_work(); - } else { - r1.release_work(); - } - - if (SDL_JoystickGetButton(joy,L2)==SDL_PRESSED) { - l2.push_work(); - } else { - l2.release_work(); - } - - if (SDL_JoystickGetButton(joy,R2)==SDL_PRESSED) { - r2.push_work(); - } else { - r2.release_work(); - } - - if (SDL_JoystickGetButton(joy,START)==SDL_PRESSED) { - start.push_work(); - } else { - start.release_work(); - } - - if (SDL_JoystickGetButton(joy,SELECT)==SDL_PRESSED) { - select.push_work(); - } else { - select.release_work(); - } - - if (SDL_JoystickGetButton(joy,L3)==SDL_PRESSED) { - l3.push_work(); - } else { - l3.release_work(); - } - - if (SDL_JoystickGetButton(joy,R3)==SDL_PRESSED) { - r3.push_work(); - } else { - r3.release_work(); - } - - if (SDL_JoystickGetButton(joy,UP)==SDL_PRESSED) { - up.push_work(); - } else { - up.release_work(); - } - - if (SDL_JoystickGetButton(joy,DOWN)==SDL_PRESSED) { - down.push_work(); - } else { - down.release_work(); - } - if (SDL_JoystickGetButton(joy,RIGHT)==SDL_PRESSED) { - right.push_work(); - } else { - right.release_work(); - } - if (SDL_JoystickGetButton(joy,LEFT)==SDL_PRESSED) { - left.push_work(); - } else { - left.release_work(); - } - - axis = SDL_JoystickGetAxis(joy,0); - if (axis >= 3200) { - left.release_work(); - right.push_work(); - } else if (axis <= -3200) { - right.release_work(); - left.push_work(); - } else { - left.release_work(); - right.release_work(); - } - - axis = SDL_JoystickGetAxis(joy,1); - if (axis>=3200) { - up.release_work(); - down.push_work(); - } else if (axis<=-3200) { - down.release_work(); - up.push_work(); - } else { - up.release_work(); - down.release_work(); - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/Keyboard.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,92 @@ +#include <SDL.h> +#include "Keyboard.h" + +void +Keyboard::check(void) +{ + Uint8 *keys = SDL_GetKeyState(NULL); + + if (keys[SDLK_UP] == SDL_PRESSED) { + up.push_work(); + } else { + up.release_work(); + } + + if (keys[SDLK_DOWN] == SDL_PRESSED) { + down.push_work(); + } else { + down.release_work(); + } + + if (keys[SDLK_RIGHT] == SDL_PRESSED) { + right.push_work(); + } else { + right.release_work(); + } + + if (keys[SDLK_LEFT] == SDL_PRESSED) { + left.push_work(); + } else { + left.release_work(); + } + + if (keys[SDLK_RETURN] == SDL_PRESSED) { + start.push_work(); + } else { + start.release_work(); + } + + if (keys[SDLK_ESCAPE] == SDL_PRESSED) { + select.push_work(); + } else { + select.release_work(); + } + + if (keys[SDLK_a] == SDL_PRESSED) { + square.push_work(); + } else { + square.release_work(); + } + + if (keys[SDLK_s] == SDL_PRESSED) { + triangle.push_work(); + } else { + triangle.release_work(); + } + + if (keys[SDLK_z] == SDL_PRESSED) { + cross.push_work(); + } else { + cross.release_work(); + } + + if (keys[SDLK_x] == SDL_PRESSED) { + circle.push_work(); + } else { + circle.release_work(); + } + + if (keys[SDLK_k] == SDL_PRESSED) { + l1.push_work(); + } else { + l1.release_work(); + } + + if (keys[SDLK_o] == SDL_PRESSED) { + l2.push_work(); + } else { + l2.release_work(); + } + + if (keys[SDLK_l] == SDL_PRESSED) { + r1.push_work(); + } else { + r1.release_work(); + } + + if (keys[SDLK_p] == SDL_PRESSED) { + r2.push_work(); + } else { + r2.release_work(); + } +}
--- a/TaskManager/Test/test_render/Keyboard.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +0,0 @@ -#include <SDL.h> -#include "Keyboard.h" - -void -Keyboard::check(void) -{ - Uint8 *keys = SDL_GetKeyState(NULL); - - if (keys[SDLK_UP] == SDL_PRESSED) { - up.push_work(); - } else { - up.release_work(); - } - - if (keys[SDLK_DOWN] == SDL_PRESSED) { - down.push_work(); - } else { - down.release_work(); - } - - if (keys[SDLK_RIGHT] == SDL_PRESSED) { - right.push_work(); - } else { - right.release_work(); - } - - if (keys[SDLK_LEFT] == SDL_PRESSED) { - left.push_work(); - } else { - left.release_work(); - } - - if (keys[SDLK_RETURN] == SDL_PRESSED) { - start.push_work(); - } else { - start.release_work(); - } - - if (keys[SDLK_ESCAPE] == SDL_PRESSED) { - select.push_work(); - } else { - select.release_work(); - } - - if (keys[SDLK_a] == SDL_PRESSED) { - square.push_work(); - } else { - square.release_work(); - } - - if (keys[SDLK_s] == SDL_PRESSED) { - triangle.push_work(); - } else { - triangle.release_work(); - } - - if (keys[SDLK_z] == SDL_PRESSED) { - cross.push_work(); - } else { - cross.release_work(); - } - - if (keys[SDLK_x] == SDL_PRESSED) { - circle.push_work(); - } else { - circle.release_work(); - } - - if (keys[SDLK_k] == SDL_PRESSED) { - l1.push_work(); - } else { - l1.release_work(); - } - - if (keys[SDLK_o] == SDL_PRESSED) { - l2.push_work(); - } else { - l2.release_work(); - } - - if (keys[SDLK_l] == SDL_PRESSED) { - r1.push_work(); - } else { - r1.release_work(); - } - - if (keys[SDLK_p] == SDL_PRESSED) { - r2.push_work(); - } else { - r2.release_work(); - } -}
--- a/TaskManager/Test/test_render/Makefile.cell Wed Sep 23 12:04:29 2009 +0900 +++ b/TaskManager/Test/test_render/Makefile.cell Wed Sep 23 12:23:01 2009 +0900 @@ -1,24 +1,24 @@ include ./Makefile.def -SRCS_TMP = $(wildcard *.cpp) +SRCS_TMP = $(wildcard *.cc) SRCS_EXCLUDE = # SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP)) -OBJS = $(SRCS:.cpp=.o) +OBJS = $(SRCS:.cc=.o) TASK_DIR = task -TASK_SRCS_TMP = $(wildcard $(TASK_DIR)/*.cpp) -TASK_SRCS_EXCLUDE = span_pack_draw.cpp +TASK_SRCS_TMP = $(wildcard $(TASK_DIR)/*.cc) +TASK_SRCS_EXCLUDE = span_pack_draw.cc TASK_SRCS = $(filter-out $(TASK_SRCS_EXCLUDE),$(TASK_SRCS_TMP)) -TASK_OBJS = $(TASK_SRCS:.cpp=.o) +TASK_OBJS = $(TASK_SRCS:.cc=.o) LIBS += -lCellManager -lspe2 -lpthread CFLAGS += `sdl-config --cflags` `xml2-config --cflags` LIBS += `sdl-config --libs` -lSDL_image -lGL `xml2-config --libs` -.SUFFIXES: .cpp .o +.SUFFIXES: .cc .o -.cpp.o: +.cc.o: $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ default: all @@ -29,7 +29,7 @@ $(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS) SGList.o: create_sg_list - $(CC) $(CFLAGS) $(INCLUDE) -c SGList.cpp -o $@ + $(CC) $(CFLAGS) $(INCLUDE) -c SGList.cc -o $@ create_sg_list: @if [ ! -f SGList.h ]; then \ @@ -56,6 +56,6 @@ clean: rm -f $(TARGET) $(OBJS) $(TASK_OBJS) rm -f *~ \#* - rm -f SGList.h SGList.cpp + rm -f SGList.h SGList.cc cd task; rm -f *~ \#* cd spe; $(MAKE) clean
--- a/TaskManager/Test/test_render/Makefile.macosx Wed Sep 23 12:04:29 2009 +0900 +++ b/TaskManager/Test/test_render/Makefile.macosx Wed Sep 23 12:23:01 2009 +0900 @@ -1,24 +1,24 @@ include ./Makefile.def -SRCS_TMP = $(wildcard *.cpp) +SRCS_TMP = $(wildcard *.cc) SRCS_EXCLUDE = # SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP)) -OBJS = $(SRCS:.cpp=.o) +OBJS = $(SRCS:.cc=.o) TASK_DIR = task -TASK_SRCS_TMP = $(wildcard $(TASK_DIR)/*.cpp) -TASK_SRCS_EXCLUDE = span_pack_draw.cpp +TASK_SRCS_TMP = $(wildcard $(TASK_DIR)/*.cc) +TASK_SRCS_EXCLUDE = span_pack_draw.cc TASK_SRCS = $(filter-out $(TASK_SRCS_EXCLUDE),$(TASK_SRCS_TMP)) -TASK_OBJS = $(TASK_SRCS:.cpp=.o) +TASK_OBJS = $(TASK_SRCS:.cc=.o) LIBS += -lFifoManager CFLAGS += `sdl-config --cflags` `xml2-config --cflags` LIBS += `sdl-config --libs` `xml2-config --libs` -lSDL_image -Wl,-framework,OpenGL -.SUFFIXES: .cpp .o +.SUFFIXES: .cc .o -.cpp.o: +.cc.o: $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ all: SGList.o $(TARGET) @@ -28,7 +28,7 @@ SGList.o: create_sg_list - $(CC) $(CFLAGS) $(INCLUDE) -c SGList.cpp -o $@ + $(CC) $(CFLAGS) $(INCLUDE) -c SGList.cc -o $@ create_sg_list: @if [ ! -f SGList.h ]; then \ @@ -50,6 +50,6 @@ clean: rm -f $(TARGET) $(OBJS) $(TASK_OBJS) rm -f *~ \#* - rm -f SGList.h SGList.cpp + rm -f SGList.h SGList.cc -include depend.inc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/Pad.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,26 @@ +#include <stdio.h> +#include "Keyboard.h" +#include "Joystick.h" + +/** + * Joystick があればそれを使い、 + * 無ければキーボードを返す + */ +Pad* +create_controller(void) +{ + if (SDL_NumJoysticks()) { + SDL_Joystick *joy = SDL_JoystickOpen(0); + if (!joy) { + printf("%s: failed to open joystick", __FUNCTION__); + printf("Instead use Keyboard\n"); + return new Keyboard; + } else { + printf("Use Joystick\n"); + return new Joystick(joy); + } + } else { + printf("Use Keyboard\n"); + return new Keyboard; + } +}
--- a/TaskManager/Test/test_render/Pad.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -#include <stdio.h> -#include "Keyboard.h" -#include "Joystick.h" - -/** - * Joystick があればそれを使い、 - * 無ければキーボードを返す - */ -Pad* -create_controller(void) -{ - if (SDL_NumJoysticks()) { - SDL_Joystick *joy = SDL_JoystickOpen(0); - if (!joy) { - printf("%s: failed to open joystick", __FUNCTION__); - printf("Instead use Keyboard\n"); - return new Keyboard; - } else { - printf("Use Joystick\n"); - return new Joystick(joy); - } - } else { - printf("Use Keyboard\n"); - return new Keyboard; - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/SceneGraph.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,761 @@ +#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" +#include "TextureHash.h" +#include "texture.h" +#include "TaskManager.h" + +using namespace std; + +SceneGraphPtr scene_graph = NULL; +SceneGraphPtr scene_graph_viewer = NULL; + +static TextureHash texture_hash; +struct texture_list list[TABLE_SIZE]; + +extern int decode(char *cont, FILE *outfile); + +static void +no_move(SceneGraphPtr self, int screen_w, int screen_h) {} + +static void +no_collision(SceneGraphPtr self, int screen_w, int screen_h, + SceneGraphPtr tree) {} + +/** + * 事前に計算したテクスチャの最大縮小率 scale まで、 + * テクスチャを 1/2 縮小していく。 + * このとき、テクスチャは TEXTURE_SPLIT_PIXELx2 のブロック (Tile) で分割し、 + * これらを連続したメモリ領域に格納していく。 + * 以下の (1), (2), (3) を Tapestry と呼ぶ + * + * 例 scale = 4 の場合 + * + * Tapestry(1) 1/1 + * +---+---+---+---+ + * | 0 | 1 | 2 | 3 | + * +---+---+---+---+ + * | 4 | 5 | 6 | 7 | (2) 1/2 + * +---+---+---+---+ +---+---+ + * | 8 | 9 | 10| 11| | 16| 17| (3) 1/4 + * +---+---+---+---+ +---+---+ +---+ + * | 12| 13| 14| 15| | 18| 19| | 20| + * +---+---+---+---+ +---+---+ +---| + * + * (1) (2) (3) + * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * | * | * | 14| 15| 16| 17| 18| 19| 20| + * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + * + * @param[in] tex_w Width of orignal texture + * @param[in] tex_h Height of orignal texture + * @param[in] tex_src Original texture + * @param[in] all_pixel_num Tapestry の合計 pixel 数 + * @param[in] scale テクスチャの最大縮小率 (= 2^n) + * @return (1) のアドレス + */ +static uint32* +makeTapestry(TaskManager *manager, int tex_w, int tex_h, uint32 *tex_src, + int all_pixel_num, int scale_cnt) +{ + + int t = 0; + int diff = TEXTURE_SPLIT_PIXEL; + int p_diff = 1; + + uint32 *tex_dest = (uint32*)manager->allocate(sizeof(int)*all_pixel_num); + + while (scale_cnt) { + for (int y = 0; y < tex_h; y += diff) { + for (int x = 0; x < tex_w; x += diff) { + for (int j = 0; j < diff; j += p_diff) { + for (int i = 0; i < diff; i += p_diff) { + tex_dest[t++] + = tex_src[(x+i) + tex_w*(y+j)]; + } + } + } + } + + diff <<= 1; + p_diff <<= 1; + scale_cnt >>= 1; + } + + return tex_dest; +} + + +/** + * 何の情報も持ってない SceneGraph の生成 + * 今のところ、とりあえず木構造の繋がりに使うぐらい + */ +SceneGraph::SceneGraph(void) +{ + init(); + finalize = &SceneGraph::finalize_copy; + + this->name = "NULLPO"; +} + +/** + * orig のコピーとして SceneGraph を生成する + */ +SceneGraph::SceneGraph(SceneGraphPtr orig) +{ + init(); + memcpy(this, orig, sizeof(SceneGraph)); + + // コピーしない + //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; +} + + +/* construct polygon from xmlNode. */ +SceneGraph::SceneGraph(TaskManager *manager, xmlNodePtr surface) +{ + init(); + + 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]; + coord_xyz = (float*)manager->allocate(sizeof(float)*size*3); + coord_tex = (float*)manager->allocate(sizeof(float)*size*3); + normal = (float*)manager->allocate(sizeof(float)*size*3); + + get_data(manager, surface->children); + + finalize = &SceneGraph::finalize_original; +} + +void +SceneGraph::init(void) +{ + next = NULL; + prev = NULL; + last = NULL; + + parent = NULL; + 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; + + size = 0; + //data = NULL; + coord_xyz = NULL; + normal = NULL; + coord_tex = NULL; + + texture_id = -1; + move = no_move; + collision = no_collision; + + flag_remove = 0; + flag_drawable = 1; + sgid = -1; + gid = -1; + + frame = 0; +} + +SceneGraph::~SceneGraph(void) +{ + (this->*finalize)(); +} + +/** + * xml ファイルから生成されたオリジナル SceneGraph なので + * polygon data を削除 + */ +void +SceneGraph::finalize_original(void) +{ + //delete [] data; + free(coord_xyz); + free(coord_tex); + free(normal); +} + +/** + * SceneGraph ID から生成された、コピー SceneGraph なので + * polygon data は削除しない。オリジナルの方で削除する。 + */ +void +SceneGraph::finalize_copy(void) +{ +} + + +/** + * add Children + * 親の登録と、brother のリストへ加える + * + * @param child new child + */ +SceneGraphPtr +SceneGraph::addChild(SceneGraphPtr child) +{ + /* childrenのリストの最後に加える (brother として)*/ + if (this->lastChild != NULL) { + SceneGraphPtr last = this->lastChild; + last->brother = child; + } + + this->lastChild = child; + + if (this->children == NULL) { + this->children = child; + } + + child->parent = this; + + return child; +} + + +/** + * add Brother + * addChild() でも brother の操作をしないといけないので、そっちに回す + * + * @param bro new Brother + */ +SceneGraphPtr +SceneGraph::addBrother(SceneGraphPtr bro) +{ + if (this->parent) { + parent->addChild(bro); + } else { + fprintf(stderr, "error : SceneGraph::%s : %s doesn't have parent\n", + __FUNCTION__, this->name); + } + + return bro; +} + +/* thisの子や子孫にnameのものが存在すればそいつを返す なければNULL. */ +SceneGraphPtr +SceneGraph::searchSceneGraph(const char *name) +{ + SceneGraphPtr tmp; + SceneGraphPtr 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) +{ + SceneGraphPtr 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(TaskManager *manager, xmlNodePtr cur) +{ + //char *image_name; + + for(;cur;cur=cur->next) + { + if(!xmlStrcmp(cur->name,(xmlChar*)"coordinate")) + { + char *cont = (char *)xmlNodeGetContent(cur); + pickup_coordinate(cont); + } + else if(!xmlStrcmp(cur->name,(xmlChar*)"normal")) + { + char *cont = (char *)xmlNodeGetContent(cur); + pickup_normal(cont); + } + else if(!xmlStrcmp(cur->name,(xmlChar*)"model")) + { + char *cont = (char *)xmlNodeGetContent(cur); + pickup_model(cont); + } + else if(!xmlStrcmp(cur->name,(xmlChar*)"texture")) + { + char *cont = (char *)xmlNodeGetContent(cur); + pickup_texture(cont); + } + else if(!xmlStrcmp(cur->name,(xmlChar*)"imageflag")) + { + int id; + char *filename = (char *)xmlGetProp(cur, (xmlChar *)"name"); + texture_hash.hash_regist(filename, id); + } + else if(!xmlStrcmp(cur->name,(xmlChar*)"image")) + { + get_image(manager, cur); + } + } +} + +SDL_Surface* +SceneGraph::load_decode_image(char *image_name, xmlNodePtr cur) +{ + int fd = mkstemp(image_name); + FILE *outfile = fdopen(fd, "wb"); + + if (NULL == outfile) { + cout << "error open file\n"; + return 0; + } + + char *cont = (char *)xmlNodeGetContent(cur); + //decode(cont, image_name); + decode(cont, outfile); + fclose(outfile); + + +/** + * image を 32bit(RGBA) に変換する + */ + SDL_Surface *texture_image = IMG_Load(image_name); + 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; + } + + return texture_image; +} + +int +SceneGraph::makeTapestries(TaskManager *manager, SDL_Surface *texture_image, int id) { + uint32 *tapestry; + int scale = 1; + int tex_w = texture_image->w; + int tex_h = texture_image->h; + int all_pixel_num = 0; + + /** + * テクスチャの w or h が 8 pixel で分割できる間、 + * 1/2 の縮小画像を作る。 + * ここでは、最大の scale (1/scale) を見つける + * + * (ex) + * (128,128) => 64,64 : 32,32: 16,16 : 8,8 + * scale = 16 + * (128, 64) => 64,32 : 32,16: 16,8 + * scale = 8 + */ + while (tex_w % TEXTURE_SPLIT_PIXEL == 0 && + tex_h % TEXTURE_SPLIT_PIXEL == 0) { + all_pixel_num += tex_w*tex_h; + tex_w >>= 1; /* tex_w /= 2 */ + tex_h >>= 1; + scale <<= 1; /* scale *= 2 */ + } + + scale >>= 1; + + tapestry = makeTapestry(manager, texture_image->w, texture_image->h, + (uint32*)texture_image->pixels, + all_pixel_num, scale); + + list[id].t_w = texture_image->w; + list[id].t_h = texture_image->h; + list[id].pixels_orig = (Uint32*)texture_image->pixels; + list[id].pixels = tapestry; + list[id].scale_max = scale; + + return id; + } + +void +SceneGraph::get_image(TaskManager *manager, xmlNodePtr cur) +{ + char image_name[20] = "/tmp/image_XXXXXX"; + char *filename = (char *)xmlGetProp(cur, (xmlChar *)"name"); + + if (filename == NULL || filename[0] == 0) { + return; + } + + /** + * image_name を既に Load していれば何もしない + */ + int tex_id; + if (!texture_hash.hash_regist(filename, tex_id)) { + + SDL_Surface *texture_image = load_decode_image(image_name, cur); + + texture_id = makeTapestries(manager, texture_image, tex_id); + + if (unlink(image_name)) { + cout << "unlink error\n"; + } + } else { + /** + * 以前に Load されている Texture を共用 + */ + texture_id = tex_id; + } + + // こんなことすると list[] のいみあるのかなーと + // 微妙に思う、自分で書き換えた感想 by gongo + texture_info.t_w = list[texture_id].t_w; + texture_info.t_h = list[texture_id].t_h;; + texture_info.pixels_orig = list[texture_id].pixels_orig; + texture_info.pixels = list[texture_id].pixels; + texture_info.scale_max = list[texture_id].scale_max; +} + + +void +SceneGraph::delete_data(void) +{ + SceneGraphPtr n = this->next, m; + + //n = this; + //delete [] n->data; + + if (next) { + while (n) { + m = n->next; + delete n; + n = m; + } + } +} + +void +SceneGraph::move_execute(int w, int h) +{ + (*move)(this, w, h); +} + +void +SceneGraph::collision_check(int w, int h, SceneGraphPtr tree) +{ + (*collision)(this, w, h, tree); +} + +void +SceneGraph::all_execute(int screen_w, int screen_h) +{ + SceneGraphPtr top = this; + SceneGraphPtr t = top; + + while (t) { + t->move_execute(screen_w, screen_h); + t->collision_check(screen_w, screen_h, top); + + 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->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::set_move_collision(move_func new_move, + collision_func new_collision) +{ + this->move = new_move; + this->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; +} + +/** + * SceneGraph の clone + * @return clone SceneGraph + */ +SceneGraphPtr +SceneGraph::clone(void) { + SceneGraphPtr p = new SceneGraph(this); + return p; +} + +/** + * SceneGraph の clone + * 予め allocate されてる領域への placement new を行う + * + * @param buf clone 領域 + * @return clone SceneGraph + */ +SceneGraphPtr +SceneGraph::clone(void *buf) { + SceneGraphPtr p = new(buf) SceneGraph(this); + return p; +} + +void +SceneGraph::remove(void) +{ + this->flag_remove = 1; +} + +/** + * tree から node を削除する + * + * @param tree SceneGraphTree + * @return node削除後の SceneGraphTree + */ +SceneGraphPtr +SceneGraph::realRemoveFromTree(SceneGraphPtr tree) +{ + SceneGraphPtr node = this; + SceneGraphPtr parent = node->parent; + SceneGraphPtr ret = tree; + + if (parent) { + SceneGraphPtr brother = parent->children; + SceneGraphPtr p, p1 = NULL; + + p = brother; + if (p) { + if (p == node) { + parent->children = NULL; + parent->lastChild = NULL; + } else { + p1 = p->brother; + + while (p1 && p1 != node) { + p1 = p1->brother; + p = p->brother; + } + + if (p1) { + p->brother = p1->brother; + + // node が最後尾なら、lastChild を変更 + if (parent->lastChild == p1) { + parent->lastChild = p; + } + } else { + // Can't find remove node + } + } + } + } else { + // 親が居ない = tree root なので + // NULL を返す + ret = NULL; + } + + return ret; +} + +/** + * list から node を削除する + * + * @param list SceneGraphList + * @return node削除後の SceneGraphList + */ +SceneGraphPtr +SceneGraph::realRemoveFromList(SceneGraphPtr list) +{ + SceneGraphPtr node = this; + SceneGraphPtr prev = node->prev; + SceneGraphPtr next = node->next; + SceneGraphPtr ret = list; + + if (prev) { + prev->next = next; + } else { + ret = next; + } + + if (next) { + next->prev = prev; + } + + return ret; +} + +int +SceneGraph::isRemoved(void) +{ + return flag_remove; +} + +/** + * 平行移動 + * + * @param x Ttranslate in the x direction + * @param y Ttranslate in the y direction + * @param z Ttranslate in the z direction + */ +void +SceneGraph::translate(float x, float y, float z) +{ + this->xyz[0] = x; + this->xyz[1] = y; + this->xyz[2] = z; +} + +/** + * x 軸方向への平行移動 + * + * @param x Ttranslate in the x direction + */ +void +SceneGraph::translateX(float x) +{ + this->xyz[0] = x; +} + +/** + * y 軸方向への平行移動 + * + * @param y Ttranslate in the y direction + */ +void +SceneGraph::translateY(float y) +{ + this->xyz[1] = y; +} + +/** + * z 軸方向への平行移動 + * + * @param z Ttranslate in the z direction + */ +void +SceneGraph::translateZ(float z) +{ + this->xyz[2] = z; +}
--- a/TaskManager/Test/test_render/SceneGraph.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,761 +0,0 @@ -#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" -#include "TextureHash.h" -#include "texture.h" -#include "TaskManager.h" - -using namespace std; - -SceneGraphPtr scene_graph = NULL; -SceneGraphPtr scene_graph_viewer = NULL; - -static TextureHash texture_hash; -struct texture_list list[TABLE_SIZE]; - -extern int decode(char *cont, FILE *outfile); - -static void -no_move(SceneGraphPtr self, int screen_w, int screen_h) {} - -static void -no_collision(SceneGraphPtr self, int screen_w, int screen_h, - SceneGraphPtr tree) {} - -/** - * 事前に計算したテクスチャの最大縮小率 scale まで、 - * テクスチャを 1/2 縮小していく。 - * このとき、テクスチャは TEXTURE_SPLIT_PIXELx2 のブロック (Tile) で分割し、 - * これらを連続したメモリ領域に格納していく。 - * 以下の (1), (2), (3) を Tapestry と呼ぶ - * - * 例 scale = 4 の場合 - * - * Tapestry(1) 1/1 - * +---+---+---+---+ - * | 0 | 1 | 2 | 3 | - * +---+---+---+---+ - * | 4 | 5 | 6 | 7 | (2) 1/2 - * +---+---+---+---+ +---+---+ - * | 8 | 9 | 10| 11| | 16| 17| (3) 1/4 - * +---+---+---+---+ +---+---+ +---+ - * | 12| 13| 14| 15| | 18| 19| | 20| - * +---+---+---+---+ +---+---+ +---| - * - * (1) (2) (3) - * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ - * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * | * | * | 14| 15| 16| 17| 18| 19| 20| - * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ - * - * @param[in] tex_w Width of orignal texture - * @param[in] tex_h Height of orignal texture - * @param[in] tex_src Original texture - * @param[in] all_pixel_num Tapestry の合計 pixel 数 - * @param[in] scale テクスチャの最大縮小率 (= 2^n) - * @return (1) のアドレス - */ -static uint32* -makeTapestry(TaskManager *manager, int tex_w, int tex_h, uint32 *tex_src, - int all_pixel_num, int scale_cnt) -{ - - int t = 0; - int diff = TEXTURE_SPLIT_PIXEL; - int p_diff = 1; - - uint32 *tex_dest = (uint32*)manager->allocate(sizeof(int)*all_pixel_num); - - while (scale_cnt) { - for (int y = 0; y < tex_h; y += diff) { - for (int x = 0; x < tex_w; x += diff) { - for (int j = 0; j < diff; j += p_diff) { - for (int i = 0; i < diff; i += p_diff) { - tex_dest[t++] - = tex_src[(x+i) + tex_w*(y+j)]; - } - } - } - } - - diff <<= 1; - p_diff <<= 1; - scale_cnt >>= 1; - } - - return tex_dest; -} - - -/** - * 何の情報も持ってない SceneGraph の生成 - * 今のところ、とりあえず木構造の繋がりに使うぐらい - */ -SceneGraph::SceneGraph(void) -{ - init(); - finalize = &SceneGraph::finalize_copy; - - this->name = "NULLPO"; -} - -/** - * orig のコピーとして SceneGraph を生成する - */ -SceneGraph::SceneGraph(SceneGraphPtr orig) -{ - init(); - memcpy(this, orig, sizeof(SceneGraph)); - - // コピーしない - //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; -} - - -/* construct polygon from xmlNode. */ -SceneGraph::SceneGraph(TaskManager *manager, xmlNodePtr surface) -{ - init(); - - 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]; - coord_xyz = (float*)manager->allocate(sizeof(float)*size*3); - coord_tex = (float*)manager->allocate(sizeof(float)*size*3); - normal = (float*)manager->allocate(sizeof(float)*size*3); - - get_data(manager, surface->children); - - finalize = &SceneGraph::finalize_original; -} - -void -SceneGraph::init(void) -{ - next = NULL; - prev = NULL; - last = NULL; - - parent = NULL; - 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; - - size = 0; - //data = NULL; - coord_xyz = NULL; - normal = NULL; - coord_tex = NULL; - - texture_id = -1; - move = no_move; - collision = no_collision; - - flag_remove = 0; - flag_drawable = 1; - sgid = -1; - gid = -1; - - frame = 0; -} - -SceneGraph::~SceneGraph(void) -{ - (this->*finalize)(); -} - -/** - * xml ファイルから生成されたオリジナル SceneGraph なので - * polygon data を削除 - */ -void -SceneGraph::finalize_original(void) -{ - //delete [] data; - free(coord_xyz); - free(coord_tex); - free(normal); -} - -/** - * SceneGraph ID から生成された、コピー SceneGraph なので - * polygon data は削除しない。オリジナルの方で削除する。 - */ -void -SceneGraph::finalize_copy(void) -{ -} - - -/** - * add Children - * 親の登録と、brother のリストへ加える - * - * @param child new child - */ -SceneGraphPtr -SceneGraph::addChild(SceneGraphPtr child) -{ - /* childrenのリストの最後に加える (brother として)*/ - if (this->lastChild != NULL) { - SceneGraphPtr last = this->lastChild; - last->brother = child; - } - - this->lastChild = child; - - if (this->children == NULL) { - this->children = child; - } - - child->parent = this; - - return child; -} - - -/** - * add Brother - * addChild() でも brother の操作をしないといけないので、そっちに回す - * - * @param bro new Brother - */ -SceneGraphPtr -SceneGraph::addBrother(SceneGraphPtr bro) -{ - if (this->parent) { - parent->addChild(bro); - } else { - fprintf(stderr, "error : SceneGraph::%s : %s doesn't have parent\n", - __FUNCTION__, this->name); - } - - return bro; -} - -/* thisの子や子孫にnameのものが存在すればそいつを返す なければNULL. */ -SceneGraphPtr -SceneGraph::searchSceneGraph(const char *name) -{ - SceneGraphPtr tmp; - SceneGraphPtr 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) -{ - SceneGraphPtr 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(TaskManager *manager, xmlNodePtr cur) -{ - //char *image_name; - - for(;cur;cur=cur->next) - { - if(!xmlStrcmp(cur->name,(xmlChar*)"coordinate")) - { - char *cont = (char *)xmlNodeGetContent(cur); - pickup_coordinate(cont); - } - else if(!xmlStrcmp(cur->name,(xmlChar*)"normal")) - { - char *cont = (char *)xmlNodeGetContent(cur); - pickup_normal(cont); - } - else if(!xmlStrcmp(cur->name,(xmlChar*)"model")) - { - char *cont = (char *)xmlNodeGetContent(cur); - pickup_model(cont); - } - else if(!xmlStrcmp(cur->name,(xmlChar*)"texture")) - { - char *cont = (char *)xmlNodeGetContent(cur); - pickup_texture(cont); - } - else if(!xmlStrcmp(cur->name,(xmlChar*)"imageflag")) - { - int id; - char *filename = (char *)xmlGetProp(cur, (xmlChar *)"name"); - texture_hash.hash_regist(filename, id); - } - else if(!xmlStrcmp(cur->name,(xmlChar*)"image")) - { - get_image(manager, cur); - } - } -} - -SDL_Surface* -SceneGraph::load_decode_image(char *image_name, xmlNodePtr cur) -{ - int fd = mkstemp(image_name); - FILE *outfile = fdopen(fd, "wb"); - - if (NULL == outfile) { - cout << "error open file\n"; - return 0; - } - - char *cont = (char *)xmlNodeGetContent(cur); - //decode(cont, image_name); - decode(cont, outfile); - fclose(outfile); - - -/** - * image を 32bit(RGBA) に変換する - */ - SDL_Surface *texture_image = IMG_Load(image_name); - 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; - } - - return texture_image; -} - -int -SceneGraph::makeTapestries(TaskManager *manager, SDL_Surface *texture_image, int id) { - uint32 *tapestry; - int scale = 1; - int tex_w = texture_image->w; - int tex_h = texture_image->h; - int all_pixel_num = 0; - - /** - * テクスチャの w or h が 8 pixel で分割できる間、 - * 1/2 の縮小画像を作る。 - * ここでは、最大の scale (1/scale) を見つける - * - * (ex) - * (128,128) => 64,64 : 32,32: 16,16 : 8,8 - * scale = 16 - * (128, 64) => 64,32 : 32,16: 16,8 - * scale = 8 - */ - while (tex_w % TEXTURE_SPLIT_PIXEL == 0 && - tex_h % TEXTURE_SPLIT_PIXEL == 0) { - all_pixel_num += tex_w*tex_h; - tex_w >>= 1; /* tex_w /= 2 */ - tex_h >>= 1; - scale <<= 1; /* scale *= 2 */ - } - - scale >>= 1; - - tapestry = makeTapestry(manager, texture_image->w, texture_image->h, - (uint32*)texture_image->pixels, - all_pixel_num, scale); - - list[id].t_w = texture_image->w; - list[id].t_h = texture_image->h; - list[id].pixels_orig = (Uint32*)texture_image->pixels; - list[id].pixels = tapestry; - list[id].scale_max = scale; - - return id; - } - -void -SceneGraph::get_image(TaskManager *manager, xmlNodePtr cur) -{ - char image_name[20] = "/tmp/image_XXXXXX"; - char *filename = (char *)xmlGetProp(cur, (xmlChar *)"name"); - - if (filename == NULL || filename[0] == 0) { - return; - } - - /** - * image_name を既に Load していれば何もしない - */ - int tex_id; - if (!texture_hash.hash_regist(filename, tex_id)) { - - SDL_Surface *texture_image = load_decode_image(image_name, cur); - - texture_id = makeTapestries(manager, texture_image, tex_id); - - if (unlink(image_name)) { - cout << "unlink error\n"; - } - } else { - /** - * 以前に Load されている Texture を共用 - */ - texture_id = tex_id; - } - - // こんなことすると list[] のいみあるのかなーと - // 微妙に思う、自分で書き換えた感想 by gongo - texture_info.t_w = list[texture_id].t_w; - texture_info.t_h = list[texture_id].t_h;; - texture_info.pixels_orig = list[texture_id].pixels_orig; - texture_info.pixels = list[texture_id].pixels; - texture_info.scale_max = list[texture_id].scale_max; -} - - -void -SceneGraph::delete_data(void) -{ - SceneGraphPtr n = this->next, m; - - //n = this; - //delete [] n->data; - - if (next) { - while (n) { - m = n->next; - delete n; - n = m; - } - } -} - -void -SceneGraph::move_execute(int w, int h) -{ - (*move)(this, w, h); -} - -void -SceneGraph::collision_check(int w, int h, SceneGraphPtr tree) -{ - (*collision)(this, w, h, tree); -} - -void -SceneGraph::all_execute(int screen_w, int screen_h) -{ - SceneGraphPtr top = this; - SceneGraphPtr t = top; - - while (t) { - t->move_execute(screen_w, screen_h); - t->collision_check(screen_w, screen_h, top); - - 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->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::set_move_collision(move_func new_move, - collision_func new_collision) -{ - this->move = new_move; - this->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; -} - -/** - * SceneGraph の clone - * @return clone SceneGraph - */ -SceneGraphPtr -SceneGraph::clone(void) { - SceneGraphPtr p = new SceneGraph(this); - return p; -} - -/** - * SceneGraph の clone - * 予め allocate されてる領域への placement new を行う - * - * @param buf clone 領域 - * @return clone SceneGraph - */ -SceneGraphPtr -SceneGraph::clone(void *buf) { - SceneGraphPtr p = new(buf) SceneGraph(this); - return p; -} - -void -SceneGraph::remove(void) -{ - this->flag_remove = 1; -} - -/** - * tree から node を削除する - * - * @param tree SceneGraphTree - * @return node削除後の SceneGraphTree - */ -SceneGraphPtr -SceneGraph::realRemoveFromTree(SceneGraphPtr tree) -{ - SceneGraphPtr node = this; - SceneGraphPtr parent = node->parent; - SceneGraphPtr ret = tree; - - if (parent) { - SceneGraphPtr brother = parent->children; - SceneGraphPtr p, p1 = NULL; - - p = brother; - if (p) { - if (p == node) { - parent->children = NULL; - parent->lastChild = NULL; - } else { - p1 = p->brother; - - while (p1 && p1 != node) { - p1 = p1->brother; - p = p->brother; - } - - if (p1) { - p->brother = p1->brother; - - // node が最後尾なら、lastChild を変更 - if (parent->lastChild == p1) { - parent->lastChild = p; - } - } else { - // Can't find remove node - } - } - } - } else { - // 親が居ない = tree root なので - // NULL を返す - ret = NULL; - } - - return ret; -} - -/** - * list から node を削除する - * - * @param list SceneGraphList - * @return node削除後の SceneGraphList - */ -SceneGraphPtr -SceneGraph::realRemoveFromList(SceneGraphPtr list) -{ - SceneGraphPtr node = this; - SceneGraphPtr prev = node->prev; - SceneGraphPtr next = node->next; - SceneGraphPtr ret = list; - - if (prev) { - prev->next = next; - } else { - ret = next; - } - - if (next) { - next->prev = prev; - } - - return ret; -} - -int -SceneGraph::isRemoved(void) -{ - return flag_remove; -} - -/** - * 平行移動 - * - * @param x Ttranslate in the x direction - * @param y Ttranslate in the y direction - * @param z Ttranslate in the z direction - */ -void -SceneGraph::translate(float x, float y, float z) -{ - this->xyz[0] = x; - this->xyz[1] = y; - this->xyz[2] = z; -} - -/** - * x 軸方向への平行移動 - * - * @param x Ttranslate in the x direction - */ -void -SceneGraph::translateX(float x) -{ - this->xyz[0] = x; -} - -/** - * y 軸方向への平行移動 - * - * @param y Ttranslate in the y direction - */ -void -SceneGraph::translateY(float y) -{ - this->xyz[1] = y; -} - -/** - * z 軸方向への平行移動 - * - * @param z Ttranslate in the z direction - */ -void -SceneGraph::translateZ(float z) -{ - this->xyz[2] = z; -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/SceneGraphIterator.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,128 @@ +#include "SceneGraphIterator.h" + +void +SceneGraphIterator::set(SceneGraphPtr _list) +{ + list = cur = _list; +} + +/** + * 次の SceneGraph があるか返す + * + * @retval 1 next がある + * @retval 0 next がない + */ +int +SceneGraphIterator::hasNext(void) +{ + return (cur->next) ? 1 : 0; +} + +/** + * 指定した名前をもつ SceneGraph が以降存在するか + * + * @param id 検索したい SceneGraph の ID + * @retval 1 next がある + * @retval 0 next がない + */ +int +SceneGraphIterator::hasNext(int id) +{ + SceneGraphPtr p; + + for (p = cur->next; p; p = p->next) { + if (p->sgid == id) { + return 1; + } + } + + return 0; +} + +/*! + 指定したグループが以降存在するか + + @param id 検索したい Group の ID + @retval 1 next がある + @retval 0 next がない + */ +int +SceneGraphIterator::hasNextGroup(int id) +{ + SceneGraphPtr p; + for (p = cur->next; p; p = p->next) { + if (p->gid == id) { + return 1; + } + } + + return 0; +} + +/** + * iterator を次に進める + */ +void +SceneGraphIterator::next(void) +{ + cur = cur->next; +} + +/** + * iterator を指定した ID を持つ SceneGraph まで進める + * SceneGraph が無い場合、NULL にする + * + * @param id 検索したい SceneGraph の ID + */ +void +SceneGraphIterator::next(int id) +{ + SceneGraphPtr p; + + for (p = cur->next; p; p = p->next) { + if (p->sgid == id) { + break; + } + } + + cur = p; +} + +/*! + iterator を指定した Group ID を持つ SceneGraph まで進める + + @param id 検索したい SceneGraph の Group ID + */ +void +SceneGraphIterator::nextGroup(int id) +{ + SceneGraphPtr p; + + for (p = cur->next; p; p = p->next) { + if (p->gid == id) { + break; + } + } + + cur = p; +} + +/** + * 参照中の SceneGraph を削除する + */ +void +SceneGraphIterator::remove(void) +{ + cur->remove(); +} + +/** + * 参照中の SceneGraph を返す + * + * @return current SceneGraph + */ +SceneGraphPtr +SceneGraphIterator::get(void) +{ + return cur; +}
--- a/TaskManager/Test/test_render/SceneGraphIterator.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,128 +0,0 @@ -#include "SceneGraphIterator.h" - -void -SceneGraphIterator::set(SceneGraphPtr _list) -{ - list = cur = _list; -} - -/** - * 次の SceneGraph があるか返す - * - * @retval 1 next がある - * @retval 0 next がない - */ -int -SceneGraphIterator::hasNext(void) -{ - return (cur->next) ? 1 : 0; -} - -/** - * 指定した名前をもつ SceneGraph が以降存在するか - * - * @param id 検索したい SceneGraph の ID - * @retval 1 next がある - * @retval 0 next がない - */ -int -SceneGraphIterator::hasNext(int id) -{ - SceneGraphPtr p; - - for (p = cur->next; p; p = p->next) { - if (p->sgid == id) { - return 1; - } - } - - return 0; -} - -/*! - 指定したグループが以降存在するか - - @param id 検索したい Group の ID - @retval 1 next がある - @retval 0 next がない - */ -int -SceneGraphIterator::hasNextGroup(int id) -{ - SceneGraphPtr p; - for (p = cur->next; p; p = p->next) { - if (p->gid == id) { - return 1; - } - } - - return 0; -} - -/** - * iterator を次に進める - */ -void -SceneGraphIterator::next(void) -{ - cur = cur->next; -} - -/** - * iterator を指定した ID を持つ SceneGraph まで進める - * SceneGraph が無い場合、NULL にする - * - * @param id 検索したい SceneGraph の ID - */ -void -SceneGraphIterator::next(int id) -{ - SceneGraphPtr p; - - for (p = cur->next; p; p = p->next) { - if (p->sgid == id) { - break; - } - } - - cur = p; -} - -/*! - iterator を指定した Group ID を持つ SceneGraph まで進める - - @param id 検索したい SceneGraph の Group ID - */ -void -SceneGraphIterator::nextGroup(int id) -{ - SceneGraphPtr p; - - for (p = cur->next; p; p = p->next) { - if (p->gid == id) { - break; - } - } - - cur = p; -} - -/** - * 参照中の SceneGraph を削除する - */ -void -SceneGraphIterator::remove(void) -{ - cur->remove(); -} - -/** - * 参照中の SceneGraph を返す - * - * @return current SceneGraph - */ -SceneGraphPtr -SceneGraphIterator::get(void) -{ - return cur; -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/SceneGraphRoot.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,415 @@ +#include <SDL.h> +#include <SDL_image.h> +#include <libxml/parser.h> +#include "SceneGraphRoot.h" +#include "xml.h" +#include "sys.h" +#include "TextureHash.h" +#include "texture.h" +#include "SGList.h" + +int cnt = 0; + +SceneGraphRoot::SceneGraphRoot(float w, float h) +{ + sg_src = new SceneGraphPtr[SGLIST_LENGTH]; + camera = new Camera(w, h); + iterator = new SceneGraphIterator; + controller = create_controller(); + + sg_exec_tree = NULL; + sg_draw_tree = NULL; + sg_available_list = NULL; + sg_remove_list = NULL; + + // TODO + // 今はとりあえず camera を Root にしています + // 今はそれすらもしてません + //sg_exec_tree = camera; +} + +SceneGraphRoot::~SceneGraphRoot(void) +{ + SceneGraphPtr p = sg_available_list; + + while (p) { + 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; + delete camera; + delete iterator; + delete controller; +} + +/** + * xml ファイルから生成された SceneGraph を sg_src に登録する。 + * + * @param sg SceneGraph created by xmlfile + */ +void +SceneGraphRoot::registSceneGraph(SceneGraphPtr sg) +{ + for (int i = 0; i < SGLIST_LENGTH; i++) { + if (strcmp(sg->name, sglist_table[i]) == 0) { + sg->sgid = i; + sg_src[i] = sg; + return; + } + } + + fprintf(stderr, "error: (%s:%3d) Can't find Scene \"%s\"\n", + __FUNCTION__, __LINE__, sg->name); +} + +void +SceneGraphRoot::addNext(SceneGraphPtr sg) +{ + SceneGraphPtr last = sg_available_list; + + if (!last) { + sg_available_list = sg; + } else { + while (last->next) { + last = last->next; + } + last->next = sg; + sg->prev = last; + } + + cnt++; +} + +/* XMLファイルからポリゴンを作成 */ +void +SceneGraphRoot::createFromXMLfile(TaskManager *manager, const char *xmlfile) +{ + xmlDocPtr doc; + xmlNodePtr cur; + SceneGraphPtr tmp; + + /* パース 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(manager, cur); + + registSceneGraph(tmp); + } + + xmlFreeDoc(doc); +} + +SceneGraphPtr +SceneGraphRoot::createSceneGraph(int id) +{ + SceneGraphPtr src; + SceneGraphPtr p; + + if (id < 0 || id > SGLIST_LENGTH) { + return NULL; + } + + /* オリジナルの SceneGraph */ + src = sg_src[id]; + + /* ユーザーにはオリジナルの clone を返す */ + p = src->clone(); + + addNext(p); + + return p; +} + +/** + * 何も表示しない、move,collision もしない SceneGraph を生成 + * いずれ、Transform3D 的なものに回す予定 + */ +SceneGraphPtr +SceneGraphRoot::createSceneGraph(void) +{ + SceneGraphPtr p = new SceneGraph; + + addNext(p); + p->flag_drawable = 0; + + return p; +} + +void +SceneGraphRoot::speExecute(int screen_w, int 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); + + camera->children = NULL; + camera->lastChild = NULL; + + list->move_execute(screen_w, screen_h); + list->collision_check(screen_w, screen_h, list); + + list->frame++; + list = list->next; + + if(sg_exec_tree != NULL) { + return; + } + + /*removeのflagをもとにtreeを形成*/ + while (t) { + SceneGraphPtr c = NULL; + if (!t->isRemoved()) { + c = t->clone(); + addNext(c); + cur_parent->addChild(c); + c->frame = t->frame; + /*親の回転、座標から、子の回転、座標を算出*/ + get_matrix(c->matrix, c->angle, c->xyz, cur_parent->matrix); + } + + if (t->children != NULL && c != NULL) { + cur_parent = c; + 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 { + cur_parent = cur_parent->parent; + t = t->parent; + + } + } + } + } + } + + + + // 現在、allExecute が終わった時点では + // camera->children が User SceneGraph の root になる + + /** + * NULL じゃなかったら、setSceneData が呼ばれてるから + * そっちを次の Scene にする + */ + + sg_exec_tree = camera->children; +} + + +void +SceneGraphRoot::allExecute(int screen_w, int 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); + + camera->children = NULL; + camera->lastChild = NULL; + + /*まずは全部動作させる*/ + while (list) { + + list->move_execute(screen_w, screen_h); + list->collision_check(screen_w, screen_h, list); + + list->frame++; + list = list->next; + + } + + if(sg_exec_tree != NULL) { + return; + } + + /*removeのflagをもとにtreeを形成*/ + while (t) { + SceneGraphPtr c = NULL; + if (!t->isRemoved()) { + c = t->clone(); + addNext(c); + cur_parent->addChild(c); + c->frame = t->frame; + /*親の回転、座標から、子の回転、座標を算出*/ + get_matrix(c->matrix, c->angle, c->xyz, cur_parent->matrix); + } + + if (t->children != NULL && c != NULL) { + cur_parent = c; + 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 { + cur_parent = cur_parent->parent; + t = t->parent; + + } + } + } + } + } + + + + // 現在、allExecute が終わった時点では + // camera->children が User SceneGraph の root になる + + /** + * NULL じゃなかったら、setSceneData が呼ばれてるから + * そっちを次の Scene にする + */ + + 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 +SceneGraphRoot::checkRemove(void) +{ + SceneGraphPtr p = sg_available_list; + SceneGraphPtr p1; + + while (p) { + p1 = p->next; + if (p->isRemoved()) { + sg_exec_tree = p->realRemoveFromTree(sg_exec_tree); + sg_available_list = p->realRemoveFromList(sg_available_list); + } + delete p; + p = p1; + } +} + +SceneGraphPtr +SceneGraphRoot::getExecuteSceneGraph(void) +{ + return sg_exec_tree; +} + +SceneGraphPtr +SceneGraphRoot::getDrawSceneGraph(void) +{ + return sg_draw_tree; +} + +void +SceneGraphRoot::updateControllerState(void) +{ + controller->check(); +} + +void +SceneGraphRoot::setSceneData(SceneGraphPtr sg) +{ + sg_exec_tree = sg; +} + +Pad* +SceneGraphRoot::getController(void) +{ + return controller; +} + +SceneGraphIteratorPtr +SceneGraphRoot::getIterator(void) +{ + iterator->set(sg_remove_list); + return iterator; +} + +SceneGraphIteratorPtr +SceneGraphRoot::getIterator(SceneGraphPtr list) +{ + iterator->set(list); + return iterator; +} + +CameraPtr +SceneGraphRoot::getCamera(void) +{ + return camera; +}
--- a/TaskManager/Test/test_render/SceneGraphRoot.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,415 +0,0 @@ -#include <SDL.h> -#include <SDL_image.h> -#include <libxml/parser.h> -#include "SceneGraphRoot.h" -#include "xml.h" -#include "sys.h" -#include "TextureHash.h" -#include "texture.h" -#include "SGList.h" - -int cnt = 0; - -SceneGraphRoot::SceneGraphRoot(float w, float h) -{ - sg_src = new SceneGraphPtr[SGLIST_LENGTH]; - camera = new Camera(w, h); - iterator = new SceneGraphIterator; - controller = create_controller(); - - sg_exec_tree = NULL; - sg_draw_tree = NULL; - sg_available_list = NULL; - sg_remove_list = NULL; - - // TODO - // 今はとりあえず camera を Root にしています - // 今はそれすらもしてません - //sg_exec_tree = camera; -} - -SceneGraphRoot::~SceneGraphRoot(void) -{ - SceneGraphPtr p = sg_available_list; - - while (p) { - 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; - delete camera; - delete iterator; - delete controller; -} - -/** - * xml ファイルから生成された SceneGraph を sg_src に登録する。 - * - * @param sg SceneGraph created by xmlfile - */ -void -SceneGraphRoot::registSceneGraph(SceneGraphPtr sg) -{ - for (int i = 0; i < SGLIST_LENGTH; i++) { - if (strcmp(sg->name, sglist_table[i]) == 0) { - sg->sgid = i; - sg_src[i] = sg; - return; - } - } - - fprintf(stderr, "error: (%s:%3d) Can't find Scene \"%s\"\n", - __FUNCTION__, __LINE__, sg->name); -} - -void -SceneGraphRoot::addNext(SceneGraphPtr sg) -{ - SceneGraphPtr last = sg_available_list; - - if (!last) { - sg_available_list = sg; - } else { - while (last->next) { - last = last->next; - } - last->next = sg; - sg->prev = last; - } - - cnt++; -} - -/* XMLファイルからポリゴンを作成 */ -void -SceneGraphRoot::createFromXMLfile(TaskManager *manager, const char *xmlfile) -{ - xmlDocPtr doc; - xmlNodePtr cur; - SceneGraphPtr tmp; - - /* パース 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(manager, cur); - - registSceneGraph(tmp); - } - - xmlFreeDoc(doc); -} - -SceneGraphPtr -SceneGraphRoot::createSceneGraph(int id) -{ - SceneGraphPtr src; - SceneGraphPtr p; - - if (id < 0 || id > SGLIST_LENGTH) { - return NULL; - } - - /* オリジナルの SceneGraph */ - src = sg_src[id]; - - /* ユーザーにはオリジナルの clone を返す */ - p = src->clone(); - - addNext(p); - - return p; -} - -/** - * 何も表示しない、move,collision もしない SceneGraph を生成 - * いずれ、Transform3D 的なものに回す予定 - */ -SceneGraphPtr -SceneGraphRoot::createSceneGraph(void) -{ - SceneGraphPtr p = new SceneGraph; - - addNext(p); - p->flag_drawable = 0; - - return p; -} - -void -SceneGraphRoot::speExecute(int screen_w, int 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); - - camera->children = NULL; - camera->lastChild = NULL; - - list->move_execute(screen_w, screen_h); - list->collision_check(screen_w, screen_h, list); - - list->frame++; - list = list->next; - - if(sg_exec_tree != NULL) { - return; - } - - /*removeのflagをもとにtreeを形成*/ - while (t) { - SceneGraphPtr c = NULL; - if (!t->isRemoved()) { - c = t->clone(); - addNext(c); - cur_parent->addChild(c); - c->frame = t->frame; - /*親の回転、座標から、子の回転、座標を算出*/ - get_matrix(c->matrix, c->angle, c->xyz, cur_parent->matrix); - } - - if (t->children != NULL && c != NULL) { - cur_parent = c; - 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 { - cur_parent = cur_parent->parent; - t = t->parent; - - } - } - } - } - } - - - - // 現在、allExecute が終わった時点では - // camera->children が User SceneGraph の root になる - - /** - * NULL じゃなかったら、setSceneData が呼ばれてるから - * そっちを次の Scene にする - */ - - sg_exec_tree = camera->children; -} - - -void -SceneGraphRoot::allExecute(int screen_w, int 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); - - camera->children = NULL; - camera->lastChild = NULL; - - /*まずは全部動作させる*/ - while (list) { - - list->move_execute(screen_w, screen_h); - list->collision_check(screen_w, screen_h, list); - - list->frame++; - list = list->next; - - } - - if(sg_exec_tree != NULL) { - return; - } - - /*removeのflagをもとにtreeを形成*/ - while (t) { - SceneGraphPtr c = NULL; - if (!t->isRemoved()) { - c = t->clone(); - addNext(c); - cur_parent->addChild(c); - c->frame = t->frame; - /*親の回転、座標から、子の回転、座標を算出*/ - get_matrix(c->matrix, c->angle, c->xyz, cur_parent->matrix); - } - - if (t->children != NULL && c != NULL) { - cur_parent = c; - 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 { - cur_parent = cur_parent->parent; - t = t->parent; - - } - } - } - } - } - - - - // 現在、allExecute が終わった時点では - // camera->children が User SceneGraph の root になる - - /** - * NULL じゃなかったら、setSceneData が呼ばれてるから - * そっちを次の Scene にする - */ - - 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 -SceneGraphRoot::checkRemove(void) -{ - SceneGraphPtr p = sg_available_list; - SceneGraphPtr p1; - - while (p) { - p1 = p->next; - if (p->isRemoved()) { - sg_exec_tree = p->realRemoveFromTree(sg_exec_tree); - sg_available_list = p->realRemoveFromList(sg_available_list); - } - delete p; - p = p1; - } -} - -SceneGraphPtr -SceneGraphRoot::getExecuteSceneGraph(void) -{ - return sg_exec_tree; -} - -SceneGraphPtr -SceneGraphRoot::getDrawSceneGraph(void) -{ - return sg_draw_tree; -} - -void -SceneGraphRoot::updateControllerState(void) -{ - controller->check(); -} - -void -SceneGraphRoot::setSceneData(SceneGraphPtr sg) -{ - sg_exec_tree = sg; -} - -Pad* -SceneGraphRoot::getController(void) -{ - return controller; -} - -SceneGraphIteratorPtr -SceneGraphRoot::getIterator(void) -{ - iterator->set(sg_remove_list); - return iterator; -} - -SceneGraphIteratorPtr -SceneGraphRoot::getIterator(SceneGraphPtr list) -{ - iterator->set(list); - return iterator; -} - -CameraPtr -SceneGraphRoot::getCamera(void) -{ - return camera; -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/SpanC.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,398 @@ +#include <iostream> +#include "SpanC.h" +#include "triangle.h" +#include "polygon.h" +using namespace std; + + +// f1:xの増加量 f2:yの増加量 i:....... base:基本となる頂点のy座標 +static float calc(float f1, float f2,int i, float base){ + float ans; + ans = f1/f2*i + base; + return ans; +} + + +static Vertex *vMid1(Vertex *vMid1,Vertex *vMin, Vertex *vMid, Vertex *vMax) { + float d,d1; + + vMid1->y = vMid->y; + //vMid1->tex_y = vMid->tex_y; + d = (int)vMax->y-(int)vMin->y; + d1 = (int)vMid->y - (int)vMin->y; + /* + + if (-1.0<=vMax->y&&vMax->y<=1.0) { + a = 0.5; + } else { + a = (vMax->x-vMin->x)/d; + } + */ + //vMid1->tex_x = vMin->tex_x + a * (vMax->tex_x-vMin->tex_x); + vMid1->tex_x = calc(vMax->tex_x - vMin->tex_x, d, (int)d1 , vMin->tex_x); + vMid1->tex_y = calc(vMax->tex_y - vMin->tex_y, d, (int)d1 , vMin->tex_y); + //vMid1->x = vMin->x + a * (vMax->y -vMin->y); + vMid1->x = calc(vMax->x - vMin->x, d, (int)d1 , vMin->x); + //vMid1->z = vMin->z + a * (vMax->y -vMin->y); + vMid1->z = calc(vMax->z - vMin->z, d, (int)d1 , vMin->z); + //printf("x:%f y:%f z:%f tex_x:%f tex_y:%f\n",vMid1->x,vMid1->y,vMid1->z,vMid1->tex_x, vMid1->tex_y); + return vMid1; +} + + + +void +Span_c::half_triangle(Vertex *vMin, Vertex *vMid, Vertex *vMid1, + SDL_Surface *image) +{ + + float tmp_z,tmp_tex1, tmp_tex2 ,tmp_tey1,tmp_tey2; + //tmp_x,tmp_y,tmp_ypos ......unused + float tex_x, tex_y,tex_z; + float tmp_xpos,tmp_end,tmp_zpos; + int tex_xpos,tex_ypos,tex_zpos; + int i,j; + float div_y; + Uint32 rgb; + float z,zpos; + int x,y; + int k =0; + int l = 1; + //float incli_x1, incli_x2; + //float incli_z1, incli_z2; + //float base_x1, base_x2 , base_z1, base_z2; + //int base_y; + + /* + incli_x1 = vMid1->x - vMin->x; + incli_x2 = vMid->x - vMin->x; + incli_z1 = vMid1->z - vMin->z; + incli_z2 = vMid->z - vMin->z; + base_x1 = vMin->x; + base_x2 = vMin->x; + base_z1 = vMin->z; + base_z2 = vMin->z; + */ + //cout << vMin->x << vMin->y << vMin->z << endl; + int start_y = (int)vMid->y; + int end_y = (int)vMin->y; + + if (start_y<end_y) { + int i; i=end_y; end_y=start_y; start_y = i; //yの入れ替え + //Vertex *v; v = vMin; vMin = vMid; vMid = v; + /* + incli_x1 = vMin->x - vMid->x; incli_x2 = vMin->x - vMid1->x; + incli_z1 = vMin->z - vMid->z; incli_z2 = vMin->z - vMid1->z; + base_z1 = vMid->z; base_z2 = vMid1->z; + base_y = (int)vMid->y; + */ + k = 1; + l = -1; + } + + + + div_y = start_y - end_y; // > 0 + + //if(div_y < 1 && div_y > -1) div_y = 1; + for(i = k; i < div_y+1; i++) { + //ここでspanの左端と右端のx,zを求めてる + tmp_xpos = calc(vMid1->x - vMin->x ,div_y, i, vMin->x); + tmp_end = calc(vMid->x - vMin->x ,div_y, i, vMin->x); + tmp_z = calc(vMid1->z - vMin->z ,div_y, i, vMin->z); + tmp_zpos = calc(vMid->z - vMin->z ,div_y, i, vMin->z); + //printf("x:%f end:%f z:%f zpos:%f\n",tmp_xpos,tmp_end,tmp_z,tmp_zpos); + //ここからspanの左端と右端に対応するテクスチャを計算する + tmp_tex1 =((i/(div_y)) * vMid1->tex_x) + \ + ( ((div_y - i)/(div_y)) * vMin->tex_x); + tmp_tex2 =( (i/(div_y)) * vMid->tex_x) + \ + ( ((div_y - i)/(div_y)) * vMin->tex_x); + + tmp_tey1 =( (i/(div_y)) * vMid1->tex_y) + \ + ( ((div_y - i)/(div_y)) * vMin->tex_y); + tmp_tey2 =( (i/(div_y)) * vMid->tex_y) + \ + ( ((div_y - i)/(div_y)) * vMin->tex_y); + + //ここで左端がxposかendを判断し、描画するspanを作る + if(tmp_xpos > tmp_end) { + x = (int)tmp_end; + y = (int)vMin->y + i*l; + end = (int)(tmp_xpos)-(int)(tmp_end)+1; + z = tmp_zpos; + zpos = tmp_z; + tex1 = tmp_tex2; + tex2 = tmp_tex1; + tey1 = tmp_tey2; + tey2 = tmp_tey1; + } else { + x = (int)tmp_xpos; + y = (int)vMin->y + i*l; + end = (int)(tmp_end)-(int)(tmp_xpos)+1; + z = tmp_z; + zpos = tmp_zpos; + tex1 = tmp_tex1; + tex2 = tmp_tex2; + tey1 = tmp_tey1; + tey2 = tmp_tey2; + } + //printf("%d:%f,%f ",(int)vMin->y + i,xpos,end); + //printf("%d:%d:%d:x:%d,end:%d\n",x, y , end,(int)(tmp_end),(int)(tmp_xpos)); + //printf("x:%d y:%d end:%d z:%f zpos:%f\n",x,y,end,z , zpos); + //printf("tex1:%f tex2:%f tey1:%f tey2:%f\n",tex1,tex2,tey1,tey2); + if(end == 1) { + //printf("tex_x:%f tex_y:%f\n",tex1,tex2); + if(tex1 > 1) tex1 = 1; + if(tey1 > 1) tey1 = 1; + tex_xpos = (int)((image->h-1) * tex1); + tex_ypos = (int)((image->w-1) * tey1); + tex_zpos = (int)z; + //printf("tex_xpos:%d tex_ypos:%d\n",tex_xpos,tex_ypos); + //printf("image->h:%d tex_x:%f\n",image->h,tex1); + rgb = p->get_rgb(tex_xpos,tex_ypos); + //viewer->write_pixel(x,y,zpos,rgb); + }else { + for(j = 0; j < end; j++) { + tex_x = tex1*(end-1-j)/(end-1) + tex2*j/(end-1); + tex_y = tey1*(end-1-j)/(end-1) + tey2*j/(end-1); + tex_z = z*(end-1-j)/(end-1) + zpos*j/(end-1); + if(tex_x > 1) tex_x = 1; + if(tex_y > 1) tex_y = 1; + tex_xpos = (int)((image->h-1) * tex_x); + tex_ypos = (int)((image->w-1) * tex_y); + //printf("tex_xpos:%d tex_ypos:%d\n",tex_xpos,tex_ypos); + //printf("z:%f zpos:%f tex_z:%f\n",z,zpos,tex_z); + //printf("tex_x:%f tex_y:%f\n",tex_x,tex_y); + rgb = p->get_rgb(tex_xpos,tex_ypos); + //viewer->write_pixel(j+x,y,tex_z,rgb); + } + } + } +} + +void Span_c::create_span(Triangle *tri,SDL_Surface *image) { + Vertex *vMin , *vMid, *vMax; + /* + float tmp_z,tmp_tex1, tmp_tex2 ,tmp_tey1,tmp_tey2; + //tmp_x,tmp_y,tmp_ypos ......unused + float tex_x, tex_y,tex_z; + float tmp_xpos,tmp_end,tmp_zpos; + int top_triangle; + int tex_xpos,tex_ypos,tex_zpos; + int i,j; + float div_x,div_y; + float z,zpos; + Uint32 rgb; + */ + + //cout << "x = " << tri->vertex1->x << endl; + if(tri->vertex1->y <= tri->vertex2->y) { + if(tri->vertex2->y <= tri->vertex3->y) { + //printf("condition 1\n"); + vMin = tri->vertex1; + vMid = tri->vertex2; + vMax = tri->vertex3; + } else if(tri->vertex3->y <= tri->vertex1->y) { + //printf("condition 2\n"); + vMin = tri->vertex3; + vMid = tri->vertex1; + vMax = tri->vertex2; + } else { + //printf("condition 3\n"); + vMin = tri->vertex1; + vMid = tri->vertex3; + vMax = tri->vertex2; + } + } else { + if(tri->vertex1->y <= tri->vertex3->y) { + //printf("condition 4\n"); + vMin = tri->vertex2; + vMid = tri->vertex1; + vMax = tri->vertex3; + } else if(tri->vertex3->y <= tri->vertex2->y) { + //printf("condition 5\n"); + vMin = tri->vertex3; + vMid = tri->vertex2; + vMax = tri->vertex1; + } else { + //printf("condition 6\n"); + vMin = tri->vertex2; + vMid = tri->vertex3; + vMax = tri->vertex1; + } + } + + Vertex *vMid10 = new Vertex(0,0,0,0,0); + vMid1(vMid10,vMin,vMid,vMax); + + half_triangle(vMin,vMid,vMid10,image); + half_triangle(vMax,vMid,vMid10,image); + + free(vMid10); +#if 0 + //cout << vMin->x << vMin->y << vMin->z << endl; + div_x = (int)vMid->y - (int)vMin->y; + if(div_x < 1 && div_x > -1) div_x = 1; + div_y = (int)vMax->y - (int)vMin->y; + if(div_y < 1 && div_y > -1) div_y = 1; + + for(i = 0; i < div_x+1; i++) { + //ここでspanの左端と右端のx,zを求めてる + tmp_xpos = calc(vMax->x - vMin->x,div_y, i, vMin->x); + tmp_end = calc(vMid->x - vMin->x,div_x, i, vMin->x); + tmp_z = calc(vMax->z - vMin->z,div_y, i, vMin->z); + tmp_zpos = calc(vMid->z - vMin->z,div_x, i, vMin->z); + + //ここからspanの左端と右端に対応するテクスチャを計算する + tmp_tex1 =( (i/(div_y)) * vMax->tex_x) + \ + ( ((div_y - i)/(div_y)) * vMin->tex_x); + tmp_tex2 =( (i/(div_x)) * vMid->tex_x) + \ + ( ((div_x - i)/(div_x)) * vMin->tex_x); + + tmp_tey1 =( (i/(div_y)) * vMax->tex_y) + \ + ( ((div_y - i)/(div_y)) * vMin->tex_y); + tmp_tey2 =( (i/(div_x)) * vMid->tex_y) + \ + ( ((div_x - i)/(div_x)) * vMin->tex_y); + + //ここで左端がxposかendを判断し、描画するspanを作る + if(tmp_xpos > tmp_end) { + x = (int)tmp_end; + y = (int)vMin->y + i; + end = (int)(tmp_xpos)-(int)(tmp_end)+1; + z = tmp_z; + zpos = tmp_zpos; + tex1 = tmp_tex2; + tex2 = tmp_tex1; + tey1 = tmp_tey2; + tey2 = tmp_tey1; + } else { + x = (int)tmp_xpos; + y = (int)vMin->y + i; + end = (int)(tmp_end)-(int)(tmp_xpos)+1; + z = tmp_zpos; + zpos = tmp_z; + tex1 = tmp_tex1; + tex2 = tmp_tex2; + tey1 = tmp_tey1; + tey2 = tmp_tey2; + } + //printf("%d:%f,%f ",(int)vMin->y + i,xpos,end); + //printf("%d:%d:%d:x:%d,end:%d\n",x, y , end,(int)(tmp_end),(int)(tmp_xpos)); + //printf("x:%d y:%d end:%d z:%f zpos:%f\n",x,y,end,z , zpos); + //printf("tex1:%f tex2:%f tey1:%f tey2:%f\n",tex1,tex2,tey1,tey2); + if(end == 1) { + //printf("tex_x:%f tex_y:%f\n",tex1,tex2); + if(tex1 > 1) tex1 = 1; + if(tey1 > 1) tey1 = 1; + tex_xpos = (int)(image->h-1) * tex1; + tex_ypos = (int)(image->w-1) * tey1; + tex_zpos = z; + //printf("tex_xpos:%d tex_ypos:%d\n",tex_xpos,tex_ypos); + //printf("image->h:%d tex_x:%f\n",image->h,tex1); + rgb = p->get_rgb(tex_xpos,tex_ypos); + //viewer->write_pixel(x,y,zpos,rgb); + }else { + for(j = 0; j < end; j++) { + tex_x = tex1*(end-1-j)/(end-1) + tex2*j/(end-1); + tex_y = tey1*(end-1-j)/(end-1) + tey2*j/(end-1); + tex_z = z*(end-1-j)/(end-1) + zpos*j/(end-1); + if(tex_x > 1) tex_x = 1; + if(tex_y > 1) tex_y = 1; + tex_xpos = (int)(image->h-1) * tex_x; + tex_ypos = (int)(image->w-1) * tex_y; + //printf("tex_xpos:%d tex_ypos:%d\n",tex_xpos,tex_ypos); + //printf("z:%f zpos:%f tex_z:%f\n",z,zpos,tex_z); + //printf("tex_x:%f tex_y:%f\n",tex_x,tex_y); + rgb = p->get_rgb(tex_xpos,tex_ypos); + //viewer->write_pixel(j+x,y,tex_z,rgb); + } + } + } + + top_triangle = (int)vMid->y - (int)vMin->y; + div_x = (int)vMax->y - (int)vMid->y; + if(div_x < 1 && div_x > -1) div_x = 1; + div_y = (int)vMax->y - (int)vMin->y; + if(div_y < 1 && div_y > -1) div_y = 1; + + for(i = 0; i < div_x; i++) { + //ここでspanの左端と右端のx,zを求めてる + tmp_xpos = calc(vMax->x-vMin->x, div_y, (i+1+top_triangle), vMin->x); + tmp_end = calc(vMax->x-vMid->x, div_x, (i+1), vMid->x); + tmp_z = calc(vMax->z-vMin->z, div_y, (i+1+top_triangle), vMin->z); + tmp_zpos = calc(vMax->z-vMid->z, div_x, (i+1), vMid->z); + + tmp_tex1 =( ((i + 1 +top_triangle)/(div_y)) * vMax->tex_x) + \ + ( ((div_y - i - 1 - top_triangle)/(div_y)) * vMin->tex_x); + tmp_tex2 =( ((i+1)/(div_x)) * vMax->tex_x) + \ + ( ((div_x - i -1)/(div_x)) * vMid->tex_x); + + tmp_tey1 =( ((i+1+top_triangle)/(div_y)) * vMax->tex_y) + \ + ( ((div_y - i - 1 - top_triangle)/(div_y)) * vMin->tex_y); + tmp_tey2 =( ((i+1)/(div_x)) * vMax->tex_y) + \ + ( ((div_x - i -1)/(div_x)) * vMid->tex_y); + if(tmp_xpos > tmp_end) { + x = (int)tmp_end; + y = (int)vMid->y+i+1; + end = (int)(tmp_xpos)-(int)(tmp_end)+1; + z = tmp_z; + zpos = tmp_zpos; + tex1 = tmp_tex2; + tex2 = tmp_tex1; + tey1 = tmp_tey2; + tey2 = tmp_tey1; + } else { + x = (int)tmp_xpos; + y = (int)vMid->y+i+1; + end = (int)(tmp_end)-(int)(tmp_xpos)+1; + z = tmp_zpos; + zpos = tmp_z; + tex1 = tmp_tex1; + tex2 = tmp_tex2; + tey1 = tmp_tey1; + tey2 = tmp_tey2; + } + if(end == 0) end = 1; + //printf("%d:%d:%d\n",x, y , end); + //printf("x:%d y:%d end:%d z:%f zpos:%f\n",x,y,end,z,zpos); + //printf("tex1:%f tex2:%f tey1:%f tey2:%f\n",tex1,tex2,tey1,tey2); + if(end == 1) { + //printf("tex_x:%f tex_y:%f\n",tex1,tex2); + if(tex1 > 1) tex1 = 1; + if(tey1 > 1) tey1 = 1; + tex_xpos = (int)(image->h-1) * tex1; + tex_ypos = (int)(image->w-1) * tey1; + tex_zpos = z; + //printf("tex_x:%f tex_y:%f\n",tex_x,tex_y); + //printf("tex_xpos:%d tex_ypos:%d\n",tex_xpos,tex_ypos); + //printf("tex_x:%f tex_y:%f\n",tex_x,tex_y); + rgb = p->get_rgb(tex_xpos,tex_ypos); + //viewer->write_pixel(x,y,tex_zpos,rgb); + }else { + for(j = 0; j < end; j++) { + tex_x = tex1*(end-1-j)/(end-1) + tex2*j/(end-1); + tex_y = tey1*(end-1-j)/(end-1) + tey2*j/(end-1); + tex_z = z*(end-1-j)/(end-1) + zpos*j/(end-1); + //printf("tex_x:%f tex_y:%f\n",tex_x,tex_y); + if(tex_x > 1) tex_x = 1; + if(tex_y > 1) tex_y = 1; + tex_xpos = (int)(image->h-2) * tex_x; + tex_ypos = (int)(image->w-1) * tex_y; + //printf("z:%f zpos:%f tex_z:%f\n",z,zpos,tex_z); + //printf("tex_xpos:%d tex_ypos:%d\n",tex_xpos,tex_ypos); + //printf("tex_x:%f tex_y:%f\n",tex_x,tex_y); + //printf("tex_x:%f tex_y:%f\n",tex_x,tex_y); + rgb = p->get_rgb(tex_xpos,tex_ypos); + //viewer->write_pixel(j+x,y,tex_z,rgb); + } + } + } +#endif +} + +// i:分子、f1:長さ f2:対応する頂点1 f3:対応する頂点2 +/* +float Span::calc2(int i, float f1, float f2, float f3) { + float ans; + ans = i/f1 * f2 + (f1-i)/f1 * f3; + + */
--- a/TaskManager/Test/test_render/SpanC.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,398 +0,0 @@ -#include <iostream> -#include "SpanC.h" -#include "triangle.h" -#include "polygon.h" -using namespace std; - - -// f1:xの増加量 f2:yの増加量 i:....... base:基本となる頂点のy座標 -static float calc(float f1, float f2,int i, float base){ - float ans; - ans = f1/f2*i + base; - return ans; -} - - -static Vertex *vMid1(Vertex *vMid1,Vertex *vMin, Vertex *vMid, Vertex *vMax) { - float d,d1; - - vMid1->y = vMid->y; - //vMid1->tex_y = vMid->tex_y; - d = (int)vMax->y-(int)vMin->y; - d1 = (int)vMid->y - (int)vMin->y; - /* - - if (-1.0<=vMax->y&&vMax->y<=1.0) { - a = 0.5; - } else { - a = (vMax->x-vMin->x)/d; - } - */ - //vMid1->tex_x = vMin->tex_x + a * (vMax->tex_x-vMin->tex_x); - vMid1->tex_x = calc(vMax->tex_x - vMin->tex_x, d, (int)d1 , vMin->tex_x); - vMid1->tex_y = calc(vMax->tex_y - vMin->tex_y, d, (int)d1 , vMin->tex_y); - //vMid1->x = vMin->x + a * (vMax->y -vMin->y); - vMid1->x = calc(vMax->x - vMin->x, d, (int)d1 , vMin->x); - //vMid1->z = vMin->z + a * (vMax->y -vMin->y); - vMid1->z = calc(vMax->z - vMin->z, d, (int)d1 , vMin->z); - //printf("x:%f y:%f z:%f tex_x:%f tex_y:%f\n",vMid1->x,vMid1->y,vMid1->z,vMid1->tex_x, vMid1->tex_y); - return vMid1; -} - - - -void -Span_c::half_triangle(Vertex *vMin, Vertex *vMid, Vertex *vMid1, - SDL_Surface *image) -{ - - float tmp_z,tmp_tex1, tmp_tex2 ,tmp_tey1,tmp_tey2; - //tmp_x,tmp_y,tmp_ypos ......unused - float tex_x, tex_y,tex_z; - float tmp_xpos,tmp_end,tmp_zpos; - int tex_xpos,tex_ypos,tex_zpos; - int i,j; - float div_y; - Uint32 rgb; - float z,zpos; - int x,y; - int k =0; - int l = 1; - //float incli_x1, incli_x2; - //float incli_z1, incli_z2; - //float base_x1, base_x2 , base_z1, base_z2; - //int base_y; - - /* - incli_x1 = vMid1->x - vMin->x; - incli_x2 = vMid->x - vMin->x; - incli_z1 = vMid1->z - vMin->z; - incli_z2 = vMid->z - vMin->z; - base_x1 = vMin->x; - base_x2 = vMin->x; - base_z1 = vMin->z; - base_z2 = vMin->z; - */ - //cout << vMin->x << vMin->y << vMin->z << endl; - int start_y = (int)vMid->y; - int end_y = (int)vMin->y; - - if (start_y<end_y) { - int i; i=end_y; end_y=start_y; start_y = i; //yの入れ替え - //Vertex *v; v = vMin; vMin = vMid; vMid = v; - /* - incli_x1 = vMin->x - vMid->x; incli_x2 = vMin->x - vMid1->x; - incli_z1 = vMin->z - vMid->z; incli_z2 = vMin->z - vMid1->z; - base_z1 = vMid->z; base_z2 = vMid1->z; - base_y = (int)vMid->y; - */ - k = 1; - l = -1; - } - - - - div_y = start_y - end_y; // > 0 - - //if(div_y < 1 && div_y > -1) div_y = 1; - for(i = k; i < div_y+1; i++) { - //ここでspanの左端と右端のx,zを求めてる - tmp_xpos = calc(vMid1->x - vMin->x ,div_y, i, vMin->x); - tmp_end = calc(vMid->x - vMin->x ,div_y, i, vMin->x); - tmp_z = calc(vMid1->z - vMin->z ,div_y, i, vMin->z); - tmp_zpos = calc(vMid->z - vMin->z ,div_y, i, vMin->z); - //printf("x:%f end:%f z:%f zpos:%f\n",tmp_xpos,tmp_end,tmp_z,tmp_zpos); - //ここからspanの左端と右端に対応するテクスチャを計算する - tmp_tex1 =((i/(div_y)) * vMid1->tex_x) + \ - ( ((div_y - i)/(div_y)) * vMin->tex_x); - tmp_tex2 =( (i/(div_y)) * vMid->tex_x) + \ - ( ((div_y - i)/(div_y)) * vMin->tex_x); - - tmp_tey1 =( (i/(div_y)) * vMid1->tex_y) + \ - ( ((div_y - i)/(div_y)) * vMin->tex_y); - tmp_tey2 =( (i/(div_y)) * vMid->tex_y) + \ - ( ((div_y - i)/(div_y)) * vMin->tex_y); - - //ここで左端がxposかendを判断し、描画するspanを作る - if(tmp_xpos > tmp_end) { - x = (int)tmp_end; - y = (int)vMin->y + i*l; - end = (int)(tmp_xpos)-(int)(tmp_end)+1; - z = tmp_zpos; - zpos = tmp_z; - tex1 = tmp_tex2; - tex2 = tmp_tex1; - tey1 = tmp_tey2; - tey2 = tmp_tey1; - } else { - x = (int)tmp_xpos; - y = (int)vMin->y + i*l; - end = (int)(tmp_end)-(int)(tmp_xpos)+1; - z = tmp_z; - zpos = tmp_zpos; - tex1 = tmp_tex1; - tex2 = tmp_tex2; - tey1 = tmp_tey1; - tey2 = tmp_tey2; - } - //printf("%d:%f,%f ",(int)vMin->y + i,xpos,end); - //printf("%d:%d:%d:x:%d,end:%d\n",x, y , end,(int)(tmp_end),(int)(tmp_xpos)); - //printf("x:%d y:%d end:%d z:%f zpos:%f\n",x,y,end,z , zpos); - //printf("tex1:%f tex2:%f tey1:%f tey2:%f\n",tex1,tex2,tey1,tey2); - if(end == 1) { - //printf("tex_x:%f tex_y:%f\n",tex1,tex2); - if(tex1 > 1) tex1 = 1; - if(tey1 > 1) tey1 = 1; - tex_xpos = (int)((image->h-1) * tex1); - tex_ypos = (int)((image->w-1) * tey1); - tex_zpos = (int)z; - //printf("tex_xpos:%d tex_ypos:%d\n",tex_xpos,tex_ypos); - //printf("image->h:%d tex_x:%f\n",image->h,tex1); - rgb = p->get_rgb(tex_xpos,tex_ypos); - //viewer->write_pixel(x,y,zpos,rgb); - }else { - for(j = 0; j < end; j++) { - tex_x = tex1*(end-1-j)/(end-1) + tex2*j/(end-1); - tex_y = tey1*(end-1-j)/(end-1) + tey2*j/(end-1); - tex_z = z*(end-1-j)/(end-1) + zpos*j/(end-1); - if(tex_x > 1) tex_x = 1; - if(tex_y > 1) tex_y = 1; - tex_xpos = (int)((image->h-1) * tex_x); - tex_ypos = (int)((image->w-1) * tex_y); - //printf("tex_xpos:%d tex_ypos:%d\n",tex_xpos,tex_ypos); - //printf("z:%f zpos:%f tex_z:%f\n",z,zpos,tex_z); - //printf("tex_x:%f tex_y:%f\n",tex_x,tex_y); - rgb = p->get_rgb(tex_xpos,tex_ypos); - //viewer->write_pixel(j+x,y,tex_z,rgb); - } - } - } -} - -void Span_c::create_span(Triangle *tri,SDL_Surface *image) { - Vertex *vMin , *vMid, *vMax; - /* - float tmp_z,tmp_tex1, tmp_tex2 ,tmp_tey1,tmp_tey2; - //tmp_x,tmp_y,tmp_ypos ......unused - float tex_x, tex_y,tex_z; - float tmp_xpos,tmp_end,tmp_zpos; - int top_triangle; - int tex_xpos,tex_ypos,tex_zpos; - int i,j; - float div_x,div_y; - float z,zpos; - Uint32 rgb; - */ - - //cout << "x = " << tri->vertex1->x << endl; - if(tri->vertex1->y <= tri->vertex2->y) { - if(tri->vertex2->y <= tri->vertex3->y) { - //printf("condition 1\n"); - vMin = tri->vertex1; - vMid = tri->vertex2; - vMax = tri->vertex3; - } else if(tri->vertex3->y <= tri->vertex1->y) { - //printf("condition 2\n"); - vMin = tri->vertex3; - vMid = tri->vertex1; - vMax = tri->vertex2; - } else { - //printf("condition 3\n"); - vMin = tri->vertex1; - vMid = tri->vertex3; - vMax = tri->vertex2; - } - } else { - if(tri->vertex1->y <= tri->vertex3->y) { - //printf("condition 4\n"); - vMin = tri->vertex2; - vMid = tri->vertex1; - vMax = tri->vertex3; - } else if(tri->vertex3->y <= tri->vertex2->y) { - //printf("condition 5\n"); - vMin = tri->vertex3; - vMid = tri->vertex2; - vMax = tri->vertex1; - } else { - //printf("condition 6\n"); - vMin = tri->vertex2; - vMid = tri->vertex3; - vMax = tri->vertex1; - } - } - - Vertex *vMid10 = new Vertex(0,0,0,0,0); - vMid1(vMid10,vMin,vMid,vMax); - - half_triangle(vMin,vMid,vMid10,image); - half_triangle(vMax,vMid,vMid10,image); - - free(vMid10); -#if 0 - //cout << vMin->x << vMin->y << vMin->z << endl; - div_x = (int)vMid->y - (int)vMin->y; - if(div_x < 1 && div_x > -1) div_x = 1; - div_y = (int)vMax->y - (int)vMin->y; - if(div_y < 1 && div_y > -1) div_y = 1; - - for(i = 0; i < div_x+1; i++) { - //ここでspanの左端と右端のx,zを求めてる - tmp_xpos = calc(vMax->x - vMin->x,div_y, i, vMin->x); - tmp_end = calc(vMid->x - vMin->x,div_x, i, vMin->x); - tmp_z = calc(vMax->z - vMin->z,div_y, i, vMin->z); - tmp_zpos = calc(vMid->z - vMin->z,div_x, i, vMin->z); - - //ここからspanの左端と右端に対応するテクスチャを計算する - tmp_tex1 =( (i/(div_y)) * vMax->tex_x) + \ - ( ((div_y - i)/(div_y)) * vMin->tex_x); - tmp_tex2 =( (i/(div_x)) * vMid->tex_x) + \ - ( ((div_x - i)/(div_x)) * vMin->tex_x); - - tmp_tey1 =( (i/(div_y)) * vMax->tex_y) + \ - ( ((div_y - i)/(div_y)) * vMin->tex_y); - tmp_tey2 =( (i/(div_x)) * vMid->tex_y) + \ - ( ((div_x - i)/(div_x)) * vMin->tex_y); - - //ここで左端がxposかendを判断し、描画するspanを作る - if(tmp_xpos > tmp_end) { - x = (int)tmp_end; - y = (int)vMin->y + i; - end = (int)(tmp_xpos)-(int)(tmp_end)+1; - z = tmp_z; - zpos = tmp_zpos; - tex1 = tmp_tex2; - tex2 = tmp_tex1; - tey1 = tmp_tey2; - tey2 = tmp_tey1; - } else { - x = (int)tmp_xpos; - y = (int)vMin->y + i; - end = (int)(tmp_end)-(int)(tmp_xpos)+1; - z = tmp_zpos; - zpos = tmp_z; - tex1 = tmp_tex1; - tex2 = tmp_tex2; - tey1 = tmp_tey1; - tey2 = tmp_tey2; - } - //printf("%d:%f,%f ",(int)vMin->y + i,xpos,end); - //printf("%d:%d:%d:x:%d,end:%d\n",x, y , end,(int)(tmp_end),(int)(tmp_xpos)); - //printf("x:%d y:%d end:%d z:%f zpos:%f\n",x,y,end,z , zpos); - //printf("tex1:%f tex2:%f tey1:%f tey2:%f\n",tex1,tex2,tey1,tey2); - if(end == 1) { - //printf("tex_x:%f tex_y:%f\n",tex1,tex2); - if(tex1 > 1) tex1 = 1; - if(tey1 > 1) tey1 = 1; - tex_xpos = (int)(image->h-1) * tex1; - tex_ypos = (int)(image->w-1) * tey1; - tex_zpos = z; - //printf("tex_xpos:%d tex_ypos:%d\n",tex_xpos,tex_ypos); - //printf("image->h:%d tex_x:%f\n",image->h,tex1); - rgb = p->get_rgb(tex_xpos,tex_ypos); - //viewer->write_pixel(x,y,zpos,rgb); - }else { - for(j = 0; j < end; j++) { - tex_x = tex1*(end-1-j)/(end-1) + tex2*j/(end-1); - tex_y = tey1*(end-1-j)/(end-1) + tey2*j/(end-1); - tex_z = z*(end-1-j)/(end-1) + zpos*j/(end-1); - if(tex_x > 1) tex_x = 1; - if(tex_y > 1) tex_y = 1; - tex_xpos = (int)(image->h-1) * tex_x; - tex_ypos = (int)(image->w-1) * tex_y; - //printf("tex_xpos:%d tex_ypos:%d\n",tex_xpos,tex_ypos); - //printf("z:%f zpos:%f tex_z:%f\n",z,zpos,tex_z); - //printf("tex_x:%f tex_y:%f\n",tex_x,tex_y); - rgb = p->get_rgb(tex_xpos,tex_ypos); - //viewer->write_pixel(j+x,y,tex_z,rgb); - } - } - } - - top_triangle = (int)vMid->y - (int)vMin->y; - div_x = (int)vMax->y - (int)vMid->y; - if(div_x < 1 && div_x > -1) div_x = 1; - div_y = (int)vMax->y - (int)vMin->y; - if(div_y < 1 && div_y > -1) div_y = 1; - - for(i = 0; i < div_x; i++) { - //ここでspanの左端と右端のx,zを求めてる - tmp_xpos = calc(vMax->x-vMin->x, div_y, (i+1+top_triangle), vMin->x); - tmp_end = calc(vMax->x-vMid->x, div_x, (i+1), vMid->x); - tmp_z = calc(vMax->z-vMin->z, div_y, (i+1+top_triangle), vMin->z); - tmp_zpos = calc(vMax->z-vMid->z, div_x, (i+1), vMid->z); - - tmp_tex1 =( ((i + 1 +top_triangle)/(div_y)) * vMax->tex_x) + \ - ( ((div_y - i - 1 - top_triangle)/(div_y)) * vMin->tex_x); - tmp_tex2 =( ((i+1)/(div_x)) * vMax->tex_x) + \ - ( ((div_x - i -1)/(div_x)) * vMid->tex_x); - - tmp_tey1 =( ((i+1+top_triangle)/(div_y)) * vMax->tex_y) + \ - ( ((div_y - i - 1 - top_triangle)/(div_y)) * vMin->tex_y); - tmp_tey2 =( ((i+1)/(div_x)) * vMax->tex_y) + \ - ( ((div_x - i -1)/(div_x)) * vMid->tex_y); - if(tmp_xpos > tmp_end) { - x = (int)tmp_end; - y = (int)vMid->y+i+1; - end = (int)(tmp_xpos)-(int)(tmp_end)+1; - z = tmp_z; - zpos = tmp_zpos; - tex1 = tmp_tex2; - tex2 = tmp_tex1; - tey1 = tmp_tey2; - tey2 = tmp_tey1; - } else { - x = (int)tmp_xpos; - y = (int)vMid->y+i+1; - end = (int)(tmp_end)-(int)(tmp_xpos)+1; - z = tmp_zpos; - zpos = tmp_z; - tex1 = tmp_tex1; - tex2 = tmp_tex2; - tey1 = tmp_tey1; - tey2 = tmp_tey2; - } - if(end == 0) end = 1; - //printf("%d:%d:%d\n",x, y , end); - //printf("x:%d y:%d end:%d z:%f zpos:%f\n",x,y,end,z,zpos); - //printf("tex1:%f tex2:%f tey1:%f tey2:%f\n",tex1,tex2,tey1,tey2); - if(end == 1) { - //printf("tex_x:%f tex_y:%f\n",tex1,tex2); - if(tex1 > 1) tex1 = 1; - if(tey1 > 1) tey1 = 1; - tex_xpos = (int)(image->h-1) * tex1; - tex_ypos = (int)(image->w-1) * tey1; - tex_zpos = z; - //printf("tex_x:%f tex_y:%f\n",tex_x,tex_y); - //printf("tex_xpos:%d tex_ypos:%d\n",tex_xpos,tex_ypos); - //printf("tex_x:%f tex_y:%f\n",tex_x,tex_y); - rgb = p->get_rgb(tex_xpos,tex_ypos); - //viewer->write_pixel(x,y,tex_zpos,rgb); - }else { - for(j = 0; j < end; j++) { - tex_x = tex1*(end-1-j)/(end-1) + tex2*j/(end-1); - tex_y = tey1*(end-1-j)/(end-1) + tey2*j/(end-1); - tex_z = z*(end-1-j)/(end-1) + zpos*j/(end-1); - //printf("tex_x:%f tex_y:%f\n",tex_x,tex_y); - if(tex_x > 1) tex_x = 1; - if(tex_y > 1) tex_y = 1; - tex_xpos = (int)(image->h-2) * tex_x; - tex_ypos = (int)(image->w-1) * tex_y; - //printf("z:%f zpos:%f tex_z:%f\n",z,zpos,tex_z); - //printf("tex_xpos:%d tex_ypos:%d\n",tex_xpos,tex_ypos); - //printf("tex_x:%f tex_y:%f\n",tex_x,tex_y); - //printf("tex_x:%f tex_y:%f\n",tex_x,tex_y); - rgb = p->get_rgb(tex_xpos,tex_ypos); - //viewer->write_pixel(j+x,y,tex_z,rgb); - } - } - } -#endif -} - -// i:分子、f1:長さ f2:対応する頂点1 f3:対応する頂点2 -/* -float Span::calc2(int i, float f1, float f2, float f3) { - float ans; - ans = i/f1 * f2 + (f1-i)/f1 * f3; - - */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/TextureHash.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,53 @@ +#include <string.h> +#include <stdlib.h> +#include "TextureHash.h" + +static int id_count; + +TextureHash::TextureHash(void) +{ + table = (hashtable*)malloc(sizeof(hashtable)*TABLE_SIZE); + + for (int i = 0; i < TABLE_SIZE; i++) { + table[i].tx_id = -1; + table[i].key = NULL; + } +} + +TextureHash::~TextureHash(void) +{ + free(table); +} + +int +TextureHash::hash_function(const char *key) +{ + //float value = 0.0; + int value = 0; + + for (int i = 0; key[i]; i++) { + value += key[i]*(i+1)*17+1; + } + + return value%TABLE_SIZE; +} + +int +TextureHash::hash_regist(const char* key, int &id) +{ + int hash = hash_function(key); + + for (int i = 0; ; i++) { + if (table[hash].tx_id == -1) { + table[hash].key = (char*)key; + id = id_count++; + return 0; + + } else if (strcmp(key, table[hash].key) == 0 + && table[hash].tx_id != -1){ + id = table[hash].tx_id; + return 1; + } + hash = ((37*hash)^(11*i)) % TABLE_SIZE; + } +}
--- a/TaskManager/Test/test_render/TextureHash.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -#include <string.h> -#include <stdlib.h> -#include "TextureHash.h" - -static int id_count; - -TextureHash::TextureHash(void) -{ - table = (hashtable*)malloc(sizeof(hashtable)*TABLE_SIZE); - - for (int i = 0; i < TABLE_SIZE; i++) { - table[i].tx_id = -1; - table[i].key = NULL; - } -} - -TextureHash::~TextureHash(void) -{ - free(table); -} - -int -TextureHash::hash_function(const char *key) -{ - //float value = 0.0; - int value = 0; - - for (int i = 0; key[i]; i++) { - value += key[i]*(i+1)*17+1; - } - - return value%TABLE_SIZE; -} - -int -TextureHash::hash_regist(const char* key, int &id) -{ - int hash = hash_function(key); - - for (int i = 0; ; i++) { - if (table[hash].tx_id == -1) { - table[hash].key = (char*)key; - id = id_count++; - return 0; - - } else if (strcmp(key, table[hash].key) == 0 - && table[hash].tx_id != -1){ - id = table[hash].tx_id; - return 1; - } - hash = ((37*hash)^(11*i)) % TABLE_SIZE; - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/back_action.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,24 @@ +#include <iostream> +#include "SceneGraphRoot.h" +#include "SGList.h" +#include "ball_action.h" +using namespace std; + +void +back_move(SceneGraphPtr node, int w, int h) +{ + Pad *pad = sgroot->getController(); + + if (pad->triangle.isPush()) { + SceneGraphPtr ball = sgroot->createSceneGraph(Ball); + ball->xyz[0] = -100; + ball->set_move_collision(ball_move, ball_coll); + node->addChild(ball); + } +} + +void +back_coll(SceneGraphPtr node, int w, int h, SceneGraphPtr tree) +{ + +}
--- a/TaskManager/Test/test_render/back_action.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -#include <iostream> -#include "SceneGraphRoot.h" -#include "SGList.h" -#include "ball_action.h" -using namespace std; - -void -back_move(SceneGraphPtr node, int w, int h) -{ - Pad *pad = sgroot->getController(); - - if (pad->triangle.isPush()) { - SceneGraphPtr ball = sgroot->createSceneGraph(Ball); - ball->xyz[0] = -100; - ball->set_move_collision(ball_move, ball_coll); - node->addChild(ball); - } -} - -void -back_coll(SceneGraphPtr node, int w, int h, SceneGraphPtr tree) -{ - -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/ball_action.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,16 @@ +#include <iostream> +#include "SceneGraphRoot.h" +#include "SGList.h" +using namespace std; + +void +ball_move(SceneGraphPtr node, int w, int h) +{ + node->xyz[0] += 4; +} + +void +ball_coll(SceneGraphPtr node, int w, int h, SceneGraphPtr tree) +{ + if (node->xyz[0] > 600) node->remove(); +}
--- a/TaskManager/Test/test_render/ball_action.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -#include <iostream> -#include "SceneGraphRoot.h" -#include "SGList.h" -using namespace std; - -void -ball_move(SceneGraphPtr node, int w, int h) -{ - node->xyz[0] += 4; -} - -void -ball_coll(SceneGraphPtr node, int w, int h, SceneGraphPtr tree) -{ - if (node->xyz[0] > 600) node->remove(); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/ball_bound.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,128 @@ +#include <math.h> +#include <stdlib.h> +#include "SceneGraphRoot.h" +#include "SGList.h" + +// prototype +static void ball_move(SceneGraphPtr node, int screen_w, int screen_h); +static void ball_collision(SceneGraphPtr node, int screen_w, int screen_h, SceneGraphPtr tree); +static void ball_collision_idle(SceneGraphPtr, int w, int h, SceneGraphPtr tree); + + +static float vy = 0.0f; // y 方向速度 +static float dt = 1.0/1.0f; // frame rate + +static float e = -0.8f; // 反発係数 +static float g = 9.8f; // 重力加速度 +//static float v0 = 0.0f; // 初速は 0 + +static float h0; // 初期高さ +static float ball_radius = 100.0f; + +static float speed = 10.0f; + +static void +ball_move_idle2(SceneGraphPtr node, int screen_w, int screen_h) +{ + Pad *pad = sgroot->getController(); + + if (pad->circle.isHold()) { + if (pad->left.isHold()) { + node->xyz[0] -= speed; + if(node->xyz[0] < ball_radius) + node->xyz[0] = ball_radius; + } else if (pad->right.isHold()) { + node->xyz[0] += speed; + if(node->xyz[0] > screen_w - ball_radius) + node->xyz[0] = screen_w - ball_radius; + } + + if (pad->up.isHold()) { + node->xyz[1] -= speed; + } else if (pad->down.isHold()) { + node->xyz[1] += speed; + if(node->xyz[1] > screen_h - ball_radius) + node->xyz[1] = screen_h - ball_radius; + } + } else { + node->set_move_collision(ball_move, ball_collision); + } +} + +static int time = 0; + +static void +ball_move_idle(SceneGraphPtr node, int screen_w, int screen_h) +{ + Pad *pad = sgroot->getController(); + + if (pad->circle.isPush()) { + node->set_move_collision(ball_move_idle2, ball_collision_idle); + time = 0; + } + + time++; + + if (time > 90) { + float w = (float)random(); + + w = fmodf(w, screen_w - ball_radius*2); + node->xyz[0] = w + ball_radius; + node->xyz[1] = h0; + node->set_move_collision(ball_move, ball_collision); + time = 0; + } +} + +static void +ball_move(SceneGraphPtr node, int screen_w, int screen_h) +{ + vy += g * dt; + node->xyz[1] += vy * dt; + // node->xyz[0] += 10.0f; +} + +static void +ball_collision_idle(SceneGraphPtr, int w, int h, SceneGraphPtr tree) +{ +} + +static void +ball_collision(SceneGraphPtr node, int screen_w, int screen_h, + SceneGraphPtr tree) +{ + if (node->xyz[1] > screen_h - ball_radius) { + node->xyz[1] = screen_h - ball_radius; + + vy *= e; + if (vy > -g && vy < 0) { + vy = 0.0; + node->set_move_collision(ball_move_idle, ball_collision_idle); + } + } +} + + +void +ball_bound_init(TaskManager *manager, int screen_w, int screen_h) +{ + SceneGraphPtr ball; + + // 固定した値で srandom すると、毎回同じ、random() 列が生成される + // random な値が欲しいなら、man random に方法が書いてあります。 + srandom(100); + + sgroot->createFromXMLfile(manager, "xml_file/Ball.xml"); + ball = sgroot->createSceneGraph(Ball); + ball->set_move_collision(ball_move, ball_collision); + + h0 = screen_h/2; + h0 = -1000; + + ball->xyz[0] = screen_w/2; + //ball->xyz[0] = 0.0f; + ball->xyz[1] = h0; + ball->xyz[2] = 30.0f; + + sgroot->setSceneData(ball); +}
--- a/TaskManager/Test/test_render/ball_bound.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,128 +0,0 @@ -#include <math.h> -#include <stdlib.h> -#include "SceneGraphRoot.h" -#include "SGList.h" - -// prototype -static void ball_move(SceneGraphPtr node, int screen_w, int screen_h); -static void ball_collision(SceneGraphPtr node, int screen_w, int screen_h, SceneGraphPtr tree); -static void ball_collision_idle(SceneGraphPtr, int w, int h, SceneGraphPtr tree); - - -static float vy = 0.0f; // y 方向速度 -static float dt = 1.0/1.0f; // frame rate - -static float e = -0.8f; // 反発係数 -static float g = 9.8f; // 重力加速度 -//static float v0 = 0.0f; // 初速は 0 - -static float h0; // 初期高さ -static float ball_radius = 100.0f; - -static float speed = 10.0f; - -static void -ball_move_idle2(SceneGraphPtr node, int screen_w, int screen_h) -{ - Pad *pad = sgroot->getController(); - - if (pad->circle.isHold()) { - if (pad->left.isHold()) { - node->xyz[0] -= speed; - if(node->xyz[0] < ball_radius) - node->xyz[0] = ball_radius; - } else if (pad->right.isHold()) { - node->xyz[0] += speed; - if(node->xyz[0] > screen_w - ball_radius) - node->xyz[0] = screen_w - ball_radius; - } - - if (pad->up.isHold()) { - node->xyz[1] -= speed; - } else if (pad->down.isHold()) { - node->xyz[1] += speed; - if(node->xyz[1] > screen_h - ball_radius) - node->xyz[1] = screen_h - ball_radius; - } - } else { - node->set_move_collision(ball_move, ball_collision); - } -} - -static int time = 0; - -static void -ball_move_idle(SceneGraphPtr node, int screen_w, int screen_h) -{ - Pad *pad = sgroot->getController(); - - if (pad->circle.isPush()) { - node->set_move_collision(ball_move_idle2, ball_collision_idle); - time = 0; - } - - time++; - - if (time > 90) { - float w = (float)random(); - - w = fmodf(w, screen_w - ball_radius*2); - node->xyz[0] = w + ball_radius; - node->xyz[1] = h0; - node->set_move_collision(ball_move, ball_collision); - time = 0; - } -} - -static void -ball_move(SceneGraphPtr node, int screen_w, int screen_h) -{ - vy += g * dt; - node->xyz[1] += vy * dt; - // node->xyz[0] += 10.0f; -} - -static void -ball_collision_idle(SceneGraphPtr, int w, int h, SceneGraphPtr tree) -{ -} - -static void -ball_collision(SceneGraphPtr node, int screen_w, int screen_h, - SceneGraphPtr tree) -{ - if (node->xyz[1] > screen_h - ball_radius) { - node->xyz[1] = screen_h - ball_radius; - - vy *= e; - if (vy > -g && vy < 0) { - vy = 0.0; - node->set_move_collision(ball_move_idle, ball_collision_idle); - } - } -} - - -void -ball_bound_init(TaskManager *manager, int screen_w, int screen_h) -{ - SceneGraphPtr ball; - - // 固定した値で srandom すると、毎回同じ、random() 列が生成される - // random な値が欲しいなら、man random に方法が書いてあります。 - srandom(100); - - sgroot->createFromXMLfile(manager, "xml_file/Ball.xml"); - ball = sgroot->createSceneGraph(Ball); - ball->set_move_collision(ball_move, ball_collision); - - h0 = screen_h/2; - h0 = -1000; - - ball->xyz[0] = screen_w/2; - //ball->xyz[0] = 0.0f; - ball->xyz[1] = h0; - ball->xyz[2] = 30.0f; - - sgroot->setSceneData(ball); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/base64_de.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,91 @@ +#include <iostream> +#include <fstream> +using namespace std; + +class tagTT +{ +public: + unsigned char buf; + char *cont; + int nlen; +}; + + +unsigned char CtoNum(int c) +{ + if (c >= 'A' && c <= 'Z') return c-'A'; + if (c >= 'a' && c <= 'z') return (c - 'a')+26; + if (c >= '0' && c <= '9') return (c - '0')+52; + if (c == '+') return 62; + if (c == '/') return 63; + return 0; +} + + +int GetNumB64(tagTT &pWork) +{ + char wr; + unsigned char w; + unsigned char r; + + wr = *pWork.cont; + pWork.cont++; + if (wr=='\0' || wr=='=') + return -1; + + while(wr=='\n' || wr=='\t') + { + wr = *pWork.cont; + pWork.cont++; + } + + w = CtoNum(wr); + if (pWork.nlen == 0) + { + unsigned char w2; + + wr = *pWork.cont; + pWork.cont++; + if (wr!='\0' && wr!='=') + w2 = CtoNum(wr); + else + w2 = 0; + + pWork.buf = w << 2; + w = w2; + pWork.nlen = 6; + } + + pWork.nlen -= 2; + + r = pWork.buf | (w >> pWork.nlen); + + pWork.buf = (w << (8 - pWork.nlen)); + return r; +} + + +//int decode(char *cont, char *file_name) +int decode(char *cont, FILE *outfile) +{ + int rw; + tagTT work; + + //ofstream outfile(file_name); + + work.buf = 0; + work.nlen = 0; + work.cont = cont; + + rw = GetNumB64(work); + while ( rw != -1 ) + { + //outfile << (char)rw; + putc(rw, outfile); + rw = GetNumB64(work); + } + + //outfile.close(); + + return 0; +}
--- a/TaskManager/Test/test_render/base64_de.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,91 +0,0 @@ -#include <iostream> -#include <fstream> -using namespace std; - -class tagTT -{ -public: - unsigned char buf; - char *cont; - int nlen; -}; - - -unsigned char CtoNum(int c) -{ - if (c >= 'A' && c <= 'Z') return c-'A'; - if (c >= 'a' && c <= 'z') return (c - 'a')+26; - if (c >= '0' && c <= '9') return (c - '0')+52; - if (c == '+') return 62; - if (c == '/') return 63; - return 0; -} - - -int GetNumB64(tagTT &pWork) -{ - char wr; - unsigned char w; - unsigned char r; - - wr = *pWork.cont; - pWork.cont++; - if (wr=='\0' || wr=='=') - return -1; - - while(wr=='\n' || wr=='\t') - { - wr = *pWork.cont; - pWork.cont++; - } - - w = CtoNum(wr); - if (pWork.nlen == 0) - { - unsigned char w2; - - wr = *pWork.cont; - pWork.cont++; - if (wr!='\0' && wr!='=') - w2 = CtoNum(wr); - else - w2 = 0; - - pWork.buf = w << 2; - w = w2; - pWork.nlen = 6; - } - - pWork.nlen -= 2; - - r = pWork.buf | (w >> pWork.nlen); - - pWork.buf = (w << (8 - pWork.nlen)); - return r; -} - - -//int decode(char *cont, char *file_name) -int decode(char *cont, FILE *outfile) -{ - int rw; - tagTT work; - - //ofstream outfile(file_name); - - work.buf = 0; - work.nlen = 0; - work.cont = cont; - - rw = GetNumB64(work); - while ( rw != -1 ) - { - //outfile << (char)rw; - putc(rw, outfile); - rw = GetNumB64(work); - } - - //outfile.close(); - - return 0; -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/boss1_action.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,269 @@ +#include "SGList.h" +#include "boss1_action.h" + +/* +static void +null_move(SceneGraphPtr node, int screen_w, int screen_h) +{ +} +*/ + +static void +null_collision(SceneGraphPtr node, int screen_w, int screen_h, + SceneGraphPtr tree) +{ +} + + +static void +boss1_move_right(SceneGraphPtr node, int screen_w, int screen_h) { + node->xyz[0] += node->stack_xyz[0]; + if(node->xyz[0] > (screen_w - boss_radius_x)) { + node->set_move_collision(boss1_move_left, null_collision); + } +} + +//ボスが左に移動する動作 +static void +boss1_move_left(SceneGraphPtr node, int screen_w, int screen_h) { + node->xyz[0] -= node->stack_xyz[0]; + if(node->xyz[0] < boss_radius_x) { + node->set_move_collision(boss1_move_right, null_collision); + } +} + +//ボスが戦闘位置へ戻る時の動作 +/* +static void +boss1_move_return(SceneGraphPtr node, int screen_w, int screen_h) +{ + node->xyz[1] -= node->stack_xyz[1]; + node->xyz[2] -= node->stack_xyz[2]; + + if((node->xyz[2] = 0)) { + node->stack_xyz[0] = 1.0; + node->set_move_collision(boss1_move_left, null_collision); + } +} +*/ + +//ボス登場時の動き +/* +static void +boss1_first_move(SceneGraphPtr node, int screen_w, int screen_h) +{ + node->xyz[1] += node->stack_xyz[1]; + if(node->xyz[1] > screen_h) { + float time = first_boss1_depth / node->stack_xyz[2]; + node->stack_xyz[1] = (screen_h - boss_radius_y) / time; + node->stack_xyz[2] = return_boss1_depth_speed; + node->set_move_collision(boss1_move_return, null_collision); + } +} +*/ + +static void +player_move(SceneGraphPtr node, int screen_w, int screen_h) +{ + Pad *pad = sgroot->getController(); + + if (pad->left.isPush() + || pad->left.isHold()) { +#if 0 + SceneGraphPtr player_left; + player_left = sgroot->createSceneGraph(PLAYER_L); + player_left->set_move_collision(player_move_left, null_collision); + player_left->xyz[0] = node->xyz[0]; + player_left->xyz[1] = node->xyz[1]; + node->addChild(player_left); + node->flag_drawable = 1; +#endif + node->xyz[0] -= player_speed; + + if (node->xyz[0] - player_radius< 0) { + node->xyz[0] = player_radius; + } + } + + + if (pad->right.isPush() + || pad->right.isHold()) { + node->xyz[0] += player_speed; + + if (node->xyz[0] + player_radius > screen_w) { + node->xyz[0] = screen_w - player_radius; + } + } + + if (pad->up.isPush() + || pad->up.isHold()) { + node->xyz[1] -= player_speed; + + if (node->xyz[1] - player_radius < 0) { + node->xyz[1] = player_radius; + } + } + + if (pad->down.isPush() + || pad->down.isHold()) { + node->xyz[1] += player_speed; + + if (node->xyz[1] + player_radius > screen_h) { + node->xyz[1] = screen_h - player_radius; + } + } + + if (pad->circle.isPush()) { + SceneGraphPtr shot = sgroot->createSceneGraph(P_SHOT1); + shot->set_move_collision(shot_move, shot_collision); + shot->xyz[0] = node->xyz[0]; + shot->xyz[1] = node->xyz[1] - player_radius; + node->addBrother(shot); + } +} + +static void +player_collision(SceneGraphPtr node, int screen_w, int screen_h, + SceneGraphPtr tree) +{ + //自機とボスのx,y座標での距離と2点間の距離 + static float x_distant, y_distant, distance; + //ボスの四角形の四隅の座標 + // static float boss_low_x, boss_low_y, boss_high_x, boss_high_y; + + SceneGraphIteratorPtr it = sgroot->getIterator(tree); + + + for (; it->hasNext(BOSS1);) { + it->next(BOSS1); + SceneGraphPtr enemy = it->get(); + + //各変数の初期化 + x_distant = node->xyz[0] - enemy->xyz[0]; + y_distant = node->xyz[1] - enemy->xyz[1]; + + //hypotfで2点間の距離を求める + distance = hypotf(x_distant, y_distant); + + /*四角形と円のcollision + if( (fabs( node->xyz[1] - ( boss_low_y ))) + */ + + //円同士のcollision + if(distance < (player_radius + boss_radius_y)) { + printf("!!!CAUTION!!!\n"); + } + } +} + +static void +shot_move(SceneGraphPtr node, int screen_w, int screen_h) +{ + node->xyz[1] -= shot_speed; + + // 描画領域から抜けたら削除 + if (node->xyz[1] < 0) { + node->remove(); + } +} + +static void +shot_collision(SceneGraphPtr node, int screen_2, int screen_h, + SceneGraphPtr tree) +{ + //自機とボスのx,y座標での距離と2点間の距離 + static float x_distant, y_distant, distance; + //ボスの四角形の四隅の座標 + // static float boss_low_x, boss_low_y, boss_high_x, boss_high_y; + + SceneGraphIteratorPtr it = sgroot->getIterator(tree); + + + for (; it->hasNext(BOSS1);) { + it->next(BOSS1); + SceneGraphPtr enemy = it->get(); + + x_distant = node->xyz[0] - enemy->xyz[0]; + y_distant = node->xyz[1] - enemy->xyz[1]; + + //hypotfで2点間の距離を求める + distance = hypotf(x_distant, y_distant); + + //円同士のcollision + if(distance < boss_radius_y) { + SceneGraphPtr blast = sgroot->createSceneGraph(BLAST1); + + blast->set_move_collision(blast_move, null_collision); + blast->xyz[0] = node->xyz[0]; + blast->xyz[1] = node->xyz[1]; + node->addBrother(blast); + node->remove(); + } + } +} + +static void +blast_move(SceneGraphPtr node, int screen_w, int screen_h) +{ + if(node->sgid > BLAST8) { + SceneGraphPtr blast = sgroot->createSceneGraph(node->sgid - 1); + blast->set_move_collision(blast_move, null_collision); + blast->xyz[0] = node->xyz[0]; + blast->xyz[1] = node->xyz[1]; + node->addBrother(blast); + } + + if (node->sgid == BLAST8) { + node->flag_drawable = 1; + } + + if((node->frame > 1)) { + node->remove(); + } + node->frame += 1; +} + +void +boss1_init(TaskManager *manager, int screen_w, int screen_h) +{ + SceneGraphPtr root; + SceneGraphPtr player; + SceneGraphPtr boss1; + SceneGraphPtr left_parts; + SceneGraphPtr right_parts; + + sgroot->createFromXMLfile(manager, "xml_file/boss1.xml"); + sgroot->createFromXMLfile(manager, "xml_file/player1.xml"); + sgroot->createFromXMLfile(manager, "xml_file/p_shot.xml"); + sgroot->createFromXMLfile(manager, "xml_file/blast.xml"); + + //rootとなるSceneGraphを生成 + root = sgroot->createSceneGraph(); + + //自機の初期化 + player = sgroot->createSceneGraph(PLAYER); + player->xyz[0] = screen_w/2; + player->xyz[1] = screen_h - player_radius; + root->addChild(player); + + //ボスの初期化 + boss1 = sgroot->createSceneGraph(BOSS1); + boss1->xyz[0] = screen_w/2; + boss1->xyz[1] = boss_radius_y; + // boss1->xyz[2] = first_boss1_depth; + boss1->stack_xyz[0] = first_boss1_speed; + root->addChild(boss1); + + //ボスの左右パーツを追加 + left_parts = sgroot->createSceneGraph(BOSS1_L); + boss1->addChild(left_parts); + right_parts = sgroot->createSceneGraph(BOSS1_R); + boss1->addChild(right_parts); + + //各機体の動きと当たり判定をセット + player->set_move_collision(player_move, player_collision); + boss1->set_move_collision(boss1_move_left, null_collision); + + //仕上げ + sgroot->setSceneData(root); +}
--- a/TaskManager/Test/test_render/boss1_action.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,269 +0,0 @@ -#include "SGList.h" -#include "boss1_action.h" - -/* -static void -null_move(SceneGraphPtr node, int screen_w, int screen_h) -{ -} -*/ - -static void -null_collision(SceneGraphPtr node, int screen_w, int screen_h, - SceneGraphPtr tree) -{ -} - - -static void -boss1_move_right(SceneGraphPtr node, int screen_w, int screen_h) { - node->xyz[0] += node->stack_xyz[0]; - if(node->xyz[0] > (screen_w - boss_radius_x)) { - node->set_move_collision(boss1_move_left, null_collision); - } -} - -//ボスが左に移動する動作 -static void -boss1_move_left(SceneGraphPtr node, int screen_w, int screen_h) { - node->xyz[0] -= node->stack_xyz[0]; - if(node->xyz[0] < boss_radius_x) { - node->set_move_collision(boss1_move_right, null_collision); - } -} - -//ボスが戦闘位置へ戻る時の動作 -/* -static void -boss1_move_return(SceneGraphPtr node, int screen_w, int screen_h) -{ - node->xyz[1] -= node->stack_xyz[1]; - node->xyz[2] -= node->stack_xyz[2]; - - if((node->xyz[2] = 0)) { - node->stack_xyz[0] = 1.0; - node->set_move_collision(boss1_move_left, null_collision); - } -} -*/ - -//ボス登場時の動き -/* -static void -boss1_first_move(SceneGraphPtr node, int screen_w, int screen_h) -{ - node->xyz[1] += node->stack_xyz[1]; - if(node->xyz[1] > screen_h) { - float time = first_boss1_depth / node->stack_xyz[2]; - node->stack_xyz[1] = (screen_h - boss_radius_y) / time; - node->stack_xyz[2] = return_boss1_depth_speed; - node->set_move_collision(boss1_move_return, null_collision); - } -} -*/ - -static void -player_move(SceneGraphPtr node, int screen_w, int screen_h) -{ - Pad *pad = sgroot->getController(); - - if (pad->left.isPush() - || pad->left.isHold()) { -#if 0 - SceneGraphPtr player_left; - player_left = sgroot->createSceneGraph(PLAYER_L); - player_left->set_move_collision(player_move_left, null_collision); - player_left->xyz[0] = node->xyz[0]; - player_left->xyz[1] = node->xyz[1]; - node->addChild(player_left); - node->flag_drawable = 1; -#endif - node->xyz[0] -= player_speed; - - if (node->xyz[0] - player_radius< 0) { - node->xyz[0] = player_radius; - } - } - - - if (pad->right.isPush() - || pad->right.isHold()) { - node->xyz[0] += player_speed; - - if (node->xyz[0] + player_radius > screen_w) { - node->xyz[0] = screen_w - player_radius; - } - } - - if (pad->up.isPush() - || pad->up.isHold()) { - node->xyz[1] -= player_speed; - - if (node->xyz[1] - player_radius < 0) { - node->xyz[1] = player_radius; - } - } - - if (pad->down.isPush() - || pad->down.isHold()) { - node->xyz[1] += player_speed; - - if (node->xyz[1] + player_radius > screen_h) { - node->xyz[1] = screen_h - player_radius; - } - } - - if (pad->circle.isPush()) { - SceneGraphPtr shot = sgroot->createSceneGraph(P_SHOT1); - shot->set_move_collision(shot_move, shot_collision); - shot->xyz[0] = node->xyz[0]; - shot->xyz[1] = node->xyz[1] - player_radius; - node->addBrother(shot); - } -} - -static void -player_collision(SceneGraphPtr node, int screen_w, int screen_h, - SceneGraphPtr tree) -{ - //自機とボスのx,y座標での距離と2点間の距離 - static float x_distant, y_distant, distance; - //ボスの四角形の四隅の座標 - // static float boss_low_x, boss_low_y, boss_high_x, boss_high_y; - - SceneGraphIteratorPtr it = sgroot->getIterator(tree); - - - for (; it->hasNext(BOSS1);) { - it->next(BOSS1); - SceneGraphPtr enemy = it->get(); - - //各変数の初期化 - x_distant = node->xyz[0] - enemy->xyz[0]; - y_distant = node->xyz[1] - enemy->xyz[1]; - - //hypotfで2点間の距離を求める - distance = hypotf(x_distant, y_distant); - - /*四角形と円のcollision - if( (fabs( node->xyz[1] - ( boss_low_y ))) - */ - - //円同士のcollision - if(distance < (player_radius + boss_radius_y)) { - printf("!!!CAUTION!!!\n"); - } - } -} - -static void -shot_move(SceneGraphPtr node, int screen_w, int screen_h) -{ - node->xyz[1] -= shot_speed; - - // 描画領域から抜けたら削除 - if (node->xyz[1] < 0) { - node->remove(); - } -} - -static void -shot_collision(SceneGraphPtr node, int screen_2, int screen_h, - SceneGraphPtr tree) -{ - //自機とボスのx,y座標での距離と2点間の距離 - static float x_distant, y_distant, distance; - //ボスの四角形の四隅の座標 - // static float boss_low_x, boss_low_y, boss_high_x, boss_high_y; - - SceneGraphIteratorPtr it = sgroot->getIterator(tree); - - - for (; it->hasNext(BOSS1);) { - it->next(BOSS1); - SceneGraphPtr enemy = it->get(); - - x_distant = node->xyz[0] - enemy->xyz[0]; - y_distant = node->xyz[1] - enemy->xyz[1]; - - //hypotfで2点間の距離を求める - distance = hypotf(x_distant, y_distant); - - //円同士のcollision - if(distance < boss_radius_y) { - SceneGraphPtr blast = sgroot->createSceneGraph(BLAST1); - - blast->set_move_collision(blast_move, null_collision); - blast->xyz[0] = node->xyz[0]; - blast->xyz[1] = node->xyz[1]; - node->addBrother(blast); - node->remove(); - } - } -} - -static void -blast_move(SceneGraphPtr node, int screen_w, int screen_h) -{ - if(node->sgid > BLAST8) { - SceneGraphPtr blast = sgroot->createSceneGraph(node->sgid - 1); - blast->set_move_collision(blast_move, null_collision); - blast->xyz[0] = node->xyz[0]; - blast->xyz[1] = node->xyz[1]; - node->addBrother(blast); - } - - if (node->sgid == BLAST8) { - node->flag_drawable = 1; - } - - if((node->frame > 1)) { - node->remove(); - } - node->frame += 1; -} - -void -boss1_init(TaskManager *manager, int screen_w, int screen_h) -{ - SceneGraphPtr root; - SceneGraphPtr player; - SceneGraphPtr boss1; - SceneGraphPtr left_parts; - SceneGraphPtr right_parts; - - sgroot->createFromXMLfile(manager, "xml_file/boss1.xml"); - sgroot->createFromXMLfile(manager, "xml_file/player1.xml"); - sgroot->createFromXMLfile(manager, "xml_file/p_shot.xml"); - sgroot->createFromXMLfile(manager, "xml_file/blast.xml"); - - //rootとなるSceneGraphを生成 - root = sgroot->createSceneGraph(); - - //自機の初期化 - player = sgroot->createSceneGraph(PLAYER); - player->xyz[0] = screen_w/2; - player->xyz[1] = screen_h - player_radius; - root->addChild(player); - - //ボスの初期化 - boss1 = sgroot->createSceneGraph(BOSS1); - boss1->xyz[0] = screen_w/2; - boss1->xyz[1] = boss_radius_y; - // boss1->xyz[2] = first_boss1_depth; - boss1->stack_xyz[0] = first_boss1_speed; - root->addChild(boss1); - - //ボスの左右パーツを追加 - left_parts = sgroot->createSceneGraph(BOSS1_L); - boss1->addChild(left_parts); - right_parts = sgroot->createSceneGraph(BOSS1_R); - boss1->addChild(right_parts); - - //各機体の動きと当たり判定をセット - player->set_move_collision(player_move, player_collision); - boss1->set_move_collision(boss1_move_left, null_collision); - - //仕上げ - sgroot->setSceneData(root); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/bullet_action.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,65 @@ +#include <math.h> +#include "SceneGraphRoot.h" +#include "SGList.h" +#include "hit_judge.h" +#define PI M_PI + +int i = 0; + +void +bullet_init(SceneGraphPtr bullet, SceneGraphPtr player) +{ + bullet->xyz[0] = player->xyz[0]; + bullet->xyz[1] = player->xyz[1]; + bullet->xyz[2] = player->xyz[2]; + + bullet->angle[0] = player->angle[0]; + bullet->angle[1] = player->angle[1]; + bullet->angle[2] = player->angle[2]; +} + +void +bluebullet_move(SceneGraphPtr node, int screen_w, int screen_h) +{ + double a = (node->angle[2]+90)*PI/180; + double b = (node->angle[0]+90)*PI/180; + + double y = sin(a); + double x = cos(a); + double z = -cos(b); + + node->xyz[0] += x * 5;//x軸方向 + node->xyz[1] += y * 5;//y軸方向 + node->xyz[2] += z * 5;//z軸方向 +} + +void +bullet_collision(SceneGraphPtr node, int screen_w, int screen_h, SceneGraphPtr tree) +{ + SceneGraphIteratorPtr it = sgroot->getIterator(tree); + //static int damage = 0; + + for (; it->hasNext(E_PLANE);) { + it->next(E_PLANE); + SceneGraphPtr enemy = it->get(); + + int judge = square_judge(node, enemy); + if(judge == HIT) + { + //node->set_move_collision(null_move, bullet_collision); + //E_PLANE->set_move_collision(null_move, enemy_collision); + enemy->remove(); + node->remove(); + //printf("hit!!!\n"); + //bullet_delete(node, scene_graph); + } + } + + if(node->xyz[1] > 100) + { + node->remove(); + //scene_graph->delete_object(node, node->next,node->prev); + //i -= 1; + //printf("bullet_delete:残り弾数=%d\n",i); + } +}
--- a/TaskManager/Test/test_render/bullet_action.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -#include <math.h> -#include "SceneGraphRoot.h" -#include "SGList.h" -#include "hit_judge.h" -#define PI M_PI - -int i = 0; - -void -bullet_init(SceneGraphPtr bullet, SceneGraphPtr player) -{ - bullet->xyz[0] = player->xyz[0]; - bullet->xyz[1] = player->xyz[1]; - bullet->xyz[2] = player->xyz[2]; - - bullet->angle[0] = player->angle[0]; - bullet->angle[1] = player->angle[1]; - bullet->angle[2] = player->angle[2]; -} - -void -bluebullet_move(SceneGraphPtr node, int screen_w, int screen_h) -{ - double a = (node->angle[2]+90)*PI/180; - double b = (node->angle[0]+90)*PI/180; - - double y = sin(a); - double x = cos(a); - double z = -cos(b); - - node->xyz[0] += x * 5;//x軸方向 - node->xyz[1] += y * 5;//y軸方向 - node->xyz[2] += z * 5;//z軸方向 -} - -void -bullet_collision(SceneGraphPtr node, int screen_w, int screen_h, SceneGraphPtr tree) -{ - SceneGraphIteratorPtr it = sgroot->getIterator(tree); - //static int damage = 0; - - for (; it->hasNext(E_PLANE);) { - it->next(E_PLANE); - SceneGraphPtr enemy = it->get(); - - int judge = square_judge(node, enemy); - if(judge == HIT) - { - //node->set_move_collision(null_move, bullet_collision); - //E_PLANE->set_move_collision(null_move, enemy_collision); - enemy->remove(); - node->remove(); - //printf("hit!!!\n"); - //bullet_delete(node, scene_graph); - } - } - - if(node->xyz[1] > 100) - { - node->remove(); - //scene_graph->delete_object(node, node->next,node->prev); - //i -= 1; - //printf("bullet_delete:残り弾数=%d\n",i); - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/camera_action.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,58 @@ +#include "SceneGraphRoot.h" +#include "SGList.h" +#include "camera_action.h" + +#define MOVE_SPEED 0.10 + +void +camera_init(SceneGraphPtr node, int screen_w, int screen_h) +{ + node->xyz[0] = screen_w/2; + node->xyz[1] = screen_h/2 + 50; + node->xyz[2] = 0; + node->angle[0] = 120; +} + +void +c_move(SceneGraphPtr node, int screen_w, int screen_h) +{ + Pad *pad = sgroot->getController(); + + if(pad->right.isHold()) + { + if(node->xyz[0]>screen_w/2 - 50) + { + node->xyz[0]-=MOVE_SPEED; + } + } + + if(pad->left.isHold()) + { + if(node->xyz[0]<screen_w/2 + 50) + { + node->xyz[0]+=MOVE_SPEED; + } + } + + if(pad->down.isHold()) + { + if(node->xyz[2]>-25) + { + node->xyz[2]-=MOVE_SPEED; + } + } + + if(pad->up.isHold()) + { + if(node->xyz[2]<25) + { + node->xyz[2]+=MOVE_SPEED; + } + } + +} + +void +camera_collision(SceneGraphPtr node, int screen_w, int screen_h,SceneGraphPtr tree) +{ +}
--- a/TaskManager/Test/test_render/camera_action.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -#include "SceneGraphRoot.h" -#include "SGList.h" -#include "camera_action.h" - -#define MOVE_SPEED 0.10 - -void -camera_init(SceneGraphPtr node, int screen_w, int screen_h) -{ - node->xyz[0] = screen_w/2; - node->xyz[1] = screen_h/2 + 50; - node->xyz[2] = 0; - node->angle[0] = 120; -} - -void -c_move(SceneGraphPtr node, int screen_w, int screen_h) -{ - Pad *pad = sgroot->getController(); - - if(pad->right.isHold()) - { - if(node->xyz[0]>screen_w/2 - 50) - { - node->xyz[0]-=MOVE_SPEED; - } - } - - if(pad->left.isHold()) - { - if(node->xyz[0]<screen_w/2 + 50) - { - node->xyz[0]+=MOVE_SPEED; - } - } - - if(pad->down.isHold()) - { - if(node->xyz[2]>-25) - { - node->xyz[2]-=MOVE_SPEED; - } - } - - if(pad->up.isHold()) - { - if(node->xyz[2]<25) - { - node->xyz[2]+=MOVE_SPEED; - } - } - -} - -void -camera_collision(SceneGraphPtr node, int screen_w, int screen_h,SceneGraphPtr tree) -{ -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/chain.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,170 @@ +#include <iostream> +#include <math.h> +#include "SceneGraphRoot.h" +#include "SceneGraph.h" +#include "SGList.h" +#include "TaskManager.h" +#include "Func.h" + +#define FALSE 0 +#define TRUE !FALSE +#define CHAIN_LEN 50 + +static double chain_width = 10; + +typedef struct { + double x, y, next_x, next_y; + double vx, vy, next_vx, next_vy; + double angle[3]; + int can_move; + SceneGraphPtr parent; + int id; + //int parent; +} CHAIN_VARS; + +/* SceneGraph の property */ +CHAIN_VARS* properties[2]; +CHAIN_VARS* property; + + +//void createSceneGraphFromProperty(CHAIN_VARS* p) ; +void createSceneGraphFromProperty(void* p) ; + +void +init_chain_vars(CHAIN_VARS *cv) { + cv->x = 0, cv->y = 0, cv->next_x = 0, cv->next_y = 0; + cv->vx = 0, cv->vy = 0, cv->next_vx = 0, cv->next_vy = 0; + cv->can_move = TRUE; +} + +void +set_vector(CHAIN_VARS *p, SceneGraphPtr sg) { + sg->xyz[0] = p->next_x; + sg->xyz[1] = p->next_y; + sg->xyz[2] = 0.0f; + sg->angle[0] = p->angle[0]; + sg->angle[1] = p->angle[1]; + sg->angle[2] = p->angle[2]; +} + + +static void +chain_move_ope(SceneGraphPtr node, int screen_w, int screen_h) +{ + Pad *pad = sgroot->getController(); + + if (pad->circle.isHold()) { + property[CHAIN_LEN-1].can_move = FALSE; + if (pad->left.isHold()) { + property[CHAIN_LEN-1].x += -5.0; + } else if (pad->right.isHold()) { + property[CHAIN_LEN-1].x += 5.0; + } + + if (pad->up.isHold()) { + property[CHAIN_LEN-1].y += -5.0; + } else if (pad->down.isHold()) { + property[CHAIN_LEN-1].y += 5.0; + } + } else { + property[CHAIN_LEN-1].can_move = TRUE; + } +} + +void +chain_move(TaskManager *manager, SceneGraphPtr sg, int w, int h) +{ + int id = sg->id; + //CHAIN_VARS* p = (CHAIN_VARS*)sg->propertyptr; + HTaskPtr chain_cal; + CHAIN_VARS* output; + + // SceneGraph の切り替えもここでやる + if (property == properties[0]) { + property = properties[1]; + output = properties[0]; + }else{ + property = properties[0]; + output = properties[1]; + } + chain_cal = manager->create_task(CHAINCAL_TASK); + chain_cal->add_inData(property, sizeof(CHAIN_VARS)*CHAIN_LEN); + chain_cal->add_param(id); + chain_cal->add_outData(output, sizeof(CHAIN_VARS)*CHAIN_LEN); + chain_cal->set_post(createSceneGraphFromProperty, (void*)id); + chain_cal->spawn(); + +} + +void +chain_collision(SceneGraphPtr sg, int w, int h, SceneGraphPtr osg) +{ + +} + +void +createSceneGraphFromProperty(void* p) +{ + CHAIN_VARS* chain_p = (CHAIN_VARS*)p; + SceneGraphPtr chain_copy = sgroot->createSceneGraph(CHAIN); + chain_copy->propertyptr = (void*)chain_p; + chain_copy->property_size = sizeof(CHAIN_VARS); + set_vector(chain_p, chain_copy); + chain_p->parent->addChild(chain_copy); +} + +void +chain_init(TaskManager *manager, int w, int h) +{ + SceneGraphPtr root_chain, chain; + CHAIN_VARS rcv; + + HTaskPtr chain_init; + + + sgroot->createFromXMLfile(manager, "xml_file/chain.xml"); + + /* SPE に送る property の配列の領域確保 */ + properties[0] = (CHAIN_VARS*)manager->allocate(sizeof(CHAIN_VARS)*CHAIN_LEN); + properties[1] = (CHAIN_VARS*)manager->allocate(sizeof(CHAIN_VARS)*CHAIN_LEN); + property = properties[0]; + + root_chain = sgroot->createSceneGraph(CHAIN); + // set_move_collision()ではだめ + root_chain->set_move_collision(chain_move_ope, chain_collision); + init_chain_vars(&rcv); + rcv.next_x = w / 2; + rcv.next_y = 0.0; + rcv.angle[0] = 0; + rcv.angle[1] = 0; + rcv.angle[2] = 0; + + set_vector(&rcv, root_chain); + + for(int i = 0; i < CHAIN_LEN; i++) { + chain = sgroot->createSceneGraph(CHAIN); + property[i].id = i; + init_chain_vars(&property[i]); + property[i].x = 0; + property[i].y = chain_width * i; + set_vector(&property[i], chain); + property->angle[1] = -90 * (i % 2); + //chain->set_move_collision(chain_move, chain_collision); + chain->propertyptr = &property[i]; + chain->property_size = sizeof(CHAIN_VARS); + root_chain->addChild(chain); + property[i].parent = root_chain; + } + property[0].can_move = FALSE; + + // property を SPU の共有領域へコピーする + chain_init = manager->create_task(CHAININIT_TASK); + chain_init->add_inData(property, sizeof(CHAIN_VARS)*CHAIN_LEN); + chain_init->add_param(CHAIN_LEN); + chain_init->set_cpu(SPE_0); + chain_init->set_post(createSceneGraphFromProperty, (void*)property); + chain_init->spawn(); + + sgroot->setSceneData(root_chain); +} +
--- a/TaskManager/Test/test_render/chain.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,170 +0,0 @@ -#include <iostream> -#include <math.h> -#include "SceneGraphRoot.h" -#include "SceneGraph.h" -#include "SGList.h" -#include "TaskManager.h" -#include "Func.h" - -#define FALSE 0 -#define TRUE !FALSE -#define CHAIN_LEN 50 - -static double chain_width = 10; - -typedef struct { - double x, y, next_x, next_y; - double vx, vy, next_vx, next_vy; - double angle[3]; - int can_move; - SceneGraphPtr parent; - int id; - //int parent; -} CHAIN_VARS; - -/* SceneGraph の property */ -CHAIN_VARS* properties[2]; -CHAIN_VARS* property; - - -//void createSceneGraphFromProperty(CHAIN_VARS* p) ; -void createSceneGraphFromProperty(void* p) ; - -void -init_chain_vars(CHAIN_VARS *cv) { - cv->x = 0, cv->y = 0, cv->next_x = 0, cv->next_y = 0; - cv->vx = 0, cv->vy = 0, cv->next_vx = 0, cv->next_vy = 0; - cv->can_move = TRUE; -} - -void -set_vector(CHAIN_VARS *p, SceneGraphPtr sg) { - sg->xyz[0] = p->next_x; - sg->xyz[1] = p->next_y; - sg->xyz[2] = 0.0f; - sg->angle[0] = p->angle[0]; - sg->angle[1] = p->angle[1]; - sg->angle[2] = p->angle[2]; -} - - -static void -chain_move_ope(SceneGraphPtr node, int screen_w, int screen_h) -{ - Pad *pad = sgroot->getController(); - - if (pad->circle.isHold()) { - property[CHAIN_LEN-1].can_move = FALSE; - if (pad->left.isHold()) { - property[CHAIN_LEN-1].x += -5.0; - } else if (pad->right.isHold()) { - property[CHAIN_LEN-1].x += 5.0; - } - - if (pad->up.isHold()) { - property[CHAIN_LEN-1].y += -5.0; - } else if (pad->down.isHold()) { - property[CHAIN_LEN-1].y += 5.0; - } - } else { - property[CHAIN_LEN-1].can_move = TRUE; - } -} - -void -chain_move(TaskManager *manager, SceneGraphPtr sg, int w, int h) -{ - int id = sg->id; - //CHAIN_VARS* p = (CHAIN_VARS*)sg->propertyptr; - HTaskPtr chain_cal; - CHAIN_VARS* output; - - // SceneGraph の切り替えもここでやる - if (property == properties[0]) { - property = properties[1]; - output = properties[0]; - }else{ - property = properties[0]; - output = properties[1]; - } - chain_cal = manager->create_task(CHAINCAL_TASK); - chain_cal->add_inData(property, sizeof(CHAIN_VARS)*CHAIN_LEN); - chain_cal->add_param(id); - chain_cal->add_outData(output, sizeof(CHAIN_VARS)*CHAIN_LEN); - chain_cal->set_post(createSceneGraphFromProperty, (void*)id); - chain_cal->spawn(); - -} - -void -chain_collision(SceneGraphPtr sg, int w, int h, SceneGraphPtr osg) -{ - -} - -void -createSceneGraphFromProperty(void* p) -{ - CHAIN_VARS* chain_p = (CHAIN_VARS*)p; - SceneGraphPtr chain_copy = sgroot->createSceneGraph(CHAIN); - chain_copy->propertyptr = (void*)chain_p; - chain_copy->property_size = sizeof(CHAIN_VARS); - set_vector(chain_p, chain_copy); - chain_p->parent->addChild(chain_copy); -} - -void -chain_init(TaskManager *manager, int w, int h) -{ - SceneGraphPtr root_chain, chain; - CHAIN_VARS rcv; - - HTaskPtr chain_init; - - - sgroot->createFromXMLfile(manager, "xml_file/chain.xml"); - - /* SPE に送る property の配列の領域確保 */ - properties[0] = (CHAIN_VARS*)manager->allocate(sizeof(CHAIN_VARS)*CHAIN_LEN); - properties[1] = (CHAIN_VARS*)manager->allocate(sizeof(CHAIN_VARS)*CHAIN_LEN); - property = properties[0]; - - root_chain = sgroot->createSceneGraph(CHAIN); - // set_move_collision()ではだめ - root_chain->set_move_collision(chain_move_ope, chain_collision); - init_chain_vars(&rcv); - rcv.next_x = w / 2; - rcv.next_y = 0.0; - rcv.angle[0] = 0; - rcv.angle[1] = 0; - rcv.angle[2] = 0; - - set_vector(&rcv, root_chain); - - for(int i = 0; i < CHAIN_LEN; i++) { - chain = sgroot->createSceneGraph(CHAIN); - property[i].id = i; - init_chain_vars(&property[i]); - property[i].x = 0; - property[i].y = chain_width * i; - set_vector(&property[i], chain); - property->angle[1] = -90 * (i % 2); - //chain->set_move_collision(chain_move, chain_collision); - chain->propertyptr = &property[i]; - chain->property_size = sizeof(CHAIN_VARS); - root_chain->addChild(chain); - property[i].parent = root_chain; - } - property[0].can_move = FALSE; - - // property を SPU の共有領域へコピーする - chain_init = manager->create_task(CHAININIT_TASK); - chain_init->add_inData(property, sizeof(CHAIN_VARS)*CHAIN_LEN); - chain_init->add_param(CHAIN_LEN); - chain_init->set_cpu(SPE_0); - chain_init->set_post(createSceneGraphFromProperty, (void*)property); - chain_init->spawn(); - - sgroot->setSceneData(root_chain); -} -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/cube.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,174 @@ +#include <math.h> +#include "SceneGraphRoot.h" +#include "vacuum.h" +#include "SGList.h" +#define SELECT 2 + +void +cube_collision(SceneGraphPtr node, int screen_w, int screen_h, + SceneGraphPtr tree) +{ + if (node->frame > 120) { + cube_split(node,tree); + } +} + +void +cube_move_left(SceneGraphPtr node, int screen_w, int screen_h) +{ + node->xyz[0] -= node->stack_xyz[0]; + node->xyz[1] += node->stack_xyz[1]; + + if (node->xyz[0] < 0) { + node->set_move_collision(cube_move_right, cube_collision); + } + + if (node->xyz[1] < 0 || node->xyz[1] > screen_h) { + node->stack_xyz[1] = -node->stack_xyz[1]; + } +} + +void +cube_rotate(SceneGraphPtr node, int w, int h) +{ + node->angle[0] += 2.0f; + node->angle[1] += 2.0f; + node->angle[2] += 2.0f; +} + +void +cube_move_right(SceneGraphPtr node, int screen_w, int screen_h) +{ + node->xyz[0] += node->stack_xyz[0]; + node->xyz[1] += node->stack_xyz[1]; + + if (node->xyz[0] > screen_w) { + node->set_move_collision(cube_move_left, cube_collision); + } + + if (node->xyz[1] < 0 || node->xyz[1] > screen_h) { + node->stack_xyz[1] = -node->stack_xyz[1]; + } + +} + + +void +cube_split(SceneGraphPtr root,SceneGraphPtr tree) +{ + + SceneGraphPtr p; + // SceneGraphPtr common_move = sgroot->createSceneGraph(); + // SceneGraphPtr root_common_move = root->parent; + + if(random()%SELECT) { + p = sgroot->createSceneGraph(REDCUBE); + } + else { + p = sgroot->createSceneGraph(ENEMY); + } + + root->set_move_collision(cube_move_right, cube_collision); + p->set_move_collision(cube_move_left, cube_collision); + + root->frame = 0; + p->frame = 0; + + p->xyz[0] = root->xyz[0] + 2; + p->xyz[1] = root->xyz[1]; + p->xyz[2] = root->xyz[2]; + + p->stack_xyz[0] = 2.0f; + p->stack_xyz[1] = random()%3-1; + p->stack_xyz[2] = 0.0f; + + root->xyz[0] -= 2; + root->stack_xyz[0] = 2.0f; + root->stack_xyz[1] = random()%3-1; + + //common_move->addChild(p); + root->addBrother(p); + +} + + +void +collision_red(SceneGraphIteratorPtr it,SceneGraphPtr node) +{ + float dx, dy,ddx,ddy, r; + float q = 0; + + for (; it->hasNext(REDCUBE);) { + + it->next(REDCUBE); + SceneGraphPtr mcube = it->get(); + dx = node->xyz[0] - mcube->xyz[0]; + dy = node->xyz[1] - mcube->xyz[1]; + + ddx = dx*dx; + ddy = dy*dy; + + if(sqrt(ddx) < 10 && sqrt(ddy) < 10) { + mcube->remove(); + continue; + } + r = sqrt(ddx + ddy); + if (r >= 1) q = 200/r; + if (dx == 0) { + if(mcube->xyz[1] > node->xyz[1]) { + mcube->stack_xyz[1] -= q; + } else if(mcube->xyz[1] < node->xyz[1]) { + mcube->stack_xyz[1] += q; + } + } else { + if(mcube->xyz[0] > node->xyz[0]) { + mcube->xyz[0] -= q*cos(atan(dy/dx)); + mcube->xyz[1] -= q*sin(atan(dy/dx)); + } else if(mcube->xyz[0] < node->xyz[0]) { + mcube->xyz[0] += q*cos(atan(dy/dx)); + mcube->xyz[1] += q*sin(atan(dy/dx)); + } + } + } +} + +void +collision_purple(SceneGraphIteratorPtr it,SceneGraphPtr node,int w,int h) +{ + float dx, dy,ddx,ddy, r; + float q = 0; + + for (; it->hasNext(ENEMY);) { + it->next(ENEMY); + SceneGraphPtr mcube = it->get(); + + dx = node->xyz[0] - mcube->xyz[0]; + dy = node->xyz[1] - mcube->xyz[1]; + ddx = dx*dx; + ddy = dy*dy; + + if(sqrt(ddx) < 10 && sqrt(ddy) < 10) { + gameover_scene(w,h,mcube); + node->remove(); + break; + } + r = sqrt(ddx + ddy); + if (r >= 1) q = 200/r; + if (dx == 0) { + if(mcube->xyz[1] > node->xyz[1]) { + mcube->stack_xyz[1] -= q; + } else if(mcube->xyz[1] < node->xyz[1]) { + mcube->stack_xyz[1] += q; + } + } else { + + if(mcube->xyz[0] > node->xyz[0]) { + mcube->xyz[0] -= q*cos(atan(dy/dx)); + mcube->xyz[1] -= q*sin(atan(dy/dx)); + } else if(mcube->xyz[0] < node->xyz[0]) { + mcube->xyz[0] += q*cos(atan(dy/dx)); + mcube->xyz[1] += q*sin(atan(dy/dx)); + } + } + } +}
--- a/TaskManager/Test/test_render/cube.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,174 +0,0 @@ -#include <math.h> -#include "SceneGraphRoot.h" -#include "vacuum.h" -#include "SGList.h" -#define SELECT 2 - -void -cube_collision(SceneGraphPtr node, int screen_w, int screen_h, - SceneGraphPtr tree) -{ - if (node->frame > 120) { - cube_split(node,tree); - } -} - -void -cube_move_left(SceneGraphPtr node, int screen_w, int screen_h) -{ - node->xyz[0] -= node->stack_xyz[0]; - node->xyz[1] += node->stack_xyz[1]; - - if (node->xyz[0] < 0) { - node->set_move_collision(cube_move_right, cube_collision); - } - - if (node->xyz[1] < 0 || node->xyz[1] > screen_h) { - node->stack_xyz[1] = -node->stack_xyz[1]; - } -} - -void -cube_rotate(SceneGraphPtr node, int w, int h) -{ - node->angle[0] += 2.0f; - node->angle[1] += 2.0f; - node->angle[2] += 2.0f; -} - -void -cube_move_right(SceneGraphPtr node, int screen_w, int screen_h) -{ - node->xyz[0] += node->stack_xyz[0]; - node->xyz[1] += node->stack_xyz[1]; - - if (node->xyz[0] > screen_w) { - node->set_move_collision(cube_move_left, cube_collision); - } - - if (node->xyz[1] < 0 || node->xyz[1] > screen_h) { - node->stack_xyz[1] = -node->stack_xyz[1]; - } - -} - - -void -cube_split(SceneGraphPtr root,SceneGraphPtr tree) -{ - - SceneGraphPtr p; - // SceneGraphPtr common_move = sgroot->createSceneGraph(); - // SceneGraphPtr root_common_move = root->parent; - - if(random()%SELECT) { - p = sgroot->createSceneGraph(REDCUBE); - } - else { - p = sgroot->createSceneGraph(ENEMY); - } - - root->set_move_collision(cube_move_right, cube_collision); - p->set_move_collision(cube_move_left, cube_collision); - - root->frame = 0; - p->frame = 0; - - p->xyz[0] = root->xyz[0] + 2; - p->xyz[1] = root->xyz[1]; - p->xyz[2] = root->xyz[2]; - - p->stack_xyz[0] = 2.0f; - p->stack_xyz[1] = random()%3-1; - p->stack_xyz[2] = 0.0f; - - root->xyz[0] -= 2; - root->stack_xyz[0] = 2.0f; - root->stack_xyz[1] = random()%3-1; - - //common_move->addChild(p); - root->addBrother(p); - -} - - -void -collision_red(SceneGraphIteratorPtr it,SceneGraphPtr node) -{ - float dx, dy,ddx,ddy, r; - float q = 0; - - for (; it->hasNext(REDCUBE);) { - - it->next(REDCUBE); - SceneGraphPtr mcube = it->get(); - dx = node->xyz[0] - mcube->xyz[0]; - dy = node->xyz[1] - mcube->xyz[1]; - - ddx = dx*dx; - ddy = dy*dy; - - if(sqrt(ddx) < 10 && sqrt(ddy) < 10) { - mcube->remove(); - continue; - } - r = sqrt(ddx + ddy); - if (r >= 1) q = 200/r; - if (dx == 0) { - if(mcube->xyz[1] > node->xyz[1]) { - mcube->stack_xyz[1] -= q; - } else if(mcube->xyz[1] < node->xyz[1]) { - mcube->stack_xyz[1] += q; - } - } else { - if(mcube->xyz[0] > node->xyz[0]) { - mcube->xyz[0] -= q*cos(atan(dy/dx)); - mcube->xyz[1] -= q*sin(atan(dy/dx)); - } else if(mcube->xyz[0] < node->xyz[0]) { - mcube->xyz[0] += q*cos(atan(dy/dx)); - mcube->xyz[1] += q*sin(atan(dy/dx)); - } - } - } -} - -void -collision_purple(SceneGraphIteratorPtr it,SceneGraphPtr node,int w,int h) -{ - float dx, dy,ddx,ddy, r; - float q = 0; - - for (; it->hasNext(ENEMY);) { - it->next(ENEMY); - SceneGraphPtr mcube = it->get(); - - dx = node->xyz[0] - mcube->xyz[0]; - dy = node->xyz[1] - mcube->xyz[1]; - ddx = dx*dx; - ddy = dy*dy; - - if(sqrt(ddx) < 10 && sqrt(ddy) < 10) { - gameover_scene(w,h,mcube); - node->remove(); - break; - } - r = sqrt(ddx + ddy); - if (r >= 1) q = 200/r; - if (dx == 0) { - if(mcube->xyz[1] > node->xyz[1]) { - mcube->stack_xyz[1] -= q; - } else if(mcube->xyz[1] < node->xyz[1]) { - mcube->stack_xyz[1] += q; - } - } else { - - if(mcube->xyz[0] > node->xyz[0]) { - mcube->xyz[0] -= q*cos(atan(dy/dx)); - mcube->xyz[1] -= q*sin(atan(dy/dx)); - } else if(mcube->xyz[0] < node->xyz[0]) { - mcube->xyz[0] += q*cos(atan(dy/dx)); - mcube->xyz[1] += q*sin(atan(dy/dx)); - } - } - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/cube_action.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,132 @@ +#include <math.h> +#include "SceneGraphRoot.h" +#include "SGList.h" + +static void cube_move_left(SceneGraphPtr node, int screen_w, int screen_h); +static void cube_move_right(SceneGraphPtr node, int screen_w, int screen_h); +static void cube_move_idle(SceneGraphPtr node, int screen_w, int screen_h); +static void cube_collision(SceneGraphPtr node, int screen_w, int screen_h, + SceneGraphPtr tree); + +static void cube_split(SceneGraphPtr root); + +static void +cube_move_left(SceneGraphPtr node, int screen_w, int screen_h) +{ + node->xyz[0] -= node->stack_xyz[0]; + node->xyz[1] -= node->stack_xyz[0] * node->stack_xyz[1]; + node->xyz[2] -= node->stack_xyz[0] * node->stack_xyz[2]; + + if (node->xyz[0] < 0) { + node->set_move_collision(cube_move_right, cube_collision); + } + + if (node->xyz[1] < 0 || node->xyz[1] > screen_h) { + node->stack_xyz[1] = -node->stack_xyz[1]; + } + + 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); + } +} + +static void +cube_move_right(SceneGraphPtr node, int screen_w, int screen_h) +{ + node->xyz[0] += node->stack_xyz[0]; + node->xyz[1] -= node->stack_xyz[0] * node->stack_xyz[1]; + node->xyz[2] -= node->stack_xyz[0] * node->stack_xyz[2]; + + if (node->xyz[0] > screen_w) { + node->set_move_collision(cube_move_left, cube_collision); + } + + if (node->xyz[1] < 0 || node->xyz[1] > screen_h) { + node->stack_xyz[1] = -node->stack_xyz[1]; + } + + 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); + } +} + +static void +cube_split(SceneGraphPtr root) +{ + SceneGraphPtr p = root->clone(); + root->addBrother(p); + + 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]; + + p->stack_xyz[0] = 2.0f; + p->stack_xyz[1] = random()%3-1; + p->stack_xyz[2] = random()%3-1; + + root->xyz[0] -= 2; + root->stack_xyz[0] = 2.0f; + root->stack_xyz[1] = random()%3-1; + root->stack_xyz[2] = random()%3-1; +} + + +static void +cube_move_idle(SceneGraphPtr node, int screen_w, int screen_h) +{ + node->xyz[0] = screen_w/2; + node->xyz[1] = screen_h/2; + //node->xyz[2] = -300.0f; + + if (sgroot->controller->circle.isPush()) { + cube_split(node); + } +} + +static void +cube_collision(SceneGraphPtr node, int screen_w, int screen_h, + SceneGraphPtr tree) +{ +} + +void +create_cube_split(TaskManager *manager, int number) +{ + SceneGraphPtr cube; + SceneGraphPtr back; + + sgroot->createFromXMLfile(manager, "xml_file/cube.xml"); + + // 何もしない親 + // 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); + + back->addChild(cube); + + sgroot->setSceneData(back); +}
--- a/TaskManager/Test/test_render/cube_action.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,132 +0,0 @@ -#include <math.h> -#include "SceneGraphRoot.h" -#include "SGList.h" - -static void cube_move_left(SceneGraphPtr node, int screen_w, int screen_h); -static void cube_move_right(SceneGraphPtr node, int screen_w, int screen_h); -static void cube_move_idle(SceneGraphPtr node, int screen_w, int screen_h); -static void cube_collision(SceneGraphPtr node, int screen_w, int screen_h, - SceneGraphPtr tree); - -static void cube_split(SceneGraphPtr root); - -static void -cube_move_left(SceneGraphPtr node, int screen_w, int screen_h) -{ - node->xyz[0] -= node->stack_xyz[0]; - node->xyz[1] -= node->stack_xyz[0] * node->stack_xyz[1]; - node->xyz[2] -= node->stack_xyz[0] * node->stack_xyz[2]; - - if (node->xyz[0] < 0) { - node->set_move_collision(cube_move_right, cube_collision); - } - - if (node->xyz[1] < 0 || node->xyz[1] > screen_h) { - node->stack_xyz[1] = -node->stack_xyz[1]; - } - - 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); - } -} - -static void -cube_move_right(SceneGraphPtr node, int screen_w, int screen_h) -{ - node->xyz[0] += node->stack_xyz[0]; - node->xyz[1] -= node->stack_xyz[0] * node->stack_xyz[1]; - node->xyz[2] -= node->stack_xyz[0] * node->stack_xyz[2]; - - if (node->xyz[0] > screen_w) { - node->set_move_collision(cube_move_left, cube_collision); - } - - if (node->xyz[1] < 0 || node->xyz[1] > screen_h) { - node->stack_xyz[1] = -node->stack_xyz[1]; - } - - 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); - } -} - -static void -cube_split(SceneGraphPtr root) -{ - SceneGraphPtr p = root->clone(); - root->addBrother(p); - - 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]; - - p->stack_xyz[0] = 2.0f; - p->stack_xyz[1] = random()%3-1; - p->stack_xyz[2] = random()%3-1; - - root->xyz[0] -= 2; - root->stack_xyz[0] = 2.0f; - root->stack_xyz[1] = random()%3-1; - root->stack_xyz[2] = random()%3-1; -} - - -static void -cube_move_idle(SceneGraphPtr node, int screen_w, int screen_h) -{ - node->xyz[0] = screen_w/2; - node->xyz[1] = screen_h/2; - //node->xyz[2] = -300.0f; - - if (sgroot->controller->circle.isPush()) { - cube_split(node); - } -} - -static void -cube_collision(SceneGraphPtr node, int screen_w, int screen_h, - SceneGraphPtr tree) -{ -} - -void -create_cube_split(TaskManager *manager, int number) -{ - SceneGraphPtr cube; - SceneGraphPtr back; - - sgroot->createFromXMLfile(manager, "xml_file/cube.xml"); - - // 何もしない親 - // 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); - - back->addChild(cube); - - sgroot->setSceneData(back); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/direction.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,93 @@ +#include "SceneGraphRoot.h" +#include "SGList.h" + +static void +x_move(SceneGraphPtr node, int w, int h) +{ + Pad *pad = sgroot->getController(); + + node->xyz[0] = w/2; + node->xyz[1] = h/2; + + if (pad->circle.isPush() || pad->circle.isHold()) { + node->angle[1] += 10.0f; + if (node->angle[1] > 360.0f) node->angle[1] = 0.0f; + } + + if (pad->triangle.isPush() || pad->triangle.isHold()) { + node->angle[0] += 10.0f; + if (node->angle[0] > 360.0f) node->angle[0] = 0.0f; + } + + if (pad->start.isPush()) { + node->angle[0] = 0.0f; + node->angle[1] = 90.0f; + } + +} + +static void +y_move(SceneGraphPtr node, int w, int h) +{ + Pad *pad = sgroot->getController(); + + node->xyz[0] = w/2; + node->xyz[1] = h/2; + + if (pad->cross.isPush() || pad->cross.isHold()) { + node->angle[2] += 10.0f; + } + + if (pad->square.isPush() || pad->square.isHold()) { + node->angle[0] += 10.0f; + } + + if (pad->start.isPush()) { + node->angle[0] = 90.0f; + node->angle[1] = 0.0f; + } + +} + +static void +z_move(SceneGraphPtr node, int w, int h) +{ + node->xyz[0] = w/2; + node->xyz[1] = h/2; +} + +static void +dir_collision(SceneGraphPtr node, int w, int h, SceneGraphPtr tree) +{ +} + +void +direction_init(TaskManager *manager) +{ + SceneGraphPtr dx; + SceneGraphPtr dy; + SceneGraphPtr dz; + SceneGraphPtr back; + + sgroot->createFromXMLfile(manager, "xml_file/direction.xml"); + + dx = sgroot->createSceneGraph(Dirx); + dy = sgroot->createSceneGraph(Diry); + dz = sgroot->createSceneGraph(Dirz); + back = sgroot->createSceneGraph(); + + back->addChild(dx); + back->addChild(dy); + back->addChild(dz); + + dx->set_move_collision(x_move, dir_collision); + dx->angle[1] = 90.0f; + dy->set_move_collision(y_move, dir_collision); + dy->angle[0] = 90.0f; + dz->set_move_collision(z_move, dir_collision); + + back->angle[0] = 30.0f; + back->angle[1] = -30.0f; + + sgroot->setSceneData(back); +}
--- a/TaskManager/Test/test_render/direction.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,93 +0,0 @@ -#include "SceneGraphRoot.h" -#include "SGList.h" - -static void -x_move(SceneGraphPtr node, int w, int h) -{ - Pad *pad = sgroot->getController(); - - node->xyz[0] = w/2; - node->xyz[1] = h/2; - - if (pad->circle.isPush() || pad->circle.isHold()) { - node->angle[1] += 10.0f; - if (node->angle[1] > 360.0f) node->angle[1] = 0.0f; - } - - if (pad->triangle.isPush() || pad->triangle.isHold()) { - node->angle[0] += 10.0f; - if (node->angle[0] > 360.0f) node->angle[0] = 0.0f; - } - - if (pad->start.isPush()) { - node->angle[0] = 0.0f; - node->angle[1] = 90.0f; - } - -} - -static void -y_move(SceneGraphPtr node, int w, int h) -{ - Pad *pad = sgroot->getController(); - - node->xyz[0] = w/2; - node->xyz[1] = h/2; - - if (pad->cross.isPush() || pad->cross.isHold()) { - node->angle[2] += 10.0f; - } - - if (pad->square.isPush() || pad->square.isHold()) { - node->angle[0] += 10.0f; - } - - if (pad->start.isPush()) { - node->angle[0] = 90.0f; - node->angle[1] = 0.0f; - } - -} - -static void -z_move(SceneGraphPtr node, int w, int h) -{ - node->xyz[0] = w/2; - node->xyz[1] = h/2; -} - -static void -dir_collision(SceneGraphPtr node, int w, int h, SceneGraphPtr tree) -{ -} - -void -direction_init(TaskManager *manager) -{ - SceneGraphPtr dx; - SceneGraphPtr dy; - SceneGraphPtr dz; - SceneGraphPtr back; - - sgroot->createFromXMLfile(manager, "xml_file/direction.xml"); - - dx = sgroot->createSceneGraph(Dirx); - dy = sgroot->createSceneGraph(Diry); - dz = sgroot->createSceneGraph(Dirz); - back = sgroot->createSceneGraph(); - - back->addChild(dx); - back->addChild(dy); - back->addChild(dz); - - dx->set_move_collision(x_move, dir_collision); - dx->angle[1] = 90.0f; - dy->set_move_collision(y_move, dir_collision); - dy->angle[0] = 90.0f; - dz->set_move_collision(z_move, dir_collision); - - back->angle[0] = 30.0f; - back->angle[1] = -30.0f; - - sgroot->setSceneData(back); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/enemy_action.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,38 @@ +#include <math.h> +#include "SceneGraph.h" +#include "enemy_action.h" + +#define PI M_PI + +double vx = 5.0; + +void +enemy_move(SceneGraphPtr node, int screen_w, int screen_h) +{ + double vxr = (node->xyz[0])*PI/180; + if(node->xyz[0] > screen_w/2 || node->xyz[0] < -screen_w/2) + { + vx *= -1; + } + //printf("%f\n", vx); + node->angle[1]+=vx; + + node->xyz[0] += vx; + node->xyz[1] = -sin(vxr*2)*20*vx; + node->xyz[2] = sin(vxr*4)*2*vx; +} + + +void +enemy_collision(SceneGraphPtr node, int screen_w, int screen_h, SceneGraphPtr tree) +{ +#if 0 + int judge = square_judge(E_PLANE, BULEBULLET, tree); + if(judge == HIT) + { + E_PLANE->set_move_collision(null_move, enemy_collision); + printf("ENEMY_hit!!!\n"); + //scene_graph->delete_object(node, node->next,node->prev); + } +#endif +}
--- a/TaskManager/Test/test_render/enemy_action.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -#include <math.h> -#include "SceneGraph.h" -#include "enemy_action.h" - -#define PI M_PI - -double vx = 5.0; - -void -enemy_move(SceneGraphPtr node, int screen_w, int screen_h) -{ - double vxr = (node->xyz[0])*PI/180; - if(node->xyz[0] > screen_w/2 || node->xyz[0] < -screen_w/2) - { - vx *= -1; - } - //printf("%f\n", vx); - node->angle[1]+=vx; - - node->xyz[0] += vx; - node->xyz[1] = -sin(vxr*2)*20*vx; - node->xyz[2] = sin(vxr*4)*2*vx; -} - - -void -enemy_collision(SceneGraphPtr node, int screen_w, int screen_h, SceneGraphPtr tree) -{ -#if 0 - int judge = square_judge(E_PLANE, BULEBULLET, tree); - if(judge == HIT) - { - E_PLANE->set_move_collision(null_move, enemy_collision); - printf("ENEMY_hit!!!\n"); - //scene_graph->delete_object(node, node->next,node->prev); - } -#endif -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/game_over.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,42 @@ +#include "SceneGraphRoot.h" +#include "vacuum.h" +#include "SGList.h" + + +void +gameover_scene(int w,int h,SceneGraphPtr node) +{ + + SceneGraphPtr over; + + over = sgroot->createSceneGraph(GAMEOVER); + over->xyz[0] = w/2; + over->xyz[1] = h/2; + over->set_move_collision(gameover_idle,gameover_collision); + node->addBrother(over); +} + +void +gameover_idle(SceneGraphPtr node,int screen_w,int screen_h) +{ +} + +void +gameover_collision(SceneGraphPtr node,int screen_w,int screen_h,SceneGraphPtr tree) +{ + + Pad *pad = sgroot->getController(); + + if(pad->start.isPush()) { + + SceneGraphPtr title; + + title = sgroot->createSceneGraph(TITLE); + title->xyz[0] = screen_w/2; + title->xyz[1] = screen_h/2; + title->set_move_collision(no_move_idle, title_collision); + sgroot->setSceneData(title); + + } + +}
--- a/TaskManager/Test/test_render/game_over.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -#include "SceneGraphRoot.h" -#include "vacuum.h" -#include "SGList.h" - - -void -gameover_scene(int w,int h,SceneGraphPtr node) -{ - - SceneGraphPtr over; - - over = sgroot->createSceneGraph(GAMEOVER); - over->xyz[0] = w/2; - over->xyz[1] = h/2; - over->set_move_collision(gameover_idle,gameover_collision); - node->addBrother(over); -} - -void -gameover_idle(SceneGraphPtr node,int screen_w,int screen_h) -{ -} - -void -gameover_collision(SceneGraphPtr node,int screen_w,int screen_h,SceneGraphPtr tree) -{ - - Pad *pad = sgroot->getController(); - - if(pad->start.isPush()) { - - SceneGraphPtr title; - - title = sgroot->createSceneGraph(TITLE); - title->xyz[0] = screen_w/2; - title->xyz[1] = screen_h/2; - title->set_move_collision(no_move_idle, title_collision); - sgroot->setSceneData(title); - - } - -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/gaplant.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,30 @@ +#include "SceneGraphRoot.h" +#include "SGList.h" +#include "gaplant_action.h" +#include "back_action.h" + +void +init_gaplant(TaskManager *manager, int w, int h) +{ + SceneGraphPtr back; + SceneGraphPtr gaplant; + sgroot->createFromXMLfile(manager, "xml_file/gap_plane_test.xml"); + sgroot->createFromXMLfile(manager, "xml_file/Ball.xml"); + + back = sgroot->createSceneGraph(); + back->set_move_collision(back_move, back_coll); + gaplant = sgroot->createSceneGraph(); + gaplant->xyz[0] = 200; + gaplant->angle[0] = -60; + gaplant->angle[1] = 0; + gaplant->angle[2] = 0; + gaplant->set_move_collision(gaplant_move, gaplant_coll); + + for (int i = arm_L_D; i <= foot_L_A; i++) { + SceneGraphPtr p = sgroot->createSceneGraph(i); + gaplant->addChild(p); + } + + back->addChild(gaplant); + sgroot->setSceneData(back); +}
--- a/TaskManager/Test/test_render/gaplant.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -#include "SceneGraphRoot.h" -#include "SGList.h" -#include "gaplant_action.h" -#include "back_action.h" - -void -init_gaplant(TaskManager *manager, int w, int h) -{ - SceneGraphPtr back; - SceneGraphPtr gaplant; - sgroot->createFromXMLfile(manager, "xml_file/gap_plane_test.xml"); - sgroot->createFromXMLfile(manager, "xml_file/Ball.xml"); - - back = sgroot->createSceneGraph(); - back->set_move_collision(back_move, back_coll); - gaplant = sgroot->createSceneGraph(); - gaplant->xyz[0] = 200; - gaplant->angle[0] = -60; - gaplant->angle[1] = 0; - gaplant->angle[2] = 0; - gaplant->set_move_collision(gaplant_move, gaplant_coll); - - for (int i = arm_L_D; i <= foot_L_A; i++) { - SceneGraphPtr p = sgroot->createSceneGraph(i); - gaplant->addChild(p); - } - - back->addChild(gaplant); - sgroot->setSceneData(back); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/gaplant_action.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,98 @@ +#include <iostream> +#include <cmath> +#include "SceneGraphRoot.h" +#include "SGList.h" +#include "gaplant.h" +using namespace std; + +void +move_right(SceneGraphPtr node) +{ + /*cout << "右を押したんだ " << node->angle[2] << "\n"; + node->angle[2] -= 1; + if (node->angle[2] < -30) { + node->angle[2] = -30; + }*/ + node->xyz[0] += 5; +} + +void +move_left(SceneGraphPtr node) +{ + /*cout << "左を押したんだ " << node->angle[2] << "\n"; + node->angle[1] += 1; + if (node->angle[2] > 30) { + node->angle[2] = 30; + }*/ + node->xyz[0] -= 5; +} + +void +move_down(SceneGraphPtr node) +{ + /*cout << "下だって押したくなる時はある "<< node->angle[0] << "\n"; + node->angle[0] += 1; + if (node->angle[0] > -60) { + node->angle[0] = -60; + }*/ + node->xyz[1] += 5; +} + +void +move_up(SceneGraphPtr node) +{ + /*cout << "上を押したんだ "<< node->angle[0] << "\n"; + node->angle[0] -= 1; + if (node->angle[0] < -120) { + node->angle[0] = -120; + }*/ + node->xyz[1] -= 5; +} + +void +gaplant_move(SceneGraphPtr node, int w, int h) +{ + Pad *pad = sgroot->getController(); + + if (pad->right.isHold() || pad->left.isHold() || pad->down.isHold() || pad->up.isHold()) { + if (pad->right.isHold()) { + move_right(node); + } else if (pad->left.isHold()) { + move_left(node); + } else if (pad->down.isHold()) { + move_down(node); + } else if (pad->up.isHold()) { + move_up(node); + } + } + + if (pad->cross.isHold() || pad->circle.isHold()) { + if (pad->cross.isHold()) { + node->xyz[2] += 5; + } else if (pad->circle.isHold()) { + node->xyz[2] -= 5; + } + } +} + +void +gaplant_coll(SceneGraphPtr node, int w, int h, SceneGraphPtr tree) +{ + SceneGraphIteratorPtr it = sgroot->getIterator(tree); + //static int damage = 0; + + for (; it->hasNext(Ball);) { + it->next(Ball); + SceneGraphPtr ball = it->get(); + + double dis_x = node->xyz[0] - ball->xyz[0]; + double dis_y = node->xyz[1] - ball->xyz[1]; + double dis_z = node->xyz[2] - ball->xyz[2]; + double distance = sqrt(dis_x*dis_x + dis_y*dis_y + dis_z*dis_z); + + if (distance < CHECK_HIT_RAD + BALL_RAD) { + cout << "今からもっと細かく判定するよ ^q^\n"; + ball->remove(); + } + } +}
--- a/TaskManager/Test/test_render/gaplant_action.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,98 +0,0 @@ -#include <iostream> -#include <cmath> -#include "SceneGraphRoot.h" -#include "SGList.h" -#include "gaplant.h" -using namespace std; - -void -move_right(SceneGraphPtr node) -{ - /*cout << "右を押したんだ " << node->angle[2] << "\n"; - node->angle[2] -= 1; - if (node->angle[2] < -30) { - node->angle[2] = -30; - }*/ - node->xyz[0] += 5; -} - -void -move_left(SceneGraphPtr node) -{ - /*cout << "左を押したんだ " << node->angle[2] << "\n"; - node->angle[1] += 1; - if (node->angle[2] > 30) { - node->angle[2] = 30; - }*/ - node->xyz[0] -= 5; -} - -void -move_down(SceneGraphPtr node) -{ - /*cout << "下だって押したくなる時はある "<< node->angle[0] << "\n"; - node->angle[0] += 1; - if (node->angle[0] > -60) { - node->angle[0] = -60; - }*/ - node->xyz[1] += 5; -} - -void -move_up(SceneGraphPtr node) -{ - /*cout << "上を押したんだ "<< node->angle[0] << "\n"; - node->angle[0] -= 1; - if (node->angle[0] < -120) { - node->angle[0] = -120; - }*/ - node->xyz[1] -= 5; -} - -void -gaplant_move(SceneGraphPtr node, int w, int h) -{ - Pad *pad = sgroot->getController(); - - if (pad->right.isHold() || pad->left.isHold() || pad->down.isHold() || pad->up.isHold()) { - if (pad->right.isHold()) { - move_right(node); - } else if (pad->left.isHold()) { - move_left(node); - } else if (pad->down.isHold()) { - move_down(node); - } else if (pad->up.isHold()) { - move_up(node); - } - } - - if (pad->cross.isHold() || pad->circle.isHold()) { - if (pad->cross.isHold()) { - node->xyz[2] += 5; - } else if (pad->circle.isHold()) { - node->xyz[2] -= 5; - } - } -} - -void -gaplant_coll(SceneGraphPtr node, int w, int h, SceneGraphPtr tree) -{ - SceneGraphIteratorPtr it = sgroot->getIterator(tree); - //static int damage = 0; - - for (; it->hasNext(Ball);) { - it->next(Ball); - SceneGraphPtr ball = it->get(); - - double dis_x = node->xyz[0] - ball->xyz[0]; - double dis_y = node->xyz[1] - ball->xyz[1]; - double dis_z = node->xyz[2] - ball->xyz[2]; - double distance = sqrt(dis_x*dis_x + dis_y*dis_y + dis_z*dis_z); - - if (distance < CHECK_HIT_RAD + BALL_RAD) { - cout << "今からもっと細かく判定するよ ^q^\n"; - ball->remove(); - } - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/hit_judge.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,80 @@ +#include "SceneGraph.h" +#include "hit_judge.h" +#include "SGList.h" + +#define FUSELAGE_W 6 +#define FUSELAGE_H 6 +#define FUSELAGE_Z 6 +#define E_PLANE_W 6*4 +#define E_PLANE_H 6*4 +#define E_PLANE_Z 6*4 +#define BULLTE_W 2*4 +#define BULLTE_H 6*4 +#define BULLTE_Z 2*4 + +int +square_judge(SceneGraphPtr oneself, SceneGraphPtr partner) +{ + int ow = 0, oh = 0, oz = 0; + int pw = 0, ph = 0, pz = 0; + if (oneself->sgid == IDLE) + { + ow = FUSELAGE_W; + oh = FUSELAGE_H; + oz = FUSELAGE_Z; + } + else if (oneself->sgid == E_PLANE) + { + ow = E_PLANE_W; + oh = E_PLANE_H; + oz = E_PLANE_Z; + } + else if(oneself->sgid == BULEBULLET) + { + ow = BULLTE_W; + oh = BULLTE_H; + oz = BULLTE_Z; + } + if(partner->sgid == IDLE) + { + pw = FUSELAGE_W; + ph = FUSELAGE_H; + pz = FUSELAGE_Z; + } + else if(partner->sgid == E_PLANE) + { + pw = E_PLANE_W; + ph = E_PLANE_H; + pz = E_PLANE_Z; + } + else if(partner->sgid == BULEBULLET) + { + pw = BULLTE_W; + ph = BULLTE_H; + pz = BULLTE_Z; + } + + + int ox_min = (int)(oneself->xyz[0] + oneself->c_xyz[0] - ow/2); + int oy_min = (int)(oneself->xyz[1] + oneself->c_xyz[1] - oh/2); + int oz_min = (int)(oneself->xyz[2] + oneself->c_xyz[2] - oz/2); + + int ox_max = (int)(oneself->xyz[0] + oneself->c_xyz[0] + ow/2); + int oy_max = (int)(oneself->xyz[1] + oneself->c_xyz[1] + oh/2); + int oz_max = (int)(oneself->xyz[2] + oneself->c_xyz[2] + oz/2); + + int px_min = (int)(partner->xyz[0] + partner->c_xyz[0] - pw/2); + int py_min = (int)(partner->xyz[1] + partner->c_xyz[1] - ph/2); + int pz_min = (int)(partner->xyz[2] + partner->c_xyz[2] - pz/2); + + int px_max = (int)(partner->xyz[0] + partner->c_xyz[0] + pw/2); + int py_max = (int)(partner->xyz[1] + partner->c_xyz[1] + ph/2); + int pz_max = (int)(partner->xyz[2] + partner->c_xyz[2] + pz/2); + + if(ox_max < px_min || px_max < ox_min || oy_max < py_min || py_max < oy_min || oz_max < pz_min || pz_max < oz_min) + { + } else { + return HIT; + } + return 0; +}
--- a/TaskManager/Test/test_render/hit_judge.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -#include "SceneGraph.h" -#include "hit_judge.h" -#include "SGList.h" - -#define FUSELAGE_W 6 -#define FUSELAGE_H 6 -#define FUSELAGE_Z 6 -#define E_PLANE_W 6*4 -#define E_PLANE_H 6*4 -#define E_PLANE_Z 6*4 -#define BULLTE_W 2*4 -#define BULLTE_H 6*4 -#define BULLTE_Z 2*4 - -int -square_judge(SceneGraphPtr oneself, SceneGraphPtr partner) -{ - int ow = 0, oh = 0, oz = 0; - int pw = 0, ph = 0, pz = 0; - if (oneself->sgid == IDLE) - { - ow = FUSELAGE_W; - oh = FUSELAGE_H; - oz = FUSELAGE_Z; - } - else if (oneself->sgid == E_PLANE) - { - ow = E_PLANE_W; - oh = E_PLANE_H; - oz = E_PLANE_Z; - } - else if(oneself->sgid == BULEBULLET) - { - ow = BULLTE_W; - oh = BULLTE_H; - oz = BULLTE_Z; - } - if(partner->sgid == IDLE) - { - pw = FUSELAGE_W; - ph = FUSELAGE_H; - pz = FUSELAGE_Z; - } - else if(partner->sgid == E_PLANE) - { - pw = E_PLANE_W; - ph = E_PLANE_H; - pz = E_PLANE_Z; - } - else if(partner->sgid == BULEBULLET) - { - pw = BULLTE_W; - ph = BULLTE_H; - pz = BULLTE_Z; - } - - - int ox_min = (int)(oneself->xyz[0] + oneself->c_xyz[0] - ow/2); - int oy_min = (int)(oneself->xyz[1] + oneself->c_xyz[1] - oh/2); - int oz_min = (int)(oneself->xyz[2] + oneself->c_xyz[2] - oz/2); - - int ox_max = (int)(oneself->xyz[0] + oneself->c_xyz[0] + ow/2); - int oy_max = (int)(oneself->xyz[1] + oneself->c_xyz[1] + oh/2); - int oz_max = (int)(oneself->xyz[2] + oneself->c_xyz[2] + oz/2); - - int px_min = (int)(partner->xyz[0] + partner->c_xyz[0] - pw/2); - int py_min = (int)(partner->xyz[1] + partner->c_xyz[1] - ph/2); - int pz_min = (int)(partner->xyz[2] + partner->c_xyz[2] - pz/2); - - int px_max = (int)(partner->xyz[0] + partner->c_xyz[0] + pw/2); - int py_max = (int)(partner->xyz[1] + partner->c_xyz[1] + ph/2); - int pz_max = (int)(partner->xyz[2] + partner->c_xyz[2] + pz/2); - - if(ox_max < px_min || px_max < ox_min || oy_max < py_min || py_max < oy_min || oz_max < pz_min || pz_max < oz_min) - { - } else { - return HIT; - } - return 0; -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/ieshoot.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,216 @@ +#include "SceneGraphRoot.h" +#include "SGList.h" + +static const float jiki_speed = 6.0f; +static const float jiki_radius = 32.0f; + +static const float tama_speed = 10.0f; +static const float tama_radius = 16.0f; + +static const float boss_radius_x = 64.0f; +static const float boss_radius_y = 128.0f; + +static const float iebosstama_speed = 15.0f; + +static void +ieboss_collision(SceneGraphPtr node, int screen_w, int screen_h, + SceneGraphPtr tree); +static void +ieboss_collision_invincibil(SceneGraphPtr node, int screen_w, int screen_h, SceneGraphPtr tree); +static void ieboss_move(SceneGraphPtr node, int screen_w, int screen_h); + +static void iebosstama_move(SceneGraphPtr node, int screen_w, int screen_h); + + +static void +iejiki_collision(SceneGraphPtr node, int screen_w, int screen_h, + SceneGraphPtr tree) +{ +} + +static void +ietama_collision(SceneGraphPtr node, int screen_w, int screen_h, + SceneGraphPtr tree) +{ +} + +static void +ieboss_collision(SceneGraphPtr node, int screen_w, int screen_h, + SceneGraphPtr tree) +{ + SceneGraphIteratorPtr it = sgroot->getIterator(tree); + static int damage = 0; + + for (; it->hasNext(IETAMA);) { + it->next(IETAMA); + SceneGraphPtr tama = it->get(); + + if (node->xyz[0] - boss_radius_x < tama->xyz[0] + tama_radius + && node->xyz[0] + boss_radius_x > tama->xyz[0] - tama_radius + && node->xyz[1] + boss_radius_y > tama->xyz[1] - tama_radius) { + tama->remove(); + + node->set_move_collision(ieboss_move, ieboss_collision_invincibil); + + SceneGraphPtr iebosstama = sgroot->createSceneGraph(Earth); + 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] = 50.0f; + node->addBrother(iebosstama); + + damage++; + } + } + + if (damage > 10) { + node->remove(); + } +} + +static void +ieboss_move(SceneGraphPtr node, int screen_w, int screen_h) +{ + /** + * TODO + * Boss が複数居た場合、これじゃ駄目 + */ + static float x_speed = 5.0f; + static float z_speed = 5.0f; + + node->xyz[0] += x_speed; + + if (node->xyz[0] - boss_radius_x < 0) { + x_speed = -x_speed; + node->xyz[0] = boss_radius_x; + } else if (node->xyz[0] + boss_radius_x > screen_w) { + 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 +ieboss_collision_invincibil(SceneGraphPtr node, int screen_w, int screen_h, + SceneGraphPtr tree) +{ + static int frame = 0; + + frame++; + + node->flag_drawable ^= 1; + + if (frame > 60) { + frame = 0; + node->flag_drawable = 1; + node->set_move_collision(ieboss_move, ieboss_collision); + } +} + +static void +iebosstama_move(SceneGraphPtr node, int screen_w, int screen_h) +{ + node->xyz[1] += iebosstama_speed; + + // 描画領域から抜けたら削除 + if (node->xyz[1] > screen_h) { + node->remove(); + } +} + +static void +ietama_move(SceneGraphPtr node, int screen_w, int screen_h) +{ + node->xyz[1] -= tama_speed; + + // 描画領域から抜けたら削除 + if (node->xyz[1] < 0) { + node->remove(); + } +} + +static void +iejiki_move(SceneGraphPtr node, int screen_w, int screen_h) +{ + Pad *pad = sgroot->getController(); + + if (pad->left.isPush() + || pad->left.isHold()) { + node->xyz[0] -= jiki_speed; + + if (node->xyz[0] - jiki_radius< 0) { + node->xyz[0] = jiki_radius; + } + } + + if (pad->right.isPush() + || pad->right.isHold()) { + node->xyz[0] += jiki_speed; + + if (node->xyz[0] + jiki_radius > screen_w) { + node->xyz[0] = screen_w - jiki_radius; + } + } + + if (pad->up.isPush() + || pad->up.isHold()) { + node->xyz[1] -= jiki_speed; + + if (node->xyz[1] - jiki_radius < 0) { + node->xyz[1] = jiki_radius; + } + } + + if (pad->down.isPush() + || pad->down.isHold()) { + node->xyz[1] += jiki_speed; + + if (node->xyz[1] + jiki_radius > screen_h) { + node->xyz[1] = screen_h - jiki_radius; + } + } + + if (pad->circle.isPush()) { + SceneGraphPtr ietama = sgroot->createSceneGraph(IETAMA); + ietama->set_move_collision(ietama_move, ietama_collision); + ietama->xyz[0] = node->xyz[0]; + ietama->xyz[1] = node->xyz[1]; + node->addBrother(ietama); + } +} + + +void +ieshoot_init(TaskManager *manager) +{ + SceneGraphPtr iejiki; + SceneGraphPtr enemy; + SceneGraphPtr back; + + sgroot->createFromXMLfile(manager, "xml_file/ietama.xml"); + sgroot->createFromXMLfile(manager, "xml_file/ieboss.xml"); + sgroot->createFromXMLfile(manager, "xml_file/iejiki.xml"); + sgroot->createFromXMLfile(manager, "xml_file/universe.xml"); + + back = sgroot->createSceneGraph(); + + iejiki = sgroot->createSceneGraph(IEJIKI); + iejiki->set_move_collision(iejiki_move, iejiki_collision); + iejiki->xyz[2] = 20; + back->addChild(iejiki); + + enemy = sgroot->createSceneGraph(IEBOSS); + enemy->set_move_collision(ieboss_move, ieboss_collision); + enemy->xyz[1] = boss_radius_y; + back->addChild(enemy); + + sgroot->setSceneData(back); +}
--- a/TaskManager/Test/test_render/ieshoot.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,216 +0,0 @@ -#include "SceneGraphRoot.h" -#include "SGList.h" - -static const float jiki_speed = 6.0f; -static const float jiki_radius = 32.0f; - -static const float tama_speed = 10.0f; -static const float tama_radius = 16.0f; - -static const float boss_radius_x = 64.0f; -static const float boss_radius_y = 128.0f; - -static const float iebosstama_speed = 15.0f; - -static void -ieboss_collision(SceneGraphPtr node, int screen_w, int screen_h, - SceneGraphPtr tree); -static void -ieboss_collision_invincibil(SceneGraphPtr node, int screen_w, int screen_h, SceneGraphPtr tree); -static void ieboss_move(SceneGraphPtr node, int screen_w, int screen_h); - -static void iebosstama_move(SceneGraphPtr node, int screen_w, int screen_h); - - -static void -iejiki_collision(SceneGraphPtr node, int screen_w, int screen_h, - SceneGraphPtr tree) -{ -} - -static void -ietama_collision(SceneGraphPtr node, int screen_w, int screen_h, - SceneGraphPtr tree) -{ -} - -static void -ieboss_collision(SceneGraphPtr node, int screen_w, int screen_h, - SceneGraphPtr tree) -{ - SceneGraphIteratorPtr it = sgroot->getIterator(tree); - static int damage = 0; - - for (; it->hasNext(IETAMA);) { - it->next(IETAMA); - SceneGraphPtr tama = it->get(); - - if (node->xyz[0] - boss_radius_x < tama->xyz[0] + tama_radius - && node->xyz[0] + boss_radius_x > tama->xyz[0] - tama_radius - && node->xyz[1] + boss_radius_y > tama->xyz[1] - tama_radius) { - tama->remove(); - - node->set_move_collision(ieboss_move, ieboss_collision_invincibil); - - SceneGraphPtr iebosstama = sgroot->createSceneGraph(Earth); - 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] = 50.0f; - node->addBrother(iebosstama); - - damage++; - } - } - - if (damage > 10) { - node->remove(); - } -} - -static void -ieboss_move(SceneGraphPtr node, int screen_w, int screen_h) -{ - /** - * TODO - * Boss が複数居た場合、これじゃ駄目 - */ - static float x_speed = 5.0f; - static float z_speed = 5.0f; - - node->xyz[0] += x_speed; - - if (node->xyz[0] - boss_radius_x < 0) { - x_speed = -x_speed; - node->xyz[0] = boss_radius_x; - } else if (node->xyz[0] + boss_radius_x > screen_w) { - 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 -ieboss_collision_invincibil(SceneGraphPtr node, int screen_w, int screen_h, - SceneGraphPtr tree) -{ - static int frame = 0; - - frame++; - - node->flag_drawable ^= 1; - - if (frame > 60) { - frame = 0; - node->flag_drawable = 1; - node->set_move_collision(ieboss_move, ieboss_collision); - } -} - -static void -iebosstama_move(SceneGraphPtr node, int screen_w, int screen_h) -{ - node->xyz[1] += iebosstama_speed; - - // 描画領域から抜けたら削除 - if (node->xyz[1] > screen_h) { - node->remove(); - } -} - -static void -ietama_move(SceneGraphPtr node, int screen_w, int screen_h) -{ - node->xyz[1] -= tama_speed; - - // 描画領域から抜けたら削除 - if (node->xyz[1] < 0) { - node->remove(); - } -} - -static void -iejiki_move(SceneGraphPtr node, int screen_w, int screen_h) -{ - Pad *pad = sgroot->getController(); - - if (pad->left.isPush() - || pad->left.isHold()) { - node->xyz[0] -= jiki_speed; - - if (node->xyz[0] - jiki_radius< 0) { - node->xyz[0] = jiki_radius; - } - } - - if (pad->right.isPush() - || pad->right.isHold()) { - node->xyz[0] += jiki_speed; - - if (node->xyz[0] + jiki_radius > screen_w) { - node->xyz[0] = screen_w - jiki_radius; - } - } - - if (pad->up.isPush() - || pad->up.isHold()) { - node->xyz[1] -= jiki_speed; - - if (node->xyz[1] - jiki_radius < 0) { - node->xyz[1] = jiki_radius; - } - } - - if (pad->down.isPush() - || pad->down.isHold()) { - node->xyz[1] += jiki_speed; - - if (node->xyz[1] + jiki_radius > screen_h) { - node->xyz[1] = screen_h - jiki_radius; - } - } - - if (pad->circle.isPush()) { - SceneGraphPtr ietama = sgroot->createSceneGraph(IETAMA); - ietama->set_move_collision(ietama_move, ietama_collision); - ietama->xyz[0] = node->xyz[0]; - ietama->xyz[1] = node->xyz[1]; - node->addBrother(ietama); - } -} - - -void -ieshoot_init(TaskManager *manager) -{ - SceneGraphPtr iejiki; - SceneGraphPtr enemy; - SceneGraphPtr back; - - sgroot->createFromXMLfile(manager, "xml_file/ietama.xml"); - sgroot->createFromXMLfile(manager, "xml_file/ieboss.xml"); - sgroot->createFromXMLfile(manager, "xml_file/iejiki.xml"); - sgroot->createFromXMLfile(manager, "xml_file/universe.xml"); - - back = sgroot->createSceneGraph(); - - iejiki = sgroot->createSceneGraph(IEJIKI); - iejiki->set_move_collision(iejiki_move, iejiki_collision); - iejiki->xyz[2] = 20; - back->addChild(iejiki); - - enemy = sgroot->createSceneGraph(IEBOSS); - enemy->set_move_collision(ieboss_move, ieboss_collision); - enemy->xyz[1] = boss_radius_y; - back->addChild(enemy); - - sgroot->setSceneData(back); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/init_position.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,36 @@ +#include "SceneGraphRoot.h" +#include "SGList.h" +#include "player_action.h" +#include "enemy_action.h" +#include "camera_action.h" + +void +init_position(TaskManager *manager, int w, int h) +{ + SceneGraphPtr back; + SceneGraphPtr player; + SceneGraphPtr enemy; + //SceneGraphPtr bullet; + + sgroot->createFromXMLfile(manager, "xml_file/player.xml"); + back = sgroot->createSceneGraph(BACK); + //back = sgroot->createSceneGraph(); + player = sgroot->createSceneGraph(IDLE); + //bullet = sgroot->createSceneGraph(BULEBULLET); + + camera_init(back, w, h); + back->set_move_collision(camera_init, camera_collision); + player->set_move_collision(player_move_all, player_collision); + + + back->addChild(player); + + for (int i = 0; i < 10; i++) { + enemy = sgroot->createSceneGraph(E_PLANE); + enemy->set_move_collision(enemy_move, enemy_collision); + enemy->xyz[0] = 50.0*i; + back->addChild(enemy); + } + + sgroot->setSceneData(back); +}
--- a/TaskManager/Test/test_render/init_position.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -#include "SceneGraphRoot.h" -#include "SGList.h" -#include "player_action.h" -#include "enemy_action.h" -#include "camera_action.h" - -void -init_position(TaskManager *manager, int w, int h) -{ - SceneGraphPtr back; - SceneGraphPtr player; - SceneGraphPtr enemy; - //SceneGraphPtr bullet; - - sgroot->createFromXMLfile(manager, "xml_file/player.xml"); - back = sgroot->createSceneGraph(BACK); - //back = sgroot->createSceneGraph(); - player = sgroot->createSceneGraph(IDLE); - //bullet = sgroot->createSceneGraph(BULEBULLET); - - camera_init(back, w, h); - back->set_move_collision(camera_init, camera_collision); - player->set_move_collision(player_move_all, player_collision); - - - back->addChild(player); - - for (int i = 0; i < 10; i++) { - enemy = sgroot->createSceneGraph(E_PLANE); - enemy->set_move_collision(enemy_move, enemy_collision); - enemy->xyz[0] = 50.0*i; - back->addChild(enemy); - } - - sgroot->setSceneData(back); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/lindaapi.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,626 @@ +// $Id: lindaapi.c,v 1.9 2006/04/03 08:17:11 kono Exp $ +// + +/*---------------------------------------------------------------------- + 롼ɥեɤ߹ +----------------------------------------------------------------------*/ +#include <sys/file.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <fcntl.h> +#include <sys/uio.h> +#include <sys/time.h> +#include <sys/select.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <netinet/in.h> +#include <netinet/tcp.h> +#include <signal.h> +#include <termios.h> +#include <netdb.h> +#include <errno.h> +#include <sys/select.h> + +#include "lindaapi.h" + +#define TIMEDELTA 10 +#if 0 +#define PSX_Debug(deb) (putchar(PS_DEB)),\ + (printf deb ),\ + (putchar(PS_DEB)) +#define DEB(a) +#else +#define PSX_Debug(deb) +#define DEB(a) /* a */ +#endif + +COMMAND *q_top, *q_end; +REPLY *reply, *r_end; + +int qsize, ps; +unsigned short seq; + +#ifdef COUNT_PACKET +// print packet count message per PRINT_INTERVAL sec +#define PRINT_INTERVAL 4 + +/*-------------------------------------------------------------------/ + void + count_packet (char type): + ѥåȤȤ + + : + type - (char: s,r) +/-------------------------------------------------------------------*/ +void count_packet(char type) +{ + static int send_packet=-1,receive_packet=0; + static struct timeval start,now,previous; + + if (out_packet == -1) { + gettimeofday(&start,NULL); + gettimeofday(&previous,NULL); + send_packet = 0; + printf("packet\tout\tread\t\ttime\n"); + } + + if (type == 's') { + send_packet++; + } else if (type == 'r') { + receive_packet++; + } else { + fprintf(stderr,"No type in count_packet function\n"); + return; + } + + gettimeofday(&now,NULL); + if ((now.tv_sec-previous.tv_sec) > PRINT_INTERVAL) { + printf("log\t%d\t%d\t%ld\n", + send_packet,receive_packet,now.tv_sec-start.tv_sec); + fflush(stdout); + + previous.tv_sec = now.tv_sec; + send_packet = receive_packet = 0; + } +} +#endif + + +#define unix_open open +#define unix_read_w read +/*-------------------------------------------------------------------/ + int + unix_read (int fd, char *buf, unsigned int size): + ФTUPLEɤߤࡣ + ߤϻȤƤʤ + + : + fd - ФΥեǥץ + buf - ǡγǼ(TUPLEإåޤ) + size - bufbyte + ֤: + ɤߤbyte +/-------------------------------------------------------------------*/ +int +unix_read(int fd,char *buf,unsigned int size) { + int len,a,i; + if(read(fd,buf,INT_SIZE)!=INT_SIZE) { // INT_SIZE is sizeof(int) + fprintf(stderr, "read error! on fd:%d len=%d %s\n", fd, + *(unsigned int*)&buf[0], + strerror(errno)); + exit(1); + } + len = ntohl(*(unsigned int*)&buf[0]); + if((unsigned int)len>size) len=(int)size; + for(a=0;a<len;a+=i) { + if((i=read(fd,buf+a,len-a))<0) { + fprintf(stderr, "ldserv: client read error! on i=%d len= %d %s\n", + i, len, strerror(errno)); + exit(1); + } + } + return len; +} + +/*-------------------------------------------------------------------/ + int + unix_write (int fd, unsigned char *buf, unsigned int size): + ФTUPLE롣 + + : + fd - ФΥեǥץ + buf - Фǡ(TUPLEإåޤ) + size - bufbyte + ֤: + ä()ǡbyte +/-------------------------------------------------------------------*/ +int +unix_write(int fd,unsigned char *buf,unsigned int size) { + int i,nsize; + nsize = htonl(size); + i = write(fd,&nsize,INT_SIZE); + i += write(fd,buf,size); // size == datasize + LINDA_HEADER_SIZE +#ifdef COUNT_PACKET + count_packet('s'); +#endif + return(i); +} + +#define unix_write_w unix_write + +#define SERV_NAME unix_port +#define PROTO_NAME "tcp" +#define SERVER_NAME hostname +#define MAX_REQ 16 + +int fd,paddrlen; +struct hostent *hoste; +struct sockaddr_in serv_addr; +struct sockaddr_un serv_addr_un; +unsigned char ipaddr[4]; + + +/*-------------------------------------------------------------------/ + int + start_linda (char * hostname): + ФȤΥͥΩCOMMAND塼REPLY塼 + Ԥʤ + + : + hostname - ФΥۥ̾ + ֤: + ͥΩȤΥեǥץ֤ + Ԥ -1 ֤ +/-------------------------------------------------------------------*/ +int +start_linda(char * hostname){ + char *p; + + if (! hostname) { + hostname = "/tmp/ldserv"; + } + if (hostname[0]=='/') { + /* Unix domain */ + if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == FAIL){ + fprintf(stderr, "socket open error! errno :%d %s\n", errno, + strerror(errno)); + return(-1); + } + serv_addr_un.sun_family = AF_UNIX; + strcpy(serv_addr_un.sun_path, hostname); + fprintf(stdout,"connecting ... %d\n", ntohs(serv_addr.sin_port)); + if (connect(fd, (struct sockaddr *)&serv_addr_un,sizeof(serv_addr_un)) == FAIL){ + fprintf(stderr,"connection error! errno :%d %s\n", errno, + strerror(errno)); + close(fd); + return(-1); + } + + } else { + /* INET domain */ + if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == FAIL){ + fprintf(stderr, "socket open error! errno :%d %s\n", errno, + strerror(errno)); + return(-1); + } + /* check optional port number */ + serv_addr.sin_port = htons(10000); + p = (char *)malloc(strlen(hostname)); + strcpy(p,hostname); + hostname = p; + while(*p) { + if (*p==':') { + serv_addr.sin_port = htons(atoi(p+1)); + *p = 0; + break; + } + p++; + } + if ((hoste = gethostbyname(hostname)) == NULL){ + fprintf(stderr,"hostname error\n"); + close(fd); + return(-1); + } + free(hostname); hostname=0; + serv_addr.sin_family = AF_INET; + serv_addr.sin_addr.s_addr = ((struct in_addr *)(hoste->h_addr))->s_addr; + if (serv_addr.sin_family == AF_INET) { + int tmp = 1; + setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, + (char *) &tmp, sizeof (int)); + } + fprintf(stdout,"connecting ... %d\n", ntohs(serv_addr.sin_port)); + if (connect(fd, (struct sockaddr *)&serv_addr,sizeof(serv_addr)) == FAIL){ + fprintf(stderr,"connection error! errno :%d %s\n", errno, + strerror(errno)); + close(fd); + return(-1); + } + } + + ps = fd; + fprintf(stdout," connect middle server %d\n", fd); + q_end = q_top = NULL; + r_end = reply = NULL; + qsize = seq = 0; + seq = 120; + return ps; +} + +/*-------------------------------------------------------------------/ + int + psx_out (unsigned int id, unsigned char *data, unsigned int size): + outޥɤCOMMAND塼ί롣 + + : + id - TUPLE SpaceID + data - ǡ + size - dataΥ + ֤: + ֹ +/-------------------------------------------------------------------*/ +int +psx_out(unsigned int id, unsigned char *data, unsigned int size){ + if (psx_queue(id, size, data, 'o', NULL, NULL) == FAIL){ + return(FAIL); + } + DEB( fprintf(stdout, "psx_out: size = %d, command = %s\n", + q_end->size, q_end->command+LINDA_HEADER_SIZE)); + return(seq); +} + +/*-------------------------------------------------------------------/ + int + psx_ld (unsigned int id, char mode, void(*callback)(char*,void*), + void * obj): + in,read,waitʤɤμޥɤCOMMAND塼ί롣 + psx_in,psx_rd,psx_wait_rdʤɤ֤Ƥ롣 + + : + id - TUPLE SpaceID + mode - i,r,w ʸꡢơin,read,waitɽƤ롣 + callback - ХåѤδؿؤΥݥ + ѤʤNULL롣 + obj - ХåѤؿΰ + ֤: + psx_queuemalloc줿REPLY¤ΤؤΥݥ +/-------------------------------------------------------------------*/ +int +psx_ld(unsigned int id, char mode,void(*callback)(char *,void *),void * obj){ + int r; + if ((r=psx_queue(id, 0, NULL, mode, callback, obj)) == FAIL){ + return(FAIL); + } + return(r); +} + +/*-------------------------------------------------------------------/ + unsigned char * + psx_reply (int seq): + Ф褿ǡ֤ + + : + seq - psx_ld()֤͡ + ֤: + seqбǡ֤ǡޤƤʤ + NULL֤ +/-------------------------------------------------------------------*/ +unsigned char * +psx_reply(int seq){ + REPLY *p, *q; + char *ans; + + DEB(fprintf(stdout, "psx_reply: search of seq = %d\n", seq)); + PSX_Debug(("psx_reply: seq %d", seq)); + for(q = NULL,p = reply;p;q = p,p = p->next){ + if (p->seq == (unsigned)seq){ + DEB(fprintf(stdout, "psx_reply: match of seq = %d\n", seq)); + if (p->mode == '!'){ + ans = (char *)p->answer; + if (q == NULL){ + reply = p->next; + if(p==r_end) { + r_end = p->next; + } + } else { + q->next = p->next; + if(p==r_end) { + r_end = q; + } + } + PSX_Debug(("psx_reply: reply %x r_end %x p %x q %x",reply,r_end,p,q)); + free(p); + DEB( for(p=reply;p;p=p->next) { PSX_Debug(("psx_queue dump: seq %d mode %c %x %x",p->seq,p->mode,p,p->next))}); + DEB( fprintf(stdout, "psx_reply: returned answer = %s\n", ans)); + PSX_Debug(("psx_reply: answer %s",ans)); + return((unsigned char *)ans); + } else { + if (p->mode == '?'){ + DEB(fprintf(stdout, "psx_reply: don't accept anser\n")); + return(NULL); + } + } + } + + } + PSX_Debug(("psx_reply: no match seq %d",seq)); + DEB(fprintf(stdout, "psx_reply: no match of seq\n")); + return(NULL); +} + +/*-------------------------------------------------------------------/ + void + psx_sync_n (): + Фȥǡ롣COMMAND塼ίޤäǡ + Ф褿ǡбREPLYؤ롣 +/-------------------------------------------------------------------*/ +void +psx_sync_n(){ + int acount; + COMMAND *c, *t; + + fd_set tmp, fds; + struct timeval timeout; + timeout.tv_sec=0; + timeout.tv_usec=TIMEDELTA * 1000; + + acount = 0; + while (q_top != NULL){ + c = q_top; + unix_write_w(ps, c->command, c->size); + free(c->command); + t = c->next; + free(c); + q_top = c = t;qsize--; + } + FD_ZERO(&fds); + FD_SET(ps, &fds); + tmp = fds; + while(select(32, &tmp, NULL, NULL, &timeout) > 0) { + if(FD_ISSET(ps, &tmp)) { + unix_chkserv(); + } + } +} + +/*-------------------------------------------------------------------/ + int + psx_queue (unsigned int id, unsigned int size, unsigned char *data, + char mode, void(*callback)(char*,void*), void * obj): + out,in,read,waitʤɤΥޥɤCOMMAND塼ί롣ǡ + 륳ޥ(in,read,wait)ΤȤϼäȤ˥ǡ + ǼREPLY¤Τ롣 + + : + id - TUPLE SpaceID + size - dataΥ + data - ǡNULL + mode - ޥɤΥ⡼(out,in,read,wait ϳơchar: o,i,r,w) + callback - ХåѤδؿؤΥݥ + ѤʤNULL + obj - ХåѤؿ˰Ϥǡ + ֤: + - mallocREPLY¤ΤؤΥݥoutξ + 0֤롣 + Ԥ - FAIL(-1)֤롣 +/-------------------------------------------------------------------*/ +int +psx_queue(unsigned int id, unsigned int size, unsigned char *data, char mode, + void(*callback)(char *,void *), void * obj){ + REPLY *p; + COMMAND *c; + + seq++; + if (qsize >= MAX_QUEUE){ +// PSX_Debug(("max queue: qsize=%d",qsize)); + psx_sync_n(); + } + + for(p=reply;p;p=p->next){ + if(p->seq == seq){ + printf("same seq number: %d\n",seq); + } + } + + if (q_top == NULL){ + if ((q_top = (COMMAND *) malloc (sizeof(COMMAND))) == NULL){ + return(FAIL); + } + c = q_end = q_top; + } else { + if ((q_end->next = (COMMAND *) malloc (sizeof(COMMAND))) == NULL){ + return(FAIL); + } + c = q_end; + q_end = q_end->next; + } + + // size DATASIZE + if ((q_end->command = (unsigned char *) malloc(size+LINDA_HEADER_SIZE)) == NULL){ + free(q_end); + c->next = NULL; + return(FAIL); + } + + if (mode != 'o'){ + if (reply == NULL){ + if ((reply = (REPLY *) malloc (sizeof(REPLY))) == NULL){ + return(FAIL); + } + p = r_end = reply; p->next = NULL; + } else { + if ((r_end->next = (REPLY *) malloc (sizeof(REPLY))) == NULL){ + return(FAIL); + } + p = r_end->next; r_end = p; p->next = NULL; + } + p->mode = '?'; + p->seq = (int)p; // ¤ΤΥɥ쥹Ǽ + p->callback = callback; + p->obj = obj; + PSX_Debug(("psx_queue: seq %d reply %x p %x r_end %x",seq,reply,p,r_end)); + }else{ + p=0; + } + q_end->command[LINDA_MODE_OFFSET] = mode; + + q_end->command[LINDA_ID_OFFSET] = id >> 8; + q_end->command[LINDA_ID_OFFSET+1] = id & 0xff; + + q_end->command[LINDA_SEQ_OFFSET] = ((int)p>>24) & 0xff; + q_end->command[LINDA_SEQ_OFFSET+1] = ((int)p>>16) & 0xff; + q_end->command[LINDA_SEQ_OFFSET+2] = ((int)p>>8) & 0xff; + q_end->command[LINDA_SEQ_OFFSET+3] = ((int)p) & 0xff; + + q_end->command[LINDA_DATA_LENGTH_OFFSET] = (size>>24) & 0xff; + q_end->command[LINDA_DATA_LENGTH_OFFSET+1] = (size>>16) & 0xff; + q_end->command[LINDA_DATA_LENGTH_OFFSET+2] = (size>>8) & 0xff; + q_end->command[LINDA_DATA_LENGTH_OFFSET+3] = (size) & 0xff; + + q_end->size = size+LINDA_HEADER_SIZE; /* command size */ + q_end->next = NULL; qsize++; + if (data && size>0) memcpy(q_end->command+LINDA_HEADER_SIZE, data, size); + return((int)p); +} + +/*-------------------------------------------------------------------/ + void + unix_chkserv (): + Фǡ(TUPLE)롣REPLY¤Τ˥Хåؿ + ꤵƤФδؿ¹ԤREPLY¤Τ塼 + ХåؿꤵƤʤREPLY¤Τ˥ǡ + Ϥ +/-------------------------------------------------------------------*/ +void +unix_chkserv(){ + int i,k,pkt,npkt; + REPLY *r,*prev; + int a; + unsigned char * tuple = 0; + + if((i=read(ps,&npkt,INT_SIZE))<0) { + fprintf(stderr, "size read error! on fd:%d %s\n", ps, + strerror(errno)); + exit(1); + } + pkt = ntohl(npkt); + DEB(printf("pkt: %d\n",pkt)); + DEB(fprintf(stdout, "psx_chkserv: queue number: %d , size = %d\n", i, pkt)); + if((tuple = (unsigned char *)malloc(pkt))==NULL){ + fprintf(stderr,"allocate error! errno :%d %s",errno,strerror(errno)); + exit(1); + } + for(a=0;a<pkt;a+=i) { + if((i=unix_read_w(ps,tuple+a,pkt-a))<0) { + fprintf(stderr, "psx_chkserv: read error! on i=%d pkt=%d %s\n", + i, pkt, strerror(errno)); + exit(1);//close(ps); + } + } + +#ifdef COUNT_PACKET + count_packet('r'); +#endif + + i = tuple[LINDA_ID_OFFSET] * 256 + tuple[LINDA_ID_OFFSET+1]; /* id */ + k = (tuple[LINDA_SEQ_OFFSET] <<24) + + (tuple[LINDA_SEQ_OFFSET+1]<<16) + + (tuple[LINDA_SEQ_OFFSET+2]<<8) + + (tuple[LINDA_SEQ_OFFSET+3]); /* seq */ + PSX_Debug(("psx_chkserv: anser packet size = %d id %d seq %d", pkt,i,k)); + DEB(fprintf(stdout, "psx_chkserv: data from server: %s id=%d seq = %d\n", tuple, i, k)); + DEB ( + for(p=reply;p;p=p->next) { + PSX_Debug(printf("psx_queue dump: seq %d mode %c %x %x",p->seq,p->mode,p,p->next)); + }) + + for(prev = NULL,r = reply; r; prev = r,r = r->next){ + DEB(fprintf(stdout,"seq: %d\n",r->seq);) + if (r->seq == (unsigned int)k){ + if(r->callback){ // call callback function + (*r->callback)((char *)tuple,r->obj); + if (prev == NULL){ + reply = r->next; + if(r == r_end) { + r_end = r->next; + } + } else { + prev->next = r->next; + if(r == r_end) { + r_end = prev; + } + } + free(r); + }else{ // normal reply + PSX_Debug(("psx_chkserv: copy answer r %x seq %d",r,k)); + r->answer = tuple; + r->mode = '!'; + } + break; + } + } + tuple = 0; + if (!r){ + DEB(fprintf(stdout, "unix_chkserv: accepted seq %d does not match. \n",k)); + } +} + +void psx_free(char * tuple) +{ +// free(tuple - LINDA_HEADER_SIZE); + free(tuple); +} + +/*-------------------------------------------------------------------/ + int + get_int(unsigned char * tuple, int offset): + TUPLEΥإå˳Ǽ줿 int Υǡ뤿δؿ + psx_get_datalength() psx_get_seq() ƤФ롣 + + : + tuple - إåޤTUPLEpsx_reply()ΤǤ⤤ + offset - ǡΥեåȡLINDA_DATA_LENGTH_OFFSET + LINDA_SEQ_OFFSET + + ֤: + ꤷեåȤ˳ǼƤ(int) +/-------------------------------------------------------------------*/ +static +int get_int(unsigned char * tuple, int offset){ + int i; + i = (tuple[offset] <<24) + + (tuple[offset+1]<<16) + + (tuple[offset+2]<<8) + + (tuple[offset+3]); + return i; +} + +int psx_get_datalength(unsigned char * tuple){ + return get_int(tuple,LINDA_DATA_LENGTH_OFFSET); +} + +unsigned char *psx_get_data(unsigned char * tuple){ + return tuple+LINDA_HEADER_SIZE; +} + +int psx_get_seq(unsigned char * tuple){ + return get_int(tuple,LINDA_SEQ_OFFSET); +} + +short psx_get_id(unsigned char * tuple){ + short s; + s = tuple[LINDA_ID_OFFSET] * 256 + + tuple[LINDA_ID_OFFSET+1]; + return s; +} + +char psx_get_mode(unsigned char * tuple){ + return tuple[LINDA_MODE_OFFSET]; +} + + +/* end */
--- a/TaskManager/Test/test_render/lindaapi.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,626 +0,0 @@ -// $Id: lindaapi.c,v 1.9 2006/04/03 08:17:11 kono Exp $ -// - -/*---------------------------------------------------------------------- - 롼ɥեɤ߹ -----------------------------------------------------------------------*/ -#include <sys/file.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <fcntl.h> -#include <sys/uio.h> -#include <sys/time.h> -#include <sys/select.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/un.h> -#include <netinet/in.h> -#include <netinet/tcp.h> -#include <signal.h> -#include <termios.h> -#include <netdb.h> -#include <errno.h> -#include <sys/select.h> - -#include "lindaapi.h" - -#define TIMEDELTA 10 -#if 0 -#define PSX_Debug(deb) (putchar(PS_DEB)),\ - (printf deb ),\ - (putchar(PS_DEB)) -#define DEB(a) -#else -#define PSX_Debug(deb) -#define DEB(a) /* a */ -#endif - -COMMAND *q_top, *q_end; -REPLY *reply, *r_end; - -int qsize, ps; -unsigned short seq; - -#ifdef COUNT_PACKET -// print packet count message per PRINT_INTERVAL sec -#define PRINT_INTERVAL 4 - -/*-------------------------------------------------------------------/ - void - count_packet (char type): - ѥåȤȤ - - : - type - (char: s,r) -/-------------------------------------------------------------------*/ -void count_packet(char type) -{ - static int send_packet=-1,receive_packet=0; - static struct timeval start,now,previous; - - if (out_packet == -1) { - gettimeofday(&start,NULL); - gettimeofday(&previous,NULL); - send_packet = 0; - printf("packet\tout\tread\t\ttime\n"); - } - - if (type == 's') { - send_packet++; - } else if (type == 'r') { - receive_packet++; - } else { - fprintf(stderr,"No type in count_packet function\n"); - return; - } - - gettimeofday(&now,NULL); - if ((now.tv_sec-previous.tv_sec) > PRINT_INTERVAL) { - printf("log\t%d\t%d\t%ld\n", - send_packet,receive_packet,now.tv_sec-start.tv_sec); - fflush(stdout); - - previous.tv_sec = now.tv_sec; - send_packet = receive_packet = 0; - } -} -#endif - - -#define unix_open open -#define unix_read_w read -/*-------------------------------------------------------------------/ - int - unix_read (int fd, char *buf, unsigned int size): - ФTUPLEɤߤࡣ - ߤϻȤƤʤ - - : - fd - ФΥեǥץ - buf - ǡγǼ(TUPLEإåޤ) - size - bufbyte - ֤: - ɤߤbyte -/-------------------------------------------------------------------*/ -int -unix_read(int fd,char *buf,unsigned int size) { - int len,a,i; - if(read(fd,buf,INT_SIZE)!=INT_SIZE) { // INT_SIZE is sizeof(int) - fprintf(stderr, "read error! on fd:%d len=%d %s\n", fd, - *(unsigned int*)&buf[0], - strerror(errno)); - exit(1); - } - len = ntohl(*(unsigned int*)&buf[0]); - if((unsigned int)len>size) len=(int)size; - for(a=0;a<len;a+=i) { - if((i=read(fd,buf+a,len-a))<0) { - fprintf(stderr, "ldserv: client read error! on i=%d len= %d %s\n", - i, len, strerror(errno)); - exit(1); - } - } - return len; -} - -/*-------------------------------------------------------------------/ - int - unix_write (int fd, unsigned char *buf, unsigned int size): - ФTUPLE롣 - - : - fd - ФΥեǥץ - buf - Фǡ(TUPLEإåޤ) - size - bufbyte - ֤: - ä()ǡbyte -/-------------------------------------------------------------------*/ -int -unix_write(int fd,unsigned char *buf,unsigned int size) { - int i,nsize; - nsize = htonl(size); - i = write(fd,&nsize,INT_SIZE); - i += write(fd,buf,size); // size == datasize + LINDA_HEADER_SIZE -#ifdef COUNT_PACKET - count_packet('s'); -#endif - return(i); -} - -#define unix_write_w unix_write - -#define SERV_NAME unix_port -#define PROTO_NAME "tcp" -#define SERVER_NAME hostname -#define MAX_REQ 16 - -int fd,paddrlen; -struct hostent *hoste; -struct sockaddr_in serv_addr; -struct sockaddr_un serv_addr_un; -unsigned char ipaddr[4]; - - -/*-------------------------------------------------------------------/ - int - start_linda (char * hostname): - ФȤΥͥΩCOMMAND塼REPLY塼 - Ԥʤ - - : - hostname - ФΥۥ̾ - ֤: - ͥΩȤΥեǥץ֤ - Ԥ -1 ֤ -/-------------------------------------------------------------------*/ -int -start_linda(char * hostname){ - char *p; - - if (! hostname) { - hostname = "/tmp/ldserv"; - } - if (hostname[0]=='/') { - /* Unix domain */ - if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == FAIL){ - fprintf(stderr, "socket open error! errno :%d %s\n", errno, - strerror(errno)); - return(-1); - } - serv_addr_un.sun_family = AF_UNIX; - strcpy(serv_addr_un.sun_path, hostname); - fprintf(stdout,"connecting ... %d\n", ntohs(serv_addr.sin_port)); - if (connect(fd, (struct sockaddr *)&serv_addr_un,sizeof(serv_addr_un)) == FAIL){ - fprintf(stderr,"connection error! errno :%d %s\n", errno, - strerror(errno)); - close(fd); - return(-1); - } - - } else { - /* INET domain */ - if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == FAIL){ - fprintf(stderr, "socket open error! errno :%d %s\n", errno, - strerror(errno)); - return(-1); - } - /* check optional port number */ - serv_addr.sin_port = htons(10000); - p = (char *)malloc(strlen(hostname)); - strcpy(p,hostname); - hostname = p; - while(*p) { - if (*p==':') { - serv_addr.sin_port = htons(atoi(p+1)); - *p = 0; - break; - } - p++; - } - if ((hoste = gethostbyname(hostname)) == NULL){ - fprintf(stderr,"hostname error\n"); - close(fd); - return(-1); - } - free(hostname); hostname=0; - serv_addr.sin_family = AF_INET; - serv_addr.sin_addr.s_addr = ((struct in_addr *)(hoste->h_addr))->s_addr; - if (serv_addr.sin_family == AF_INET) { - int tmp = 1; - setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, - (char *) &tmp, sizeof (int)); - } - fprintf(stdout,"connecting ... %d\n", ntohs(serv_addr.sin_port)); - if (connect(fd, (struct sockaddr *)&serv_addr,sizeof(serv_addr)) == FAIL){ - fprintf(stderr,"connection error! errno :%d %s\n", errno, - strerror(errno)); - close(fd); - return(-1); - } - } - - ps = fd; - fprintf(stdout," connect middle server %d\n", fd); - q_end = q_top = NULL; - r_end = reply = NULL; - qsize = seq = 0; - seq = 120; - return ps; -} - -/*-------------------------------------------------------------------/ - int - psx_out (unsigned int id, unsigned char *data, unsigned int size): - outޥɤCOMMAND塼ί롣 - - : - id - TUPLE SpaceID - data - ǡ - size - dataΥ - ֤: - ֹ -/-------------------------------------------------------------------*/ -int -psx_out(unsigned int id, unsigned char *data, unsigned int size){ - if (psx_queue(id, size, data, 'o', NULL, NULL) == FAIL){ - return(FAIL); - } - DEB( fprintf(stdout, "psx_out: size = %d, command = %s\n", - q_end->size, q_end->command+LINDA_HEADER_SIZE)); - return(seq); -} - -/*-------------------------------------------------------------------/ - int - psx_ld (unsigned int id, char mode, void(*callback)(char*,void*), - void * obj): - in,read,waitʤɤμޥɤCOMMAND塼ί롣 - psx_in,psx_rd,psx_wait_rdʤɤ֤Ƥ롣 - - : - id - TUPLE SpaceID - mode - i,r,w ʸꡢơin,read,waitɽƤ롣 - callback - ХåѤδؿؤΥݥ - ѤʤNULL롣 - obj - ХåѤؿΰ - ֤: - psx_queuemalloc줿REPLY¤ΤؤΥݥ -/-------------------------------------------------------------------*/ -int -psx_ld(unsigned int id, char mode,void(*callback)(char *,void *),void * obj){ - int r; - if ((r=psx_queue(id, 0, NULL, mode, callback, obj)) == FAIL){ - return(FAIL); - } - return(r); -} - -/*-------------------------------------------------------------------/ - unsigned char * - psx_reply (int seq): - Ф褿ǡ֤ - - : - seq - psx_ld()֤͡ - ֤: - seqбǡ֤ǡޤƤʤ - NULL֤ -/-------------------------------------------------------------------*/ -unsigned char * -psx_reply(int seq){ - REPLY *p, *q; - char *ans; - - DEB(fprintf(stdout, "psx_reply: search of seq = %d\n", seq)); - PSX_Debug(("psx_reply: seq %d", seq)); - for(q = NULL,p = reply;p;q = p,p = p->next){ - if (p->seq == (unsigned)seq){ - DEB(fprintf(stdout, "psx_reply: match of seq = %d\n", seq)); - if (p->mode == '!'){ - ans = (char *)p->answer; - if (q == NULL){ - reply = p->next; - if(p==r_end) { - r_end = p->next; - } - } else { - q->next = p->next; - if(p==r_end) { - r_end = q; - } - } - PSX_Debug(("psx_reply: reply %x r_end %x p %x q %x",reply,r_end,p,q)); - free(p); - DEB( for(p=reply;p;p=p->next) { PSX_Debug(("psx_queue dump: seq %d mode %c %x %x",p->seq,p->mode,p,p->next))}); - DEB( fprintf(stdout, "psx_reply: returned answer = %s\n", ans)); - PSX_Debug(("psx_reply: answer %s",ans)); - return((unsigned char *)ans); - } else { - if (p->mode == '?'){ - DEB(fprintf(stdout, "psx_reply: don't accept anser\n")); - return(NULL); - } - } - } - - } - PSX_Debug(("psx_reply: no match seq %d",seq)); - DEB(fprintf(stdout, "psx_reply: no match of seq\n")); - return(NULL); -} - -/*-------------------------------------------------------------------/ - void - psx_sync_n (): - Фȥǡ롣COMMAND塼ίޤäǡ - Ф褿ǡбREPLYؤ롣 -/-------------------------------------------------------------------*/ -void -psx_sync_n(){ - int acount; - COMMAND *c, *t; - - fd_set tmp, fds; - struct timeval timeout; - timeout.tv_sec=0; - timeout.tv_usec=TIMEDELTA * 1000; - - acount = 0; - while (q_top != NULL){ - c = q_top; - unix_write_w(ps, c->command, c->size); - free(c->command); - t = c->next; - free(c); - q_top = c = t;qsize--; - } - FD_ZERO(&fds); - FD_SET(ps, &fds); - tmp = fds; - while(select(32, &tmp, NULL, NULL, &timeout) > 0) { - if(FD_ISSET(ps, &tmp)) { - unix_chkserv(); - } - } -} - -/*-------------------------------------------------------------------/ - int - psx_queue (unsigned int id, unsigned int size, unsigned char *data, - char mode, void(*callback)(char*,void*), void * obj): - out,in,read,waitʤɤΥޥɤCOMMAND塼ί롣ǡ - 륳ޥ(in,read,wait)ΤȤϼäȤ˥ǡ - ǼREPLY¤Τ롣 - - : - id - TUPLE SpaceID - size - dataΥ - data - ǡNULL - mode - ޥɤΥ⡼(out,in,read,wait ϳơchar: o,i,r,w) - callback - ХåѤδؿؤΥݥ - ѤʤNULL - obj - ХåѤؿ˰Ϥǡ - ֤: - - mallocREPLY¤ΤؤΥݥoutξ - 0֤롣 - Ԥ - FAIL(-1)֤롣 -/-------------------------------------------------------------------*/ -int -psx_queue(unsigned int id, unsigned int size, unsigned char *data, char mode, - void(*callback)(char *,void *), void * obj){ - REPLY *p; - COMMAND *c; - - seq++; - if (qsize >= MAX_QUEUE){ -// PSX_Debug(("max queue: qsize=%d",qsize)); - psx_sync_n(); - } - - for(p=reply;p;p=p->next){ - if(p->seq == seq){ - printf("same seq number: %d\n",seq); - } - } - - if (q_top == NULL){ - if ((q_top = (COMMAND *) malloc (sizeof(COMMAND))) == NULL){ - return(FAIL); - } - c = q_end = q_top; - } else { - if ((q_end->next = (COMMAND *) malloc (sizeof(COMMAND))) == NULL){ - return(FAIL); - } - c = q_end; - q_end = q_end->next; - } - - // size DATASIZE - if ((q_end->command = (unsigned char *) malloc(size+LINDA_HEADER_SIZE)) == NULL){ - free(q_end); - c->next = NULL; - return(FAIL); - } - - if (mode != 'o'){ - if (reply == NULL){ - if ((reply = (REPLY *) malloc (sizeof(REPLY))) == NULL){ - return(FAIL); - } - p = r_end = reply; p->next = NULL; - } else { - if ((r_end->next = (REPLY *) malloc (sizeof(REPLY))) == NULL){ - return(FAIL); - } - p = r_end->next; r_end = p; p->next = NULL; - } - p->mode = '?'; - p->seq = (int)p; // ¤ΤΥɥ쥹Ǽ - p->callback = callback; - p->obj = obj; - PSX_Debug(("psx_queue: seq %d reply %x p %x r_end %x",seq,reply,p,r_end)); - }else{ - p=0; - } - q_end->command[LINDA_MODE_OFFSET] = mode; - - q_end->command[LINDA_ID_OFFSET] = id >> 8; - q_end->command[LINDA_ID_OFFSET+1] = id & 0xff; - - q_end->command[LINDA_SEQ_OFFSET] = ((int)p>>24) & 0xff; - q_end->command[LINDA_SEQ_OFFSET+1] = ((int)p>>16) & 0xff; - q_end->command[LINDA_SEQ_OFFSET+2] = ((int)p>>8) & 0xff; - q_end->command[LINDA_SEQ_OFFSET+3] = ((int)p) & 0xff; - - q_end->command[LINDA_DATA_LENGTH_OFFSET] = (size>>24) & 0xff; - q_end->command[LINDA_DATA_LENGTH_OFFSET+1] = (size>>16) & 0xff; - q_end->command[LINDA_DATA_LENGTH_OFFSET+2] = (size>>8) & 0xff; - q_end->command[LINDA_DATA_LENGTH_OFFSET+3] = (size) & 0xff; - - q_end->size = size+LINDA_HEADER_SIZE; /* command size */ - q_end->next = NULL; qsize++; - if (data && size>0) memcpy(q_end->command+LINDA_HEADER_SIZE, data, size); - return((int)p); -} - -/*-------------------------------------------------------------------/ - void - unix_chkserv (): - Фǡ(TUPLE)롣REPLY¤Τ˥Хåؿ - ꤵƤФδؿ¹ԤREPLY¤Τ塼 - ХåؿꤵƤʤREPLY¤Τ˥ǡ - Ϥ -/-------------------------------------------------------------------*/ -void -unix_chkserv(){ - int i,k,pkt,npkt; - REPLY *r,*prev; - int a; - unsigned char * tuple = 0; - - if((i=read(ps,&npkt,INT_SIZE))<0) { - fprintf(stderr, "size read error! on fd:%d %s\n", ps, - strerror(errno)); - exit(1); - } - pkt = ntohl(npkt); - DEB(printf("pkt: %d\n",pkt)); - DEB(fprintf(stdout, "psx_chkserv: queue number: %d , size = %d\n", i, pkt)); - if((tuple = (unsigned char *)malloc(pkt))==NULL){ - fprintf(stderr,"allocate error! errno :%d %s",errno,strerror(errno)); - exit(1); - } - for(a=0;a<pkt;a+=i) { - if((i=unix_read_w(ps,tuple+a,pkt-a))<0) { - fprintf(stderr, "psx_chkserv: read error! on i=%d pkt=%d %s\n", - i, pkt, strerror(errno)); - exit(1);//close(ps); - } - } - -#ifdef COUNT_PACKET - count_packet('r'); -#endif - - i = tuple[LINDA_ID_OFFSET] * 256 + tuple[LINDA_ID_OFFSET+1]; /* id */ - k = (tuple[LINDA_SEQ_OFFSET] <<24) + - (tuple[LINDA_SEQ_OFFSET+1]<<16) + - (tuple[LINDA_SEQ_OFFSET+2]<<8) + - (tuple[LINDA_SEQ_OFFSET+3]); /* seq */ - PSX_Debug(("psx_chkserv: anser packet size = %d id %d seq %d", pkt,i,k)); - DEB(fprintf(stdout, "psx_chkserv: data from server: %s id=%d seq = %d\n", tuple, i, k)); - DEB ( - for(p=reply;p;p=p->next) { - PSX_Debug(printf("psx_queue dump: seq %d mode %c %x %x",p->seq,p->mode,p,p->next)); - }) - - for(prev = NULL,r = reply; r; prev = r,r = r->next){ - DEB(fprintf(stdout,"seq: %d\n",r->seq);) - if (r->seq == (unsigned int)k){ - if(r->callback){ // call callback function - (*r->callback)((char *)tuple,r->obj); - if (prev == NULL){ - reply = r->next; - if(r == r_end) { - r_end = r->next; - } - } else { - prev->next = r->next; - if(r == r_end) { - r_end = prev; - } - } - free(r); - }else{ // normal reply - PSX_Debug(("psx_chkserv: copy answer r %x seq %d",r,k)); - r->answer = tuple; - r->mode = '!'; - } - break; - } - } - tuple = 0; - if (!r){ - DEB(fprintf(stdout, "unix_chkserv: accepted seq %d does not match. \n",k)); - } -} - -void psx_free(char * tuple) -{ -// free(tuple - LINDA_HEADER_SIZE); - free(tuple); -} - -/*-------------------------------------------------------------------/ - int - get_int(unsigned char * tuple, int offset): - TUPLEΥإå˳Ǽ줿 int Υǡ뤿δؿ - psx_get_datalength() psx_get_seq() ƤФ롣 - - : - tuple - إåޤTUPLEpsx_reply()ΤǤ⤤ - offset - ǡΥեåȡLINDA_DATA_LENGTH_OFFSET - LINDA_SEQ_OFFSET - - ֤: - ꤷեåȤ˳ǼƤ(int) -/-------------------------------------------------------------------*/ -static -int get_int(unsigned char * tuple, int offset){ - int i; - i = (tuple[offset] <<24) + - (tuple[offset+1]<<16) + - (tuple[offset+2]<<8) + - (tuple[offset+3]); - return i; -} - -int psx_get_datalength(unsigned char * tuple){ - return get_int(tuple,LINDA_DATA_LENGTH_OFFSET); -} - -unsigned char *psx_get_data(unsigned char * tuple){ - return tuple+LINDA_HEADER_SIZE; -} - -int psx_get_seq(unsigned char * tuple){ - return get_int(tuple,LINDA_SEQ_OFFSET); -} - -short psx_get_id(unsigned char * tuple){ - short s; - s = tuple[LINDA_ID_OFFSET] * 256 + - tuple[LINDA_ID_OFFSET+1]; - return s; -} - -char psx_get_mode(unsigned char * tuple){ - return tuple[LINDA_MODE_OFFSET]; -} - - -/* end */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/long_cube.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,31 @@ +#include "SceneGraphRoot.h" +#include "SGList.h" + +// prototype +static void lcube_move(SceneGraphPtr node, int screen_w, int screen_h); +//static void lcube_collision(SceneGraphPtr node, int screen_w, int screen_h); + + +static void +lcube_move(SceneGraphPtr node, int screen_w, int screen_h) +{ +} + +static void +lcube_collision(SceneGraphPtr node, int screen_w, int screen_h, + SceneGraphPtr tree) +{ +} + + +void +lcube_init(TaskManager *manager, int screen_w, int screen_h) +{ + SceneGraphPtr lcube; + + sgroot->createFromXMLfile(manager, "xml_file/LongCube.xml"); + lcube = sgroot->createSceneGraph(LongCube); + lcube->set_move_collision(lcube_move, lcube_collision); + + sgroot->setSceneData(lcube); +}
--- a/TaskManager/Test/test_render/long_cube.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -#include "SceneGraphRoot.h" -#include "SGList.h" - -// prototype -static void lcube_move(SceneGraphPtr node, int screen_w, int screen_h); -//static void lcube_collision(SceneGraphPtr node, int screen_w, int screen_h); - - -static void -lcube_move(SceneGraphPtr node, int screen_w, int screen_h) -{ -} - -static void -lcube_collision(SceneGraphPtr node, int screen_w, int screen_h, - SceneGraphPtr tree) -{ -} - - -void -lcube_init(TaskManager *manager, int screen_w, int screen_h) -{ - SceneGraphPtr lcube; - - sgroot->createFromXMLfile(manager, "xml_file/LongCube.xml"); - lcube = sgroot->createSceneGraph(LongCube); - lcube->set_move_collision(lcube_move, lcube_collision); - - sgroot->setSceneData(lcube); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/main.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,100 @@ +#include "TaskManager.h" +#include "viewer.h" +#include "viewerSDL.h" +#include "viewerFB.h" +#include "Func.h" + +/* prototype */ +static int init(TaskManager *manager, int argc, char *argv[]); +static void TMend(TaskManager *manager); + +extern void task_initialize(); + +// 帯域変数は禁止 +//static Viewer *screen; +static int sg_number = 0; + + +const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n\ + -cpu Number of SPE (default 1)\n\ + -width, -height window size (default 640x480)\n\ + -sg Draw SceneGraph\n\ + 0: Joystick の 丸ボタン(Keyboard だとx) を押すと、キューブが二つに分かれる\n\ + 1: 0 のキューブが大きい版\n\ + 2: テクスチャテスト:576x384\n\ + 3: テクスチャテスト:1024x768\n\ + 4: テクスチャテスト:2048x1536\n\ + 5: 地球が動き、その周りを月が自転、公転する\n\ + 6 以降: キューブが跳ね返りながら、勝手にキューブが増えて行く\n"; + +int +init(TaskManager *manager, int argc, char *argv[]) +{ + int bpp = 32; + int width = 640; + int height = 480; + int spenum = 1; + const char *xml = "xml_file/cube.xml"; + video_type vtype = VTYPE_SDL; + + for(int i = 1; argv[i]; ++i) + { + if (strcmp(argv[i], "-bpp") == 0) { + bpp = atoi(argv[++i]); + } + if (strcmp(argv[i], "-width") == 0) { + width = atoi(argv[++i]); + } + if (strcmp(argv[i], "-height") == 0) { + height = atoi(argv[++i]); + } + if (strcmp(argv[i], "-xml") == 0) { + xml = argv[++i]; + } + if (strcmp(argv[i], "-sg") == 0) { + sg_number = (atoi)(argv[++i]); + } + if (strcmp(argv[i], "-cpu") == 0) { + spenum = atoi(argv[++i]); + } + if (strcmp(argv[i], "-video") == 0) { + if (strcmp(argv[i+1], "sdl") == 0) { + vtype = VTYPE_SDL; + } else if (strcmp(argv[i+1], "fb") == 0) { + vtype = VTYPE_FB; + } + i++; + } + } + + Viewer *screen; + if (vtype == VTYPE_SDL) { + screen = new ViewerSDL(manager, bpp, width, height, spenum); + } else if (vtype == VTYPE_FB) { + screen = new ViewerFB(manager, bpp, width, height, spenum); + }else{ + screen = new ViewerSDL(manager, bpp, width, height, spenum); + } + + screen->video_init(manager); + screen->run_init(manager, xml, sg_number); + + manager->set_TMend(TMend); + + return 0; +} + +int +TMmain(TaskManager *manager, int argc, char *argv[]) +{ + task_initialize(); + return init(manager, argc, argv); + + //return 0; +} + +void +TMend(TaskManager *manager) +{ + printf("test_nogl end\n"); +}
--- a/TaskManager/Test/test_render/main.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,100 +0,0 @@ -#include "TaskManager.h" -#include "viewer.h" -#include "viewerSDL.h" -#include "viewerFB.h" -#include "Func.h" - -/* prototype */ -static int init(TaskManager *manager, int argc, char *argv[]); -static void TMend(TaskManager *manager); - -extern void task_initialize(); - -// 帯域変数は禁止 -//static Viewer *screen; -static int sg_number = 0; - - -const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n\ - -cpu Number of SPE (default 1)\n\ - -width, -height window size (default 640x480)\n\ - -sg Draw SceneGraph\n\ - 0: Joystick の 丸ボタン(Keyboard だとx) を押すと、キューブが二つに分かれる\n\ - 1: 0 のキューブが大きい版\n\ - 2: テクスチャテスト:576x384\n\ - 3: テクスチャテスト:1024x768\n\ - 4: テクスチャテスト:2048x1536\n\ - 5: 地球が動き、その周りを月が自転、公転する\n\ - 6 以降: キューブが跳ね返りながら、勝手にキューブが増えて行く\n"; - -int -init(TaskManager *manager, int argc, char *argv[]) -{ - int bpp = 32; - int width = 640; - int height = 480; - int spenum = 1; - const char *xml = "xml_file/cube.xml"; - video_type vtype = VTYPE_SDL; - - for(int i = 1; argv[i]; ++i) - { - if (strcmp(argv[i], "-bpp") == 0) { - bpp = atoi(argv[++i]); - } - if (strcmp(argv[i], "-width") == 0) { - width = atoi(argv[++i]); - } - if (strcmp(argv[i], "-height") == 0) { - height = atoi(argv[++i]); - } - if (strcmp(argv[i], "-xml") == 0) { - xml = argv[++i]; - } - if (strcmp(argv[i], "-sg") == 0) { - sg_number = (atoi)(argv[++i]); - } - if (strcmp(argv[i], "-cpu") == 0) { - spenum = atoi(argv[++i]); - } - if (strcmp(argv[i], "-video") == 0) { - if (strcmp(argv[i+1], "sdl") == 0) { - vtype = VTYPE_SDL; - } else if (strcmp(argv[i+1], "fb") == 0) { - vtype = VTYPE_FB; - } - i++; - } - } - - Viewer *screen; - if (vtype == VTYPE_SDL) { - screen = new ViewerSDL(manager, bpp, width, height, spenum); - } else if (vtype == VTYPE_FB) { - screen = new ViewerFB(manager, bpp, width, height, spenum); - }else{ - screen = new ViewerSDL(manager, bpp, width, height, spenum); - } - - screen->video_init(manager); - screen->run_init(manager, xml, sg_number); - - manager->set_TMend(TMend); - - return 0; -} - -int -TMmain(TaskManager *manager, int argc, char *argv[]) -{ - task_initialize(); - return init(manager, argc, argv); - - //return 0; -} - -void -TMend(TaskManager *manager) -{ - printf("test_nogl end\n"); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/node.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,72 @@ +#include <stdlib.h> +#include "SceneGraphRoot.h" +#include "SceneGraph.h" +#include "xml_file/cube.h" + +static void +cube_collision(SceneGraphPtr node, int screen_w, int screen_h, + SceneGraphPtr tree) +{ +} + +static void +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) { + + // 実は微妙に意味が無い + // そうじゃなくて、やっちゃいけないことです。 + // srandom(random()); + + SceneGraphPtr p = node->clone(); + p->position_init(); + node->addBrother(p); + p->set_move_collision(cube_move2, cube_collision); + p->stack_xyz[0] = (float)(random() % 5); + p->stack_xyz[1] = (float)(random() % 5); + //p->xyz[0] = screen_w/2; + //p->xyz[1] = screen_h/2; + p->xyz[2] = node->xyz[2]+1000.0f; + + node->stack_xyz[1] = -node->stack_xyz[1]; + } +} + +void +node_init(TaskManager *manager) +{ + sgroot->createFromXMLfile(manager, "xml_file/cube.xml"); + Cube->set_move_collision(cube_move, cube_collision); + Cube->stack_xyz[0] = 2.0f; + Cube->stack_xyz[1] = 2.0f; +}
--- a/TaskManager/Test/test_render/node.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -#include <stdlib.h> -#include "SceneGraphRoot.h" -#include "SceneGraph.h" -#include "xml_file/cube.h" - -static void -cube_collision(SceneGraphPtr node, int screen_w, int screen_h, - SceneGraphPtr tree) -{ -} - -static void -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) { - - // 実は微妙に意味が無い - // そうじゃなくて、やっちゃいけないことです。 - // srandom(random()); - - SceneGraphPtr p = node->clone(); - p->position_init(); - node->addBrother(p); - p->set_move_collision(cube_move2, cube_collision); - p->stack_xyz[0] = (float)(random() % 5); - p->stack_xyz[1] = (float)(random() % 5); - //p->xyz[0] = screen_w/2; - //p->xyz[1] = screen_h/2; - p->xyz[2] = node->xyz[2]+1000.0f; - - node->stack_xyz[1] = -node->stack_xyz[1]; - } -} - -void -node_init(TaskManager *manager) -{ - sgroot->createFromXMLfile(manager, "xml_file/cube.xml"); - Cube->set_move_collision(cube_move, cube_collision); - Cube->stack_xyz[0] = 2.0f; - Cube->stack_xyz[1] = 2.0f; -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/panel.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,38 @@ +#include "SceneGraphRoot.h" +#include "SGList.h" + +static void panel_move(SceneGraphPtr node, int screen_w, int screen_h); +static void panel_collision(SceneGraphPtr node, int screen_w, int screen_h, + SceneGraphPtr tree); + +static void +panel_move(SceneGraphPtr node, int screen_w, int screen_h) +{ +} + +static void +panel_collision(SceneGraphPtr node, int screen_w, int screen_h, + SceneGraphPtr tree) +{ +} + +void +panel_init(TaskManager *manager, int bg) +{ + SceneGraphPtr panel; + + if (bg == 2) { + sgroot->createFromXMLfile(manager, "xml_file/panel_512.xml"); + panel = sgroot->createSceneGraph(PANEL_512); + } else if (bg == 3) { + sgroot->createFromXMLfile(manager, "xml_file/panel_1024.xml"); + panel = sgroot->createSceneGraph(PANEL_1024); + } else { + sgroot->createFromXMLfile(manager, "xml_file/panel_2048.xml"); + panel = sgroot->createSceneGraph(PANEL_2048); + } + + panel->set_move_collision(panel_move, panel_collision); + panel->xyz[2] = 30.0f; + sgroot->setSceneData(panel); +}
--- a/TaskManager/Test/test_render/panel.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -#include "SceneGraphRoot.h" -#include "SGList.h" - -static void panel_move(SceneGraphPtr node, int screen_w, int screen_h); -static void panel_collision(SceneGraphPtr node, int screen_w, int screen_h, - SceneGraphPtr tree); - -static void -panel_move(SceneGraphPtr node, int screen_w, int screen_h) -{ -} - -static void -panel_collision(SceneGraphPtr node, int screen_w, int screen_h, - SceneGraphPtr tree) -{ -} - -void -panel_init(TaskManager *manager, int bg) -{ - SceneGraphPtr panel; - - if (bg == 2) { - sgroot->createFromXMLfile(manager, "xml_file/panel_512.xml"); - panel = sgroot->createSceneGraph(PANEL_512); - } else if (bg == 3) { - sgroot->createFromXMLfile(manager, "xml_file/panel_1024.xml"); - panel = sgroot->createSceneGraph(PANEL_1024); - } else { - sgroot->createFromXMLfile(manager, "xml_file/panel_2048.xml"); - panel = sgroot->createSceneGraph(PANEL_2048); - } - - panel->set_move_collision(panel_move, panel_collision); - panel->xyz[2] = 30.0f; - sgroot->setSceneData(panel); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/player_action.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,146 @@ +#include "SceneGraphRoot.h" +#include "bullet_action.h" +#include "SGList.h" + +#define MOVE_SPEED 5.00 + + +void +player_move_right(SceneGraphPtr node, int screen_w, int screen_h) +{ + if(node->xyz[0]<screen_w/2) + { + node->xyz[0] += MOVE_SPEED; + } + if(node->angle[1]<=20) + { + node->angle[1]+=1.0; + } + if(node->angle[2]>=-45) + { + node->angle[2]-=1.0; + } +} + +void +player_move_left(SceneGraphPtr node, int screen_w, int screen_h) +{ + if(node->xyz[0]> -screen_w/2) + { + node->xyz[0] -= MOVE_SPEED; + } + if(node->angle[1]>=-20) + { + node->angle[1]-=1.0; + } + if(node->angle[2]<=45) + { + node->angle[2]+=1.0; + } +} + +void +player_move_up(SceneGraphPtr node, int screen_w, int screen_h) +{ + if(node->xyz[2]<screen_h/2 + 100) + { + node->xyz[2] += MOVE_SPEED; + } + if(node->angle[0]<45) + { + node->angle[0] += 2.0; + } +} + +void +player_move_down(SceneGraphPtr node, int screen_w, int screen_h) +{ + if(node->xyz[2]> -screen_h/2) + { + node->xyz[2] -= MOVE_SPEED; + } + if(node->angle[0]>-45) + { + node->angle[0] -= 2.0; + } +} + +void +player_move_idle(SceneGraphPtr node) +{ + if (node->angle[1]>0) + { + node->angle[1]-=1.0; + } + else if(node->angle[1]<0) + { + node->angle[1]+=1.0; + } + + if(node->angle[2]<0) + { + node->angle[2]+=0.5; + } + else if(node->angle[2]>0) + { + node->angle[2]-=0.5; + } + + if(node->angle[0]<0) + { + node->angle[0]+=1.0; + } + else if(node->angle[0]>0) + { + node->angle[0]-=1.0; + } +} + +void +player_move_all(SceneGraphPtr node, int screen_w, int screen_h) +{ + Pad *pad = sgroot->getController(); + + if (pad->right.isHold() || pad->left.isHold() || + pad->up.isHold() || pad->down.isHold()) { + if (pad->right.isHold()) { + player_move_right(node, screen_w, screen_h); + } else if (pad->left.isHold()) { + player_move_left(node, screen_w, screen_h); + } + + if (pad->down.isHold()) { + player_move_up(node, screen_w, screen_h); + } else if(pad->up.isHold()) { + player_move_down(node, screen_w, screen_h); + } + } else { + player_move_idle(node); + } + + if (pad->r2.isHold()) { + node->xyz[2] -= 10.0f; + } + + if (pad->circle.isPush()) { + SceneGraphPtr bullet = sgroot->createSceneGraph(BULEBULLET); + bullet->set_move_collision(bluebullet_move, bullet_collision); + bullet_init(bullet, node); + node->addBrother(bullet); + } +} + +void +player_collision(SceneGraphPtr node, int screen_w, int screen_h, + SceneGraphPtr tree) +{ +#if 0 + int judge = square_judge(node, BULEBULLET, scene_graph); + + if (judge == HIT) + { + node->set_move_collision(player_move_all,player_collision); + } +#endif +} +
--- a/TaskManager/Test/test_render/player_action.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,146 +0,0 @@ -#include "SceneGraphRoot.h" -#include "bullet_action.h" -#include "SGList.h" - -#define MOVE_SPEED 5.00 - - -void -player_move_right(SceneGraphPtr node, int screen_w, int screen_h) -{ - if(node->xyz[0]<screen_w/2) - { - node->xyz[0] += MOVE_SPEED; - } - if(node->angle[1]<=20) - { - node->angle[1]+=1.0; - } - if(node->angle[2]>=-45) - { - node->angle[2]-=1.0; - } -} - -void -player_move_left(SceneGraphPtr node, int screen_w, int screen_h) -{ - if(node->xyz[0]> -screen_w/2) - { - node->xyz[0] -= MOVE_SPEED; - } - if(node->angle[1]>=-20) - { - node->angle[1]-=1.0; - } - if(node->angle[2]<=45) - { - node->angle[2]+=1.0; - } -} - -void -player_move_up(SceneGraphPtr node, int screen_w, int screen_h) -{ - if(node->xyz[2]<screen_h/2 + 100) - { - node->xyz[2] += MOVE_SPEED; - } - if(node->angle[0]<45) - { - node->angle[0] += 2.0; - } -} - -void -player_move_down(SceneGraphPtr node, int screen_w, int screen_h) -{ - if(node->xyz[2]> -screen_h/2) - { - node->xyz[2] -= MOVE_SPEED; - } - if(node->angle[0]>-45) - { - node->angle[0] -= 2.0; - } -} - -void -player_move_idle(SceneGraphPtr node) -{ - if (node->angle[1]>0) - { - node->angle[1]-=1.0; - } - else if(node->angle[1]<0) - { - node->angle[1]+=1.0; - } - - if(node->angle[2]<0) - { - node->angle[2]+=0.5; - } - else if(node->angle[2]>0) - { - node->angle[2]-=0.5; - } - - if(node->angle[0]<0) - { - node->angle[0]+=1.0; - } - else if(node->angle[0]>0) - { - node->angle[0]-=1.0; - } -} - -void -player_move_all(SceneGraphPtr node, int screen_w, int screen_h) -{ - Pad *pad = sgroot->getController(); - - if (pad->right.isHold() || pad->left.isHold() || - pad->up.isHold() || pad->down.isHold()) { - if (pad->right.isHold()) { - player_move_right(node, screen_w, screen_h); - } else if (pad->left.isHold()) { - player_move_left(node, screen_w, screen_h); - } - - if (pad->down.isHold()) { - player_move_up(node, screen_w, screen_h); - } else if(pad->up.isHold()) { - player_move_down(node, screen_w, screen_h); - } - } else { - player_move_idle(node); - } - - if (pad->r2.isHold()) { - node->xyz[2] -= 10.0f; - } - - if (pad->circle.isPush()) { - SceneGraphPtr bullet = sgroot->createSceneGraph(BULEBULLET); - bullet->set_move_collision(bluebullet_move, bullet_collision); - bullet_init(bullet, node); - node->addBrother(bullet); - } -} - -void -player_collision(SceneGraphPtr node, int screen_w, int screen_h, - SceneGraphPtr tree) -{ -#if 0 - int judge = square_judge(node, BULEBULLET, scene_graph); - - if (judge == HIT) - { - node->set_move_collision(player_move_all,player_collision); - } -#endif -} -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/polygon.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,307 @@ +#include <iostream> +#include <SDL.h> +#include <SDL_opengl.h> +#include <SDL_image.h> +#include "polygon.h" +#include "xml.h" +#include "sys.h" +#include "triangle.h" +#include "vertex.h" +#include "Span.h" +#include "SpanC.h" +#include "scene_graph_pack.h" +#include "error.h" +#include "viewer_types.h" +using namespace std; + +//extern int decode(char *cont, char *file_name); +extern int decode(char *cont, FILE *outfile); + + +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; + + for (int i = 0; i < 16; i++) { + matrix[i] = 0; + } +} + +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) +{ + float xyz1[4],xyz2[4],xyz3[4]; + + /***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; + + 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]); + + 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++) + { + 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; + } +} + +void Polygon::draw(SpanPack *sp) +{ + Span *span; + + for (int n = 0; n < sp->info.size; n++) { + span = &sp->span[n]; + + //int x = span->x; + //int y = span->y; + float z = span->start_z; + int end = span->length_x; + float zpos = span->end_z; + float tex1 = span->tex_x1; + float tex2 = span->tex_x2; + float tey1 = span->tex_y1; + float tey2 = span->tex_y2; + Uint32 rgb; + int tex_xpos; + int tex_ypos; + int tex_zpos; + float tex_x, tex_y, tex_z; + + if (end == 1) { + tex_xpos = (int)((span->tex_height-1) * tex1); + tex_ypos = (int)((span->tex_width-1) * tey1); + tex_zpos = (int)z; + rgb = get_rgb(tex_xpos, tex_ypos); + //viewer->write_pixel(x, y, zpos, rgb); + } else { + for (int j = 0; j < end; j++) { + tex_x = tex1*(end-1-j)/(end-1) + tex2*j/(end-1); + tex_y = tey1*(end-1-j)/(end-1) + tey2*j/(end-1); + tex_z = z*(end-1-j)/(end-1) + zpos*j/(end-1); + if (tex_x > 1) tex_x = 1; + if (tex_y > 1) tex_y = 1; + tex_xpos = (int)((span->tex_height-1) * tex_x); + tex_ypos = (int)((span->tex_width-1) * tex_y); + rgb = get_rgb(tex_xpos,tex_ypos); + //viewer->write_pixel(j + x, y, tex_z, rgb); + } + } + } +} + +#endif + +void Polygon::pickup_coordinate(char *cont) +{ + for(int n=0; n<size*3; n+=3) + { + cont = pickup_float(cont, coord_xyz+n); + cont = pickup_float(cont, coord_xyz+n+1); + cont = pickup_float(cont, coord_xyz+n+2); + + if (cont == NULL) + { + cout << "Analyzing obj data failed coordinate\n"; + } + } +} + +void Polygon::pickup_normal(char *cont) +{ + for (int n = 0; n<size*3; n += 3) + { + cont = pickup_float(cont, normal+n); + cont = pickup_float(cont, normal+n+1); + cont = pickup_float(cont, normal+n+2); + + if (cont == NULL) + { + 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); + + if (cont == NULL) + { + cout << "Analyzing obj data failed model\n"; + } +} + +void Polygon::pickup_texture(char *cont) +{ + for (int n = 0; n < size*3; n += 3) + { + cont = pickup_float(cont, coord_tex+n); + cont = pickup_float(cont, coord_tex+n+1); + coord_tex[n+2] = 1.0; + + if (cont == NULL) + { + 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)); +} + +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; +} + +Uint32 Polygon::get_rgb(int tx, int ty) +{ + SDL_PixelFormat *fmt; + //Uint32 temp, pixel; + Uint8 red, green, blue; + + 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 ; + + + + //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); + + 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->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]; + + //printf("tx = %d ty = %d ", tx,ty); + //printf("pixel color => R: %d, G: %d, B: %d\n", red, green, blue); + + SDL_PixelFormat *pf = NULL; + //pf = viewer->screen->format; + + //cout << SDL_MapRGB(pf, red, green, blue) << endl; + return SDL_MapRGB(pf, red, green, blue); +}
--- a/TaskManager/Test/test_render/polygon.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,307 +0,0 @@ -#include <iostream> -#include <SDL.h> -#include <SDL_opengl.h> -#include <SDL_image.h> -#include "polygon.h" -#include "xml.h" -#include "sys.h" -#include "triangle.h" -#include "vertex.h" -#include "Span.h" -#include "SpanC.h" -#include "scene_graph_pack.h" -#include "error.h" -#include "viewer_types.h" -using namespace std; - -//extern int decode(char *cont, char *file_name); -extern int decode(char *cont, FILE *outfile); - - -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; - - for (int i = 0; i < 16; i++) { - matrix[i] = 0; - } -} - -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) -{ - float xyz1[4],xyz2[4],xyz3[4]; - - /***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; - - 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]); - - 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++) - { - 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; - } -} - -void Polygon::draw(SpanPack *sp) -{ - Span *span; - - for (int n = 0; n < sp->info.size; n++) { - span = &sp->span[n]; - - //int x = span->x; - //int y = span->y; - float z = span->start_z; - int end = span->length_x; - float zpos = span->end_z; - float tex1 = span->tex_x1; - float tex2 = span->tex_x2; - float tey1 = span->tex_y1; - float tey2 = span->tex_y2; - Uint32 rgb; - int tex_xpos; - int tex_ypos; - int tex_zpos; - float tex_x, tex_y, tex_z; - - if (end == 1) { - tex_xpos = (int)((span->tex_height-1) * tex1); - tex_ypos = (int)((span->tex_width-1) * tey1); - tex_zpos = (int)z; - rgb = get_rgb(tex_xpos, tex_ypos); - //viewer->write_pixel(x, y, zpos, rgb); - } else { - for (int j = 0; j < end; j++) { - tex_x = tex1*(end-1-j)/(end-1) + tex2*j/(end-1); - tex_y = tey1*(end-1-j)/(end-1) + tey2*j/(end-1); - tex_z = z*(end-1-j)/(end-1) + zpos*j/(end-1); - if (tex_x > 1) tex_x = 1; - if (tex_y > 1) tex_y = 1; - tex_xpos = (int)((span->tex_height-1) * tex_x); - tex_ypos = (int)((span->tex_width-1) * tex_y); - rgb = get_rgb(tex_xpos,tex_ypos); - //viewer->write_pixel(j + x, y, tex_z, rgb); - } - } - } -} - -#endif - -void Polygon::pickup_coordinate(char *cont) -{ - for(int n=0; n<size*3; n+=3) - { - cont = pickup_float(cont, coord_xyz+n); - cont = pickup_float(cont, coord_xyz+n+1); - cont = pickup_float(cont, coord_xyz+n+2); - - if (cont == NULL) - { - cout << "Analyzing obj data failed coordinate\n"; - } - } -} - -void Polygon::pickup_normal(char *cont) -{ - for (int n = 0; n<size*3; n += 3) - { - cont = pickup_float(cont, normal+n); - cont = pickup_float(cont, normal+n+1); - cont = pickup_float(cont, normal+n+2); - - if (cont == NULL) - { - 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); - - if (cont == NULL) - { - cout << "Analyzing obj data failed model\n"; - } -} - -void Polygon::pickup_texture(char *cont) -{ - for (int n = 0; n < size*3; n += 3) - { - cont = pickup_float(cont, coord_tex+n); - cont = pickup_float(cont, coord_tex+n+1); - coord_tex[n+2] = 1.0; - - if (cont == NULL) - { - 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)); -} - -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; -} - -Uint32 Polygon::get_rgb(int tx, int ty) -{ - SDL_PixelFormat *fmt; - //Uint32 temp, pixel; - Uint8 red, green, blue; - - 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 ; - - - - //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); - - 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->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]; - - //printf("tx = %d ty = %d ", tx,ty); - //printf("pixel color => R: %d, G: %d, B: %d\n", red, green, blue); - - SDL_PixelFormat *pf = NULL; - //pf = viewer->screen->format; - - //cout << SDL_MapRGB(pf, red, green, blue) << endl; - return SDL_MapRGB(pf, red, green, blue); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/post.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,30 @@ +#include "viewer.h" + +/* +// post.cppの中身を viewer.cpp の中に持って行く +extern Viewer *screen; + +void +post2runLoop(void *arg) +{ + screen->run_loop(); +} + +void +post2runDraw(void *arg) +{ + screen->run_draw(); +} + +void +post2runMove(void *arg) +{ + screen->run_move(); +} + +void +post2exchange_sgroot(void *arg) +{ + screen->exchange_sgroot(); +} +*/
--- a/TaskManager/Test/test_render/post.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -#include "viewer.h" - -/* -// post.cppの中身を viewer.cpp の中に持って行く -extern Viewer *screen; - -void -post2runLoop(void *arg) -{ - screen->run_loop(); -} - -void -post2runDraw(void *arg) -{ - screen->run_draw(); -} - -void -post2runMove(void *arg) -{ - screen->run_move(); -} - -void -post2exchange_sgroot(void *arg) -{ - screen->exchange_sgroot(); -} -*/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/show_time.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,32 @@ +#include <stdio.h> +#include "TaskManager.h" +#include "Func.h" + +void +show_time() +{ + /* + HTaskPtr show; + HTaskPtr pre_show; + */ + /* + show = manager->create_task(SHOW_TIME); + show->set_cpu(SPE_0); + show->spawn(); + printf("testですよ\n"); + */ + + /* + pre_show = manager->create_task(SHOW_TIME); + pre_show->set_cpu((CPU_TYPE)((int)SPE_0)); + pre_show->spawn(); + + for (int i = 1; i < 6; i++) { + show = manager->create_task(SHOW_TIME); + show->set_cpu((CPU_TYPE)((int)SPE_0 + i)); + show->wait_for(pre_show); + show->spawn(); + pre_show = show; + } + */ +}
--- a/TaskManager/Test/test_render/show_time.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -#include <stdio.h> -#include "TaskManager.h" -#include "Func.h" - -void -show_time() -{ - /* - HTaskPtr show; - HTaskPtr pre_show; - */ - /* - show = manager->create_task(SHOW_TIME); - show->set_cpu(SPE_0); - show->spawn(); - printf("testですよ\n"); - */ - - /* - pre_show = manager->create_task(SHOW_TIME); - pre_show->set_cpu((CPU_TYPE)((int)SPE_0)); - pre_show->spawn(); - - for (int i = 1; i < 6; i++) { - show = manager->create_task(SHOW_TIME); - show->set_cpu((CPU_TYPE)((int)SPE_0 + i)); - show->wait_for(pre_show); - show->spawn(); - pre_show = show; - } - */ -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/sys.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,243 @@ +#include <stdlib.h> +#include <iostream> +#include <string.h> +#include <math.h> +#include "sys.h" +using namespace std; + +void noMoreMemory() +{ + cout << "can't allocate memory\n"; + 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]; + } +} + +/** + * ベクトルの正規化 + * + * @param[out] v0 output vector + * @param[in] v1 input vector + */ +void +normalize(float *v0, float *v1) +{ + float norm, dnorm; + + norm = sqrt(v1[0]*v1[0] + v1[1]*v1[1] + v1[2]*v1[2]); + if (norm > 0) { + dnorm = 1.0/norm; + v0[0] = v1[0]*dnorm; + v0[1] = v1[1]*dnorm; + v0[2] = v1[2]*dnorm; + v0[3] = v1[3]*dnorm; + } +} + +/** + * ベクトルの減算 v0 = v1 - v2 + */ +void +subVector(float *v0, float *v1, float *v2) +{ + v0[0] = v1[0] - v2[0]; + v0[1] = v1[1] - v2[1]; + v0[2] = v1[2] - v2[2]; + v0[3] = v1[3] - v2[3]; +} + +/** + * ベクトルの外積 v0 = v1 x v2 + */ +void +outerProduct(float *v0, float *v1, float *v2) +{ + v0[0] = v1[1] * v2[2] - v1[2] * v2[1]; + v0[1] = v1[2] * v2[0] - v1[0] * v2[2]; + v0[2] = v1[0] * v2[1] - v1[1] * v2[0]; + 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 + */ +float +innerProduct(float *v0, float *v1) +{ + return (v0[0]*v1[0] + v0[1]*v1[1] + v0[2]*v1[2]); +} + +void matrix4x4(float *xyz, float *xyz1, float *xyz2) //xyz[16] +{ + 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 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); + + /* View Transform */ + 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); + } + +} + +void rotate_x(float *xyz, float r) +{ + float rad = r*3.14/180; + + xyz[0] = xyz[0]; + xyz[1] = xyz[1]*cos(rad) - xyz[2]*sin(rad); + xyz[2] = xyz[1]*sin(rad) + xyz[2]*cos(rad); +} + +void rotate_y(float *xyz, float r) +{ + float rad = r*3.14/180; + + xyz[0] = xyz[0]*cos(rad) + xyz[2]*sin(rad); + xyz[1] = xyz[1]; + xyz[2] = -xyz[0]*sin(rad) + xyz[2]*cos(rad); +} + +void rotate_z(float *xyz, float r) +{ + float rad = r*3.14/180; + + xyz[0] = xyz[0]*cos(rad) - xyz[1]*sin(rad); + xyz[1] = xyz[0]*sin(rad) + xyz[1]*cos(rad); + xyz[2] = xyz[2]; +} + +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]*rot[i] + abc[1]*rot[i+4] + abc[2]*rot[i+8] + abc[3]*rot[i+12]; + xyz[i] = abc[0]*matrix[i] + abc[1]*matrix[i+4] + abc[2]*matrix[i+8] + abc[3]*matrix[i+12]; + } +} + + +void translate(float *xyz, float x, float y, float z) +{ + xyz[0] += x; + xyz[1] += y; + xyz[2] += z; +}
--- a/TaskManager/Test/test_render/sys.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,243 +0,0 @@ -#include <stdlib.h> -#include <iostream> -#include <string.h> -#include <math.h> -#include "sys.h" -using namespace std; - -void noMoreMemory() -{ - cout << "can't allocate memory\n"; - 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]; - } -} - -/** - * ベクトルの正規化 - * - * @param[out] v0 output vector - * @param[in] v1 input vector - */ -void -normalize(float *v0, float *v1) -{ - float norm, dnorm; - - norm = sqrt(v1[0]*v1[0] + v1[1]*v1[1] + v1[2]*v1[2]); - if (norm > 0) { - dnorm = 1.0/norm; - v0[0] = v1[0]*dnorm; - v0[1] = v1[1]*dnorm; - v0[2] = v1[2]*dnorm; - v0[3] = v1[3]*dnorm; - } -} - -/** - * ベクトルの減算 v0 = v1 - v2 - */ -void -subVector(float *v0, float *v1, float *v2) -{ - v0[0] = v1[0] - v2[0]; - v0[1] = v1[1] - v2[1]; - v0[2] = v1[2] - v2[2]; - v0[3] = v1[3] - v2[3]; -} - -/** - * ベクトルの外積 v0 = v1 x v2 - */ -void -outerProduct(float *v0, float *v1, float *v2) -{ - v0[0] = v1[1] * v2[2] - v1[2] * v2[1]; - v0[1] = v1[2] * v2[0] - v1[0] * v2[2]; - v0[2] = v1[0] * v2[1] - v1[1] * v2[0]; - 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 - */ -float -innerProduct(float *v0, float *v1) -{ - return (v0[0]*v1[0] + v0[1]*v1[1] + v0[2]*v1[2]); -} - -void matrix4x4(float *xyz, float *xyz1, float *xyz2) //xyz[16] -{ - 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 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); - - /* View Transform */ - 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); - } - -} - -void rotate_x(float *xyz, float r) -{ - float rad = r*3.14/180; - - xyz[0] = xyz[0]; - xyz[1] = xyz[1]*cos(rad) - xyz[2]*sin(rad); - xyz[2] = xyz[1]*sin(rad) + xyz[2]*cos(rad); -} - -void rotate_y(float *xyz, float r) -{ - float rad = r*3.14/180; - - xyz[0] = xyz[0]*cos(rad) + xyz[2]*sin(rad); - xyz[1] = xyz[1]; - xyz[2] = -xyz[0]*sin(rad) + xyz[2]*cos(rad); -} - -void rotate_z(float *xyz, float r) -{ - float rad = r*3.14/180; - - xyz[0] = xyz[0]*cos(rad) - xyz[1]*sin(rad); - xyz[1] = xyz[0]*sin(rad) + xyz[1]*cos(rad); - xyz[2] = xyz[2]; -} - -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]*rot[i] + abc[1]*rot[i+4] + abc[2]*rot[i+8] + abc[3]*rot[i+12]; - xyz[i] = abc[0]*matrix[i] + abc[1]*matrix[i+4] + abc[2]*matrix[i+8] + abc[3]*matrix[i+12]; - } -} - - -void translate(float *xyz, float x, float y, float z) -{ - xyz[0] += x; - xyz[1] += y; - xyz[2] += z; -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/task/CreatePolygon.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,188 @@ +/** + * SceneGraph が増えてくると動かなくなるかもしれない。 + * 一応 mainMem とかで動くようになるとは思うけど。 + * だめだったら、そこら辺が怪しいと思うべき + */ + +#include "CreatePolygon.h" +#include "polygon_pack.h" +#include "scene_graph_pack.h" + +SchedDefineTask(CreatePolygon); + +#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 +CreatePolygon::run(SchedTask *smanager, void *rbuf, void *wbuf) +{ + float xyz1[4],xyz2[4],xyz3[4]; + + SceneGraphPackPtr sgp = (SceneGraphPack*)smanager->get_input(0); + SceneGraphPackPtr next_sgp = + (SceneGraphPackPtr)smanager->allocate(sizeof(SceneGraphPack)); + SceneGraphPackPtr free_sgp = next_sgp; + SceneGraphPackPtr tmp_sgp; + + SceneGraphNodePtr node; + SceneGraphNodePtr next_node + = (SceneGraphNodePtr)smanager->allocate(sizeof(SceneGraphNode)); + SceneGraphNodePtr free_node = next_node; + SceneGraphNodePtr tmp_node; + + PolygonPackPtr pp + = (PolygonPackPtr)smanager->allocate(sizeof(PolygonPack)); + PolygonPackPtr send_pp + = (PolygonPackPtr)smanager->allocate(sizeof(PolygonPack)); + PolygonPackPtr pp_addr = (PolygonPackPtr)smanager->get_param(0); + PolygonPackPtr tmp_pp; + + pp->init(); + send_pp->init(); + + do { + if (sgp->next != NULL) { + smanager->dma_load(next_sgp, (uint32)sgp->next, + sizeof(SceneGraphPack), SG_PACK_LOAD); + } else { + next_sgp = NULL; + } + + for (int i = 0; i < sgp->info.size; i++) { + node = &sgp->node[i]; + + do { + if (node->next != NULL) { + smanager->dma_load(next_node, (uint32)node->next, + sizeof(SceneGraphNode), SG_NODE_LOAD); + } else { + next_node = NULL; + } + + for (int n = 0, nt = 0; n < node->size*3; n+=9, nt+=6) { + + 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] = 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); + + triangle->ver1.x = xyz1[0]; + triangle->ver1.y = xyz1[1]; + triangle->ver1.z = xyz1[2]; + triangle->ver1.tex_x = node->texture[nt]; + triangle->ver1.tex_y = node->texture[nt+1]; + + triangle->ver2.x = xyz2[0]; + triangle->ver2.y = xyz2[1]; + triangle->ver2.z = xyz2[2]; + triangle->ver2.tex_x = node->texture[nt+2]; + triangle->ver2.tex_y = node->texture[nt+2+1]; + + triangle->ver3.x = xyz3[0]; + triangle->ver3.y = xyz3[1]; + triangle->ver3.z = xyz3[2]; + triangle->ver3.tex_x = node->texture[nt+4]; + triangle->ver3.tex_y = node->texture[nt+4+1]; + +#if 1 + triangle->tex_info.addr = node->tex_addr; + triangle->tex_info.width = node->tex_width; + triangle->tex_info.height = node->tex_height; +#else + triangle->tex_info.addr = node->texture_info.pixels; + triangle->tex_info.width = node->texture_info.t_w; + triangle->tex_info.height = node->texture_info.t_h; +#endif + } + + smanager->dma_wait(SG_NODE_LOAD); + + tmp_node = node; + node = next_node; + next_node = tmp_node; + } while (node); + + next_node = free_node; + } + + smanager->dma_wait(SG_PACK_LOAD); + + tmp_sgp = sgp; + sgp = next_sgp; + next_sgp = tmp_sgp; + } while (sgp); + + 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); + free(free_node); + free(free_sgp); + + return 0; +}
--- a/TaskManager/Test/test_render/task/CreatePolygon.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,188 +0,0 @@ -/** - * SceneGraph が増えてくると動かなくなるかもしれない。 - * 一応 mainMem とかで動くようになるとは思うけど。 - * だめだったら、そこら辺が怪しいと思うべき - */ - -#include "CreatePolygon.h" -#include "polygon_pack.h" -#include "scene_graph_pack.h" - -SchedDefineTask(CreatePolygon); - -#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 -CreatePolygon::run(SchedTask *smanager, void *rbuf, void *wbuf) -{ - float xyz1[4],xyz2[4],xyz3[4]; - - SceneGraphPackPtr sgp = (SceneGraphPack*)smanager->get_input(0); - SceneGraphPackPtr next_sgp = - (SceneGraphPackPtr)smanager->allocate(sizeof(SceneGraphPack)); - SceneGraphPackPtr free_sgp = next_sgp; - SceneGraphPackPtr tmp_sgp; - - SceneGraphNodePtr node; - SceneGraphNodePtr next_node - = (SceneGraphNodePtr)smanager->allocate(sizeof(SceneGraphNode)); - SceneGraphNodePtr free_node = next_node; - SceneGraphNodePtr tmp_node; - - PolygonPackPtr pp - = (PolygonPackPtr)smanager->allocate(sizeof(PolygonPack)); - PolygonPackPtr send_pp - = (PolygonPackPtr)smanager->allocate(sizeof(PolygonPack)); - PolygonPackPtr pp_addr = (PolygonPackPtr)smanager->get_param(0); - PolygonPackPtr tmp_pp; - - pp->init(); - send_pp->init(); - - do { - if (sgp->next != NULL) { - smanager->dma_load(next_sgp, (uint32)sgp->next, - sizeof(SceneGraphPack), SG_PACK_LOAD); - } else { - next_sgp = NULL; - } - - for (int i = 0; i < sgp->info.size; i++) { - node = &sgp->node[i]; - - do { - if (node->next != NULL) { - smanager->dma_load(next_node, (uint32)node->next, - sizeof(SceneGraphNode), SG_NODE_LOAD); - } else { - next_node = NULL; - } - - for (int n = 0, nt = 0; n < node->size*3; n+=9, nt+=6) { - - 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] = 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); - - triangle->ver1.x = xyz1[0]; - triangle->ver1.y = xyz1[1]; - triangle->ver1.z = xyz1[2]; - triangle->ver1.tex_x = node->texture[nt]; - triangle->ver1.tex_y = node->texture[nt+1]; - - triangle->ver2.x = xyz2[0]; - triangle->ver2.y = xyz2[1]; - triangle->ver2.z = xyz2[2]; - triangle->ver2.tex_x = node->texture[nt+2]; - triangle->ver2.tex_y = node->texture[nt+2+1]; - - triangle->ver3.x = xyz3[0]; - triangle->ver3.y = xyz3[1]; - triangle->ver3.z = xyz3[2]; - triangle->ver3.tex_x = node->texture[nt+4]; - triangle->ver3.tex_y = node->texture[nt+4+1]; - -#if 1 - triangle->tex_info.addr = node->tex_addr; - triangle->tex_info.width = node->tex_width; - triangle->tex_info.height = node->tex_height; -#else - triangle->tex_info.addr = node->texture_info.pixels; - triangle->tex_info.width = node->texture_info.t_w; - triangle->tex_info.height = node->texture_info.t_h; -#endif - } - - smanager->dma_wait(SG_NODE_LOAD); - - tmp_node = node; - node = next_node; - next_node = tmp_node; - } while (node); - - next_node = free_node; - } - - smanager->dma_wait(SG_PACK_LOAD); - - tmp_sgp = sgp; - sgp = next_sgp; - next_sgp = tmp_sgp; - } while (sgp); - - 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); - free(free_node); - free(free_sgp); - - return 0; -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/task/CreatePolygonFromSceneGraph.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,246 @@ +/** + * 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 + +/** + * ベクトルに行列を乗算する + * @param[out] v vector (float[4]) + * @param[in] m matrix (float[16]) + */ +static void +ApplyMatrix(float *v, float *m) +{ + float t[4]; + + t[0] = v[0]; + t[1] = v[1]; + t[2] = v[2]; + t[3] = v[3]; + + 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]; + } +} + +static void +ApplyNormalMatrix(float *v, float *m) +{ + float t[4]; + + t[0] = v[0]; + t[1] = v[1]; + t[2] = v[2]; + + for (int i = 0; i < 3; i++) { + v[i] = t[0]*m[i] + t[1]*m[i+4] + t[2]*m[i+8]; + } +} + + +/** + * 行列の積 + * + * @param[out] m0 output matrix + * @param[in] m1 input left matrix + * @param[in] m2 input right matrix + */ +/* +static void +MulMatrix(float *m0, float *m1, float *m2) //xyz[16] +{ + 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]; + } + } +} +*/ +int +CreatePolygonFromSceneGraph::run(SchedTask *smanager, void *rbuf, void *wbuf) +{ + float xyz1[4], xyz2[4], xyz3[4]; + /* + *頂点毎に法線ベクトルがある + *面毎じゃない + *なにかに使うのかな?わからないから、一応とっておく。 + *by yutaka + */ + float normal1[4],normal2[4],normal3[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) { + if (sg->flag_drawable) { // sg->isDrawable() とかの方がよくね? + 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->coord_xyz[(i+0)*3]; + xyz1[1] = sg->coord_xyz[(i+0)*3+1]; + xyz1[2] = sg->coord_xyz[(i+0)*3+2]*-1.0f; + xyz1[3] = 1.0f; + + xyz2[0] = sg->coord_xyz[(i+1)*3]; + xyz2[1] = sg->coord_xyz[(i+1)*3+1]; + xyz2[2] = sg->coord_xyz[(i+1)*3+2]*-1.0f; + xyz2[3] = 1.0f; + + xyz3[0] = sg->coord_xyz[(i+2)*3]; + xyz3[1] = sg->coord_xyz[(i+2)*3+1]; + xyz3[2] = sg->coord_xyz[(i+2)*3+2]*-1.0f; + xyz3[3] = 1.0f; + + // sg->matrix = 回転行列*透視変換行列 + ApplyMatrix(xyz1, sg->matrix); + ApplyMatrix(xyz2, sg->matrix); + ApplyMatrix(xyz3, sg->matrix); + + xyz1[0] /= xyz1[2]; + xyz1[1] /= xyz1[2]; + xyz2[0] /= xyz2[2]; + xyz2[1] /= xyz2[2]; + xyz3[0] /= xyz3[2]; + xyz3[1] /= xyz3[2]; + + triangle->ver1.x = xyz1[0]; + triangle->ver1.y = xyz1[1]; + triangle->ver1.z = xyz1[2]; + triangle->ver1.tex_x = sg->coord_tex[(i+0)*3]; + triangle->ver1.tex_y = sg->coord_tex[(i+0)*3+1]; + + triangle->ver2.x = xyz2[0]; + triangle->ver2.y = xyz2[1]; + triangle->ver2.z = xyz2[2]; + triangle->ver2.tex_x = sg->coord_tex[(i+1)*3]; + triangle->ver2.tex_y = sg->coord_tex[(i+1)*3+1]; + + triangle->ver3.x = xyz3[0]; + triangle->ver3.y = xyz3[1]; + triangle->ver3.z = xyz3[2]; + triangle->ver3.tex_x = sg->coord_tex[(i+2)*3]; + triangle->ver3.tex_y = sg->coord_tex[(i+2)*3+1]; + + //法線もApplyMatrixとかするのかな?一応値をとっておくby yutaka + + normal1[0] = sg->normal[(i+0)*3]; + normal1[1] = sg->normal[(i+0)*3+1]; + normal1[2] = sg->normal[(i+0)*3+2]*-1.0f; + normal1[3] = 1.0f; + + normal2[0] = sg->normal[(i+1)*3]; + normal2[1] = sg->normal[(i+1)*3+1]; + normal2[2] = sg->normal[(i+1)*3+2]*-1.0f; + normal2[3] = 1.0f; + + normal3[0] = sg->normal[(i+2)*3]; + normal3[1] = sg->normal[(i+2)*3+1]; + normal3[2] = sg->normal[(i+2)*3+2]*-1.0f; + normal3[3] = 1.0f; + + ApplyNormalMatrix(normal1,sg->matrix); + + //ここでpolygonに法線ベクトルの情報がわたったby yutaka + + triangle->normal1.x = normal1[0]; + triangle->normal1.y = normal1[1]; + triangle->normal1.z = normal1[2]; + + triangle->normal2.x = normal2[0]; + triangle->normal2.y = normal2[1]; + triangle->normal2.z = normal2[2]; + + triangle->normal3.x = normal3[0]; + triangle->normal3.y = normal3[1]; + triangle->normal3.z = normal3[2]; + + + + triangle->tex_info.addr = sg->texture_info.pixels; + triangle->tex_info.width = sg->texture_info.t_w; + triangle->tex_info.height = sg->texture_info.t_h; + triangle->tex_info.scale_max = sg->texture_info.scale_max; + } + } + + 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; +}
--- a/TaskManager/Test/test_render/task/CreatePolygonFromSceneGraph.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,246 +0,0 @@ -/** - * 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 - -/** - * ベクトルに行列を乗算する - * @param[out] v vector (float[4]) - * @param[in] m matrix (float[16]) - */ -static void -ApplyMatrix(float *v, float *m) -{ - float t[4]; - - t[0] = v[0]; - t[1] = v[1]; - t[2] = v[2]; - t[3] = v[3]; - - 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]; - } -} - -static void -ApplyNormalMatrix(float *v, float *m) -{ - float t[4]; - - t[0] = v[0]; - t[1] = v[1]; - t[2] = v[2]; - - for (int i = 0; i < 3; i++) { - v[i] = t[0]*m[i] + t[1]*m[i+4] + t[2]*m[i+8]; - } -} - - -/** - * 行列の積 - * - * @param[out] m0 output matrix - * @param[in] m1 input left matrix - * @param[in] m2 input right matrix - */ -/* -static void -MulMatrix(float *m0, float *m1, float *m2) //xyz[16] -{ - 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]; - } - } -} -*/ -int -CreatePolygonFromSceneGraph::run(SchedTask *smanager, void *rbuf, void *wbuf) -{ - float xyz1[4], xyz2[4], xyz3[4]; - /* - *頂点毎に法線ベクトルがある - *面毎じゃない - *なにかに使うのかな?わからないから、一応とっておく。 - *by yutaka - */ - float normal1[4],normal2[4],normal3[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) { - if (sg->flag_drawable) { // sg->isDrawable() とかの方がよくね? - 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->coord_xyz[(i+0)*3]; - xyz1[1] = sg->coord_xyz[(i+0)*3+1]; - xyz1[2] = sg->coord_xyz[(i+0)*3+2]*-1.0f; - xyz1[3] = 1.0f; - - xyz2[0] = sg->coord_xyz[(i+1)*3]; - xyz2[1] = sg->coord_xyz[(i+1)*3+1]; - xyz2[2] = sg->coord_xyz[(i+1)*3+2]*-1.0f; - xyz2[3] = 1.0f; - - xyz3[0] = sg->coord_xyz[(i+2)*3]; - xyz3[1] = sg->coord_xyz[(i+2)*3+1]; - xyz3[2] = sg->coord_xyz[(i+2)*3+2]*-1.0f; - xyz3[3] = 1.0f; - - // sg->matrix = 回転行列*透視変換行列 - ApplyMatrix(xyz1, sg->matrix); - ApplyMatrix(xyz2, sg->matrix); - ApplyMatrix(xyz3, sg->matrix); - - xyz1[0] /= xyz1[2]; - xyz1[1] /= xyz1[2]; - xyz2[0] /= xyz2[2]; - xyz2[1] /= xyz2[2]; - xyz3[0] /= xyz3[2]; - xyz3[1] /= xyz3[2]; - - triangle->ver1.x = xyz1[0]; - triangle->ver1.y = xyz1[1]; - triangle->ver1.z = xyz1[2]; - triangle->ver1.tex_x = sg->coord_tex[(i+0)*3]; - triangle->ver1.tex_y = sg->coord_tex[(i+0)*3+1]; - - triangle->ver2.x = xyz2[0]; - triangle->ver2.y = xyz2[1]; - triangle->ver2.z = xyz2[2]; - triangle->ver2.tex_x = sg->coord_tex[(i+1)*3]; - triangle->ver2.tex_y = sg->coord_tex[(i+1)*3+1]; - - triangle->ver3.x = xyz3[0]; - triangle->ver3.y = xyz3[1]; - triangle->ver3.z = xyz3[2]; - triangle->ver3.tex_x = sg->coord_tex[(i+2)*3]; - triangle->ver3.tex_y = sg->coord_tex[(i+2)*3+1]; - - //法線もApplyMatrixとかするのかな?一応値をとっておくby yutaka - - normal1[0] = sg->normal[(i+0)*3]; - normal1[1] = sg->normal[(i+0)*3+1]; - normal1[2] = sg->normal[(i+0)*3+2]*-1.0f; - normal1[3] = 1.0f; - - normal2[0] = sg->normal[(i+1)*3]; - normal2[1] = sg->normal[(i+1)*3+1]; - normal2[2] = sg->normal[(i+1)*3+2]*-1.0f; - normal2[3] = 1.0f; - - normal3[0] = sg->normal[(i+2)*3]; - normal3[1] = sg->normal[(i+2)*3+1]; - normal3[2] = sg->normal[(i+2)*3+2]*-1.0f; - normal3[3] = 1.0f; - - ApplyNormalMatrix(normal1,sg->matrix); - - //ここでpolygonに法線ベクトルの情報がわたったby yutaka - - triangle->normal1.x = normal1[0]; - triangle->normal1.y = normal1[1]; - triangle->normal1.z = normal1[2]; - - triangle->normal2.x = normal2[0]; - triangle->normal2.y = normal2[1]; - triangle->normal2.z = normal2[2]; - - triangle->normal3.x = normal3[0]; - triangle->normal3.y = normal3[1]; - triangle->normal3.z = normal3[2]; - - - - triangle->tex_info.addr = sg->texture_info.pixels; - triangle->tex_info.width = sg->texture_info.t_w; - triangle->tex_info.height = sg->texture_info.t_h; - triangle->tex_info.scale_max = sg->texture_info.scale_max; - } - } - - 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/CreateSpan.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,510 @@ +#include "CreateSpan.h" +#include "viewer_types.h" + +static const int SPAN_PACK_LOAD = 5; +static const int SPAN_PACK_STORE = 6; +static const int POLYGON_PACK_LOAD = 7; +static const int TILE_ALLOCATE = 8; +static const int TILE_LOAD = 9; +static const int TILE_STORE = 10; + +static SpanPackPtr spack = NULL; +static SpanPackPtr send_spack = NULL; +static int prev_index = 0; + +SchedDefineTask(CreateSpan); + +static float +calc(float f1, float f2,int i, float base) +{ + float ans; + ans = f1/f2*i + base; + return ans; +} + + +/** + * TrianglePack から、vMin, vMid, vMax を求める + * + * @param [triPack] TrianglePack + * @param [vMin] [vMid] [vMax] + */ +static void +make_vertex(TrianglePack *triPack, + VertexPackPtr *vMin, VertexPackPtr *vMid, VertexPackPtr *vMax, + NormalPackPtr *normal1, NormalPackPtr *normal2, NormalPackPtr *normal3) +{ + if (triPack->ver1.y <= triPack->ver2.y) { + if (triPack->ver2.y <= triPack->ver3.y) { + *vMin = &triPack->ver1; + *vMid = &triPack->ver2; + *vMax = &triPack->ver3; + } else if (triPack->ver3.y <= triPack->ver1.y) { + *vMin = &triPack->ver3; + *vMid = &triPack->ver1; + *vMax = &triPack->ver2; + } else { + *vMin = &triPack->ver1; + *vMid = &triPack->ver3; + *vMax = &triPack->ver2; + } + } else { + if (triPack->ver1.y <= triPack->ver3.y) { + *vMin = &triPack->ver2; + *vMid = &triPack->ver1; + *vMax = &triPack->ver3; + } else if (triPack->ver3.y <= triPack->ver2.y) { + *vMin = &triPack->ver3; + *vMid = &triPack->ver2; + *vMax = &triPack->ver1; + } else { + *vMin = &triPack->ver2; + *vMid = &triPack->ver3; + *vMax = &triPack->ver1; + } + } + + *normal1 = &triPack->normal1; + *normal2 = &triPack->normal2; + *normal3 = &triPack->normal3; + +} + +static void +make_vMid10(VertexPack *v, VertexPack *vMin, + VertexPack *vMid, VertexPack *vMax) +{ + //int d, d1; + float d; + int d1; + + d = vMax->y - vMin->y; + d1 = (int)(vMid->y - vMin->y); + + v->tex_x = calc(vMax->tex_x - vMin->tex_x, d, d1, vMin->tex_x); + v->tex_y = calc(vMax->tex_y - vMin->tex_y, d, d1, vMin->tex_y); + v->x = calc(vMax->x - vMin->x, d, d1, vMin->x); + v->y = vMid->y; + v->z = calc(vMax->z - vMin->z, d, d1, vMin->z); +} + +/** + * 与えられた scale から、実際に使うテクスチャの Tapestry を選択する + * + * テクスチャは、オリジナルのサイズから、可能なかぎり 1/2 で縮小していき、 + * 下の図の様に連続した領域に入れられる + * + * Tapestry (1) + * +---+---+---+---+ + * | 0 | 1 | 2 | 3 | + * +---+---+---+---+ + * | 4 | 5 | 6 | 7 | (2) + * +---+---+---+---+ +---+---+ + * | 8 | 9 | 10| 11| | 16| 17| (3) + * +---+---+---+---+ +---+---+ +---+ + * | 12| 13| 14| 15| | 18| 19| | 20| + * +---+---+---+---+ +---+---+ +---| + * + * (1) (2) (3) + * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * | * | * | 14| 15| 16| 17| 18| 19| 20| + * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ + * + * scale の値から、各 Tapestry の先頭アドレスを返す + * + * @param[in] tw Width of texture + * @param[in] th Height of texture + * @param[in] scale テクスチャの縮小率 (= 2^n) + * @param[in] addr_top テクスチャの先頭アドレス (上の図での (1) + * @return scale に対応する Tapestry のアドレス (上の図での (1) or (2) or(3) + */ +static uint32* +getTapestry(int tw, int th, int scale, uint32 *addr_top) +{ + int index = 0; + + for (int s = 1; s < scale; s <<= 1) { + index += tw*th; + tw >>= 1; /* tw /= 2 */ + th >>= 1; + } + + return addr_top + index; +} + + +/** + * span の width,height と texture の width,height を比べて + * span を描画する際に使う texture の比率を求める + * + * @param[in] width Width of span + * @param[in] height Height of span + * @param[in] tex_width Width of 1/1 texture that span use + * @param[in] tex_height Height of 1/1 texture that span use + * @param[in] scale_max この Span で使う texture の最大縮小率 + * 計算結果が scale_max 以上になるのを防ぐ + * @return 描画に使う texture の比率 + * width と height は 1/scale の画像を使う + * + */ +static int +getScale(int width, int height, int tex_width, int tex_height, int scale_max) +{ + int base, tex_base; + int scale = 1; + + /** + * width と height で、長い方を基準に、 + * texture の scale を決める + */ + if (width > height) { + base = width; + tex_base = tex_width; + } else { + base = height; + tex_base = tex_height; + } + + if (tex_base > base) { + int t_scale = tex_base/base; + while (t_scale >>= 1) { + scale <<= 1; + } + } + + return (scale > scale_max) ? scale_max : scale; + //return scale_max; +} + +/** + * x軸に水平な辺を持つ三角形ポリゴンから、 + * Span を抜き出す + * + * @param[in] spackList triangle から生成された span を格納する List + * @param[in] charge_y_top 担当する y の範囲開始地点 + * @param[in] charge_y_end 担当する y の範囲終了地点 + * @param[in] tex_addr triangle が参照するテクスチャの先頭アドレス + * @param[in] tex_width テクスチャの width + * @param[in] tex_height テクスチャの height + * @param[in] tex_scale_max テクスチャの最大縮小率 (2^n) + * @param[in] vMin triangle の座標 + * @param[in] vMid triangle の座標。triangle を二つに分けて出来た新しい座標 + * @param[in] vMid10 triangle の座標 + * @param[in] length_y 分割する前の Triangle の y の長さ + * @param[in] tex_y_len 分割する前の Triangle に貼られている Texture の + * 長さの割合 (0 ... 1) + */ +void +CreateSpan::half_triangle(SchedTask *smanager, SpanPackPtr *spackList, + int charge_y_top, int charge_y_end, + TriangleTexInfoPtr tex_info, + VertexPack *vMin,VertexPack *vMid,VertexPack *vMid10, + NormalPack *normal1, NormalPack *normal2, NormalPack *normal3, + int length_y, float tex_y_len) +{ + float tmp_z,tmp_tex1, tmp_tex2 ,tmp_tey1,tmp_tey2; + float tmp_xpos,tmp_end,tmp_zpos; + float start_z, end_z; + 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軸に水平に二つに分けようとして + * ある一辺がすでに水平だった場合、つまり + * + * |\ + * | \ + * | \ + * ----- + * + * + * 上のようなポリゴンだった場合は、本来なら上の部分の三角形にだけ + * half_triangle の処理をするべきだが、現在の処理だと + * この half_triangle に「上の部分の三角形」と、 + * 「『下の部分の三角形と判断してしまった』直線」が来てしまう。 + * 直線の部分が来ると、calc() で 0 除算とかで、値不定で暴走するので + * 現在はこれで代用。 + * half_triangle 呼ぶ前にこれを判断できれば良いかもしれない。 + * てかこんなんでいいのかよ。。。 + */ +#if 1 + if ((int)div_y == 0) { + return; + } +#else + if (vMid10->x == vMin->x && vMid10->y == vMin->y) { + return; + } +#endif + + if (div_y < 0) { + div_y = -div_y; + k = 1; + l = -1; + } + + for (int i = k; i < (int)div_y+1; i++) { + y = (int)vMin->y + i*l; +#if 1 + + /** + * 担当 y 範囲内 + */ + if (charge_y_top <= y && y <= charge_y_end) { + // 1..8 を index0, 9..16 を index1 にするために y を -1 + int index = (y-1) / split_screen_h; + + /** + * 違う SpanPack を扱う場合、 + * 現在の SpanPack をメインメモリに送り、 + * 新しい SpanPack を取ってくる + */ + if (index != prev_index) { + tmp_spack = spack; + spack = send_spack; + send_spack = tmp_spack; + + smanager->dma_wait(SPAN_PACK_STORE); + smanager->dma_store(send_spack, (uint32)spackList[prev_index], + sizeof(SpanPack), SPAN_PACK_STORE); + + smanager->dma_load(spack, (uint32)spackList[index], + sizeof(SpanPack), SPAN_PACK_LOAD); + prev_index = index; + smanager->dma_wait(SPAN_PACK_LOAD); + } + + /** + * 書き込む SpanPack が満杯だったら + * メインメモリで allocate した領域 (next) を持ってきて + * 現在の spack->next につなぎ、next を次の spack とする。 + */ + if (spack->info.size >= MAX_SIZE_SPAN) { + SpanPackPtr next; + + smanager->mainMem_alloc(0, sizeof(SpanPack)); + smanager->mainMem_wait(); + next = (SpanPackPtr)smanager->mainMem_get(0); + + spack->next = next; + + tmp_spack = spack; + spack = send_spack; + send_spack = tmp_spack; + + smanager->dma_wait(SPAN_PACK_STORE); + smanager->dma_store(send_spack, (uint32)spackList[index], + sizeof(SpanPack), SPAN_PACK_STORE); + + spackList[index] = next; + + smanager->dma_load(spack, (uint32)spackList[index], + sizeof(SpanPack), SPAN_PACK_LOAD); + smanager->dma_wait(SPAN_PACK_LOAD); + spack->init((index+1)*split_screen_h); + } + } else { + /** + * 担当範囲外だったら無視 + */ + continue; + } + + tmp_xpos = calc(vMid10->x - vMin->x ,div_y, i, vMin->x); + tmp_end = calc(vMid->x - vMin->x ,div_y, i, vMin->x); + tmp_z = calc(vMid10->z - vMin->z ,div_y, i, vMin->z); + tmp_zpos = calc(vMid->z - vMin->z ,div_y, i, vMin->z); + + length = (tmp_xpos > tmp_end) + ? (int)tmp_xpos - (int)tmp_end : (int)tmp_end - (int)tmp_xpos; + if (length == 0) { + continue; + } + + tmp_tex1 =((i/(div_y)) * vMid10->tex_x) + + ( ((div_y - i)/(div_y)) * vMin->tex_x); + tmp_tex2 =( (i/(div_y)) * vMid->tex_x) + + ( ((div_y - i)/(div_y)) * vMin->tex_x); + + tmp_tey1 =( (i/(div_y)) * vMid10->tex_y) + + ( ((div_y - i)/(div_y)) * vMin->tex_y); + tmp_tey2 =( (i/(div_y)) * vMid->tex_y) + + ( ((div_y - i)/(div_y)) * vMin->tex_y); + + if (tmp_xpos > tmp_end) { + x = (int)tmp_end; + length = (int)(tmp_xpos)-(int)(tmp_end)+1; + start_z = tmp_zpos; + end_z = tmp_z; + start_tex_x = tmp_tex2; + end_tex_x = tmp_tex1; + start_tex_y = tmp_tey2; + end_tex_y = tmp_tey1; + } else { + x = (int)tmp_xpos; + length = (int)(tmp_end)-(int)(tmp_xpos)+1; + start_z = tmp_z; + end_z = tmp_zpos; + start_tex_x = tmp_tex1; + end_tex_x = tmp_tex2; + start_tex_y = tmp_tey1; + end_tex_y = tmp_tey2; + } + + smanager->dma_wait(SPAN_PACK_LOAD); + + Span *span = &spack->span[spack->info.size++]; + + span->x = x; + span->y = y; + span->length_x = length; + span->start_z = start_z; + span->end_z = end_z; + span->tex_x1 = start_tex_x; + span->tex_x2 = end_tex_x; + span->tex_y1 = start_tex_y; + span->tex_y2 = end_tex_y; + /*ここで頂点分法線ベクトルがあったんだけど、 + * 一つだけ取り出して、spanに一つの法線ベクトルを持たしている + *by yutaka + */ + span->normal_x = normal1->x; + span->normal_y = normal1->y; + span->normal_z = normal1->z; + + + float tex_x_len = span->tex_x2 - span->tex_x1; + + /** + * tex_x_len, tex_y_len を掛ける理由は + * Changelog の 2008-12-16 を参照 + */ + int scale = getScale(span->length_x, length_y, + (int)(span->tex_width*tex_x_len), + (int)(span->tex_height*tex_y_len), + tex_info->scale_max); + //scale = tex_info->scale_max; + + uint32 *tapestry = getTapestry(tex_info->width, + tex_info->height, scale, + tex_info->addr); + span->tex_addr = tapestry; + span->tex_width = tex_info->width/scale; + span->tex_height = tex_info->height/scale; + } +#else + + /** + * ここに SIMD 化した記述をしようとして断念 + */ + +#endif + +} + + +int +CreateSpan::run(SchedTask *smanager, void *rbuf, void *wbuf) +{ + PolygonPack *pp = (PolygonPack*)smanager->get_input(0); + PolygonPack *next_pp = + (PolygonPack*)smanager->allocate(sizeof(PolygonPack)); + PolygonPack *free_pp = next_pp; + PolygonPack *tmp_pp; + + TrianglePackPtr triPack; + VertexPackPtr vMin, vMid, vMax; + VertexPackPtr vMid10 + = (VertexPackPtr)smanager->allocate(sizeof(VertexPack)); + NormalPackPtr normal1,normal2, normal3; + SpanPackPtr *spackList = (SpanPackPtr*)smanager->get_input(1); + spack = (SpanPackPtr)smanager->get_input(2); + send_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); + prev_index = get_param(0); + + // spack と send_spack は swap しながら DMA を繰り返すので + // 自分で allocate した send_spack を覚えてないといけない + SpanPackPtr free_spack = send_spack; + + int charge_y_top = get_param(1); + int charge_y_end = get_param(2); + + do { + if (pp->next != NULL) { + smanager->dma_load(next_pp, (uint32)pp->next, + sizeof(PolygonPack), POLYGON_PACK_LOAD); + } else { + next_pp = NULL; + } + + for (int i = 0; i < pp->info.size; i++) { + triPack = &pp->tri[i]; + + TriangleTexInfoPtr tri_tex_info = &triPack->tex_info; + + make_vertex(triPack, &vMin, &vMid, &vMax, &normal1, &normal2, &normal3); + make_vMid10(vMid10, vMin, vMid, vMax); + + /** + * ポリゴンを、x軸に水平に分割して二つの三角形を作り、 + * それぞれから Span を求める + * + * vMax + * |\ + * | \ + * | \ + * | \ + * vMid10 ------ vMid + * | / + * | / + * | / + * |/ + * vMin + * + * (vMax, vMid, vMin) という triangle を + * (vMax, vMid, vMid10) (vMin, vMid, vMid10) という + * 二つの Triangle に分けている + */ + half_triangle(smanager, spackList, charge_y_top, charge_y_end, + tri_tex_info, vMin, vMid, vMid10, + normal1,normal2,normal3, + (int)(vMax->y - vMin->y), vMax->tex_y - vMin->tex_y); + half_triangle(smanager, spackList, charge_y_top, charge_y_end, + tri_tex_info, vMax, vMid, vMid10, + normal1,normal2,normal3, + (int)(vMax->y - vMin->y), vMax->tex_y - vMin->tex_y); + } + + smanager->dma_wait(POLYGON_PACK_LOAD); + + tmp_pp = pp; + pp = next_pp; + next_pp = tmp_pp; + } while (pp); + + smanager->dma_wait(SPAN_PACK_STORE); + smanager->dma_store(spack, (uint32)spackList[prev_index], + sizeof(SpanPack), SPAN_PACK_STORE); + smanager->dma_wait(SPAN_PACK_STORE); + + free(free_pp); + free(free_spack); + free(vMid10); + + return 0; +}
--- a/TaskManager/Test/test_render/task/CreateSpan.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,510 +0,0 @@ -#include "CreateSpan.h" -#include "viewer_types.h" - -static const int SPAN_PACK_LOAD = 5; -static const int SPAN_PACK_STORE = 6; -static const int POLYGON_PACK_LOAD = 7; -static const int TILE_ALLOCATE = 8; -static const int TILE_LOAD = 9; -static const int TILE_STORE = 10; - -static SpanPackPtr spack = NULL; -static SpanPackPtr send_spack = NULL; -static int prev_index = 0; - -SchedDefineTask(CreateSpan); - -static float -calc(float f1, float f2,int i, float base) -{ - float ans; - ans = f1/f2*i + base; - return ans; -} - - -/** - * TrianglePack から、vMin, vMid, vMax を求める - * - * @param [triPack] TrianglePack - * @param [vMin] [vMid] [vMax] - */ -static void -make_vertex(TrianglePack *triPack, - VertexPackPtr *vMin, VertexPackPtr *vMid, VertexPackPtr *vMax, - NormalPackPtr *normal1, NormalPackPtr *normal2, NormalPackPtr *normal3) -{ - if (triPack->ver1.y <= triPack->ver2.y) { - if (triPack->ver2.y <= triPack->ver3.y) { - *vMin = &triPack->ver1; - *vMid = &triPack->ver2; - *vMax = &triPack->ver3; - } else if (triPack->ver3.y <= triPack->ver1.y) { - *vMin = &triPack->ver3; - *vMid = &triPack->ver1; - *vMax = &triPack->ver2; - } else { - *vMin = &triPack->ver1; - *vMid = &triPack->ver3; - *vMax = &triPack->ver2; - } - } else { - if (triPack->ver1.y <= triPack->ver3.y) { - *vMin = &triPack->ver2; - *vMid = &triPack->ver1; - *vMax = &triPack->ver3; - } else if (triPack->ver3.y <= triPack->ver2.y) { - *vMin = &triPack->ver3; - *vMid = &triPack->ver2; - *vMax = &triPack->ver1; - } else { - *vMin = &triPack->ver2; - *vMid = &triPack->ver3; - *vMax = &triPack->ver1; - } - } - - *normal1 = &triPack->normal1; - *normal2 = &triPack->normal2; - *normal3 = &triPack->normal3; - -} - -static void -make_vMid10(VertexPack *v, VertexPack *vMin, - VertexPack *vMid, VertexPack *vMax) -{ - //int d, d1; - float d; - int d1; - - d = vMax->y - vMin->y; - d1 = (int)(vMid->y - vMin->y); - - v->tex_x = calc(vMax->tex_x - vMin->tex_x, d, d1, vMin->tex_x); - v->tex_y = calc(vMax->tex_y - vMin->tex_y, d, d1, vMin->tex_y); - v->x = calc(vMax->x - vMin->x, d, d1, vMin->x); - v->y = vMid->y; - v->z = calc(vMax->z - vMin->z, d, d1, vMin->z); -} - -/** - * 与えられた scale から、実際に使うテクスチャの Tapestry を選択する - * - * テクスチャは、オリジナルのサイズから、可能なかぎり 1/2 で縮小していき、 - * 下の図の様に連続した領域に入れられる - * - * Tapestry (1) - * +---+---+---+---+ - * | 0 | 1 | 2 | 3 | - * +---+---+---+---+ - * | 4 | 5 | 6 | 7 | (2) - * +---+---+---+---+ +---+---+ - * | 8 | 9 | 10| 11| | 16| 17| (3) - * +---+---+---+---+ +---+---+ +---+ - * | 12| 13| 14| 15| | 18| 19| | 20| - * +---+---+---+---+ +---+---+ +---| - * - * (1) (2) (3) - * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ - * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * | * | * | 14| 15| 16| 17| 18| 19| 20| - * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ - * - * scale の値から、各 Tapestry の先頭アドレスを返す - * - * @param[in] tw Width of texture - * @param[in] th Height of texture - * @param[in] scale テクスチャの縮小率 (= 2^n) - * @param[in] addr_top テクスチャの先頭アドレス (上の図での (1) - * @return scale に対応する Tapestry のアドレス (上の図での (1) or (2) or(3) - */ -static uint32* -getTapestry(int tw, int th, int scale, uint32 *addr_top) -{ - int index = 0; - - for (int s = 1; s < scale; s <<= 1) { - index += tw*th; - tw >>= 1; /* tw /= 2 */ - th >>= 1; - } - - return addr_top + index; -} - - -/** - * span の width,height と texture の width,height を比べて - * span を描画する際に使う texture の比率を求める - * - * @param[in] width Width of span - * @param[in] height Height of span - * @param[in] tex_width Width of 1/1 texture that span use - * @param[in] tex_height Height of 1/1 texture that span use - * @param[in] scale_max この Span で使う texture の最大縮小率 - * 計算結果が scale_max 以上になるのを防ぐ - * @return 描画に使う texture の比率 - * width と height は 1/scale の画像を使う - * - */ -static int -getScale(int width, int height, int tex_width, int tex_height, int scale_max) -{ - int base, tex_base; - int scale = 1; - - /** - * width と height で、長い方を基準に、 - * texture の scale を決める - */ - if (width > height) { - base = width; - tex_base = tex_width; - } else { - base = height; - tex_base = tex_height; - } - - if (tex_base > base) { - int t_scale = tex_base/base; - while (t_scale >>= 1) { - scale <<= 1; - } - } - - return (scale > scale_max) ? scale_max : scale; - //return scale_max; -} - -/** - * x軸に水平な辺を持つ三角形ポリゴンから、 - * Span を抜き出す - * - * @param[in] spackList triangle から生成された span を格納する List - * @param[in] charge_y_top 担当する y の範囲開始地点 - * @param[in] charge_y_end 担当する y の範囲終了地点 - * @param[in] tex_addr triangle が参照するテクスチャの先頭アドレス - * @param[in] tex_width テクスチャの width - * @param[in] tex_height テクスチャの height - * @param[in] tex_scale_max テクスチャの最大縮小率 (2^n) - * @param[in] vMin triangle の座標 - * @param[in] vMid triangle の座標。triangle を二つに分けて出来た新しい座標 - * @param[in] vMid10 triangle の座標 - * @param[in] length_y 分割する前の Triangle の y の長さ - * @param[in] tex_y_len 分割する前の Triangle に貼られている Texture の - * 長さの割合 (0 ... 1) - */ -void -CreateSpan::half_triangle(SchedTask *smanager, SpanPackPtr *spackList, - int charge_y_top, int charge_y_end, - TriangleTexInfoPtr tex_info, - VertexPack *vMin,VertexPack *vMid,VertexPack *vMid10, - NormalPack *normal1, NormalPack *normal2, NormalPack *normal3, - int length_y, float tex_y_len) -{ - float tmp_z,tmp_tex1, tmp_tex2 ,tmp_tey1,tmp_tey2; - float tmp_xpos,tmp_end,tmp_zpos; - float start_z, end_z; - 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軸に水平に二つに分けようとして - * ある一辺がすでに水平だった場合、つまり - * - * |\ - * | \ - * | \ - * ----- - * - * - * 上のようなポリゴンだった場合は、本来なら上の部分の三角形にだけ - * half_triangle の処理をするべきだが、現在の処理だと - * この half_triangle に「上の部分の三角形」と、 - * 「『下の部分の三角形と判断してしまった』直線」が来てしまう。 - * 直線の部分が来ると、calc() で 0 除算とかで、値不定で暴走するので - * 現在はこれで代用。 - * half_triangle 呼ぶ前にこれを判断できれば良いかもしれない。 - * てかこんなんでいいのかよ。。。 - */ -#if 1 - if ((int)div_y == 0) { - return; - } -#else - if (vMid10->x == vMin->x && vMid10->y == vMin->y) { - return; - } -#endif - - if (div_y < 0) { - div_y = -div_y; - k = 1; - l = -1; - } - - for (int i = k; i < (int)div_y+1; i++) { - y = (int)vMin->y + i*l; -#if 1 - - /** - * 担当 y 範囲内 - */ - if (charge_y_top <= y && y <= charge_y_end) { - // 1..8 を index0, 9..16 を index1 にするために y を -1 - int index = (y-1) / split_screen_h; - - /** - * 違う SpanPack を扱う場合、 - * 現在の SpanPack をメインメモリに送り、 - * 新しい SpanPack を取ってくる - */ - if (index != prev_index) { - tmp_spack = spack; - spack = send_spack; - send_spack = tmp_spack; - - smanager->dma_wait(SPAN_PACK_STORE); - smanager->dma_store(send_spack, (uint32)spackList[prev_index], - sizeof(SpanPack), SPAN_PACK_STORE); - - smanager->dma_load(spack, (uint32)spackList[index], - sizeof(SpanPack), SPAN_PACK_LOAD); - prev_index = index; - smanager->dma_wait(SPAN_PACK_LOAD); - } - - /** - * 書き込む SpanPack が満杯だったら - * メインメモリで allocate した領域 (next) を持ってきて - * 現在の spack->next につなぎ、next を次の spack とする。 - */ - if (spack->info.size >= MAX_SIZE_SPAN) { - SpanPackPtr next; - - smanager->mainMem_alloc(0, sizeof(SpanPack)); - smanager->mainMem_wait(); - next = (SpanPackPtr)smanager->mainMem_get(0); - - spack->next = next; - - tmp_spack = spack; - spack = send_spack; - send_spack = tmp_spack; - - smanager->dma_wait(SPAN_PACK_STORE); - smanager->dma_store(send_spack, (uint32)spackList[index], - sizeof(SpanPack), SPAN_PACK_STORE); - - spackList[index] = next; - - smanager->dma_load(spack, (uint32)spackList[index], - sizeof(SpanPack), SPAN_PACK_LOAD); - smanager->dma_wait(SPAN_PACK_LOAD); - spack->init((index+1)*split_screen_h); - } - } else { - /** - * 担当範囲外だったら無視 - */ - continue; - } - - tmp_xpos = calc(vMid10->x - vMin->x ,div_y, i, vMin->x); - tmp_end = calc(vMid->x - vMin->x ,div_y, i, vMin->x); - tmp_z = calc(vMid10->z - vMin->z ,div_y, i, vMin->z); - tmp_zpos = calc(vMid->z - vMin->z ,div_y, i, vMin->z); - - length = (tmp_xpos > tmp_end) - ? (int)tmp_xpos - (int)tmp_end : (int)tmp_end - (int)tmp_xpos; - if (length == 0) { - continue; - } - - tmp_tex1 =((i/(div_y)) * vMid10->tex_x) + - ( ((div_y - i)/(div_y)) * vMin->tex_x); - tmp_tex2 =( (i/(div_y)) * vMid->tex_x) + - ( ((div_y - i)/(div_y)) * vMin->tex_x); - - tmp_tey1 =( (i/(div_y)) * vMid10->tex_y) + - ( ((div_y - i)/(div_y)) * vMin->tex_y); - tmp_tey2 =( (i/(div_y)) * vMid->tex_y) + - ( ((div_y - i)/(div_y)) * vMin->tex_y); - - if (tmp_xpos > tmp_end) { - x = (int)tmp_end; - length = (int)(tmp_xpos)-(int)(tmp_end)+1; - start_z = tmp_zpos; - end_z = tmp_z; - start_tex_x = tmp_tex2; - end_tex_x = tmp_tex1; - start_tex_y = tmp_tey2; - end_tex_y = tmp_tey1; - } else { - x = (int)tmp_xpos; - length = (int)(tmp_end)-(int)(tmp_xpos)+1; - start_z = tmp_z; - end_z = tmp_zpos; - start_tex_x = tmp_tex1; - end_tex_x = tmp_tex2; - start_tex_y = tmp_tey1; - end_tex_y = tmp_tey2; - } - - smanager->dma_wait(SPAN_PACK_LOAD); - - Span *span = &spack->span[spack->info.size++]; - - span->x = x; - span->y = y; - span->length_x = length; - span->start_z = start_z; - span->end_z = end_z; - span->tex_x1 = start_tex_x; - span->tex_x2 = end_tex_x; - span->tex_y1 = start_tex_y; - span->tex_y2 = end_tex_y; - /*ここで頂点分法線ベクトルがあったんだけど、 - * 一つだけ取り出して、spanに一つの法線ベクトルを持たしている - *by yutaka - */ - span->normal_x = normal1->x; - span->normal_y = normal1->y; - span->normal_z = normal1->z; - - - float tex_x_len = span->tex_x2 - span->tex_x1; - - /** - * tex_x_len, tex_y_len を掛ける理由は - * Changelog の 2008-12-16 を参照 - */ - int scale = getScale(span->length_x, length_y, - (int)(span->tex_width*tex_x_len), - (int)(span->tex_height*tex_y_len), - tex_info->scale_max); - //scale = tex_info->scale_max; - - uint32 *tapestry = getTapestry(tex_info->width, - tex_info->height, scale, - tex_info->addr); - span->tex_addr = tapestry; - span->tex_width = tex_info->width/scale; - span->tex_height = tex_info->height/scale; - } -#else - - /** - * ここに SIMD 化した記述をしようとして断念 - */ - -#endif - -} - - -int -CreateSpan::run(SchedTask *smanager, void *rbuf, void *wbuf) -{ - PolygonPack *pp = (PolygonPack*)smanager->get_input(0); - PolygonPack *next_pp = - (PolygonPack*)smanager->allocate(sizeof(PolygonPack)); - PolygonPack *free_pp = next_pp; - PolygonPack *tmp_pp; - - TrianglePackPtr triPack; - VertexPackPtr vMin, vMid, vMax; - VertexPackPtr vMid10 - = (VertexPackPtr)smanager->allocate(sizeof(VertexPack)); - NormalPackPtr normal1,normal2, normal3; - SpanPackPtr *spackList = (SpanPackPtr*)smanager->get_input(1); - spack = (SpanPackPtr)smanager->get_input(2); - send_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); - prev_index = get_param(0); - - // spack と send_spack は swap しながら DMA を繰り返すので - // 自分で allocate した send_spack を覚えてないといけない - SpanPackPtr free_spack = send_spack; - - int charge_y_top = get_param(1); - int charge_y_end = get_param(2); - - do { - if (pp->next != NULL) { - smanager->dma_load(next_pp, (uint32)pp->next, - sizeof(PolygonPack), POLYGON_PACK_LOAD); - } else { - next_pp = NULL; - } - - for (int i = 0; i < pp->info.size; i++) { - triPack = &pp->tri[i]; - - TriangleTexInfoPtr tri_tex_info = &triPack->tex_info; - - make_vertex(triPack, &vMin, &vMid, &vMax, &normal1, &normal2, &normal3); - make_vMid10(vMid10, vMin, vMid, vMax); - - /** - * ポリゴンを、x軸に水平に分割して二つの三角形を作り、 - * それぞれから Span を求める - * - * vMax - * |\ - * | \ - * | \ - * | \ - * vMid10 ------ vMid - * | / - * | / - * | / - * |/ - * vMin - * - * (vMax, vMid, vMin) という triangle を - * (vMax, vMid, vMid10) (vMin, vMid, vMid10) という - * 二つの Triangle に分けている - */ - half_triangle(smanager, spackList, charge_y_top, charge_y_end, - tri_tex_info, vMin, vMid, vMid10, - normal1,normal2,normal3, - (int)(vMax->y - vMin->y), vMax->tex_y - vMin->tex_y); - half_triangle(smanager, spackList, charge_y_top, charge_y_end, - tri_tex_info, vMax, vMid, vMid10, - normal1,normal2,normal3, - (int)(vMax->y - vMin->y), vMax->tex_y - vMin->tex_y); - } - - smanager->dma_wait(POLYGON_PACK_LOAD); - - tmp_pp = pp; - pp = next_pp; - next_pp = tmp_pp; - } while (pp); - - smanager->dma_wait(SPAN_PACK_STORE); - smanager->dma_store(spack, (uint32)spackList[prev_index], - sizeof(SpanPack), SPAN_PACK_STORE); - smanager->dma_wait(SPAN_PACK_STORE); - - free(free_pp); - free(free_spack); - free(vMid10); - - return 0; -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/task/DrawBack.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,32 @@ +#include <stdlib.h> +#include <string.h> +#include "DrawBack.h" +#include "viewer_types.h" + +SchedDefineTask(DrawBack); + +void +DrawBack::linebuf_init(int *buf, int x, int rgb) +{ + for (int i = 0; i < x; i++) { + buf[i] = rgb; + } +} + +int +DrawBack::run(SchedTask *smanager, void *rbuf, void *wbuf) +{ + int rgb = smanager->get_param(0); + int rangex_start = smanager->get_param(1); + int rangex_end = smanager->get_param(2); + int rangey = smanager->get_param(3); + int rangex = rangex_end - rangex_start + 1; + int *linebuf; + + for (int i = 0; i < rangey; i++) { + linebuf = (int*)smanager->get_output(i); + linebuf_init(linebuf, rangex, rgb); + } + + return 0; +}
--- a/TaskManager/Test/test_render/task/DrawBack.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -#include <stdlib.h> -#include <string.h> -#include "DrawBack.h" -#include "viewer_types.h" - -SchedDefineTask(DrawBack); - -void -DrawBack::linebuf_init(int *buf, int x, int rgb) -{ - for (int i = 0; i < x; i++) { - buf[i] = rgb; - } -} - -int -DrawBack::run(SchedTask *smanager, void *rbuf, void *wbuf) -{ - int rgb = smanager->get_param(0); - int rangex_start = smanager->get_param(1); - int rangex_end = smanager->get_param(2); - int rangey = smanager->get_param(3); - int rangex = rangex_end - rangex_start + 1; - int *linebuf; - - for (int i = 0; i < rangey; i++) { - linebuf = (int*)smanager->get_output(i); - linebuf_init(linebuf, rangex, rgb); - } - - return 0; -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/task/DrawSpan.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,474 @@ +#include <stdlib.h> +#include <string.h> +#include "DrawSpan.h" +#include "polygon_pack.h" +#include "texture.h" +#include "viewer_types.h" +#include "Func.h" +#include "sys.h" +#include "global_alloc.h" + +SchedDefineTask(DrawSpan); + +#define TEX_LOAD1 0 +#define TEX_LOAD2 1 +#define SPAN_PACK_LOAD 2 +#define FB_STORE 3 + +DrawSpan::~DrawSpan() +{ + dma_wait(FB_STORE); + free((void*)((int)linebuf*doneWrite)); +} + +/** + * テクスチャは、TEXTURE_SPLIT_PIXEL^2 のブロックに分割する + * + * +---+---+---+---+---+---+ + * | 0 | 1 | 2 | 3 | 4 | 5 | + * +---+---+---+---+---+---+ + * | | | | | |11 | + * +---+---+---+---+---+---+ + * | | | | | |17 | + * +---+---+---+---+---+---+ + * | | | | | |23 | + * +---+---+---+---+---+---+ + * | | | | | |29 | + * +---+---+---+---+---+---+ + * | | | | | |35 | + * +---+---+---+---+---+---+ + * + * 一辺を TEXTURE_SPLIT とする + * 各ブロックの数字がブロックIDとなる。 + */ + +/** + * テクスチャの座標から、 + * テクスチャのどのブロックかを求める + * + * @param[in] tx X coordinates of texture + * @param[in] tx Y coordinates of texture + * @param[in] twidth Width of texture + * @return block ID + */ +int +DrawSpan::getTexBlock(int tx, int ty, int twidth) +{ + int blockX, blockY; + + blockX = tx / TEXTURE_SPLIT_PIXEL; + blockY = ty / TEXTURE_SPLIT_PIXEL; + + return blockX + (twidth/TEXTURE_SPLIT_PIXEL)*blockY; +} + +/** + * block ID と、テクスチャの TOP address から + * (tx,ty) で使われるテクスチャの Tile addres を求める + * + * @param[in] tx X coordinates of texture + * @param[in] tx Y coordinates of texture + * @param[in] tw Width of texture + * @param[in] tex_addr_top (tx,ty) で使うテクスチャの先頭address + * @return block ID + */ +memaddr +DrawSpan::getTile(int tx, int ty, int tw, memaddr tex_addr_top) +{ + int block = getTexBlock(tx, ty, tw); + return tex_addr_top + block * TEXTURE_BLOCK_SIZE * sizeof(uint32); +} + +/** + * FrameBuffer に書き込む rgb の領域初期化 + * + * @param width Width of Buffer + * @param height Height of Buffer + * @param rgb Initial value of RGB at Buffer + * @return Buffer + */ +int* +DrawSpan::linebuf_init(SchedTask *smanager, int width, int height, int rgb) +{ + int *buf = (int*)smanager->allocate(sizeof(int)*width*height); + + for (int i = 0; i < width*height; i++) { + buf[i] = rgb; + } + + return buf; +} + +/** + * Z-Buffer の初期化 + * + * @param width Width of Z-Buffer + * @param height Height of Z-Buffer + * @return Z-Buffer + */ +float* +DrawSpan::zRow_init(SchedTask *smanager, int width, int height) +{ + float *buf = (float*)smanager->allocate(sizeof(float)*width*height); + float def = 65535.0f; + + for (int i = 0; i < width*height; i++) { + buf[i] = def; + } + + return buf; +} + + +uint32 +DrawSpan::get_rgb(int tx, int ty, TilePtr tile) +{ + uint32 *data = (uint32 *)tile->data; + return data[(TEXTURE_SPLIT_PIXEL)*ty+tx]; +} + + +void +DrawSpan::writebuffer(SchedTask *smanager, unsigned int display, + int buf_width, int height, int screen_width) +{ + for (int i = 0; i < height; i++) { + smanager->dma_store(&linebuf[i*buf_width], + display + (sizeof(int)*screen_width*i), + sizeof(int)*buf_width, FB_STORE); + } + + doneWrite = 1; +} + +/** + * zRow と Linebuf を更新する + * + * @param zpos 更新する pixel のZ座標 + * @param rangex このタスクが処理する描画領域の x の長さ + * @param x pixel の、描画領域内での x 座標 + * @param y 〃 の、y 座標 + * @param tex_x pixel が使用するテクスチャの、Tile (8x8) 内での x 座標 + * @param tex_y 〃 の y 座標 + * @param tex_addr テクスチャのアドレス(MainMemory) + */ +void +DrawSpan::updateBuffer(float zpos, int rangex, int x, int y, int tex_x, int tex_y, + float normal_x, float normal_y, float normal_z, TilePtr tile) +{ + + int color = get_rgb(tex_x, tex_y, tile); + /*下位4bitを抽出*/ + int alpha = color & 0x000F; + /*完全に透けているか判断*/ + int flag = (alpha != 0); + + color = infinity_light_calc(color,normal_x,normal_y,normal_z); + + zRow[x + (rangex*y)] = zpos*flag + zRow[x + (rangex*y)]*(1-flag); + linebuf[x + (rangex*y)] = color*flag + linebuf[x + (rangex*y)]*(1-flag); + +} + +/** + * 長さが 1 の Span の描画 (要するに 1 pixel) + * + * @param span Span + * @param startx 描画開始範囲 + * @param endx 描画終了範囲 + */ +int +DrawSpan::drawDot1(SchedTask *smanager, SpanPtr span, int startx, int endx, int wait_tag) +{ + int rangex = endx - startx + 1; + + float normal_x = span->normal_x; + float normal_y = span->normal_y; + float normal_z = span->normal_z; + + + /* span->x に対応する Texture の座標 (tex_xpos, tex_ypos) */ + int tex_xpos, tex_ypos; + + // span の始点に対応する Texture の座標 (tex1, tey1) + float tex = span->tex_x1; + float tey = span->tex_y1; + + // span の始点に対応する z 座標 + float zpos = span->start_z; + + /* Tile 内での座標 */ + int localx = getLocalX(span->x-1); + int localy = getLocalY(span->y-1); + + /** + * (tex_xpos, tex_ypos) の、Tile 内(上の図参照)での座標と + * そのブロックのアドレス(MainMemory) + */ + int tex_localx; + int tex_localy; + memaddr tex_addr; + + if (span->x < startx || endx < span->x) { + return -1; + } + + tex_xpos = (int)((span->tex_width-1) * tex); + tex_ypos = (int)((span->tex_height-1) * tey); + + if (zpos < zRow[localx + (rangex*localy)]) { + tex_addr = getTile(tex_xpos, tex_ypos, + span->tex_width, (memaddr)span->tex_addr); + tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; + tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; + + TilePtr tile = smanager->get_segment(tex_addr,tileList); + smanager->wait_segment(tile); + + updateBuffer(zpos, rangex, localx, localy, + tex_localx, tex_localy, + normal_x,normal_y,normal_z,tile); + } + + return -1; +} + +void +DrawSpan::drawDot2(SchedTask *smanager, SpanPtr span, int startx, int end, int js, int wait_tag) +{ + //printf("%d\n", js); +} + +/** + * 長さが 1 より大きい Span の描画 + * + * 本来の目的として、この関数(drawLine1) では + * : 既に SPE 上に Tile のある pixel だけ描画 + * : それ以外は、ここで予め DMA load しておき、 + * : drawLine2 で一気に描画する + * ってものだったんだけど、どうも上手く行かなかったので + * 今は drawLine1 で load -> wait -> rendering を全部やってます + * (rendering といっても、rendering buffer に書き込むだけで + * まだ main memory (frame buffer) に dma store してるわけではない) + * + * @param span Span + * @param startx 描画開始範囲 + * @param endx 描画終了範囲 + * @return 「span のどの位置まで rendering が終わったか」の x 座標 + */ +int +DrawSpan::drawLine1(SchedTask *smanager, SpanPtr span, int startx, int endx, int wait_tag) +{ + int x = span->x; + int rangex = endx - startx + 1; + int x_len = span->length_x; + + float normal_x = span->normal_x; + float normal_y = span->normal_y; + float normal_z = span->normal_z; + + + int js = (x < startx) ? startx - x : 0; + int je = (x + x_len > endx) ? endx - x : x_len; + + /* span->x に対応する Texture の座標 (tex_xpos, tex_ypos) */ + int tex_xpos, tex_ypos; + + // span の始点に対応する座標 (tex1, tey1) + float tex1 = span->tex_x1; + float tey1 = span->tex_y1; + + // span の終点に対応する座標 (tex2, tey2) + float tex2 = span->tex_x2; + float tey2 = span->tex_y2; + + // span の始点、終点に対応する z 座標 + float zpos1 = span->start_z; + float zpos2 = span->end_z; + + // Tile 内での座標 + int localx, localy = getLocalY(span->y-1); + + int ret = je+1; + + //for (int j = js; j <= je; j++) { + for (int j = je; j >= js; j--) { + float tex_x, tex_y, tex_z; + + localx = getLocalX(x-1+j); + + tex_z = zpos1*(x_len-1-j)/(x_len-1) + zpos2*j/(x_len-1); + + tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); + tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); + if (tex_x > 1) tex_x = 1; + if (tex_x < 0) tex_x = 0; + if (tex_y > 1) tex_y = 1; + if (tex_y < 0) tex_y = 0; + tex_xpos = (int)((span->tex_width-1) * tex_x); + tex_ypos = (int)((span->tex_height-1) * tex_y); + + if (tex_z < zRow[localx + (rangex*localy)]) { + // (tex_xpos, tex_ypos) の、Tile 内(上の図参照)での座標と + // そのブロックのアドレス(MainMemory) + memaddr tex_addr; + int tex_localx; + int tex_localy; + + tex_addr = getTile(tex_xpos, tex_ypos, + span->tex_width, (memaddr)span->tex_addr); + tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; + tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; + TilePtr tile = smanager->get_segment(tex_addr,tileList); + smanager->wait_segment(tile); + + updateBuffer(tex_z, rangex, localx, localy, + tex_localx, tex_localy, + normal_x, normal_y, normal_z, tile); + } + } + + return ret; +} + +int +DrawSpan::infinity_light_calc(int color,float normal_x, float normal_y, float normal_z) +{ + unsigned char rgb[4]; + int light_rgb; + int flag; + float normal_vector[4] = {normal_x,normal_y,normal_z,0}; + // 光のベクトル,きめうちしちゃった。どうにかする + float light_vector[4] = {0,0,-1,0}; + float inner_product; + + // 引数で受け取った color の rgb 情報の抜き出し + rgb[0] = (color & 0xff000000) >> 24; + rgb[1] = (color & 0x00ff0000) >> 16; + rgb[2] = (color & 0x0000ff00) >> 8; + rgb[3] = (color & 0x000000ff); + + // 法線ベクトルと光源ベクトルとの内積をとる + inner_product = innerProduct(normal_vector,light_vector); + // 内積がマイナスの場合は色がない。 + flag = (inner_product > 0); + + // 内積を rgb にかけていく + rgb[0] = (unsigned char)(rgb[0]*inner_product*flag); + rgb[1] = (unsigned char)(rgb[1]*inner_product*flag); + rgb[2] = (unsigned char)(rgb[2]*inner_product*flag); + + //計算した rgb を light_rgb にまとめる。 + light_rgb = (rgb[0] << 24) + (rgb[1] << 16) + (rgb[2] << 8) + (rgb[3]); + + return light_rgb; +} + + +int +DrawSpan::run(SchedTask *smanager, void *rbuf, void *wbuf) +{ + SpanPackPtr spack = (SpanPackPtr)smanager->get_input(0); + SpanPackPtr next_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); + SpanPackPtr free_spack = next_spack; // next_spack の free() 用 + Span *span; + + Span nop_span; + nop_span.length_x = 1; + + int (DrawSpan::*drawFunc1[2])(SchedTask *, SpanPtr, int, int, int) = { + &DrawSpan::drawDot1, &DrawSpan::drawLine1 + }; + + uint32 display = smanager->get_param(0); + int screen_width = smanager->get_param(1); + int rangex_start = smanager->get_param(2); + int rangex_end = smanager->get_param(3); + + // このタスクが担当する x の範囲 + int rangex = rangex_end - rangex_start + 1; + + // y の範囲 + int rangey = smanager->get_param(4); + tileList = (TileListPtr)smanager->global_get(GLOBAL_TILE_LIST); + + zRow = zRow_init(smanager, rangex, rangey); + //linebuf = linebuf_init(rangex, rangey, 0x00ffffff); + linebuf = linebuf_init(smanager, rangex, rangey, 0); + + doneWrite = 0; + + int tl_tag[2] = {TEX_LOAD1, TEX_LOAD2}; + int tl_tag_flg1 = 0; + int tl_tag_flg2 = 1; + + do { + /** + * SpanPack->next が存在する場合、 + * 現在の SpanPack を処理してる間に + * 次の SpanPack の DMA 転送を行う + */ + if (spack->next != NULL) { + smanager->dma_load(next_spack, (uint32)spack->next, + sizeof(SpanPack), SPAN_PACK_LOAD); + } else { + next_spack = NULL; + } + + SpanPtr resume_span = &nop_span; + int resume_span_x = 0; + + for (int t = 0; t < spack->info.size; t++) { + SpanPtr next_span; + int next_span_x; + + span = &spack->span[t]; + + /** + * span の長さによって、drawLine か drawDot を選択している + */ + next_span_x + = (this->*drawFunc1[(span->length_x != 1)])( + smanager, + span, rangex_start, rangex_end, tl_tag[tl_tag_flg1]); + next_span = span; + + resume_span = next_span; + resume_span_x = next_span_x; + + //smanager->dma_wait(tl_tag[tl_tag_flg1]); + + tl_tag_flg1 ^= 1; + tl_tag_flg2 ^= 1; + } + + // 現在 drawLine2、drawDot2 は機能してないので + //(this->*drawFunc2[(resume_span->length_x != 1)])( + //resume_span, rangex_start, rangex_end, resume_span_x, + //tl_tag[tl_tag_flg1]); + + smanager->dma_wait(SPAN_PACK_LOAD); + + SpanPackPtr tmp_spack = spack; + spack = next_spack; + next_spack = tmp_spack; + } while (spack); + + writebuffer(smanager, display, rangex, rangey, screen_width); + + // linebuf は、writebuffer() の dma_store を wait する + // DrawSpan::~DrawSpan() 内で free する。 + //free(linebuf); + free(zRow); + +//FINISH: + /** + * goto FINISH; の時は reboot なので + * linebuf, zRow は free() しない + */ + + free(free_spack); + return 0; +} + +/* end */
--- a/TaskManager/Test/test_render/task/DrawSpan.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,474 +0,0 @@ -#include <stdlib.h> -#include <string.h> -#include "DrawSpan.h" -#include "polygon_pack.h" -#include "texture.h" -#include "viewer_types.h" -#include "Func.h" -#include "sys.h" -#include "global_alloc.h" - -SchedDefineTask(DrawSpan); - -#define TEX_LOAD1 0 -#define TEX_LOAD2 1 -#define SPAN_PACK_LOAD 2 -#define FB_STORE 3 - -DrawSpan::~DrawSpan() -{ - dma_wait(FB_STORE); - free((void*)((int)linebuf*doneWrite)); -} - -/** - * テクスチャは、TEXTURE_SPLIT_PIXEL^2 のブロックに分割する - * - * +---+---+---+---+---+---+ - * | 0 | 1 | 2 | 3 | 4 | 5 | - * +---+---+---+---+---+---+ - * | | | | | |11 | - * +---+---+---+---+---+---+ - * | | | | | |17 | - * +---+---+---+---+---+---+ - * | | | | | |23 | - * +---+---+---+---+---+---+ - * | | | | | |29 | - * +---+---+---+---+---+---+ - * | | | | | |35 | - * +---+---+---+---+---+---+ - * - * 一辺を TEXTURE_SPLIT とする - * 各ブロックの数字がブロックIDとなる。 - */ - -/** - * テクスチャの座標から、 - * テクスチャのどのブロックかを求める - * - * @param[in] tx X coordinates of texture - * @param[in] tx Y coordinates of texture - * @param[in] twidth Width of texture - * @return block ID - */ -int -DrawSpan::getTexBlock(int tx, int ty, int twidth) -{ - int blockX, blockY; - - blockX = tx / TEXTURE_SPLIT_PIXEL; - blockY = ty / TEXTURE_SPLIT_PIXEL; - - return blockX + (twidth/TEXTURE_SPLIT_PIXEL)*blockY; -} - -/** - * block ID と、テクスチャの TOP address から - * (tx,ty) で使われるテクスチャの Tile addres を求める - * - * @param[in] tx X coordinates of texture - * @param[in] tx Y coordinates of texture - * @param[in] tw Width of texture - * @param[in] tex_addr_top (tx,ty) で使うテクスチャの先頭address - * @return block ID - */ -memaddr -DrawSpan::getTile(int tx, int ty, int tw, memaddr tex_addr_top) -{ - int block = getTexBlock(tx, ty, tw); - return tex_addr_top + block * TEXTURE_BLOCK_SIZE * sizeof(uint32); -} - -/** - * FrameBuffer に書き込む rgb の領域初期化 - * - * @param width Width of Buffer - * @param height Height of Buffer - * @param rgb Initial value of RGB at Buffer - * @return Buffer - */ -int* -DrawSpan::linebuf_init(SchedTask *smanager, int width, int height, int rgb) -{ - int *buf = (int*)smanager->allocate(sizeof(int)*width*height); - - for (int i = 0; i < width*height; i++) { - buf[i] = rgb; - } - - return buf; -} - -/** - * Z-Buffer の初期化 - * - * @param width Width of Z-Buffer - * @param height Height of Z-Buffer - * @return Z-Buffer - */ -float* -DrawSpan::zRow_init(SchedTask *smanager, int width, int height) -{ - float *buf = (float*)smanager->allocate(sizeof(float)*width*height); - float def = 65535.0f; - - for (int i = 0; i < width*height; i++) { - buf[i] = def; - } - - return buf; -} - - -uint32 -DrawSpan::get_rgb(int tx, int ty, TilePtr tile) -{ - uint32 *data = (uint32 *)tile->data; - return data[(TEXTURE_SPLIT_PIXEL)*ty+tx]; -} - - -void -DrawSpan::writebuffer(SchedTask *smanager, unsigned int display, - int buf_width, int height, int screen_width) -{ - for (int i = 0; i < height; i++) { - smanager->dma_store(&linebuf[i*buf_width], - display + (sizeof(int)*screen_width*i), - sizeof(int)*buf_width, FB_STORE); - } - - doneWrite = 1; -} - -/** - * zRow と Linebuf を更新する - * - * @param zpos 更新する pixel のZ座標 - * @param rangex このタスクが処理する描画領域の x の長さ - * @param x pixel の、描画領域内での x 座標 - * @param y 〃 の、y 座標 - * @param tex_x pixel が使用するテクスチャの、Tile (8x8) 内での x 座標 - * @param tex_y 〃 の y 座標 - * @param tex_addr テクスチャのアドレス(MainMemory) - */ -void -DrawSpan::updateBuffer(float zpos, int rangex, int x, int y, int tex_x, int tex_y, - float normal_x, float normal_y, float normal_z, TilePtr tile) -{ - - int color = get_rgb(tex_x, tex_y, tile); - /*下位4bitを抽出*/ - int alpha = color & 0x000F; - /*完全に透けているか判断*/ - int flag = (alpha != 0); - - color = infinity_light_calc(color,normal_x,normal_y,normal_z); - - zRow[x + (rangex*y)] = zpos*flag + zRow[x + (rangex*y)]*(1-flag); - linebuf[x + (rangex*y)] = color*flag + linebuf[x + (rangex*y)]*(1-flag); - -} - -/** - * 長さが 1 の Span の描画 (要するに 1 pixel) - * - * @param span Span - * @param startx 描画開始範囲 - * @param endx 描画終了範囲 - */ -int -DrawSpan::drawDot1(SchedTask *smanager, SpanPtr span, int startx, int endx, int wait_tag) -{ - int rangex = endx - startx + 1; - - float normal_x = span->normal_x; - float normal_y = span->normal_y; - float normal_z = span->normal_z; - - - /* span->x に対応する Texture の座標 (tex_xpos, tex_ypos) */ - int tex_xpos, tex_ypos; - - // span の始点に対応する Texture の座標 (tex1, tey1) - float tex = span->tex_x1; - float tey = span->tex_y1; - - // span の始点に対応する z 座標 - float zpos = span->start_z; - - /* Tile 内での座標 */ - int localx = getLocalX(span->x-1); - int localy = getLocalY(span->y-1); - - /** - * (tex_xpos, tex_ypos) の、Tile 内(上の図参照)での座標と - * そのブロックのアドレス(MainMemory) - */ - int tex_localx; - int tex_localy; - memaddr tex_addr; - - if (span->x < startx || endx < span->x) { - return -1; - } - - tex_xpos = (int)((span->tex_width-1) * tex); - tex_ypos = (int)((span->tex_height-1) * tey); - - if (zpos < zRow[localx + (rangex*localy)]) { - tex_addr = getTile(tex_xpos, tex_ypos, - span->tex_width, (memaddr)span->tex_addr); - tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; - tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; - - TilePtr tile = smanager->get_segment(tex_addr,tileList); - smanager->wait_segment(tile); - - updateBuffer(zpos, rangex, localx, localy, - tex_localx, tex_localy, - normal_x,normal_y,normal_z,tile); - } - - return -1; -} - -void -DrawSpan::drawDot2(SchedTask *smanager, SpanPtr span, int startx, int end, int js, int wait_tag) -{ - //printf("%d\n", js); -} - -/** - * 長さが 1 より大きい Span の描画 - * - * 本来の目的として、この関数(drawLine1) では - * : 既に SPE 上に Tile のある pixel だけ描画 - * : それ以外は、ここで予め DMA load しておき、 - * : drawLine2 で一気に描画する - * ってものだったんだけど、どうも上手く行かなかったので - * 今は drawLine1 で load -> wait -> rendering を全部やってます - * (rendering といっても、rendering buffer に書き込むだけで - * まだ main memory (frame buffer) に dma store してるわけではない) - * - * @param span Span - * @param startx 描画開始範囲 - * @param endx 描画終了範囲 - * @return 「span のどの位置まで rendering が終わったか」の x 座標 - */ -int -DrawSpan::drawLine1(SchedTask *smanager, SpanPtr span, int startx, int endx, int wait_tag) -{ - int x = span->x; - int rangex = endx - startx + 1; - int x_len = span->length_x; - - float normal_x = span->normal_x; - float normal_y = span->normal_y; - float normal_z = span->normal_z; - - - int js = (x < startx) ? startx - x : 0; - int je = (x + x_len > endx) ? endx - x : x_len; - - /* span->x に対応する Texture の座標 (tex_xpos, tex_ypos) */ - int tex_xpos, tex_ypos; - - // span の始点に対応する座標 (tex1, tey1) - float tex1 = span->tex_x1; - float tey1 = span->tex_y1; - - // span の終点に対応する座標 (tex2, tey2) - float tex2 = span->tex_x2; - float tey2 = span->tex_y2; - - // span の始点、終点に対応する z 座標 - float zpos1 = span->start_z; - float zpos2 = span->end_z; - - // Tile 内での座標 - int localx, localy = getLocalY(span->y-1); - - int ret = je+1; - - //for (int j = js; j <= je; j++) { - for (int j = je; j >= js; j--) { - float tex_x, tex_y, tex_z; - - localx = getLocalX(x-1+j); - - tex_z = zpos1*(x_len-1-j)/(x_len-1) + zpos2*j/(x_len-1); - - tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); - tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); - if (tex_x > 1) tex_x = 1; - if (tex_x < 0) tex_x = 0; - if (tex_y > 1) tex_y = 1; - if (tex_y < 0) tex_y = 0; - tex_xpos = (int)((span->tex_width-1) * tex_x); - tex_ypos = (int)((span->tex_height-1) * tex_y); - - if (tex_z < zRow[localx + (rangex*localy)]) { - // (tex_xpos, tex_ypos) の、Tile 内(上の図参照)での座標と - // そのブロックのアドレス(MainMemory) - memaddr tex_addr; - int tex_localx; - int tex_localy; - - tex_addr = getTile(tex_xpos, tex_ypos, - span->tex_width, (memaddr)span->tex_addr); - tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; - tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; - TilePtr tile = smanager->get_segment(tex_addr,tileList); - smanager->wait_segment(tile); - - updateBuffer(tex_z, rangex, localx, localy, - tex_localx, tex_localy, - normal_x, normal_y, normal_z, tile); - } - } - - return ret; -} - -int -DrawSpan::infinity_light_calc(int color,float normal_x, float normal_y, float normal_z) -{ - unsigned char rgb[4]; - int light_rgb; - int flag; - float normal_vector[4] = {normal_x,normal_y,normal_z,0}; - // 光のベクトル,きめうちしちゃった。どうにかする - float light_vector[4] = {0,0,-1,0}; - float inner_product; - - // 引数で受け取った color の rgb 情報の抜き出し - rgb[0] = (color & 0xff000000) >> 24; - rgb[1] = (color & 0x00ff0000) >> 16; - rgb[2] = (color & 0x0000ff00) >> 8; - rgb[3] = (color & 0x000000ff); - - // 法線ベクトルと光源ベクトルとの内積をとる - inner_product = innerProduct(normal_vector,light_vector); - // 内積がマイナスの場合は色がない。 - flag = (inner_product > 0); - - // 内積を rgb にかけていく - rgb[0] = (unsigned char)(rgb[0]*inner_product*flag); - rgb[1] = (unsigned char)(rgb[1]*inner_product*flag); - rgb[2] = (unsigned char)(rgb[2]*inner_product*flag); - - //計算した rgb を light_rgb にまとめる。 - light_rgb = (rgb[0] << 24) + (rgb[1] << 16) + (rgb[2] << 8) + (rgb[3]); - - return light_rgb; -} - - -int -DrawSpan::run(SchedTask *smanager, void *rbuf, void *wbuf) -{ - SpanPackPtr spack = (SpanPackPtr)smanager->get_input(0); - SpanPackPtr next_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); - SpanPackPtr free_spack = next_spack; // next_spack の free() 用 - Span *span; - - Span nop_span; - nop_span.length_x = 1; - - int (DrawSpan::*drawFunc1[2])(SchedTask *, SpanPtr, int, int, int) = { - &DrawSpan::drawDot1, &DrawSpan::drawLine1 - }; - - uint32 display = smanager->get_param(0); - int screen_width = smanager->get_param(1); - int rangex_start = smanager->get_param(2); - int rangex_end = smanager->get_param(3); - - // このタスクが担当する x の範囲 - int rangex = rangex_end - rangex_start + 1; - - // y の範囲 - int rangey = smanager->get_param(4); - tileList = (TileListPtr)smanager->global_get(GLOBAL_TILE_LIST); - - zRow = zRow_init(smanager, rangex, rangey); - //linebuf = linebuf_init(rangex, rangey, 0x00ffffff); - linebuf = linebuf_init(smanager, rangex, rangey, 0); - - doneWrite = 0; - - int tl_tag[2] = {TEX_LOAD1, TEX_LOAD2}; - int tl_tag_flg1 = 0; - int tl_tag_flg2 = 1; - - do { - /** - * SpanPack->next が存在する場合、 - * 現在の SpanPack を処理してる間に - * 次の SpanPack の DMA 転送を行う - */ - if (spack->next != NULL) { - smanager->dma_load(next_spack, (uint32)spack->next, - sizeof(SpanPack), SPAN_PACK_LOAD); - } else { - next_spack = NULL; - } - - SpanPtr resume_span = &nop_span; - int resume_span_x = 0; - - for (int t = 0; t < spack->info.size; t++) { - SpanPtr next_span; - int next_span_x; - - span = &spack->span[t]; - - /** - * span の長さによって、drawLine か drawDot を選択している - */ - next_span_x - = (this->*drawFunc1[(span->length_x != 1)])( - smanager, - span, rangex_start, rangex_end, tl_tag[tl_tag_flg1]); - next_span = span; - - resume_span = next_span; - resume_span_x = next_span_x; - - //smanager->dma_wait(tl_tag[tl_tag_flg1]); - - tl_tag_flg1 ^= 1; - tl_tag_flg2 ^= 1; - } - - // 現在 drawLine2、drawDot2 は機能してないので - //(this->*drawFunc2[(resume_span->length_x != 1)])( - //resume_span, rangex_start, rangex_end, resume_span_x, - //tl_tag[tl_tag_flg1]); - - smanager->dma_wait(SPAN_PACK_LOAD); - - SpanPackPtr tmp_spack = spack; - spack = next_spack; - next_spack = tmp_spack; - } while (spack); - - writebuffer(smanager, display, rangex, rangey, screen_width); - - // linebuf は、writebuffer() の dma_store を wait する - // DrawSpan::~DrawSpan() 内で free する。 - //free(linebuf); - free(zRow); - -//FINISH: - /** - * goto FINISH; の時は reboot なので - * linebuf, zRow は free() しない - */ - - free(free_spack); - return 0; -} - -/* end */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/task/DrawSpanRenew.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,223 @@ +#if 0 +#include <stdlib.h> +#include <string.h> +#include "DrawSpanRenew.h" +#include "polygon_pack.h" +#include "SpanPack.h" +#include "texture.h" +#include "viewer_types.h" +#include "Func.h" +#include "global_alloc.h" + +#define SPAN_PACK_LOAD 0 +#define TEX_LOAD 1 +#define FB_STORE 2 + +SchedDefineTask(DrawSpanRenew); + +void +DrawSpanRenew::reboot(SpanPackPtr spack, int cur_span_x) +{ + TaskPtr renew_task = smanager->create_task(TASK_DRAW_SPAN2); + + renew_task->add_param((int)args); + + SpanPackPtr curr = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); + memcpy(curr, spack, sizeof(SpanPack)); + renew_task->add_param((int)curr); + renew_task->add_param(cur_span_x); + + // linebuf と zRow も引き継がせる + renew_task->add_param((int)linebuf); + renew_task->add_param((int)zRow); + + //fprintf(stderr, "[%p] start %u\n", curr, spu_readch(SPU_RdDec)); + + /** + * 再起動したタスクを待つ + */ + smanager->wait_task(renew_task); + + // next_spack は free() するので wait する + smanager->dma_wait(SPAN_PACK_LOAD); +} + +int +DrawSpanRenew::run(void *rbuf, void *wbuf) +{ + SpanPackPtr spack = (SpanPackPtr)smanager->get_param(1); + SpanPackPtr next_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); + SpanPackPtr free_spack1 = spack; + SpanPackPtr free_spack2 = next_spack; + Span *span; + + args = (DrawSpanArgPtr)smanager->get_param(0); + uint32 display = args->display; + int screen_width = args->screen_width; + int rangex_start = args->rangex_start; + int rangex_end = args->rangex_end; + + // このタスクが担当する x の範囲 + int rangex = rangex_end - rangex_start + 1; + + // y の範囲 (render_y + rangey - 1) + int rangey = args->rangey; + + hash = (TileHashPtr)smanager->global_get(GLOBAL_TEXTURE_HASH); + tileList = (TileListPtr)smanager->global_get(GLOBAL_TILE_LIST); + + linebuf = (int*)smanager->get_param(3); + zRow = (float*)smanager->get_param(4); + + doneWrite = 0; + + // span->length_x の処理での再起動位置 + int js_cont = smanager->get_param(2); + + //fprintf(stderr, "[%p] end %u\n", spack, spu_readch(SPU_RdDec)); + + smanager->dma_wait(TEX_LOAD); + + do { + /** + * SpanPack->next が存在する場合、 + * 現在の SpanPack を処理してる間に + * 次の SpanPack の DMA 転送を行う + */ + if (spack->next != NULL) { + smanager->dma_load(next_spack, (uint32)spack->next, + sizeof(SpanPack), SPAN_PACK_LOAD); + } else { + next_spack = NULL; + } + + for (int t = spack->info.start; t < spack->info.size; t++) { + span = &spack->span[t]; + + uint32 rgb = 0x00ff0000; + float tex1 = span->tex_x1; + float tex2 = span->tex_x2; + float tey1 = span->tex_y1; + float tey2 = span->tex_y2; + + /** + * Span が持つ 1 pixel 毎の + * テクスチャの座標 + */ + int tex_xpos; + int tex_ypos; + + /** + * (tex_xpos, tex_ypos) の、ブロック内(上の図参照)での座標と + * そのブロックのアドレス(MainMemory) + */ + int tex_localx; + int tex_localy; + memaddr tex_addr; + + int x = span->x; + int y = span->y; + int x_len = span->length_x; + float z = span->start_z; + float zpos = span->end_z; + + // 座標が [0 .. split_screen_w-1] に入るように x,y を -1 + int localx = getLocalX(x-1); + int localy = getLocalY(y-1); + + if (x_len == 1) { + if (x < rangex_start || rangex_end < x) { + continue; + } + + tex_xpos = (int)((span->tex_width-1) * tex1); + tex_ypos = (int)((span->tex_height-1) * tey1); + + if (zpos < zRow[localx + (rangex * localy)]) { + tex_addr = getTile(tex_xpos, tex_ypos, + span->tex_width, (memaddr)span->tex_addr); + tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; + tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; + + TilePtr tile; + if (!(tile = isAvailableTile(tex_addr))) { + tile = set_rgb(tex_addr, 0); + smanager->dma_wait(0); + } + + rgb = get_rgb(tex_localx, tex_localy, tile); + + zRow[localx + (rangex*localy)] = zpos; + linebuf[localx + (rangex*localy)] = rgb; + } + } else { + int js = (x < rangex_start) ? rangex_start - x : 0; + int je = (x + x_len > rangex_end) ? rangex_end - x : x_len; + float tex_x, tex_y, tex_z; + + /** + * 一回比較すれば、以後再起動するまでは + * js_cont は使わないから 0 にしてるわけだけど、 + * 最初の一回のためだけにこれはめんどくさいのー。 + */ + js = (js < js_cont) ? js_cont : js; + js_cont = 0; + + for (int j = js; j <= je; j++) { + localx = getLocalX(x-1+j); + + tex_z = z*(x_len-1-j)/(x_len-1) + zpos*j/(x_len-1); + + tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); + tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); + if (tex_x > 1) tex_x = 1; + if (tex_x < 0) tex_x = 0; + if (tex_y > 1) tex_y = 1; + if (tex_y < 0) tex_y = 0; + tex_xpos = (int)((span->tex_width-1) * tex_x); + tex_ypos = (int)((span->tex_height-1) * tex_y); + + if (tex_z < zRow[localx + (rangex*localy)]) { + tex_addr = getTile(tex_xpos, tex_ypos, + span->tex_width, (memaddr)span->tex_addr); + tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; + tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; + + TilePtr tile; + if (!(tile = isAvailableTile(tex_addr))) { + spack->info.start = t; + tile = set_rgb(tex_addr, TEX_LOAD); + smanager->dma_wait(TEX_LOAD); + } + + rgb = get_rgb(tex_localx, tex_localy, tile); + + zRow[localx + (rangex*localy)] = tex_z; + linebuf[localx + (rangex*localy)] = rgb; + } + } + } + } + + smanager->dma_wait(SPAN_PACK_LOAD); + + SpanPackPtr tmp_spack = spack; + spack = next_spack; + next_spack = tmp_spack; + } while (spack); + + writebuffer(display, rangex, rangey, screen_width); + + free(zRow); + free(args); + + //FINISH: + /** + * linebuf, zRow, args は RenewTask が引き継ぐ + */ + free(free_spack1); + free(free_spack2); + + return 0; +} +#endif
--- a/TaskManager/Test/test_render/task/DrawSpanRenew.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,223 +0,0 @@ -#if 0 -#include <stdlib.h> -#include <string.h> -#include "DrawSpanRenew.h" -#include "polygon_pack.h" -#include "SpanPack.h" -#include "texture.h" -#include "viewer_types.h" -#include "Func.h" -#include "global_alloc.h" - -#define SPAN_PACK_LOAD 0 -#define TEX_LOAD 1 -#define FB_STORE 2 - -SchedDefineTask(DrawSpanRenew); - -void -DrawSpanRenew::reboot(SpanPackPtr spack, int cur_span_x) -{ - TaskPtr renew_task = smanager->create_task(TASK_DRAW_SPAN2); - - renew_task->add_param((int)args); - - SpanPackPtr curr = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); - memcpy(curr, spack, sizeof(SpanPack)); - renew_task->add_param((int)curr); - renew_task->add_param(cur_span_x); - - // linebuf と zRow も引き継がせる - renew_task->add_param((int)linebuf); - renew_task->add_param((int)zRow); - - //fprintf(stderr, "[%p] start %u\n", curr, spu_readch(SPU_RdDec)); - - /** - * 再起動したタスクを待つ - */ - smanager->wait_task(renew_task); - - // next_spack は free() するので wait する - smanager->dma_wait(SPAN_PACK_LOAD); -} - -int -DrawSpanRenew::run(void *rbuf, void *wbuf) -{ - SpanPackPtr spack = (SpanPackPtr)smanager->get_param(1); - SpanPackPtr next_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); - SpanPackPtr free_spack1 = spack; - SpanPackPtr free_spack2 = next_spack; - Span *span; - - args = (DrawSpanArgPtr)smanager->get_param(0); - uint32 display = args->display; - int screen_width = args->screen_width; - int rangex_start = args->rangex_start; - int rangex_end = args->rangex_end; - - // このタスクが担当する x の範囲 - int rangex = rangex_end - rangex_start + 1; - - // y の範囲 (render_y + rangey - 1) - int rangey = args->rangey; - - hash = (TileHashPtr)smanager->global_get(GLOBAL_TEXTURE_HASH); - tileList = (TileListPtr)smanager->global_get(GLOBAL_TILE_LIST); - - linebuf = (int*)smanager->get_param(3); - zRow = (float*)smanager->get_param(4); - - doneWrite = 0; - - // span->length_x の処理での再起動位置 - int js_cont = smanager->get_param(2); - - //fprintf(stderr, "[%p] end %u\n", spack, spu_readch(SPU_RdDec)); - - smanager->dma_wait(TEX_LOAD); - - do { - /** - * SpanPack->next が存在する場合、 - * 現在の SpanPack を処理してる間に - * 次の SpanPack の DMA 転送を行う - */ - if (spack->next != NULL) { - smanager->dma_load(next_spack, (uint32)spack->next, - sizeof(SpanPack), SPAN_PACK_LOAD); - } else { - next_spack = NULL; - } - - for (int t = spack->info.start; t < spack->info.size; t++) { - span = &spack->span[t]; - - uint32 rgb = 0x00ff0000; - float tex1 = span->tex_x1; - float tex2 = span->tex_x2; - float tey1 = span->tex_y1; - float tey2 = span->tex_y2; - - /** - * Span が持つ 1 pixel 毎の - * テクスチャの座標 - */ - int tex_xpos; - int tex_ypos; - - /** - * (tex_xpos, tex_ypos) の、ブロック内(上の図参照)での座標と - * そのブロックのアドレス(MainMemory) - */ - int tex_localx; - int tex_localy; - memaddr tex_addr; - - int x = span->x; - int y = span->y; - int x_len = span->length_x; - float z = span->start_z; - float zpos = span->end_z; - - // 座標が [0 .. split_screen_w-1] に入るように x,y を -1 - int localx = getLocalX(x-1); - int localy = getLocalY(y-1); - - if (x_len == 1) { - if (x < rangex_start || rangex_end < x) { - continue; - } - - tex_xpos = (int)((span->tex_width-1) * tex1); - tex_ypos = (int)((span->tex_height-1) * tey1); - - if (zpos < zRow[localx + (rangex * localy)]) { - tex_addr = getTile(tex_xpos, tex_ypos, - span->tex_width, (memaddr)span->tex_addr); - tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; - tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; - - TilePtr tile; - if (!(tile = isAvailableTile(tex_addr))) { - tile = set_rgb(tex_addr, 0); - smanager->dma_wait(0); - } - - rgb = get_rgb(tex_localx, tex_localy, tile); - - zRow[localx + (rangex*localy)] = zpos; - linebuf[localx + (rangex*localy)] = rgb; - } - } else { - int js = (x < rangex_start) ? rangex_start - x : 0; - int je = (x + x_len > rangex_end) ? rangex_end - x : x_len; - float tex_x, tex_y, tex_z; - - /** - * 一回比較すれば、以後再起動するまでは - * js_cont は使わないから 0 にしてるわけだけど、 - * 最初の一回のためだけにこれはめんどくさいのー。 - */ - js = (js < js_cont) ? js_cont : js; - js_cont = 0; - - for (int j = js; j <= je; j++) { - localx = getLocalX(x-1+j); - - tex_z = z*(x_len-1-j)/(x_len-1) + zpos*j/(x_len-1); - - tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); - tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); - if (tex_x > 1) tex_x = 1; - if (tex_x < 0) tex_x = 0; - if (tex_y > 1) tex_y = 1; - if (tex_y < 0) tex_y = 0; - tex_xpos = (int)((span->tex_width-1) * tex_x); - tex_ypos = (int)((span->tex_height-1) * tex_y); - - if (tex_z < zRow[localx + (rangex*localy)]) { - tex_addr = getTile(tex_xpos, tex_ypos, - span->tex_width, (memaddr)span->tex_addr); - tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; - tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; - - TilePtr tile; - if (!(tile = isAvailableTile(tex_addr))) { - spack->info.start = t; - tile = set_rgb(tex_addr, TEX_LOAD); - smanager->dma_wait(TEX_LOAD); - } - - rgb = get_rgb(tex_localx, tex_localy, tile); - - zRow[localx + (rangex*localy)] = tex_z; - linebuf[localx + (rangex*localy)] = rgb; - } - } - } - } - - smanager->dma_wait(SPAN_PACK_LOAD); - - SpanPackPtr tmp_spack = spack; - spack = next_spack; - next_spack = tmp_spack; - } while (spack); - - writebuffer(display, rangex, rangey, screen_width); - - free(zRow); - free(args); - - //FINISH: - /** - * linebuf, zRow, args は RenewTask が引き継ぐ - */ - free(free_spack1); - free(free_spack2); - - return 0; -} -#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/task/Load_Texture.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,25 @@ +#include <stdlib.h> +#include <string.h> +#include "Load_Texture.h" +#include "texture.h" +#if !USE_MEMHASH +#include "TileHash.h" +#endif +#include "Func.h" +#include "global_alloc.h" +#include "Tapestry.h" + +SchedDefineTask(LoadTexture); + +/** + * 「Load」といいながら、結局 DrawSpan で使う + * Hash の準備だけなので、名前変えないとなー + */ +int +LoadTexture::run(SchedTask *smanager, void *rbuf , void *wbuf) +{ + MemList *ml = smanager->createMemList(sizeof(uint32) * TEXTURE_BLOCK_SIZE, MAX_TILE); + smanager->global_set(GLOBAL_TILE_LIST, (void *)ml); + + return 0; +}
--- a/TaskManager/Test/test_render/task/Load_Texture.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -#include <stdlib.h> -#include <string.h> -#include "Load_Texture.h" -#include "texture.h" -#if !USE_MEMHASH -#include "TileHash.h" -#endif -#include "Func.h" -#include "global_alloc.h" -#include "Tapestry.h" - -SchedDefineTask(LoadTexture); - -/** - * 「Load」といいながら、結局 DrawSpan で使う - * Hash の準備だけなので、名前変えないとなー - */ -int -LoadTexture::run(SchedTask *smanager, void *rbuf , void *wbuf) -{ - MemList *ml = smanager->createMemList(sizeof(uint32) * TEXTURE_BLOCK_SIZE, MAX_TILE); - smanager->global_set(GLOBAL_TILE_LIST, (void *)ml); - - return 0; -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/task/Set_Texture.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,32 @@ +#include <string.h> +#include "Set_Texture.h" +#include "texture.h" +#include "global_alloc.h" + +SchedDefineTask(SetTexture); + +//texture をglobal 領域にコピーするタスク +int +SetTexture::run(void *rbuf, void *wbuf) +{ + void *src[4]; + + src[0] = get_input(rbuf, 0); + src[1] = get_input(rbuf, 1); + src[2] = get_input(rbuf, 2); + src[3] = get_input(rbuf, 3); + + if (global_get(TEXTURE_ID)) { + return 0; + } else { + //タスクが共有できる領域確保 + void *data = global_alloc(TEXTURE_ID, MAX_LOAD_SIZE*4); + + memcpy(data, src[0], MAX_LOAD_SIZE); + memcpy((void*)((int)data + MAX_LOAD_SIZE), src[1], MAX_LOAD_SIZE); + memcpy((void*)((int)data + MAX_LOAD_SIZE*2), src[2], MAX_LOAD_SIZE); + memcpy((void*)((int)data + MAX_LOAD_SIZE*3), src[3], MAX_LOAD_SIZE); + } + + return 0; +}
--- a/TaskManager/Test/test_render/task/Set_Texture.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -#include <string.h> -#include "Set_Texture.h" -#include "texture.h" -#include "global_alloc.h" - -SchedDefineTask(SetTexture); - -//texture をglobal 領域にコピーするタスク -int -SetTexture::run(void *rbuf, void *wbuf) -{ - void *src[4]; - - src[0] = get_input(rbuf, 0); - src[1] = get_input(rbuf, 1); - src[2] = get_input(rbuf, 2); - src[3] = get_input(rbuf, 3); - - if (global_get(TEXTURE_ID)) { - return 0; - } else { - //タスクが共有できる領域確保 - void *data = global_alloc(TEXTURE_ID, MAX_LOAD_SIZE*4); - - memcpy(data, src[0], MAX_LOAD_SIZE); - memcpy((void*)((int)data + MAX_LOAD_SIZE), src[1], MAX_LOAD_SIZE); - memcpy((void*)((int)data + MAX_LOAD_SIZE*2), src[2], MAX_LOAD_SIZE); - memcpy((void*)((int)data + MAX_LOAD_SIZE*3), src[3], MAX_LOAD_SIZE); - } - - return 0; -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/task/ShowTime.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,16 @@ +#include "ShowTime.h" +#include "stdio.h" + +SchedDefineTask(ShowTime); + +int +ShowTime::run(void *rbuf, void *wbuf) +{ + /* + * ここで show_dma_wait() を呼びたい + */ + //printf("Show Time !\n"); + + return 0; +} +
--- a/TaskManager/Test/test_render/task/ShowTime.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -#include "ShowTime.h" -#include "stdio.h" - -SchedDefineTask(ShowTime); - -int -ShowTime::run(void *rbuf, void *wbuf) -{ - /* - * ここで show_dma_wait() を呼びたい - */ - //printf("Show Time !\n"); - - return 0; -} -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/task/TileHash.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,88 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include "TileHash.h" + +static unsigned short PRIME[8] = { + 0x002, 0x065, 0x0c7, 0x133, 0x191, 0x1f3, 0x259, 0x2bd, +}; + +int +TileHash::hash(memaddr data) +{ + int value = 0; + int n = 0; + int key; + + for (unsigned int i = 0; i < sizeof(memaddr) * 2; i ++) { + key = data & 0xf; + value += key * PRIME[n++ & 7]; + data >>= 4; + } + + return value % hashSize; +} + +TileHash::TileHash(void) +{ + hashSize = 263; + tableSize = sizeof(TilePtr)*hashSize; + + table = (TilePtr*)malloc(tableSize); + clear(); +} + +int +TileHash::put(memaddr key, TilePtr data) +{ + int hashval = hash(key); + + for (int i = 0; i < hashSize/2; i++) { + int index = (hashval + i*i)%hashSize; + + if (table[index] == 0) { // 空の table に入れる + table[index] = data; + return index; + } + } + + return -1; +} + +TilePtr +TileHash::get(memaddr key) +{ + int hashval = hash(key); + + for (int i = 0; i < hashSize/2; i++) { + int index = (hashval + i*i)%hashSize; + + if (table[index] != NULL && + table[index]->address == key) { + return table[index]; + } + } + + return NULL; +} + +void +TileHash::remove(memaddr key) +{ + int hashval = hash(key); + + for (int i = 0; i < hashSize/2; i++) { + int index = (hashval + i*i)%hashSize; + + if (table[index] != NULL && + table[index]->address == key) { + table[index] = NULL; + } + } +} + +void +TileHash::clear(void) +{ + bzero(table, tableSize); +}
--- a/TaskManager/Test/test_render/task/TileHash.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include "TileHash.h" - -static unsigned short PRIME[8] = { - 0x002, 0x065, 0x0c7, 0x133, 0x191, 0x1f3, 0x259, 0x2bd, -}; - -int -TileHash::hash(memaddr data) -{ - int value = 0; - int n = 0; - int key; - - for (unsigned int i = 0; i < sizeof(memaddr) * 2; i ++) { - key = data & 0xf; - value += key * PRIME[n++ & 7]; - data >>= 4; - } - - return value % hashSize; -} - -TileHash::TileHash(void) -{ - hashSize = 263; - tableSize = sizeof(TilePtr)*hashSize; - - table = (TilePtr*)malloc(tableSize); - clear(); -} - -int -TileHash::put(memaddr key, TilePtr data) -{ - int hashval = hash(key); - - for (int i = 0; i < hashSize/2; i++) { - int index = (hashval + i*i)%hashSize; - - if (table[index] == 0) { // 空の table に入れる - table[index] = data; - return index; - } - } - - return -1; -} - -TilePtr -TileHash::get(memaddr key) -{ - int hashval = hash(key); - - for (int i = 0; i < hashSize/2; i++) { - int index = (hashval + i*i)%hashSize; - - if (table[index] != NULL && - table[index]->address == key) { - return table[index]; - } - } - - return NULL; -} - -void -TileHash::remove(memaddr key) -{ - int hashval = hash(key); - - for (int i = 0; i < hashSize/2; i++) { - int index = (hashval + i*i)%hashSize; - - if (table[index] != NULL && - table[index]->address == key) { - table[index] = NULL; - } - } -} - -void -TileHash::clear(void) -{ - bzero(table, tableSize); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/task/create_sgp.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,129 @@ +#include "scene_graph_pack.h" +#include "SceneGraph.h" +#include "create_sgp.h" +#include "TaskManager.h" +using namespace std; + +SchedDefineTask(Create_SGP); + +/** + * TODO + * 入りきらない分は SceneGraphPack を next で繋げてるので + * node->pn をつかって sgp->node[node->pn] とかやって + * 親?の要素を探す事は出来ないかもしれません。 + * next を辿って node->pn == とかやるのは確実だけどさ。。。 + */ +int +//create_sgp(Polygon *sg, SceneGraphPack *sgp) +Create_SGP::run(SchedTask *smanager, void *rbuf, void *wbuf) +{ + //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; + + SceneGraph *t = sg; + + while(t) { + // blocking はこれでいいのかな? + if (curNumber >= MAX_NODE ){ + SceneGraphPack *sgp_new = + //(SceneGraphPack*)manager->malloc(sizeof(SceneGraphPack)); + (SceneGraphPack*)smanager->allocate(sizeof(SceneGraphPack)); + sgp_new->init(); + sgp->info.size = curNumber-1; + curNumber = 0; + sgp->next = sgp_new; + sgp = sgp_new; + } + + node = &sgp->node[curNumber]; + node->init(); + + for (int i = 0,d = 0,tex = 0; i < t->size; i++, d += 3, tex += 2) { + if (node->size >= MAX_POLYGON) { + SceneGraphNodePtr node_new = (SceneGraphNodePtr)smanager->allocate(sizeof(SceneGraphNode)); + node_new->init(); + node->next = node_new; + node = node_new; + d = 0; + tex = 0; + } + + /** + * struct texture { + * int texture_id; + * float vertex[3]; + * float texture[2]; + * } + */ + + node->vertex[d] = t->coord_xyz[i*3]; + node->vertex[d+1] = t->coord_xyz[i*3+1]; + node->vertex[d+2] = t->coord_xyz[i*3+2]; + node->texture[tex] = t->coord_tex[i*3]; + node->texture[tex+1] = t->coord_tex[i*3+1]; + node->size++; + } + + node = &sgp->node[curNumber]; + + SceneGraphNode *p = node; + do { + p->obj_pos[0] = 0; + p->obj_pos[1] = 0; + p->obj_pos[2] = 0; + p->obj_pos[3] = 1; + p->angle[0] = 0; + p->angle[1] = 0; + p->angle[2] = 0; + p->angle[3] = 1; + + for (int tm = 0; tm < 16; tm++) { + p->translation[tm] = 0; + } + + 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; + p->tex_height = t->texture_image->h; + p = p->next; + } while (p); + + if (t->children != NULL) { + nnpn = curNumber; + t = t->children; + } else if (t->brother != NULL) { + nnpn = node->pn; + t = t->brother; + } else { + while (t) { + if (t->brother != NULL) { + t = t->brother; + break; + } else { + if (t->parent == NULL) { + t = NULL; + break; + } + nnpn = sgp->node[nnpn].pn; + t = t->parent; + } + } + } + curNumber++; + } + sgp->info.size = curNumber; + + return 0; +}
--- a/TaskManager/Test/test_render/task/create_sgp.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,129 +0,0 @@ -#include "scene_graph_pack.h" -#include "SceneGraph.h" -#include "create_sgp.h" -#include "TaskManager.h" -using namespace std; - -SchedDefineTask(Create_SGP); - -/** - * TODO - * 入りきらない分は SceneGraphPack を next で繋げてるので - * node->pn をつかって sgp->node[node->pn] とかやって - * 親?の要素を探す事は出来ないかもしれません。 - * next を辿って node->pn == とかやるのは確実だけどさ。。。 - */ -int -//create_sgp(Polygon *sg, SceneGraphPack *sgp) -Create_SGP::run(SchedTask *smanager, void *rbuf, void *wbuf) -{ - //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; - - SceneGraph *t = sg; - - while(t) { - // blocking はこれでいいのかな? - if (curNumber >= MAX_NODE ){ - SceneGraphPack *sgp_new = - //(SceneGraphPack*)manager->malloc(sizeof(SceneGraphPack)); - (SceneGraphPack*)smanager->allocate(sizeof(SceneGraphPack)); - sgp_new->init(); - sgp->info.size = curNumber-1; - curNumber = 0; - sgp->next = sgp_new; - sgp = sgp_new; - } - - node = &sgp->node[curNumber]; - node->init(); - - for (int i = 0,d = 0,tex = 0; i < t->size; i++, d += 3, tex += 2) { - if (node->size >= MAX_POLYGON) { - SceneGraphNodePtr node_new = (SceneGraphNodePtr)smanager->allocate(sizeof(SceneGraphNode)); - node_new->init(); - node->next = node_new; - node = node_new; - d = 0; - tex = 0; - } - - /** - * struct texture { - * int texture_id; - * float vertex[3]; - * float texture[2]; - * } - */ - - node->vertex[d] = t->coord_xyz[i*3]; - node->vertex[d+1] = t->coord_xyz[i*3+1]; - node->vertex[d+2] = t->coord_xyz[i*3+2]; - node->texture[tex] = t->coord_tex[i*3]; - node->texture[tex+1] = t->coord_tex[i*3+1]; - node->size++; - } - - node = &sgp->node[curNumber]; - - SceneGraphNode *p = node; - do { - p->obj_pos[0] = 0; - p->obj_pos[1] = 0; - p->obj_pos[2] = 0; - p->obj_pos[3] = 1; - p->angle[0] = 0; - p->angle[1] = 0; - p->angle[2] = 0; - p->angle[3] = 1; - - for (int tm = 0; tm < 16; tm++) { - p->translation[tm] = 0; - } - - 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; - p->tex_height = t->texture_image->h; - p = p->next; - } while (p); - - if (t->children != NULL) { - nnpn = curNumber; - t = t->children; - } else if (t->brother != NULL) { - nnpn = node->pn; - t = t->brother; - } else { - while (t) { - if (t->brother != NULL) { - t = t->brother; - break; - } else { - if (t->parent == NULL) { - t = NULL; - break; - } - nnpn = sgp->node[nnpn].pn; - t = t->parent; - } - } - } - curNumber++; - } - sgp->info.size = curNumber; - - return 0; -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/task/dummy.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,9 @@ +#include "dummy.h" + +SchedDefineTask(Dummy); + +int +Dummy::run(void *rbuf, void *wbuf) +{ + return 0; +}
--- a/TaskManager/Test/test_render/task/dummy.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -#include "dummy.hpp" - -SchedDefineTask(Dummy); - -int -Dummy::run(void *rbuf, void *wbuf) -{ - return 0; -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/task/dummy.h Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,8 @@ +#include "SchedTask.h" + +class Dummy : public SchedTask { +public: + SchedConstructor(Dummy); + + int run(void *rbuf, void *wbuf); +};
--- a/TaskManager/Test/test_render/task/dummy.hpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -#include "SchedTask.h" - -class Dummy : public SchedTask { -public: - SchedConstructor(Dummy); - - int run(void *rbuf, void *wbuf); -};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/task/task_init.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,49 @@ +#include "../Func.h" +#include "Scheduler.h" + +SchedExternTask(Create_SGP); +SchedExternTask(Update_SGP); +SchedExternTask(CreatePolygon); +SchedExternTask(CreatePolygonFromSceneGraph); +SchedExternTask(CreateSpan); + +SchedExternTask(DrawSpan); +SchedExternTask(DrawSpanRenew); +SchedExternTask(DrawBack); + +SchedExternTask(LoadTexture); +SchedExternTask(SetTexture); + +// SchedExternTask(Move); +// SchedExternTask(Draw); + +SchedExternTask(Dummy); + +SchedExternTask(ShowTime); + + +/** + * set_cpu(CPU_PPE) で動作する task + */ +void +task_initialize() +{ + 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); +// SchedRegisterTask(TASK_DRAW_SPAN2, DrawSpanRenew); + SchedRegisterTask(TASK_DRAW_BACK, DrawBack); + + SchedRegisterTask(TASK_INIT_TEXTURE, LoadTexture); + SchedRegisterTask(TASK_SET_TEXTURE, SetTexture); + +// SchedRegisterTask(TASK_MOVE, Move); +// SchedRegisterTask(TASK_DRAW, Draw); + + SchedRegisterTask(TASK_DUMMY, Dummy); + SchedRegisterTask(SHOW_TIME, ShowTime); +}
--- a/TaskManager/Test/test_render/task/task_init.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -#include "../Func.h" -#include "Scheduler.h" - -SchedExternTask(Create_SGP); -SchedExternTask(Update_SGP); -SchedExternTask(CreatePolygon); -SchedExternTask(CreatePolygonFromSceneGraph); -SchedExternTask(CreateSpan); - -SchedExternTask(DrawSpan); -SchedExternTask(DrawSpanRenew); -SchedExternTask(DrawBack); - -SchedExternTask(LoadTexture); -SchedExternTask(SetTexture); - -// SchedExternTask(Move); -// SchedExternTask(Draw); - -SchedExternTask(Dummy); - -SchedExternTask(ShowTime); - - -/** - * set_cpu(CPU_PPE) で動作する task - */ -void -task_initialize() -{ - 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); -// SchedRegisterTask(TASK_DRAW_SPAN2, DrawSpanRenew); - SchedRegisterTask(TASK_DRAW_BACK, DrawBack); - - SchedRegisterTask(TASK_INIT_TEXTURE, LoadTexture); - SchedRegisterTask(TASK_SET_TEXTURE, SetTexture); - -// SchedRegisterTask(TASK_MOVE, Move); -// SchedRegisterTask(TASK_DRAW, Draw); - - SchedRegisterTask(TASK_DUMMY, Dummy); - SchedRegisterTask(SHOW_TIME, ShowTime); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/task/update_sgp.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,42 @@ +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <math.h> +#include "scene_graph_pack.h" +#include "sys.h" +#include "update_sgp.h" + +SchedDefineTask(Update_SGP); + +int +Update_SGP::run(void *rbuf, void *wbuf) +{ + SceneGraphNodePtr node; + SceneGraphPack *sgp = (SceneGraphPack*)get_input(rbuf, 0); + SceneGraphPack *_sgp = (SceneGraphPack*)get_output(wbuf, 0); + //int screen_width = get_param(0); + //int screen_height = get_param(1); + + // 本当はここでやるもんじゃないんだが。。。 + for (int i = 0; i < sgp->info.size && i < 3; i++) { + node = &sgp->node[i]; + + do { + if (node->pn != -1) { + get_matrix(node->translation, + node->angle, node->obj_pos, + sgp->node[node->pn].translation); + } else { + get_matrix(node->translation, + node->angle, node->obj_pos, + NULL); + } + + node = node->next; + } while (node); + } + + memcpy(_sgp, sgp, sizeof(SceneGraphPack)); + + return 0; +}
--- a/TaskManager/Test/test_render/task/update_sgp.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <math.h> -#include "scene_graph_pack.h" -#include "sys.h" -#include "update_sgp.hpp" - -SchedDefineTask(Update_SGP); - -int -Update_SGP::run(void *rbuf, void *wbuf) -{ - SceneGraphNodePtr node; - SceneGraphPack *sgp = (SceneGraphPack*)get_input(rbuf, 0); - SceneGraphPack *_sgp = (SceneGraphPack*)get_output(wbuf, 0); - //int screen_width = get_param(0); - //int screen_height = get_param(1); - - // 本当はここでやるもんじゃないんだが。。。 - for (int i = 0; i < sgp->info.size && i < 3; i++) { - node = &sgp->node[i]; - - do { - if (node->pn != -1) { - get_matrix(node->translation, - node->angle, node->obj_pos, - sgp->node[node->pn].translation); - } else { - get_matrix(node->translation, - node->angle, node->obj_pos, - NULL); - } - - node = node->next; - } while (node); - } - - memcpy(_sgp, sgp, sizeof(SceneGraphPack)); - - return 0; -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/task/update_sgp.h Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,9 @@ +#include "SchedTask.h" + +class Update_SGP : public SchedTask { +public: + SchedConstructor(Update_SGP); + + //int update_sgp(void *rbuf, void *wbuf); + int run(void *rbuf, void *wbuf); +};
--- a/TaskManager/Test/test_render/task/update_sgp.hpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -#include "SchedTask.h" - -class Update_SGP : public SchedTask { -public: - SchedConstructor(Update_SGP); - - //int update_sgp(void *rbuf, void *wbuf); - int run(void *rbuf, void *wbuf); -};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/texture.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,93 @@ +#include <iostream> +#include <SDL.h> +#include <SDL_opengl.h> +#include <SDL_image.h> +#include <libxml/parser.h> +using namespace std; + +int power_of_two(int input) +{ + int value = 1; + + while ( value < input ) + { + value <<= 1; + } + return value; +} + +GLuint SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord) +{ + GLuint texture; + int w, h; + SDL_Surface *image; + SDL_Rect area; + Uint32 saved_flags; + Uint8 saved_alpha; + + /* Use the surface width and height expanded to powers of 2 */ + w = power_of_two(surface->w); + h = power_of_two(surface->h); + texcoord[0] = 0.0f; /* Min X */ + texcoord[1] = 0.0f; /* Min Y */ + texcoord[2] = (GLfloat)surface->w / w; /* Max X */ + texcoord[3] = (GLfloat)surface->h / h; /* Max Y */ + + image = SDL_CreateRGBSurface( + SDL_SWSURFACE, + w, h, + 32, +#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */ + 0x000000FF, + 0x0000FF00, + 0x00FF0000, + 0xFF000000 +#else + 0xFF000000, + 0x00FF0000, + 0x0000FF00, + 0x000000FF +#endif + ); + if ( image == NULL ) + { + return 0; + } + + /* Save the alpha blending attributes */ + saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK); + saved_alpha = surface->format->alpha; + if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) + { + SDL_SetAlpha(surface, 0, 0); + } + /* Copy the surface into the GL texture image */ + area.x = 0; + area.y = 0; + area.w = surface->w; + area.h = surface->h; + SDL_BlitSurface(surface, &area, image, &area); + + /* Restore the alpha blending attributes */ + if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) + { + SDL_SetAlpha(surface, saved_flags, saved_alpha); + } + + /* Create an OpenGL texture for the image */ + glGenTextures(1, &texture); + glBindTexture(GL_TEXTURE_2D, texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexImage2D(GL_TEXTURE_2D, + 0, + GL_RGBA, + w, h, + 0, + GL_RGBA, + GL_UNSIGNED_BYTE, + image->pixels); + SDL_FreeSurface(image); /* No longer needed */ + + return texture; +}
--- a/TaskManager/Test/test_render/texture.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,93 +0,0 @@ -#include <iostream> -#include <SDL.h> -#include <SDL_opengl.h> -#include <SDL_image.h> -#include <libxml/parser.h> -using namespace std; - -int power_of_two(int input) -{ - int value = 1; - - while ( value < input ) - { - value <<= 1; - } - return value; -} - -GLuint SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord) -{ - GLuint texture; - int w, h; - SDL_Surface *image; - SDL_Rect area; - Uint32 saved_flags; - Uint8 saved_alpha; - - /* Use the surface width and height expanded to powers of 2 */ - w = power_of_two(surface->w); - h = power_of_two(surface->h); - texcoord[0] = 0.0f; /* Min X */ - texcoord[1] = 0.0f; /* Min Y */ - texcoord[2] = (GLfloat)surface->w / w; /* Max X */ - texcoord[3] = (GLfloat)surface->h / h; /* Max Y */ - - image = SDL_CreateRGBSurface( - SDL_SWSURFACE, - w, h, - 32, -#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */ - 0x000000FF, - 0x0000FF00, - 0x00FF0000, - 0xFF000000 -#else - 0xFF000000, - 0x00FF0000, - 0x0000FF00, - 0x000000FF -#endif - ); - if ( image == NULL ) - { - return 0; - } - - /* Save the alpha blending attributes */ - saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK); - saved_alpha = surface->format->alpha; - if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) - { - SDL_SetAlpha(surface, 0, 0); - } - /* Copy the surface into the GL texture image */ - area.x = 0; - area.y = 0; - area.w = surface->w; - area.h = surface->h; - SDL_BlitSurface(surface, &area, image, &area); - - /* Restore the alpha blending attributes */ - if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) - { - SDL_SetAlpha(surface, saved_flags, saved_alpha); - } - - /* Create an OpenGL texture for the image */ - glGenTextures(1, &texture); - glBindTexture(GL_TEXTURE_2D, texture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexImage2D(GL_TEXTURE_2D, - 0, - GL_RGBA, - w, h, - 0, - GL_RGBA, - GL_UNSIGNED_BYTE, - image->pixels); - SDL_FreeSurface(image); /* No longer needed */ - - return texture; -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/title.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,28 @@ +#include "SceneGraphRoot.h" +#include "vacuum.h" +#include "SGList.h" + +void +title_collision(SceneGraphPtr node, int w, int h,SceneGraphPtr tree) +{ + + Pad *pad = sgroot->getController(); + + if(pad->start.isPush()) { + + SceneGraphPtr vacuum; + SceneGraphPtr back = sgroot->createSceneGraph(); + + vacuum = sgroot->createSceneGraph(BIGCUBE); + vacuum->xyz[0] = w/2; + vacuum->xyz[1] = h*0.8; + vacuum->set_move_collision(vacuum_move, vacuum_coll); + + back->addChild(vacuum); + + add_cubecollision_object(REDCUBE,vacuum,w,h); + + sgroot->setSceneData(back); + + } +}
--- a/TaskManager/Test/test_render/title.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -#include "SceneGraphRoot.h" -#include "vacuum.h" -#include "SGList.h" - -void -title_collision(SceneGraphPtr node, int w, int h,SceneGraphPtr tree) -{ - - Pad *pad = sgroot->getController(); - - if(pad->start.isPush()) { - - SceneGraphPtr vacuum; - SceneGraphPtr back = sgroot->createSceneGraph(); - - vacuum = sgroot->createSceneGraph(BIGCUBE); - vacuum->xyz[0] = w/2; - vacuum->xyz[1] = h*0.8; - vacuum->set_move_collision(vacuum_move, vacuum_coll); - - back->addChild(vacuum); - - add_cubecollision_object(REDCUBE,vacuum,w,h); - - sgroot->setSceneData(back); - - } -}
--- a/TaskManager/Test/test_render/tools/create_sglist.pl Wed Sep 23 12:04:29 2009 +0900 +++ b/TaskManager/Test/test_render/tools/create_sglist.pl Wed Sep 23 12:23:01 2009 +0900 @@ -61,7 +61,7 @@ use XML::LibXML; my $outfile_h = "SGList.h"; -my $outfile_c = "SGList.cpp"; +my $outfile_c = "SGList.cc"; my $id = 0; my @table;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/triangle.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,8 @@ +#include "triangle.h" +#include "vertex.h" + +Triangle::Triangle(Vertex *tmp_vertex1,Vertex *tmp_vertex2,Vertex *tmp_vertex3) { + vertex1 = tmp_vertex1; + vertex2 = tmp_vertex2; + vertex3 = tmp_vertex3; +}
--- a/TaskManager/Test/test_render/triangle.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -#include "triangle.h" -#include "vertex.h" - -Triangle::Triangle(Vertex *tmp_vertex1,Vertex *tmp_vertex2,Vertex *tmp_vertex3) { - vertex1 = tmp_vertex1; - vertex2 = tmp_vertex2; - vertex3 = tmp_vertex3; -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/universe.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,68 @@ +#include <stdlib.h> +#include "SceneGraphRoot.h" +#include "SGList.h" + +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 +moon_move(SceneGraphPtr node, int screen_w, int screen_h) +{ + node->angle[0] += 3.0f; +} + + +static void +earth_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) { + node->stack_xyz[1] = -node->stack_xyz[1]; + } +} + +void +universe_init(TaskManager *manager) +{ + SceneGraphPtr earth; + SceneGraphPtr moon; + + sgroot->createFromXMLfile(manager, "xml_file/universe.xml"); + + // SGList.h にある SceneGraph ID から SceneGraph を生成する + earth = sgroot->createSceneGraph(Earth); + + // SceneGraph の move と collision を設定 + earth->set_move_collision(earth_move, earth_collision); + earth->stack_xyz[0] = 3.0f; + earth->stack_xyz[1] = 3.0f; + + moon = sgroot->createSceneGraph(Moon); + moon->set_move_collision(moon_move, moon_collision); + + // SceneGraph 同士の親子関係を設定 (今回は 親 earth、子 moon) + earth->addChild(moon); + + // SceneGraphRoot に、使用する SceneGraph を設定する + // このとき、ユーザーが記述した SceneGraph の root を渡す。 + sgroot->setSceneData(earth); +}
--- a/TaskManager/Test/test_render/universe.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -#include <stdlib.h> -#include "SceneGraphRoot.h" -#include "SGList.h" - -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 -moon_move(SceneGraphPtr node, int screen_w, int screen_h) -{ - node->angle[0] += 3.0f; -} - - -static void -earth_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) { - node->stack_xyz[1] = -node->stack_xyz[1]; - } -} - -void -universe_init(TaskManager *manager) -{ - SceneGraphPtr earth; - SceneGraphPtr moon; - - sgroot->createFromXMLfile(manager, "xml_file/universe.xml"); - - // SGList.h にある SceneGraph ID から SceneGraph を生成する - earth = sgroot->createSceneGraph(Earth); - - // SceneGraph の move と collision を設定 - earth->set_move_collision(earth_move, earth_collision); - earth->stack_xyz[0] = 3.0f; - earth->stack_xyz[1] = 3.0f; - - moon = sgroot->createSceneGraph(Moon); - moon->set_move_collision(moon_move, moon_collision); - - // SceneGraph 同士の親子関係を設定 (今回は 親 earth、子 moon) - earth->addChild(moon); - - // SceneGraphRoot に、使用する SceneGraph を設定する - // このとき、ユーザーが記述した SceneGraph の root を渡す。 - sgroot->setSceneData(earth); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/untitled.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,149 @@ +#include <stdlib.h> +#include "SceneGraphRoot.h" +#include "SGList.h" +#include <math.h> + +static void +cubetest_collision(SceneGraphPtr node, int screen_w, int screen_h, + SceneGraphPtr tree) +{ +} + +static void +test_collision(SceneGraphPtr node, int screen_w, int screen_h, + SceneGraphPtr tree) +{ + // test +} + +static void +test_move(SceneGraphPtr node, int screen_w, int screen_h) +{ + + node->angle[0] += 10.0f; + /* + node->stack_xyz[0] = 2.0f; + node->stack_xyz[1] = 2.0f; + + //node->xyz[0] += node->stack_xyz[0]; + node->xyz[0] += node->stack_xyz[0]; + node->xyz[1] += node->stack_xyz[1]; + + if ((int)node->xyz[0] > screen_w + || (int)node->xyz[0] < 0) { + node->stack_xyz[0] = -node->stack_xyz[0]; + } + + if ((int)node->xyz[1] > screen_w + || (int)node->xyz[1] < 0) { + node->stack_xyz[1] = -node->stack_xyz[1]; + } + + if ((int)node->xyz[2] > 1000 + || (int)node->xyz[2] < 100) { + node->stack_xyz[1] = -node->stack_xyz[1]; + } + */ + +} + +static void +cubetest_move(SceneGraphPtr node, int screen_w, int screen_h) +{ + node->angle[1] += 10.0f; + if (node->angle[1] > 360.0f) { + node->angle[1] = 0.0f; + } + //node->xyz[0] = screen_w/2; + 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] = screen_h/2; + 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]; + } + + node->xyz[2] = 1000; + //node->xyz[2] += node->stack_xyz[2]; + //if ((int)node->xyz[2] > screen_h || (int)node->xyz[2] < 100) { + //node->stack_xyz[2] = -node->stack_xyz[2]; + //} + +} + +void +untitled_init(TaskManager *manager) +{ + SceneGraphPtr test00; + SceneGraphPtr test01; + SceneGraphPtr test02; + SceneGraphPtr test03; + SceneGraphPtr test04; + SceneGraphPtr test05; + SceneGraphPtr test06; + SceneGraphPtr test07; + SceneGraphPtr test08; + SceneGraphPtr test09; + + sgroot->createFromXMLfile(manager, "xml_file/Venus.xml"); + + // SGList.h にある SceneGraph ID から SceneGraph を生成する + /* + test00 = sgroot->createSceneGraph(cubetest000); + test01 = sgroot->createSceneGraph(cubetest009); + test02 = sgroot->createSceneGraph(cubetest008); + test03 = sgroot->createSceneGraph(cubetest007); + test04 = sgroot->createSceneGraph(cubetest006); + test05 = sgroot->createSceneGraph(cubetest005); + test06 = sgroot->createSceneGraph(cubetest004); + test07 = sgroot->createSceneGraph(cubetest003); + test08 = sgroot->createSceneGraph(cubetest002); + test09 = sgroot->createSceneGraph(cubetest001); + */ + test00 = sgroot->createSceneGraph(Venus000); + test01 = sgroot->createSceneGraph(Venus009); + test02 = sgroot->createSceneGraph(Venus008); + test03 = sgroot->createSceneGraph(Venus007); + test04 = sgroot->createSceneGraph(Venus006); + test05 = sgroot->createSceneGraph(Venus005); + test06 = sgroot->createSceneGraph(Venus004); + test07 = sgroot->createSceneGraph(Venus003); + test08 = sgroot->createSceneGraph(Venus002); + test09 = sgroot->createSceneGraph(Venus001); + + // SceneGraph の move と collision を設定 + test00->set_move_collision(cubetest_move, cubetest_collision); + test00->stack_xyz[0] = 3.0f; + test00->stack_xyz[1] = 3.0f; + test00->stack_xyz[2] = 3.0f; + + + + test01->set_move_collision(test_move, test_collision); + test02->set_move_collision(test_move, test_collision); + test03->set_move_collision(test_move, test_collision); + test04->set_move_collision(test_move, test_collision); + test05->set_move_collision(test_move, test_collision); + test06->set_move_collision(test_move, test_collision); + test07->set_move_collision(test_move, test_collision); + test08->set_move_collision(test_move, test_collision); + test09->set_move_collision(test_move, test_collision); + + // SceneGraph 同士の親子関係を設定 (今回は 親 test00、子 その他) + test00->addChild(test01); + test00->addChild(test02); + test00->addChild(test03); + test00->addChild(test04); + test00->addChild(test05); + test00->addChild(test06); + test00->addChild(test07); + test00->addChild(test08); + test00->addChild(test09); + + // SceneGraphRoot に、使用する SceneGraph を設定する + // このとき、ユーザーが記述した SceneGraph の root を渡す。 + sgroot->setSceneData(test00); + +}
--- a/TaskManager/Test/test_render/untitled.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,149 +0,0 @@ -#include <stdlib.h> -#include "SceneGraphRoot.h" -#include "SGList.h" -#include <math.h> - -static void -cubetest_collision(SceneGraphPtr node, int screen_w, int screen_h, - SceneGraphPtr tree) -{ -} - -static void -test_collision(SceneGraphPtr node, int screen_w, int screen_h, - SceneGraphPtr tree) -{ - // test -} - -static void -test_move(SceneGraphPtr node, int screen_w, int screen_h) -{ - - node->angle[0] += 10.0f; - /* - node->stack_xyz[0] = 2.0f; - node->stack_xyz[1] = 2.0f; - - //node->xyz[0] += node->stack_xyz[0]; - node->xyz[0] += node->stack_xyz[0]; - node->xyz[1] += node->stack_xyz[1]; - - if ((int)node->xyz[0] > screen_w - || (int)node->xyz[0] < 0) { - node->stack_xyz[0] = -node->stack_xyz[0]; - } - - if ((int)node->xyz[1] > screen_w - || (int)node->xyz[1] < 0) { - node->stack_xyz[1] = -node->stack_xyz[1]; - } - - if ((int)node->xyz[2] > 1000 - || (int)node->xyz[2] < 100) { - node->stack_xyz[1] = -node->stack_xyz[1]; - } - */ - -} - -static void -cubetest_move(SceneGraphPtr node, int screen_w, int screen_h) -{ - node->angle[1] += 10.0f; - if (node->angle[1] > 360.0f) { - node->angle[1] = 0.0f; - } - //node->xyz[0] = screen_w/2; - 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] = screen_h/2; - 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]; - } - - node->xyz[2] = 1000; - //node->xyz[2] += node->stack_xyz[2]; - //if ((int)node->xyz[2] > screen_h || (int)node->xyz[2] < 100) { - //node->stack_xyz[2] = -node->stack_xyz[2]; - //} - -} - -void -untitled_init(TaskManager *manager) -{ - SceneGraphPtr test00; - SceneGraphPtr test01; - SceneGraphPtr test02; - SceneGraphPtr test03; - SceneGraphPtr test04; - SceneGraphPtr test05; - SceneGraphPtr test06; - SceneGraphPtr test07; - SceneGraphPtr test08; - SceneGraphPtr test09; - - sgroot->createFromXMLfile(manager, "xml_file/Venus.xml"); - - // SGList.h にある SceneGraph ID から SceneGraph を生成する - /* - test00 = sgroot->createSceneGraph(cubetest000); - test01 = sgroot->createSceneGraph(cubetest009); - test02 = sgroot->createSceneGraph(cubetest008); - test03 = sgroot->createSceneGraph(cubetest007); - test04 = sgroot->createSceneGraph(cubetest006); - test05 = sgroot->createSceneGraph(cubetest005); - test06 = sgroot->createSceneGraph(cubetest004); - test07 = sgroot->createSceneGraph(cubetest003); - test08 = sgroot->createSceneGraph(cubetest002); - test09 = sgroot->createSceneGraph(cubetest001); - */ - test00 = sgroot->createSceneGraph(Venus000); - test01 = sgroot->createSceneGraph(Venus009); - test02 = sgroot->createSceneGraph(Venus008); - test03 = sgroot->createSceneGraph(Venus007); - test04 = sgroot->createSceneGraph(Venus006); - test05 = sgroot->createSceneGraph(Venus005); - test06 = sgroot->createSceneGraph(Venus004); - test07 = sgroot->createSceneGraph(Venus003); - test08 = sgroot->createSceneGraph(Venus002); - test09 = sgroot->createSceneGraph(Venus001); - - // SceneGraph の move と collision を設定 - test00->set_move_collision(cubetest_move, cubetest_collision); - test00->stack_xyz[0] = 3.0f; - test00->stack_xyz[1] = 3.0f; - test00->stack_xyz[2] = 3.0f; - - - - test01->set_move_collision(test_move, test_collision); - test02->set_move_collision(test_move, test_collision); - test03->set_move_collision(test_move, test_collision); - test04->set_move_collision(test_move, test_collision); - test05->set_move_collision(test_move, test_collision); - test06->set_move_collision(test_move, test_collision); - test07->set_move_collision(test_move, test_collision); - test08->set_move_collision(test_move, test_collision); - test09->set_move_collision(test_move, test_collision); - - // SceneGraph 同士の親子関係を設定 (今回は 親 test00、子 その他) - test00->addChild(test01); - test00->addChild(test02); - test00->addChild(test03); - test00->addChild(test04); - test00->addChild(test05); - test00->addChild(test06); - test00->addChild(test07); - test00->addChild(test08); - test00->addChild(test09); - - // SceneGraphRoot に、使用する SceneGraph を設定する - // このとき、ユーザーが記述した SceneGraph の root を渡す。 - sgroot->setSceneData(test00); - -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/vacuum.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,174 @@ +#include <math.h> +#include "vacuum.h" +#include "SceneGraphRoot.h" +#include "SGList.h" +#define ENCOUNT 55 +using namespace std; + +static float vacuum_speed = 10.0f; + + +/*オブジェクト毎にファイルを分けてみた + * + * + */ + + + +void +no_move_idle(SceneGraphPtr node, int screen_w, int screen_h) +{ + +} + +void +no_collision_idle(SceneGraphPtr node, int screen_w, int screen_h,SceneGraphPtr tree) +{ + +} + +void +vacuum_coll(SceneGraphPtr node, int screen_w, int screen_h, + SceneGraphPtr tree) +{ + Pad *pad = sgroot->getController(); + + if(node->frame%ENCOUNT == ENCOUNT-1) { + if(random()%2) { + add_cubecollision_object(REDCUBE,node,screen_w,screen_h); + } + else { + add_cubecollision_object(ENEMY,node,screen_w,screen_h); + } + } + + if (pad->cross.isHold()) { + SceneGraphIteratorPtr it = sgroot->getIterator(tree); + collision_red(it,node); + it = sgroot->getIterator(tree); + collision_purple(it,node,screen_w,screen_h); + } + + else if(pad->circle.isHold()) { + SceneGraphIteratorPtr it = sgroot->getIterator(tree); + lock_attack(node,it); + } + +} + +void +lock_attack(SceneGraphPtr node,SceneGraphIteratorPtr it) +{ + + SceneGraphPtr enemy; + SceneGraphPtr near_enemy = NULL; + float dx,dy,r,range = 100; + // Pad *pad = sgroot->getController(); + + for(;it->hasNext(ENEMY);) { + + it->next(ENEMY); + enemy = it->get(); + dx = enemy->xyz[0] - node->xyz[0]; + dy = enemy->xyz[1] - node->xyz[1]; + r = sqrt(dx*dx+dy*dy); + + if(range > r && enemy->stack_xyz[2] == 0) { + range = r; + near_enemy = enemy; + } + } + + + if(near_enemy != NULL) { + /*stack_xyz[2]をlockonフラグとして使うかな?*/ + SceneGraphPtr lockon; + // SceneGraphPtr near_enemy_common_move = near_enemy->parent; + near_enemy->stack_xyz[2] = 1; + lockon = sgroot->createSceneGraph(LOCK); + lockon->set_move_collision(no_move_idle,lockon_collision); + //near_enemy_common_move->addChild(lockon); + near_enemy->addChild(lockon); + } + +} + +void +lockon_collision(SceneGraphPtr node,int w,int h,SceneGraphPtr tree) { + + Pad *pad = sgroot->getController(); + SceneGraphPtr lockon_enemy = node->parent; + + /* node->angle[0] = -lockon_enemy->angle[0]; + node->angle[1] = -lockon_enemy->angle[1]; + node->angle[2] = -lockon_enemy->angle[2];*/ + + if(pad->circle.isRelease()) { + lockon_enemy->remove(); + } + +} + + +void +vacuum_move(SceneGraphPtr node , int w, int h) +{ + Pad *pad = sgroot->getController(); + + if (pad->right.isHold() && w > node->xyz[0]) { + node->xyz[0] += vacuum_speed; + node->angle[0] += 2; + } else if (pad->left.isHold() && 0 < node->xyz[0]) { + node->xyz[0] -= vacuum_speed; + node->angle[0] -= 2; + } + + if (pad->up.isHold() && 0 < node->xyz[1]) { + node->xyz[1] -= vacuum_speed; + node->angle[1] -= 2; + } else if (pad->down.isHold() && h > node->xyz[1]) { + node->xyz[1] += vacuum_speed; + node->angle[1] += 2; + } + + if (pad->start.isPush()) { + node->xyz[0] = w/2; + node->xyz[1] = h*0.8; + } +} + + + +/*cubeをランダムな場所に生成*/ +void +add_cubecollision_object(int id,SceneGraphPtr root,int w,int h) +{ + SceneGraphPtr object; + SceneGraphPtr common_move; + + common_move = sgroot->createSceneGraph(); + object = sgroot->createSceneGraph(id); + object->xyz[0] = random()%w; + object->xyz[1] = random()%h; + object->set_move_collision(no_move_idle,cube_collision); + //common_move->addChild(object); + root->addBrother(object); +} + + +void +vacuum_init2(TaskManager *manager, int w, int h) +{ + SceneGraphPtr title; + + sgroot->createFromXMLfile(manager, "xml_file/gamecube.xml"); + sgroot->createFromXMLfile(manager, "xml_file/title.xml"); + sgroot->createFromXMLfile(manager, "xml_file/gameover.xml"); + + title = sgroot->createSceneGraph(TITLE); + title->xyz[0] = w/2; + title->xyz[1] = h/2; + title->set_move_collision(no_move_idle, title_collision); + + sgroot->setSceneData(title); +}
--- a/TaskManager/Test/test_render/vacuum.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,174 +0,0 @@ -#include <math.h> -#include "vacuum.h" -#include "SceneGraphRoot.h" -#include "SGList.h" -#define ENCOUNT 55 -using namespace std; - -static float vacuum_speed = 10.0f; - - -/*オブジェクト毎にファイルを分けてみた - * - * - */ - - - -void -no_move_idle(SceneGraphPtr node, int screen_w, int screen_h) -{ - -} - -void -no_collision_idle(SceneGraphPtr node, int screen_w, int screen_h,SceneGraphPtr tree) -{ - -} - -void -vacuum_coll(SceneGraphPtr node, int screen_w, int screen_h, - SceneGraphPtr tree) -{ - Pad *pad = sgroot->getController(); - - if(node->frame%ENCOUNT == ENCOUNT-1) { - if(random()%2) { - add_cubecollision_object(REDCUBE,node,screen_w,screen_h); - } - else { - add_cubecollision_object(ENEMY,node,screen_w,screen_h); - } - } - - if (pad->cross.isHold()) { - SceneGraphIteratorPtr it = sgroot->getIterator(tree); - collision_red(it,node); - it = sgroot->getIterator(tree); - collision_purple(it,node,screen_w,screen_h); - } - - else if(pad->circle.isHold()) { - SceneGraphIteratorPtr it = sgroot->getIterator(tree); - lock_attack(node,it); - } - -} - -void -lock_attack(SceneGraphPtr node,SceneGraphIteratorPtr it) -{ - - SceneGraphPtr enemy; - SceneGraphPtr near_enemy = NULL; - float dx,dy,r,range = 100; - // Pad *pad = sgroot->getController(); - - for(;it->hasNext(ENEMY);) { - - it->next(ENEMY); - enemy = it->get(); - dx = enemy->xyz[0] - node->xyz[0]; - dy = enemy->xyz[1] - node->xyz[1]; - r = sqrt(dx*dx+dy*dy); - - if(range > r && enemy->stack_xyz[2] == 0) { - range = r; - near_enemy = enemy; - } - } - - - if(near_enemy != NULL) { - /*stack_xyz[2]をlockonフラグとして使うかな?*/ - SceneGraphPtr lockon; - // SceneGraphPtr near_enemy_common_move = near_enemy->parent; - near_enemy->stack_xyz[2] = 1; - lockon = sgroot->createSceneGraph(LOCK); - lockon->set_move_collision(no_move_idle,lockon_collision); - //near_enemy_common_move->addChild(lockon); - near_enemy->addChild(lockon); - } - -} - -void -lockon_collision(SceneGraphPtr node,int w,int h,SceneGraphPtr tree) { - - Pad *pad = sgroot->getController(); - SceneGraphPtr lockon_enemy = node->parent; - - /* node->angle[0] = -lockon_enemy->angle[0]; - node->angle[1] = -lockon_enemy->angle[1]; - node->angle[2] = -lockon_enemy->angle[2];*/ - - if(pad->circle.isRelease()) { - lockon_enemy->remove(); - } - -} - - -void -vacuum_move(SceneGraphPtr node , int w, int h) -{ - Pad *pad = sgroot->getController(); - - if (pad->right.isHold() && w > node->xyz[0]) { - node->xyz[0] += vacuum_speed; - node->angle[0] += 2; - } else if (pad->left.isHold() && 0 < node->xyz[0]) { - node->xyz[0] -= vacuum_speed; - node->angle[0] -= 2; - } - - if (pad->up.isHold() && 0 < node->xyz[1]) { - node->xyz[1] -= vacuum_speed; - node->angle[1] -= 2; - } else if (pad->down.isHold() && h > node->xyz[1]) { - node->xyz[1] += vacuum_speed; - node->angle[1] += 2; - } - - if (pad->start.isPush()) { - node->xyz[0] = w/2; - node->xyz[1] = h*0.8; - } -} - - - -/*cubeをランダムな場所に生成*/ -void -add_cubecollision_object(int id,SceneGraphPtr root,int w,int h) -{ - SceneGraphPtr object; - SceneGraphPtr common_move; - - common_move = sgroot->createSceneGraph(); - object = sgroot->createSceneGraph(id); - object->xyz[0] = random()%w; - object->xyz[1] = random()%h; - object->set_move_collision(no_move_idle,cube_collision); - //common_move->addChild(object); - root->addBrother(object); -} - - -void -vacuum_init2(TaskManager *manager, int w, int h) -{ - SceneGraphPtr title; - - sgroot->createFromXMLfile(manager, "xml_file/gamecube.xml"); - sgroot->createFromXMLfile(manager, "xml_file/title.xml"); - sgroot->createFromXMLfile(manager, "xml_file/gameover.xml"); - - title = sgroot->createSceneGraph(TITLE); - title->xyz[0] = w/2; - title->xyz[1] = h/2; - title->set_move_collision(no_move_idle, title_collision); - - sgroot->setSceneData(title); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/vertex.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,11 @@ +#include <iostream> +#include "vertex.h" +using namespace std; + +Vertex::Vertex(float tmp_x,float tmp_y, float tmp_z,float tmp_tex_x,float tmp_tex_y) { + x = tmp_x; + y = tmp_y; + z = tmp_z; + tex_x = tmp_tex_x; + tex_y = tmp_tex_y; +}
--- a/TaskManager/Test/test_render/vertex.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -#include <iostream> -#include "vertex.h" -using namespace std; - -Vertex::Vertex(float tmp_x,float tmp_y, float tmp_z,float tmp_tex_x,float tmp_tex_y) { - x = tmp_x; - y = tmp_y; - z = tmp_z; - tex_x = tmp_tex_x; - tex_y = tmp_tex_y; -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/viewer.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,458 @@ +#include <SDL.h> +#include "viewer.h" +#include "viewer_types.h" +#include "SceneGraph.h" +#include "SceneGraphRoot.h" +#include "scene_graph_pack.h" +#include "sys.h" +#include "Func.h" +#include "error.h" +#include "TaskManager.h" +#include <wchar.h> +#include "Pad.h" + +static void post2runLoop(void *viewer); +static void post2runDraw(void *viewer); +//static void post2runMove(void *viewer); +//static void post2exchange_sgroot(void *viewer); + + +/* measure for FPS (Frame Per Second) */ +int start_time; +int this_time; +int frames; + +SceneGraphRootPtr sgroot; +//SceneGraphRootPtr sgroot_2; + +/* Data Pack sent to Other CPUs (ex. SPE) */ +SceneGraphPack *sgpack; +PolygonPack *ppack; +SpanPackPtr spackList; +SpanPackPtr *spackList_ptr; + +int spackList_length; +int spackList_length_align; + +/** + * + */ + +Viewer::Viewer(int b, int w, int h, int _num) +{ + bpp = b; + width = w; + height = h; + spe_num = _num; +} + +int +Viewer::get_ticks(void) +{ + int time; + time = SDL_GetTicks(); + return time; +} + +bool +Viewer::quit_check(void) +{ + SDL_Event event; + + while(SDL_PollEvent(&event)) { + if (event.type==SDL_QUIT) { + return true; + } + } + + Uint8 *keys=SDL_GetKeyState(NULL); + + if (keys[SDLK_q] == SDL_PRESSED) { + return true; + } + + return false; +} + +void +Viewer::quit(void) +{ + SDL_Quit(); +} + +void +Viewer::swap_buffers(void) +{ + SDL_GL_SwapBuffers(); +} + +extern void node_init(TaskManager *manager); +extern void create_cube_split(TaskManager *manager, int); +extern void panel_init(TaskManager *manager, int bg); +extern void universe_init(TaskManager *manager); +extern void ieshoot_init(TaskManager *manager); +extern void ball_bound_init(TaskManager *manager, int, int); +extern void lcube_init(TaskManager *manager, int, int); +extern void direction_init(TaskManager *manager); +extern void init_position(TaskManager *manager, int, int); +extern void vacuum_init(TaskManager *manager, int w, int h); +extern void untitled_init(TaskManager *manager); +extern void chain_init(TaskManager *manager, int w, int h); +extern void boss1_init(TaskManager *manager, int w, int h); +extern void init_gaplant(TaskManager *manager, int w, int h); +extern void vacuum_init2(TaskManager *manager, int w, int h); + +void +Viewer::run_init(TaskManager *manager, const char *xml, int sg_number) +{ + this->manager = manager; + + start_time = get_ticks(); + this_time = 0; + frames = 0; + + sgroot = new SceneGraphRoot(this->width, this->height); + //sgroot_2 = new SceneGraphRoot(this->width, this->height); + //sgroot->createFromXMLFile(xml); + + switch (sg_number) { + case 0: + case 1: + create_cube_split(manager, sg_number); + break; + case 2: + case 3: + case 4: + panel_init(manager, sg_number); + break; + case 5: + universe_init(manager); + break; + case 6: + ieshoot_init(manager); + break; + case 7: + ball_bound_init(manager, this->width, this->height); + break; + case 8: + lcube_init(manager, this->width, this->height); + break; + case 9: + direction_init(manager); + break; + case 10: + init_position(manager, this->width, this->height); + break; + case 11: + // vacuum_init(manager, this->width, this->height); + break; + case 12: + untitled_init(manager); + break; + case 13: + boss1_init(manager, this->width, this->height); + break; + case 14: + init_gaplant(manager, this->width, this->height); + break; + case 15: + vacuum_init2(manager, this->width, this->height); + break; + case 16: + chain_init(manager, this->width, this-> height); + speLoop(); + return; + break; + default: + node_init(manager); + break; + } + + mainLoop(); +} + + +HTaskPtr +Viewer::initLoop() +{ + HTaskPtr task_next; + HTaskPtr task_tex; + + sgpack = (SceneGraphPack*)manager->allocate(sizeof(SceneGraphPack)); + sgpack->init(); + ppack = (PolygonPack*)manager->allocate(sizeof(PolygonPack)); + + spackList_length = (this->height + split_screen_h - 1) / split_screen_h; + spackList = (SpanPack*)manager->allocate(sizeof(SpanPack)*spackList_length); + + /** + * SPU に送る address list は 16 バイト倍数でないといけない。 + * spackList_length*sizeof(SpanPack*) が 16 バイト倍数になるような + * length_align を求めている。はみ出した部分は使われない + * (ex) spackList_length が 13 の場合 + * spackList_length_align = 16; + * 実際に送るデータは64バイトになるのでOK + * 14,15,16 の部分は何も入らない。 + */ + spackList_length_align = (spackList_length + 3)&(~3); + + /* 各 SPU が持つ、SpanPack の address list */ + spackList_ptr = + (SpanPack**)manager->allocate(sizeof(SpanPack*)*spackList_length_align); + + for (int i = 0; i < spackList_length; i++) { + spackList_ptr[i] = &spackList[i]; + } + + for (int i = 1; i <= spackList_length; i++) { + spackList[i-1].init(i*split_screen_h); + } + + task_next = manager->create_task(TASK_DUMMY); + + for (int i = 0; i < spe_num; i++) { + task_tex = manager->create_task(TASK_INIT_TEXTURE); + /* + * ここはもう少しわかりやすい使い方がいいかもしれぬ。こんなもん? + */ + task_tex->set_cpu((CPU_TYPE)((int)SPE_0 + i)); + task_next->wait_for(task_tex); + task_tex->spawn(); + } + + return task_next; +} + +void +Viewer::speLoop() +{ + HTaskPtr task_next = initLoop(); + + // post2runLoop は旧バージョン用なので post2runspeLoop の様なものを別につくるべき + task_next->set_post(post2runLoop, (void *)this); // set_post(function(this->run_loop()), NULL) + task_next->spawn(); + // TASK_INIT_TEXTURE が全て終わったら DUMMY_TASK が Viewer::run_loop() を呼ぶ +} + +void +Viewer::mainLoop() +{ + HTaskPtr task_next = initLoop(); + + task_next->set_post(&post2runLoop, (void *)this); // set_post(function(this->run_loop()), NULL) + task_next->spawn(); + // TASK_INIT_TEXTURE が全て終わったら DUMMY_TASK が Viewer::run_loop() を呼ぶ +} + + +/* +static void +post2exchange_sgroot(void *viewer_) +{ + Viewer *viewer = (Viewer*)viewer_; + HTaskPtr task_next = viewer->manager->create_task(TASK_DUMMY); + viewer->exchange_sgroot(task_next); +} + +void +Viewer::exchange_sgroot(TaskManager *manager) +{ + + SceneGraphRootPtr tmp = sgroot; + sgroot = sgroot_2; + sgroot_2 = tmp; + +} +*/ + +static void +post2runMove(void *viewer_) +{ + Viewer *viewer = (Viewer*)viewer_; + HTaskPtr task_next = viewer->manager->create_task(TASK_DUMMY); + viewer->run_move(task_next); +} + +void +Viewer::run_move(HTaskPtr task_next) +{ + sgroot->updateControllerState(); + sgroot->allExecute(width, height); +} + +void +Viewer::run_collision() +{ +} + +void +Viewer::rendering(HTaskPtr task_next) +{ + HTaskPtr task_create_pp = manager->create_task(TASK_CREATE_PP2); + + // SceneGraph(木構造) -> PolygonPack + + task_create_pp->add_param((uint32)sgroot->getDrawSceneGraph()); + task_create_pp->add_param((uint32)ppack); + + task_next->wait_for(task_create_pp); + + int range_base = spe_num; + // 切り上げのつもり + int range = (spackList_length + range_base - 1) / range_base; + + for (int i = 0; i < range_base; i++) { + int index_start = range*i; + int index_end = (index_start + range >= spackList_length) + ? spackList_length : index_start + range; + + HTaskPtr task_create_sp = manager->create_task(TASK_CREATE_SPAN); + task_create_sp->add_inData(ppack, sizeof(PolygonPack)); + task_create_sp->add_inData(spackList_ptr, + sizeof(SpanPack*)*spackList_length_align); + task_create_sp->add_inData(&spackList[index_start], sizeof(SpanPack)); + + task_create_sp->add_param(index_start); + + /** + * ex. screen_height が 480, spenum が 6 の場合、各SPEのy担当範囲 + * [ 1.. 80] [ 81..160] [161..240] + * [241..320] [321..400] [401..480] + * + * ex. screen_height が 1080, spenum が 5 の場合、 + * [ 1..216] [217..432] [433..648] + * [649..864] [865..1080] + */ + task_create_sp->add_param(index_start*split_screen_h + 1); + task_create_sp->add_param(index_end*split_screen_h); + + task_next->wait_for(task_create_sp); + task_create_sp->wait_for(task_create_pp); + + task_create_sp->set_cpu(SPE_ANY); + task_create_sp->spawn(); + } + + task_create_pp->spawn(); + + // Barrier 同期 + // run_draw() を呼ぶ post2runDraw + task_next->set_post(post2runDraw, (void*)this); // set_post(function(this->run_draw()), NULL) + task_next->spawn(); + + // TASK_CREATE_SPAN が全て終わったら DUMMY_TASK が Viewer::run_draw() を呼ぶ +} + +static void +post2runLoop(void *viewer_) +{ + Viewer *viewer = (Viewer*)viewer_; + HTaskPtr task_next = viewer->manager->create_task(TASK_DUMMY); + viewer->run_loop(task_next); + +} + +void +Viewer::run_loop(HTaskPtr task_next) +{ + bool quit_flg; + quit_flg = quit_check(); + if (quit_flg == true) { + this_time = get_ticks(); + run_finish(); + return; + } + + clean_pixels(); + + for (int i = 1; i <= spackList_length; i++) { + spackList[i-1].reinit(i*split_screen_h); + } + + //run_move(task_next); + sgroot->updateControllerState(); + sgroot->allExecute(width, height); + //sgroot->checkRemove(); + + // ここから下は Rendering という関数にする + rendering(task_next); +} + +static void +post2runDraw(void *viewer_) +{ + Viewer *viewer = (Viewer*)viewer_; + HTaskPtr task_next = viewer->manager->create_task(TASK_DUMMY); + viewer->run_draw(task_next); + +} + +void +Viewer::run_draw(HTaskPtr task_next) // 引数に post2runLoop を入れるようにする +{ + HTaskPtr task_draw; + + //task_next = manager->create_task(TASK_DUMMY); + //task_next->set_post(post2runLoop, (void*)this); + + ppack->clear(); + for (int i = 0; i < spackList_length; i++) { + SpanPack *spack = &spackList[i]; + int startx = 1; + int endx = split_screen_w; + + int starty = spack->info.y_top - split_screen_h + 1; + //int endy = spack->info.y_top; + int rangey = (starty + split_screen_h - 1 > this->height) + ? this->height - starty + 1 : split_screen_h; + + while (startx < this->width) { + if (spack->info.size > 0) { + // Draw SpanPack + task_draw = manager->create_task(TASK_DRAW_SPAN); + task_draw->add_inData(spack, sizeof(SpanPack)); + + task_draw->add_param( + (uint32)&pixels[(startx-1) + this->width*(starty-1)]); + task_draw->add_param(this->width); + } else { + memset(&pixels[(startx-1)+this->width*(starty-1)], + 0, (this->width)*sizeof(int)*rangey); + break; + } + + task_draw->add_param(startx); + task_draw->add_param(endx); + task_draw->add_param(rangey); + task_draw->set_cpu(SPE_ANY); + task_next->wait_for(task_draw); + task_draw->spawn(); + + startx += split_screen_w; + endx += split_screen_w; + + if (endx > this->width) { + endx = this->width; + } + } + } + + + task_next->set_post(post2runLoop, (void*)this); // set_post(function(this->run_loop()), NULL) + task_next->spawn(); + // TASK_DRAW_SPAN が全て終わったら DUMMY_TASK が Viewer::run_loop() を呼ぶ + + frames++; +} + +void +Viewer::run_finish(void) +{ + if (this_time != start_time) { + printf("%f FPS\n", (((float)frames)/(this_time-start_time))*1000.0); + } + + delete sgroot; + //delete sgroot_2; + quit(); +}
--- a/TaskManager/Test/test_render/viewer.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,458 +0,0 @@ -#include <SDL.h> -#include "viewer.h" -#include "viewer_types.h" -#include "SceneGraph.h" -#include "SceneGraphRoot.h" -#include "scene_graph_pack.h" -#include "sys.h" -#include "Func.h" -#include "error.h" -#include "TaskManager.h" -#include <wchar.h> -#include "Pad.h" - -static void post2runLoop(void *viewer); -static void post2runDraw(void *viewer); -//static void post2runMove(void *viewer); -//static void post2exchange_sgroot(void *viewer); - - -/* measure for FPS (Frame Per Second) */ -int start_time; -int this_time; -int frames; - -SceneGraphRootPtr sgroot; -//SceneGraphRootPtr sgroot_2; - -/* Data Pack sent to Other CPUs (ex. SPE) */ -SceneGraphPack *sgpack; -PolygonPack *ppack; -SpanPackPtr spackList; -SpanPackPtr *spackList_ptr; - -int spackList_length; -int spackList_length_align; - -/** - * - */ - -Viewer::Viewer(int b, int w, int h, int _num) -{ - bpp = b; - width = w; - height = h; - spe_num = _num; -} - -int -Viewer::get_ticks(void) -{ - int time; - time = SDL_GetTicks(); - return time; -} - -bool -Viewer::quit_check(void) -{ - SDL_Event event; - - while(SDL_PollEvent(&event)) { - if (event.type==SDL_QUIT) { - return true; - } - } - - Uint8 *keys=SDL_GetKeyState(NULL); - - if (keys[SDLK_q] == SDL_PRESSED) { - return true; - } - - return false; -} - -void -Viewer::quit(void) -{ - SDL_Quit(); -} - -void -Viewer::swap_buffers(void) -{ - SDL_GL_SwapBuffers(); -} - -extern void node_init(TaskManager *manager); -extern void create_cube_split(TaskManager *manager, int); -extern void panel_init(TaskManager *manager, int bg); -extern void universe_init(TaskManager *manager); -extern void ieshoot_init(TaskManager *manager); -extern void ball_bound_init(TaskManager *manager, int, int); -extern void lcube_init(TaskManager *manager, int, int); -extern void direction_init(TaskManager *manager); -extern void init_position(TaskManager *manager, int, int); -extern void vacuum_init(TaskManager *manager, int w, int h); -extern void untitled_init(TaskManager *manager); -extern void chain_init(TaskManager *manager, int w, int h); -extern void boss1_init(TaskManager *manager, int w, int h); -extern void init_gaplant(TaskManager *manager, int w, int h); -extern void vacuum_init2(TaskManager *manager, int w, int h); - -void -Viewer::run_init(TaskManager *manager, const char *xml, int sg_number) -{ - this->manager = manager; - - start_time = get_ticks(); - this_time = 0; - frames = 0; - - sgroot = new SceneGraphRoot(this->width, this->height); - //sgroot_2 = new SceneGraphRoot(this->width, this->height); - //sgroot->createFromXMLFile(xml); - - switch (sg_number) { - case 0: - case 1: - create_cube_split(manager, sg_number); - break; - case 2: - case 3: - case 4: - panel_init(manager, sg_number); - break; - case 5: - universe_init(manager); - break; - case 6: - ieshoot_init(manager); - break; - case 7: - ball_bound_init(manager, this->width, this->height); - break; - case 8: - lcube_init(manager, this->width, this->height); - break; - case 9: - direction_init(manager); - break; - case 10: - init_position(manager, this->width, this->height); - break; - case 11: - // vacuum_init(manager, this->width, this->height); - break; - case 12: - untitled_init(manager); - break; - case 13: - boss1_init(manager, this->width, this->height); - break; - case 14: - init_gaplant(manager, this->width, this->height); - break; - case 15: - vacuum_init2(manager, this->width, this->height); - break; - case 16: - chain_init(manager, this->width, this-> height); - speLoop(); - return; - break; - default: - node_init(manager); - break; - } - - mainLoop(); -} - - -HTaskPtr -Viewer::initLoop() -{ - HTaskPtr task_next; - HTaskPtr task_tex; - - sgpack = (SceneGraphPack*)manager->allocate(sizeof(SceneGraphPack)); - sgpack->init(); - ppack = (PolygonPack*)manager->allocate(sizeof(PolygonPack)); - - spackList_length = (this->height + split_screen_h - 1) / split_screen_h; - spackList = (SpanPack*)manager->allocate(sizeof(SpanPack)*spackList_length); - - /** - * SPU に送る address list は 16 バイト倍数でないといけない。 - * spackList_length*sizeof(SpanPack*) が 16 バイト倍数になるような - * length_align を求めている。はみ出した部分は使われない - * (ex) spackList_length が 13 の場合 - * spackList_length_align = 16; - * 実際に送るデータは64バイトになるのでOK - * 14,15,16 の部分は何も入らない。 - */ - spackList_length_align = (spackList_length + 3)&(~3); - - /* 各 SPU が持つ、SpanPack の address list */ - spackList_ptr = - (SpanPack**)manager->allocate(sizeof(SpanPack*)*spackList_length_align); - - for (int i = 0; i < spackList_length; i++) { - spackList_ptr[i] = &spackList[i]; - } - - for (int i = 1; i <= spackList_length; i++) { - spackList[i-1].init(i*split_screen_h); - } - - task_next = manager->create_task(TASK_DUMMY); - - for (int i = 0; i < spe_num; i++) { - task_tex = manager->create_task(TASK_INIT_TEXTURE); - /* - * ここはもう少しわかりやすい使い方がいいかもしれぬ。こんなもん? - */ - task_tex->set_cpu((CPU_TYPE)((int)SPE_0 + i)); - task_next->wait_for(task_tex); - task_tex->spawn(); - } - - return task_next; -} - -void -Viewer::speLoop() -{ - HTaskPtr task_next = initLoop(); - - // post2runLoop は旧バージョン用なので post2runspeLoop の様なものを別につくるべき - task_next->set_post(post2runLoop, (void *)this); // set_post(function(this->run_loop()), NULL) - task_next->spawn(); - // TASK_INIT_TEXTURE が全て終わったら DUMMY_TASK が Viewer::run_loop() を呼ぶ -} - -void -Viewer::mainLoop() -{ - HTaskPtr task_next = initLoop(); - - task_next->set_post(&post2runLoop, (void *)this); // set_post(function(this->run_loop()), NULL) - task_next->spawn(); - // TASK_INIT_TEXTURE が全て終わったら DUMMY_TASK が Viewer::run_loop() を呼ぶ -} - - -/* -static void -post2exchange_sgroot(void *viewer_) -{ - Viewer *viewer = (Viewer*)viewer_; - HTaskPtr task_next = viewer->manager->create_task(TASK_DUMMY); - viewer->exchange_sgroot(task_next); -} - -void -Viewer::exchange_sgroot(TaskManager *manager) -{ - - SceneGraphRootPtr tmp = sgroot; - sgroot = sgroot_2; - sgroot_2 = tmp; - -} -*/ - -static void -post2runMove(void *viewer_) -{ - Viewer *viewer = (Viewer*)viewer_; - HTaskPtr task_next = viewer->manager->create_task(TASK_DUMMY); - viewer->run_move(task_next); -} - -void -Viewer::run_move(HTaskPtr task_next) -{ - sgroot->updateControllerState(); - sgroot->allExecute(width, height); -} - -void -Viewer::run_collision() -{ -} - -void -Viewer::rendering(HTaskPtr task_next) -{ - HTaskPtr task_create_pp = manager->create_task(TASK_CREATE_PP2); - - // SceneGraph(木構造) -> PolygonPack - - task_create_pp->add_param((uint32)sgroot->getDrawSceneGraph()); - task_create_pp->add_param((uint32)ppack); - - task_next->wait_for(task_create_pp); - - int range_base = spe_num; - // 切り上げのつもり - int range = (spackList_length + range_base - 1) / range_base; - - for (int i = 0; i < range_base; i++) { - int index_start = range*i; - int index_end = (index_start + range >= spackList_length) - ? spackList_length : index_start + range; - - HTaskPtr task_create_sp = manager->create_task(TASK_CREATE_SPAN); - task_create_sp->add_inData(ppack, sizeof(PolygonPack)); - task_create_sp->add_inData(spackList_ptr, - sizeof(SpanPack*)*spackList_length_align); - task_create_sp->add_inData(&spackList[index_start], sizeof(SpanPack)); - - task_create_sp->add_param(index_start); - - /** - * ex. screen_height が 480, spenum が 6 の場合、各SPEのy担当範囲 - * [ 1.. 80] [ 81..160] [161..240] - * [241..320] [321..400] [401..480] - * - * ex. screen_height が 1080, spenum が 5 の場合、 - * [ 1..216] [217..432] [433..648] - * [649..864] [865..1080] - */ - task_create_sp->add_param(index_start*split_screen_h + 1); - task_create_sp->add_param(index_end*split_screen_h); - - task_next->wait_for(task_create_sp); - task_create_sp->wait_for(task_create_pp); - - task_create_sp->set_cpu(SPE_ANY); - task_create_sp->spawn(); - } - - task_create_pp->spawn(); - - // Barrier 同期 - // run_draw() を呼ぶ post2runDraw - task_next->set_post(post2runDraw, (void*)this); // set_post(function(this->run_draw()), NULL) - task_next->spawn(); - - // TASK_CREATE_SPAN が全て終わったら DUMMY_TASK が Viewer::run_draw() を呼ぶ -} - -static void -post2runLoop(void *viewer_) -{ - Viewer *viewer = (Viewer*)viewer_; - HTaskPtr task_next = viewer->manager->create_task(TASK_DUMMY); - viewer->run_loop(task_next); - -} - -void -Viewer::run_loop(HTaskPtr task_next) -{ - bool quit_flg; - quit_flg = quit_check(); - if (quit_flg == true) { - this_time = get_ticks(); - run_finish(); - return; - } - - clean_pixels(); - - for (int i = 1; i <= spackList_length; i++) { - spackList[i-1].reinit(i*split_screen_h); - } - - //run_move(task_next); - sgroot->updateControllerState(); - sgroot->allExecute(width, height); - //sgroot->checkRemove(); - - // ここから下は Rendering という関数にする - rendering(task_next); -} - -static void -post2runDraw(void *viewer_) -{ - Viewer *viewer = (Viewer*)viewer_; - HTaskPtr task_next = viewer->manager->create_task(TASK_DUMMY); - viewer->run_draw(task_next); - -} - -void -Viewer::run_draw(HTaskPtr task_next) // 引数に post2runLoop を入れるようにする -{ - HTaskPtr task_draw; - - //task_next = manager->create_task(TASK_DUMMY); - //task_next->set_post(post2runLoop, (void*)this); - - ppack->clear(); - for (int i = 0; i < spackList_length; i++) { - SpanPack *spack = &spackList[i]; - int startx = 1; - int endx = split_screen_w; - - int starty = spack->info.y_top - split_screen_h + 1; - //int endy = spack->info.y_top; - int rangey = (starty + split_screen_h - 1 > this->height) - ? this->height - starty + 1 : split_screen_h; - - while (startx < this->width) { - if (spack->info.size > 0) { - // Draw SpanPack - task_draw = manager->create_task(TASK_DRAW_SPAN); - task_draw->add_inData(spack, sizeof(SpanPack)); - - task_draw->add_param( - (uint32)&pixels[(startx-1) + this->width*(starty-1)]); - task_draw->add_param(this->width); - } else { - memset(&pixels[(startx-1)+this->width*(starty-1)], - 0, (this->width)*sizeof(int)*rangey); - break; - } - - task_draw->add_param(startx); - task_draw->add_param(endx); - task_draw->add_param(rangey); - task_draw->set_cpu(SPE_ANY); - task_next->wait_for(task_draw); - task_draw->spawn(); - - startx += split_screen_w; - endx += split_screen_w; - - if (endx > this->width) { - endx = this->width; - } - } - } - - - task_next->set_post(post2runLoop, (void*)this); // set_post(function(this->run_loop()), NULL) - task_next->spawn(); - // TASK_DRAW_SPAN が全て終わったら DUMMY_TASK が Viewer::run_loop() を呼ぶ - - frames++; -} - -void -Viewer::run_finish(void) -{ - if (this_time != start_time) { - printf("%f FPS\n", (((float)frames)/(this_time-start_time))*1000.0); - } - - delete sgroot; - //delete sgroot_2; - quit(); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/viewerFB.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,29 @@ +#include "viewerFB.h" +#include "Func.h" +#include "fb.h" + +//extern void post2runLoop(void *); + +void +ViewerFB::video_init(TaskManager *manager) +{ + Uint32 sdl_flag = default_sdl_flag | SDL_INIT_VIDEO; + + if (SDL_Init(sdl_flag) < 0) { + fprintf(stderr,"Couldn't initialize SDL: %s\n",SDL_GetError()); + exit(1); + } + + pixels = (Uint32*)get_fbdev_addr(); + + if (pixels == 0) { + pixels = (new Uint32[width*height*32/8]); + } +} + +void +ViewerFB::clean_pixels() +{ + //bzero(pixels, sizeof(int)*width*height); + //memset(pixels, 0xFF, sizeof(int)*width*height); +}
--- a/TaskManager/Test/test_render/viewerFB.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -#include "viewerFB.h" -#include "Func.h" -#include "fb.h" - -//extern void post2runLoop(void *); - -void -ViewerFB::video_init(TaskManager *manager) -{ - Uint32 sdl_flag = default_sdl_flag | SDL_INIT_VIDEO; - - if (SDL_Init(sdl_flag) < 0) { - fprintf(stderr,"Couldn't initialize SDL: %s\n",SDL_GetError()); - exit(1); - } - - pixels = (Uint32*)get_fbdev_addr(); - - if (pixels == 0) { - pixels = (new Uint32[width*height*32/8]); - } -} - -void -ViewerFB::clean_pixels() -{ - //bzero(pixels, sizeof(int)*width*height); - //memset(pixels, 0xFF, sizeof(int)*width*height); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/viewerSDL.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,60 @@ +#include "viewerSDL.h" +#include "Func.h" +#include "TaskManager.h" + +extern void post2runLoop(void *); + +extern + +void +ViewerSDL::video_init(TaskManager *manager) +{ + Uint32 sdl_flag = default_sdl_flag | SDL_INIT_VIDEO; + Uint32 *p; + + if (SDL_Init(sdl_flag) < 0) { + fprintf(stderr,"Couldn't initialize SDL: %s\n", SDL_GetError()); + exit(1); + } + + screen = SDL_SetVideoMode(width, height, bpp, SDL_SWSURFACE); + if (screen == NULL) { + fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError()); + SDL_Quit(); + exit(1); + } + + p = (Uint32*)manager->allocate(screen->pitch*height); + bitmap = SDL_CreateRGBSurfaceFrom((void *)p, + screen->w, screen->h, + screen->format->BitsPerPixel, + screen->pitch, + redMask, greenMask, blueMask, alphaMask); + + pixels = p; +} + +void +ViewerSDL::clean_pixels() +{ + //bzero(pixels, sizeof(int)*width*height); + SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,0,0)); +} + +void +ViewerSDL::run_loop(HTaskPtr task_next) +{ + SDL_BlitSurface(bitmap, NULL, screen, NULL); + SDL_UpdateRect(screen, 0, 0, 0, 0); + + Viewer::run_loop(task_next); +} + +void +ViewerSDL::run_finish() +{ + free(bitmap->pixels); + SDL_FreeSurface(bitmap); + + Viewer::run_finish(); +}
--- a/TaskManager/Test/test_render/viewerSDL.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -#include "viewerSDL.h" -#include "Func.h" -#include "TaskManager.h" - -extern void post2runLoop(void *); - -extern - -void -ViewerSDL::video_init(TaskManager *manager) -{ - Uint32 sdl_flag = default_sdl_flag | SDL_INIT_VIDEO; - Uint32 *p; - - if (SDL_Init(sdl_flag) < 0) { - fprintf(stderr,"Couldn't initialize SDL: %s\n", SDL_GetError()); - exit(1); - } - - screen = SDL_SetVideoMode(width, height, bpp, SDL_SWSURFACE); - if (screen == NULL) { - fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError()); - SDL_Quit(); - exit(1); - } - - p = (Uint32*)manager->allocate(screen->pitch*height); - bitmap = SDL_CreateRGBSurfaceFrom((void *)p, - screen->w, screen->h, - screen->format->BitsPerPixel, - screen->pitch, - redMask, greenMask, blueMask, alphaMask); - - pixels = p; -} - -void -ViewerSDL::clean_pixels() -{ - //bzero(pixels, sizeof(int)*width*height); - SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,0,0)); -} - -void -ViewerSDL::run_loop(HTaskPtr task_next) -{ - SDL_BlitSurface(bitmap, NULL, screen, NULL); - SDL_UpdateRect(screen, 0, 0, 0, 0); - - Viewer::run_loop(task_next); -} - -void -ViewerSDL::run_finish() -{ - free(bitmap->pixels); - SDL_FreeSurface(bitmap); - - Viewer::run_finish(); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/viewer_types.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,38 @@ +#include "viewer_types.h" + +static int +getLocalPosition(int d, int offset) +{ + /** + * offset が 2 の冪乗の時だけ使える。 + * 現在は offset は 2 の冪乗のみなので + * これで問題ないけどどうなの? + */ + return d & (offset-1); + + // offset が 2 の冪乗以外はこれにしないとだめ + //return d % offset; +} + +/** + * ワールド座標における x の値を + * split_screen_w で分割した領域(1 〜 split_screen_w)での座標に変換する + * (ex. split_screen_w が 256 の場合、 + * x = 1 -> 1 + * x = 256 -> 256 + * x = 257 -> 1 + */ +int +getLocalX(int x) +{ + return getLocalPosition(x, split_screen_w); +} + +/** + * getLocalX に同じ + */ +int +getLocalY(int y) +{ + return getLocalPosition(y, split_screen_h); +}
--- a/TaskManager/Test/test_render/viewer_types.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -#include "viewer_types.h" - -static int -getLocalPosition(int d, int offset) -{ - /** - * offset が 2 の冪乗の時だけ使える。 - * 現在は offset は 2 の冪乗のみなので - * これで問題ないけどどうなの? - */ - return d & (offset-1); - - // offset が 2 の冪乗以外はこれにしないとだめ - //return d % offset; -} - -/** - * ワールド座標における x の値を - * split_screen_w で分割した領域(1 〜 split_screen_w)での座標に変換する - * (ex. split_screen_w が 256 の場合、 - * x = 1 -> 1 - * x = 256 -> 256 - * x = 257 -> 1 - */ -int -getLocalX(int x) -{ - return getLocalPosition(x, split_screen_w); -} - -/** - * getLocalX に同じ - */ -int -getLocalY(int y) -{ - return getLocalPosition(y, split_screen_h); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/xml.cc Wed Sep 23 12:23:01 2009 +0900 @@ -0,0 +1,99 @@ +#include <iostream> +#include <SDL.h> +#include <SDL_opengl.h> +#include <libxml/parser.h> +#include "polygon.h" +using namespace std; + +char *skip_to_number(char *cont) +{ + if (cont == NULL) return(NULL); + for (;(*cont < '+' || *cont > '9') && (*cont != '\0');cont++) {} + if (*cont == '\0') + { + fprintf(stderr,"Content data is short\n"); + return(NULL); + } + return(cont); +} + + +char *pickup_float(char *cont, float *index) +{ + int sign=1,exp=1; + float shift=10,val_dec=0,val_int=0; + + cont = skip_to_number(cont); + if (cont == NULL) return(NULL); + + for (;*cont != ' ' && *cont != '\n' && *cont != '\t';cont++) + { + if (*cont == '-') + { + sign = -1; + } + else if (*cont == '.') + { + shift = 0.1; + } + else if (*cont >= '0' && *cont <= '9') + { + if (shift == 10) + { + val_int *= shift; + val_int += *cont - 48; + } + else + { + val_dec += (*cont - 48) * shift; + shift *= 0.1; + } + } + else if (*cont == 'e' || *cont == 'E') + { + //cont = pickup_exponent(&exp,cont+1); + if (cont == NULL) return(NULL); + } + else if (*cont == '+' || *cont == '/' || *cont == ' ') + { + // ignore + } + else + { + fprintf(stderr,"Pick up float failed : %c(%d)\n",*cont,*cont); + return(NULL); + } + } + + *index = sign * (val_int + val_dec) * exp; + cont++; + return(cont); +} + + +/* +int main(int artc, char *argv[]) +{ + xmlDocPtr doc; + xmlNodePtr cur; + char *cont; + + doc = xmlParseFile(argv[1]); + + cur = xmlDocGetRootElement(doc); + + xmlStrcmp(cur->name,(xmlChar*)"OBJECT-3D"); + + for (cur=cur->children; cur; cur=cur->next) + { + if (!xmlStrcmp(cur->name,(xmlChar*)"surface")) + { + get_data(cur->children); + } + } + + xmlFreeDoc(doc); + return 0; + +} +*/
--- a/TaskManager/Test/test_render/xml.cpp Wed Sep 23 12:04:29 2009 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,99 +0,0 @@ -#include <iostream> -#include <SDL.h> -#include <SDL_opengl.h> -#include <libxml/parser.h> -#include "polygon.h" -using namespace std; - -char *skip_to_number(char *cont) -{ - if (cont == NULL) return(NULL); - for (;(*cont < '+' || *cont > '9') && (*cont != '\0');cont++) {} - if (*cont == '\0') - { - fprintf(stderr,"Content data is short\n"); - return(NULL); - } - return(cont); -} - - -char *pickup_float(char *cont, float *index) -{ - int sign=1,exp=1; - float shift=10,val_dec=0,val_int=0; - - cont = skip_to_number(cont); - if (cont == NULL) return(NULL); - - for (;*cont != ' ' && *cont != '\n' && *cont != '\t';cont++) - { - if (*cont == '-') - { - sign = -1; - } - else if (*cont == '.') - { - shift = 0.1; - } - else if (*cont >= '0' && *cont <= '9') - { - if (shift == 10) - { - val_int *= shift; - val_int += *cont - 48; - } - else - { - val_dec += (*cont - 48) * shift; - shift *= 0.1; - } - } - else if (*cont == 'e' || *cont == 'E') - { - //cont = pickup_exponent(&exp,cont+1); - if (cont == NULL) return(NULL); - } - else if (*cont == '+' || *cont == '/' || *cont == ' ') - { - // ignore - } - else - { - fprintf(stderr,"Pick up float failed : %c(%d)\n",*cont,*cont); - return(NULL); - } - } - - *index = sign * (val_int + val_dec) * exp; - cont++; - return(cont); -} - - -/* -int main(int artc, char *argv[]) -{ - xmlDocPtr doc; - xmlNodePtr cur; - char *cont; - - doc = xmlParseFile(argv[1]); - - cur = xmlDocGetRootElement(doc); - - xmlStrcmp(cur->name,(xmlChar*)"OBJECT-3D"); - - for (cur=cur->children; cur; cur=cur->next) - { - if (!xmlStrcmp(cur->name,(xmlChar*)"surface")) - { - get_data(cur->children); - } - } - - xmlFreeDoc(doc); - return 0; - -} -*/