# HG changeset patch # User tkaito@henri.cr.ie.u-ryukyu.ac.jp # Date 1253693410 -32400 # Node ID 68e199a4ea7b49dd0afb5bed248b8260762cc1c1 # Parent f49f3d469b9f1233da1e8a0095e6f5ac12eb2d47 chain_old.cc add (Application/) diff -r f49f3d469b9f -r 68e199a4ea7b TaskManager/Test/test_render/Application/chain_old.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Test/test_render/Application/chain_old.cc Wed Sep 23 17:10:10 2009 +0900 @@ -0,0 +1,159 @@ +#include +#include +#include "SceneGraphRoot.h" +#include "SGList.h" +#include "SceneGraph.h" +#include "TaskManager.h" +#include "Func.h" + + +#define FALSE 0 +#define TRUE !FALSE +#define CHAIN_LEN 50 + +static double m = 100.0; +static double k = 7000.0; +static double g = 9.8; +static double dt = 0.003; +static double chain_width = 10; +static double safe = 0.995; + +typedef struct { + double x, y, next_x, next_y; + double vx, vy, next_vx, next_vy; + int can_move; +} CHAIN_VARS; + +CHAIN_VARS cv[CHAIN_LEN]; + +void +init_chainold_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_old_vector(CHAIN_VARS *cv, SceneGraphPtr sg) { + sg->xyz[0] = (float)cv->next_x; + sg->xyz[1] = (float)cv->next_y; + sg->xyz[2] = 0.0f; +} + + +static void +chain_old_move_ope(SceneGraphPtr node, int screen_w, int screen_h) +{ + Pad *pad = sgroot->getController(); + + if (pad->circle.isHold()) { + cv[CHAIN_LEN-1].can_move = FALSE; + if (pad->left.isHold()) { + cv[CHAIN_LEN-1].x += -5.0; + } else if (pad->right.isHold()) { + cv[CHAIN_LEN-1].x += 5.0; + } + + if (pad->up.isHold()) { + cv[CHAIN_LEN-1].y += -5.0; + } else if (pad->down.isHold()) { + cv[CHAIN_LEN-1].y += 5.0; + } + } else { + cv[CHAIN_LEN-1].can_move = TRUE; + } +} + +void +chain_old_move(SceneGraphPtr sg, int w, int h) +{ + int id = sg->id; + if(id == 0) { + for(int cnt = 0; cnt < 600; cnt++) { + for(int i = 0; i < CHAIN_LEN; i++) { + if(cv[i].can_move) { + double dx = cv[i-1].x - cv[i].x; + double dy = cv[i-1].y - cv[i].y; + double l = sqrt(dx * dx + dy * dy); + double a = k * (l - chain_width) / m; + double ax = a * dx / l; + double ay = a * dy / l; + if(i < CHAIN_LEN - 1) { + dx = cv[i+1].x - cv[i].x; + dy = cv[i+1].y - cv[i].y; + l = sqrt(dx * dx + dy * dy); + a = k * (l - chain_width) / m; + ax += a * dx / l; + ay += a * dy / l; + } + ay += g; + cv[i].vx *= safe; + cv[i].vy *= safe; + cv[i].next_vx = cv[i].vx + ax * dt; + cv[i].next_vy = cv[i].vy + ay * dt; + cv[i].next_x = cv[i].x + cv[i].vx * dt; + cv[i].next_y = cv[i].y + cv[i].vy * dt; + } else { + cv[i].next_x = cv[i].x; + cv[i].next_y = cv[i].y; + } + } + for(int i = 0; i < CHAIN_LEN; i++) { + cv[i].vx = cv[i].next_vx; + cv[i].vy = cv[i].next_vy; + cv[i].x = cv[i].next_x; + cv[i].y = cv[i].next_y; + } + } + // cout << id << ", " << sg->xyz[1] << endl; + } + set_old_vector(&cv[id], sg); + int p, n; + p = n = id; + if(p != 0) { + p--; + } + if(n != CHAIN_LEN - 1) { + n++; + } + sg->angle[2-(id%2)*2] + = 90 + atan((cv[p].next_y - cv[n].next_y) / (cv[p].next_x - cv[n].next_x)) * 180 / M_PI; +} + +void +chain_old_collision(SceneGraphPtr sg, int w, int h, SceneGraphPtr osg) +{ + +} + +void +chain_old_init(TaskManager *manager, int w, int h) +{ + SceneGraphPtr root_old_chain, chain; + CHAIN_VARS rcv; + + sgroot->createFromXMLfile(manager,"xml_file/chain.xml"); + + root_old_chain = sgroot->createSceneGraph(CHAIN); + root_old_chain->set_move_collision(chain_old_move_ope, chain_old_collision); + init_chainold_vars(&rcv); + rcv.next_x = w / 2; + rcv.next_y = 0.0; + set_old_vector(&rcv, root_old_chain); + + for(int i = 0; i < CHAIN_LEN; i++) { + chain = sgroot->createSceneGraph(CHAIN); + chain->id = i; + init_chainold_vars(&cv[i]); + cv[i].x = 0; + cv[i].y = chain_width * i; + set_old_vector(&cv[i], chain); + chain->angle[1] = -90 * (i % 2); + chain->set_move_collision(chain_old_move, chain_old_collision); + + root_old_chain->addChild(chain); + } + cv[0].can_move = FALSE; + + sgroot->setSceneData(root_old_chain); +} diff -r f49f3d469b9f -r 68e199a4ea7b TaskManager/Test/test_render/Makefile --- a/TaskManager/Test/test_render/Makefile Wed Sep 23 15:48:56 2009 +0900 +++ b/TaskManager/Test/test_render/Makefile Wed Sep 23 17:10:10 2009 +0900 @@ -34,7 +34,7 @@ run-ps3: /usr/sbin/ps3-video-mode -v 133 - ./test_nogl -video fb -width 1920 -height 1080 + ./test_nogl -video fb -width 1920 -height 1080 -sg 17 run-ps3tv: ./test_nogl -video fb -width 576 -height 384 -bpp 32 diff -r f49f3d469b9f -r 68e199a4ea7b TaskManager/Test/test_render/viewer.cc --- a/TaskManager/Test/test_render/viewer.cc Wed Sep 23 15:48:56 2009 +0900 +++ b/TaskManager/Test/test_render/viewer.cc Wed Sep 23 17:10:10 2009 +0900 @@ -100,6 +100,7 @@ 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 chain_old_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); @@ -165,6 +166,9 @@ speLoop(); return; break; + case 17: + chain_old_init(manager, this->width, this-> height); + break; default: node_init(manager); break;