Mercurial > hg > Game > Cerium
view TaskManager/Test/test_render/ball_bound.cpp @ 212:c020ccff4627 draft
fix
author | gongo@localhost.localdomain |
---|---|
date | Sat, 31 Jan 2009 08:54:22 +0900 |
parents | e75f9eb97180 |
children | 8ac35507094d |
line wrap: on
line source
#include <math.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 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 void ball_move_idle(SceneGraphPtr node, int screen_w, int screen_h) { } static void ball_move(SceneGraphPtr node, int screen_w, int screen_h) { vy += g * dt; node->xyz[1] += vy * dt; } 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(int screen_w, int screen_h) { SceneGraphPtr ball; sgroot->createFromXMLfile("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[1] = h0; ball->xyz[2] = 30.0f; sgroot->setSceneData(ball); }