Mercurial > hg > Members > e085722 > Cerium
comparison Renderer/Test_/SgRootChange.cc @ 4:b5b462ac9b3b
Cerium Blender ball_bound
author | Daiki KINJYO <e085722@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 29 Nov 2010 16:42:42 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3:3f6fe22ac669 | 4:b5b462ac9b3b |
---|---|
1 #include <math.h> | |
2 #include <stdlib.h> | |
3 #include "SceneGraphRoot.h" | |
4 #include "MainLoop.h" | |
5 #include "SgRootChange.h" | |
6 | |
7 static void ball_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h); | |
8 static void ball_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, SceneGraphPtr tree); | |
9 static void ball_collision_idle(SceneGraphPtr, void *sgroot_, int w, int h, SceneGraphPtr tree); | |
10 | |
11 | |
12 static float vy = 0.0f; // y 方向速度 | |
13 static float dt = 1.0/1.0f; // frame rate | |
14 | |
15 static float e = -0.8f; // 反発係数 | |
16 static float g = 9.8f; // 重力加速度 | |
17 //static float v0 = 0.0f; // 初速は 0 | |
18 | |
19 static float h0; // 初期高さ | |
20 static float ball_radius = 100.0f; | |
21 | |
22 static float speed = 10.0f; | |
23 | |
24 static void | |
25 ball_move_idle2(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) | |
26 { | |
27 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; | |
28 Pad *pad = sgroot->getController(); | |
29 | |
30 if (pad->circle.isHold()) { | |
31 if (pad->left.isHold()) { | |
32 node->xyz[0] -= speed; | |
33 if(node->xyz[0] < ball_radius) | |
34 node->xyz[0] = ball_radius; | |
35 } else if (pad->right.isHold()) { | |
36 node->xyz[0] += speed; | |
37 if(node->xyz[0] > screen_w - ball_radius) | |
38 node->xyz[0] = screen_w - ball_radius; | |
39 } | |
40 | |
41 if (pad->up.isHold()) { | |
42 node->xyz[1] -= speed; | |
43 } else if (pad->down.isHold()) { | |
44 node->xyz[1] += speed; | |
45 if(node->xyz[1] > screen_h - ball_radius) | |
46 node->xyz[1] = screen_h - ball_radius; | |
47 } | |
48 } else { | |
49 node->set_move_collision(ball_move, ball_collision); | |
50 } | |
51 } | |
52 | |
53 static int time = 0; | |
54 | |
55 static void | |
56 ball_move_idle(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) | |
57 { | |
58 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; | |
59 Pad *pad = sgroot->getController(); | |
60 | |
61 if (pad->circle.isPush()) { | |
62 node->set_move_collision(ball_move_idle2, ball_collision_idle); | |
63 time = 0; | |
64 } | |
65 | |
66 time++; | |
67 | |
68 if (time > 90) { | |
69 float w = (float)random(); | |
70 | |
71 w = fmodf(w, screen_w - ball_radius*2); | |
72 node->xyz[0] = w + ball_radius; | |
73 node->xyz[1] = h0; | |
74 node->set_move_collision(ball_move, ball_collision); | |
75 time = 0; | |
76 } | |
77 } | |
78 | |
79 static void | |
80 ball_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) | |
81 { | |
82 vy += g * dt; | |
83 node->xyz[1] += vy * dt; | |
84 // node->xyz[0] += 10.0f; | |
85 } | |
86 | |
87 static void | |
88 ball_collision_idle(SceneGraphPtr, void *sgroot_, int w, int h, SceneGraphPtr tree) | |
89 { | |
90 } | |
91 | |
92 static void | |
93 ball_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, | |
94 SceneGraphPtr tree) | |
95 { | |
96 if (node->xyz[1] > screen_h - ball_radius) { | |
97 node->xyz[1] = screen_h - ball_radius; | |
98 | |
99 vy *= e; | |
100 if (vy > -g && vy < 0) { | |
101 vy = 0.0; | |
102 node->set_move_collision(ball_move_idle, ball_collision_idle); | |
103 } | |
104 } | |
105 } | |
106 | |
107 // prototype | |
108 MainLoopPtr | |
109 SgRootChange::init(Viewer *viewer, int screen_w, int screen_h) | |
110 { | |
111 SgChange *sgroot = new SgChange(viewer); | |
112 SceneGraphPtr ball; | |
113 sgroot->run_init(); | |
114 srandom(100); | |
115 | |
116 sgroot->createFromXMLfile("xml_file/Ball.xml"); | |
117 ball = sgroot->createSceneGraph("Ball"); | |
118 ball->set_move_collision(ball_move, ball_collision); | |
119 | |
120 h0 = screen_h/2; | |
121 h0 = -1000; | |
122 | |
123 ball->xyz[0] = screen_w/2; | |
124 ball->xyz[1] = h0; | |
125 ball->xyz[2] = 30.0f; | |
126 | |
127 sgroot->setSceneData(ball); | |
128 | |
129 return sgroot; | |
130 } | |
131 | |
132 extern Application * | |
133 application() { | |
134 return new SgRootChange(); | |
135 } | |
136 | |
137 const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n"; | |
138 | |
139 extern int init(TaskManager *manager, int argc, char *argv[]); | |
140 extern void task_initialize(); | |
141 static void TMend(TaskManager *manager); | |
142 | |
143 int | |
144 TMmain(TaskManager *manager, int argc, char *argv[]) | |
145 { | |
146 task_initialize(); | |
147 manager->set_TMend(TMend); | |
148 return init(manager, argc, argv); | |
149 | |
150 } | |
151 | |
152 void | |
153 TMend(TaskManager *manager) | |
154 { | |
155 printf("test_nogl end\n"); | |
156 } | |
157 | |
158 /* end */ |