# HG changeset patch # User tokumoritaichirou@e075743.local # Date 1260441608 -32400 # Node ID 00e8c4e10592e940e21e23bdab1540e1f3ea1930 # Parent 09bd55f57f9cccbf7ee2ebc9aac38f63442629ed add ball_bound.cc diff -r 09bd55f57f9c -r 00e8c4e10592 walkprog/ball_bound.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/walkprog/ball_bound.cc Thu Dec 10 19:40:08 2009 +0900 @@ -0,0 +1,194 @@ +#include +#include +#include "SceneGraphRoot.h" +#include "MainLoop.h" +#include "ball_bound.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) +{ + +} + +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) +{ + node->angle[1] += 1; + //node->angle[0] += 1; + +} + +MainLoopPtr +ball_bound::init(Viewer *sgroot, int screen_w, int screen_h) +{ + SceneGraphPtr body,waist; + SceneGraphPtr arm1R, arm2R, handR; + SceneGraphPtr arm1L, arm2L, handL; + SceneGraphPtr leg1R, leg2R, footR; + SceneGraphPtr leg1L, leg2L, footL; + + // 固定した値で srandom すると、毎回同じ、random() 列が生成される + // random な値が欲しいなら、man random に方法が書いてあります。 + srandom(100); + + //sgroot->createFromXMLfile("xml_file/body_hakama.xml"); + sgroot->createFromXMLfile("xml_file/body_hakama.xml"); + + body = sgroot->createSceneGraph("body"); + //body->set_move_collision(ball_move, ball_collision); + +#if 1 + waist = sgroot->createSceneGraph("waist"); + arm1R = sgroot->createSceneGraph("arm1R"); + arm2R = sgroot->createSceneGraph("arm2R"); + arm1L = sgroot->createSceneGraph("arm1L"); + arm2L = sgroot->createSceneGraph("arm2L"); + handR = sgroot->createSceneGraph("handR"); + handL = sgroot->createSceneGraph("handL"); + + leg1R = sgroot->createSceneGraph("leg1R"); + leg2R = sgroot->createSceneGraph("leg2R"); + leg1L = sgroot->createSceneGraph("leg1L"); + leg2L = sgroot->createSceneGraph("leg2L"); + footR = sgroot->createSceneGraph("footR"); + footL = sgroot->createSceneGraph("footL"); + + body->addChild(arm1R); + body->addChild(arm1L); + arm1R->addChild(arm2R); + arm1L->addChild(arm2L); + arm2R->addChild(handR); + arm2L->addChild(handL); + + body->addChild(waist); + waist->addChild(leg1R); + waist->addChild(leg1L); + leg1R->addChild(leg2R); + leg1L->addChild(leg2L); + leg2R->addChild(footR); + leg2L->addChild(footL); +#endif + + // h0 = screen_h/2; + // h0 = -1000; + + body->xyz[0] = screen_w/2; + //ball->xyz[0] = 0.0f; + body->xyz[1] = screen_h/2; + body->xyz[2] = 100; + //ball->xyz[2] = 30.0f; + body->angle[0] = -90.0f; + body->angle[1] = 180.0f; + + arm1R->set_move_collision(ball_move, ball_collision); + + sgroot->setSceneData(body); + + return sgroot; +} + +extern Application * +application() { + return new ball_bound(); +} + +const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n"; + +extern int init(TaskManager *manager, int argc, char *argv[]); +extern void task_initialize(); +static void TMend(TaskManager *manager); + +int +TMmain(TaskManager *manager, int argc, char *argv[]) +{ + task_initialize(); + manager->set_TMend(TMend); + return init(manager, argc, argv); + +} + +void +TMend(TaskManager *manager) +{ + printf("test_nogl end\n"); +} + +/* end */