Mercurial > hg > Members > kono > Cerium
diff TaskManager/Test/test_render/ball_bound.cpp @ 213:159519cdca1f
add SceneGraph "3D Super-Dandy"
author | gongo@localhost.localdomain |
---|---|
date | Sun, 01 Feb 2009 20:45:07 +0900 |
parents | fe2cc32cd94d |
children | e1d24c951408 1c09c7e9284b |
line wrap: on
line diff
--- a/TaskManager/Test/test_render/ball_bound.cpp Sat Jan 31 08:54:22 2009 +0900 +++ b/TaskManager/Test/test_render/ball_bound.cpp Sun Feb 01 20:45:07 2009 +0900 @@ -1,10 +1,13 @@ #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); +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 @@ -16,9 +19,59 @@ static float h0; // 初期高さ static float ball_radius = 100.0f; +static int 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 @@ -26,6 +79,7 @@ { vy += g * dt; node->xyz[1] += vy * dt; + // node->xyz[0] += 10.0f; } static void @@ -54,6 +108,8 @@ { SceneGraphPtr ball; + srandom(100); + sgroot->createFromXMLfile("xml_file/Ball.xml"); ball = sgroot->createSceneGraph(Ball); ball->set_move_collision(ball_move, ball_collision); @@ -62,6 +118,7 @@ h0 = -1000; ball->xyz[0] = screen_w/2; + //ball->xyz[0] = 0.0f; ball->xyz[1] = h0; ball->xyz[2] = 30.0f;