Mercurial > hg > Game > Cerium
annotate Renderer/Test/ball_bound.cc @ 1372:7afeb56ba212 draft
old API compatible
author | Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 21 Jan 2012 22:24:51 +0900 |
parents | 90efd2aac2cb |
children | 555d2a31cf0c |
rev | line source |
---|---|
539 | 1 #include <math.h> |
2 #include <stdlib.h> | |
3 #include "SceneGraphRoot.h" | |
543 | 4 #include "MainLoop.h" |
5 #include "ball_bound.h" | |
539 | 6 |
556 | 7 |
539 | 8 // prototype |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
562
diff
changeset
|
9 static void ball_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h); |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
562
diff
changeset
|
10 static void ball_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, SceneGraphPtr tree); |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
562
diff
changeset
|
11 static void ball_collision_idle(SceneGraphPtr, void *sgroot_, int w, int h, SceneGraphPtr tree); |
539 | 12 |
13 | |
14 static float vy = 0.0f; // y 方向速度 | |
15 static float dt = 1.0/1.0f; // frame rate | |
16 | |
17 static float e = -0.8f; // 反発係数 | |
18 static float g = 9.8f; // 重力加速度 | |
19 //static float v0 = 0.0f; // 初速は 0 | |
20 | |
21 static float h0; // 初期高さ | |
22 static float ball_radius = 100.0f; | |
23 | |
24 static float speed = 10.0f; | |
25 | |
26 static void | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
562
diff
changeset
|
27 ball_move_idle2(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) |
539 | 28 { |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
562
diff
changeset
|
29 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; |
539 | 30 Pad *pad = sgroot->getController(); |
31 | |
32 if (pad->circle.isHold()) { | |
33 if (pad->left.isHold()) { | |
1372
7afeb56ba212
old API compatible
Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
1292
diff
changeset
|
34 node->xyz[0] -= speed; |
539 | 35 if(node->xyz[0] < ball_radius) |
1372
7afeb56ba212
old API compatible
Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
1292
diff
changeset
|
36 node->xyz[0] = ball_radius; |
539 | 37 } else if (pad->right.isHold()) { |
38 node->xyz[0] += speed; | |
39 if(node->xyz[0] > screen_w - ball_radius) | |
40 node->xyz[0] = screen_w - ball_radius; | |
41 } | |
42 | |
43 if (pad->up.isHold()) { | |
44 node->xyz[1] -= speed; | |
45 } else if (pad->down.isHold()) { | |
46 node->xyz[1] += speed; | |
47 if(node->xyz[1] > screen_h - ball_radius) | |
48 node->xyz[1] = screen_h - ball_radius; | |
49 } | |
50 } else { | |
51 node->set_move_collision(ball_move, ball_collision); | |
52 } | |
53 } | |
54 | |
1183
8fd004a3f02c
add SpeTaskManagerImpl to Makefile.fifo
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
1145
diff
changeset
|
55 static int time_val = 0; |
539 | 56 |
57 static void | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
562
diff
changeset
|
58 ball_move_idle(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) |
539 | 59 { |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
562
diff
changeset
|
60 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; |
539 | 61 Pad *pad = sgroot->getController(); |
62 | |
63 if (pad->circle.isPush()) { | |
64 node->set_move_collision(ball_move_idle2, ball_collision_idle); | |
1183
8fd004a3f02c
add SpeTaskManagerImpl to Makefile.fifo
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
1145
diff
changeset
|
65 time_val = 0; |
539 | 66 } |
67 | |
1183
8fd004a3f02c
add SpeTaskManagerImpl to Makefile.fifo
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
1145
diff
changeset
|
68 time_val++; |
539 | 69 |
1183
8fd004a3f02c
add SpeTaskManagerImpl to Makefile.fifo
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
1145
diff
changeset
|
70 if (time_val > 90) { |
539 | 71 float w = (float)random(); |
72 | |
73 w = fmodf(w, screen_w - ball_radius*2); | |
74 node->xyz[0] = w + ball_radius; | |
75 node->xyz[1] = h0; | |
76 node->set_move_collision(ball_move, ball_collision); | |
1183
8fd004a3f02c
add SpeTaskManagerImpl to Makefile.fifo
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
1145
diff
changeset
|
77 time_val = 0; |
539 | 78 } |
79 } | |
80 | |
81 static void | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
562
diff
changeset
|
82 ball_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) |
539 | 83 { |
1029 | 84 vy += g * dt; |
85 node->xyz[1] += vy * dt; | |
539 | 86 // node->xyz[0] += 10.0f; |
87 } | |
88 | |
89 static void | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
562
diff
changeset
|
90 ball_collision_idle(SceneGraphPtr, void *sgroot_, int w, int h, SceneGraphPtr tree) |
539 | 91 { |
92 } | |
93 | |
94 static void | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
562
diff
changeset
|
95 ball_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, |
539 | 96 SceneGraphPtr tree) |
97 { | |
1029 | 98 if (node->xyz[1] > screen_h - ball_radius) { |
99 node->xyz[1] = screen_h - ball_radius; | |
100 | |
101 vy *= e; | |
102 if (vy > -g && vy < 0) { | |
103 vy = 0.0; | |
104 node->set_move_collision(ball_move_idle, ball_collision_idle); | |
105 } | |
106 } | |
539 | 107 } |
108 | |
542 | 109 MainLoopPtr |
557
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
556
diff
changeset
|
110 ball_bound::init(Viewer *sgroot, int screen_w, int screen_h) |
539 | 111 { |
112 SceneGraphPtr ball; | |
113 | |
114 // 固定した値で srandom すると、毎回同じ、random() 列が生成される | |
115 // random な値が欲しいなら、man random に方法が書いてあります。 | |
116 srandom(100); | |
117 | |
557
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
556
diff
changeset
|
118 sgroot->createFromXMLfile("xml_file/Ball.xml"); |
542 | 119 |
1292
90efd2aac2cb
add matrix test and debug light vector
Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
1183
diff
changeset
|
120 sgroot->OnLightSysSwitch(); |
1142
801d57ae1e29
cut compile CreatePolygonTask on spe side because not enough spe memory. We have to use code loading.
yutaka@localhost.localdomain
parents:
1029
diff
changeset
|
121 |
801d57ae1e29
cut compile CreatePolygonTask on spe side because not enough spe memory. We have to use code loading.
yutaka@localhost.localdomain
parents:
1029
diff
changeset
|
122 SceneGraphPtr light = sgroot->getLight(0); |
801d57ae1e29
cut compile CreatePolygonTask on spe side because not enough spe memory. We have to use code loading.
yutaka@localhost.localdomain
parents:
1029
diff
changeset
|
123 sgroot->OnLightSwitch(0); |
801d57ae1e29
cut compile CreatePolygonTask on spe side because not enough spe memory. We have to use code loading.
yutaka@localhost.localdomain
parents:
1029
diff
changeset
|
124 light->xyz[0] = screen_w / 2; |
801d57ae1e29
cut compile CreatePolygonTask on spe side because not enough spe memory. We have to use code loading.
yutaka@localhost.localdomain
parents:
1029
diff
changeset
|
125 light->xyz[1] = screen_h / 2; |
801d57ae1e29
cut compile CreatePolygonTask on spe side because not enough spe memory. We have to use code loading.
yutaka@localhost.localdomain
parents:
1029
diff
changeset
|
126 light->xyz[2] = -100; |
801d57ae1e29
cut compile CreatePolygonTask on spe side because not enough spe memory. We have to use code loading.
yutaka@localhost.localdomain
parents:
1029
diff
changeset
|
127 |
562 | 128 ball = sgroot->createSceneGraph("Ball"); |
539 | 129 ball->set_move_collision(ball_move, ball_collision); |
130 | |
131 h0 = screen_h/2; | |
132 h0 = -1000; | |
133 | |
134 ball->xyz[0] = screen_w/2; | |
135 //ball->xyz[0] = 0.0f; | |
136 ball->xyz[1] = h0; | |
137 ball->xyz[2] = 30.0f; | |
138 | |
557
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
556
diff
changeset
|
139 sgroot->setSceneData(ball); |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
556
diff
changeset
|
140 |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
556
diff
changeset
|
141 return sgroot; |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
556
diff
changeset
|
142 } |
542 | 143 |
557
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
556
diff
changeset
|
144 extern Application * |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
556
diff
changeset
|
145 application() { |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
556
diff
changeset
|
146 return new ball_bound(); |
539 | 147 } |
542 | 148 |
557
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
556
diff
changeset
|
149 const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n"; |
764772be1e3c
fix examlples (on going)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
556
diff
changeset
|
150 |
556 | 151 extern int init(TaskManager *manager, int argc, char *argv[]); |
152 extern void task_initialize(); | |
153 static void TMend(TaskManager *manager); | |
154 | |
155 int | |
156 TMmain(TaskManager *manager, int argc, char *argv[]) | |
157 { | |
158 task_initialize(); | |
159 manager->set_TMend(TMend); | |
160 return init(manager, argc, argv); | |
161 | |
162 } | |
163 | |
164 void | |
165 TMend(TaskManager *manager) | |
166 { | |
167 printf("test_nogl end\n"); | |
168 } | |
169 | |
542 | 170 /* end */ |