Mercurial > hg > Game > Cerium
annotate Renderer/Test/SgRootChange.cc @ 996:bac3b0afc3e8 draft
add sdl_test file
author | yutaka@charles.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Mon, 11 Oct 2010 18:56:51 +0900 |
parents | 4d83a6a958fd |
children | 3f95f61faef6 |
rev | line source |
---|---|
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
1 #include <math.h> |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
2 #include <stdlib.h> |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
3 #include "SceneGraphRoot.h" |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
4 #include "MainLoop.h" |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
5 #include "SgRootChange.h" |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
6 |
747 | 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); | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
10 |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
11 |
747 | 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 } | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
106 |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
107 // prototype |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
108 MainLoopPtr |
747 | 109 SgRootChange::init(Viewer *viewer, int screen_w, int screen_h) |
110 { | |
111 SgChange *sgroot = new SgChange(viewer); | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
112 SceneGraphPtr ball; |
747 | 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); | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
119 |
747 | 120 h0 = screen_h/2; |
121 h0 = -1000; | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
122 |
747 | 123 ball->xyz[0] = screen_w/2; |
124 ball->xyz[1] = h0; | |
125 ball->xyz[2] = 30.0f; | |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
126 |
747 | 127 sgroot->setSceneData(ball); |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
128 |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
129 return sgroot; |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
130 } |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
131 |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
132 extern Application * |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
133 application() { |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
134 return new SgRootChange(); |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
135 } |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
136 |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
137 const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n"; |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
138 |
747 | 139 extern int init(TaskManager *manager, int argc, char *argv[]); |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
140 extern void task_initialize(); |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
141 static void TMend(TaskManager *manager); |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
142 |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
143 int |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
144 TMmain(TaskManager *manager, int argc, char *argv[]) |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
145 { |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
146 task_initialize(); |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
147 manager->set_TMend(TMend); |
747 | 148 return init(manager, argc, argv); |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
149 |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
150 } |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
151 |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
152 void |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
153 TMend(TaskManager *manager) |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
154 { |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
155 printf("test_nogl end\n"); |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
156 } |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
157 |
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
158 /* end */ |