Mercurial > hg > Game > Cerium
annotate TaskManager/Test/test_render/ball_bound.cpp @ 238:443c7ae1c7a7 draft
warning clean
author | admin@mcbk.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Fri, 29 May 2009 13:43:52 +0900 |
parents | 8ac35507094d |
children | 69a9d1f91dc9 |
rev | line source |
---|---|
212 | 1 #include <math.h> |
213
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
2 #include <stdlib.h> |
208 | 3 #include "SceneGraphRoot.h" |
4 #include "SGList.h" | |
5 | |
6 // prototype | |
7 static void ball_move(SceneGraphPtr node, int screen_w, int screen_h); | |
213
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
8 static void ball_collision(SceneGraphPtr node, int screen_w, int screen_h, SceneGraphPtr tree); |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
9 static void ball_collision_idle(SceneGraphPtr, int w, int h, SceneGraphPtr tree); |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
10 |
208 | 11 |
212 | 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; // 重力加速度 | |
238 | 17 //static float v0 = 0.0f; // 初速は 0 |
212 | 18 |
19 static float h0; // 初期高さ | |
20 static float ball_radius = 100.0f; | |
21 | |
213
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
22 static int speed = 10.0f; |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
23 |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
24 static void |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
25 ball_move_idle2(SceneGraphPtr node, int screen_w, int screen_h) |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
26 { |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
27 Pad *pad = sgroot->getController(); |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
28 |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
29 if (pad->circle.isHold()) { |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
30 if (pad->left.isHold()) { |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
31 node->xyz[0] -= speed; |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
32 if(node->xyz[0] < ball_radius) |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
33 node->xyz[0] = ball_radius; |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
34 } else if (pad->right.isHold()) { |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
35 node->xyz[0] += speed; |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
36 if(node->xyz[0] > screen_w - ball_radius) |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
37 node->xyz[0] = screen_w - ball_radius; |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
38 } |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
39 |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
40 if (pad->up.isHold()) { |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
41 node->xyz[1] -= speed; |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
42 } else if (pad->down.isHold()) { |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
43 node->xyz[1] += speed; |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
44 if(node->xyz[1] > screen_h - ball_radius) |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
45 node->xyz[1] = screen_h - ball_radius; |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
46 } |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
47 } else { |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
48 node->set_move_collision(ball_move, ball_collision); |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
49 } |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
50 } |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
51 |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
52 static int time = 0; |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
53 |
212 | 54 static void |
55 ball_move_idle(SceneGraphPtr node, int screen_w, int screen_h) | |
56 { | |
213
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
57 Pad *pad = sgroot->getController(); |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
58 |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
59 if (pad->circle.isPush()) { |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
60 node->set_move_collision(ball_move_idle2, ball_collision_idle); |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
61 time = 0; |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
62 } |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
63 |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
64 time++; |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
65 |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
66 if (time > 90) { |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
67 float w = (float)random(); |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
68 |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
69 w = fmodf(w, screen_w - ball_radius*2); |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
70 node->xyz[0] = w + ball_radius; |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
71 node->xyz[1] = h0; |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
72 node->set_move_collision(ball_move, ball_collision); |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
73 time = 0; |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
74 } |
212 | 75 } |
76 | |
208 | 77 static void |
78 ball_move(SceneGraphPtr node, int screen_w, int screen_h) | |
79 { | |
212 | 80 vy += g * dt; |
81 node->xyz[1] += vy * dt; | |
213
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
82 // node->xyz[0] += 10.0f; |
212 | 83 } |
84 | |
85 static void | |
86 ball_collision_idle(SceneGraphPtr, int w, int h, SceneGraphPtr tree) | |
87 { | |
208 | 88 } |
89 | |
90 static void | |
91 ball_collision(SceneGraphPtr node, int screen_w, int screen_h, | |
92 SceneGraphPtr tree) | |
93 { | |
212 | 94 if (node->xyz[1] > screen_h - ball_radius) { |
95 node->xyz[1] = screen_h - ball_radius; | |
96 | |
97 vy *= e; | |
98 if (vy > -g && vy < 0) { | |
99 vy = 0.0; | |
100 node->set_move_collision(ball_move_idle, ball_collision_idle); | |
101 } | |
102 } | |
208 | 103 } |
104 | |
105 | |
106 void | |
107 ball_bound_init(int screen_w, int screen_h) | |
108 { | |
109 SceneGraphPtr ball; | |
110 | |
213
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
111 srandom(100); |
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
112 |
210 | 113 sgroot->createFromXMLfile("xml_file/Ball.xml"); |
208 | 114 ball = sgroot->createSceneGraph(Ball); |
115 ball->set_move_collision(ball_move, ball_collision); | |
212 | 116 |
117 h0 = screen_h/2; | |
118 h0 = -1000; | |
119 | |
208 | 120 ball->xyz[0] = screen_w/2; |
213
8ac35507094d
add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents:
212
diff
changeset
|
121 //ball->xyz[0] = 0.0f; |
212 | 122 ball->xyz[1] = h0; |
123 ball->xyz[2] = 30.0f; | |
208 | 124 |
125 sgroot->setSceneData(ball); | |
126 } |