Mercurial > hg > Members > kono > Cerium
annotate Renderer/Test/viewer.cc @ 757:5238f3e854fc
Test/create_task , create SPE task from application.
author | hiroki |
---|---|
date | Fri, 29 Jan 2010 14:34:30 +0900 |
parents | b7376415fa5f |
children | c260205d3185 |
rev | line source |
---|---|
589 | 1 #include <math.h> |
2 #include <stdlib.h> | |
3 #include "SceneGraphRoot.h" | |
4 #include "MainLoop.h" | |
5 #include "viewer.h" | |
6 | |
7 | |
8 // prototype | |
656
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
589
diff
changeset
|
9 static void ball_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h); |
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
589
diff
changeset
|
10 static void ball_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, SceneGraphPtr tree); |
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
589
diff
changeset
|
11 static void ball_collision_idle(SceneGraphPtr, void *sgroot_, int w, int h, SceneGraphPtr tree); |
589 | 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 | |
656
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
589
diff
changeset
|
27 ball_move_idle2(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) |
589 | 28 { |
656
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
589
diff
changeset
|
29 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; |
589 | 30 Pad *pad = sgroot->getController(); |
31 | |
32 if (pad->circle.isHold()) { | |
33 if (pad->left.isHold()) { | |
34 node->xyz[0] -= speed; | |
35 if(node->xyz[0] < ball_radius) | |
36 node->xyz[0] = ball_radius; | |
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 | |
55 static int time = 0; | |
56 | |
57 static void | |
656
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
589
diff
changeset
|
58 ball_move_idle(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) |
589 | 59 { |
656
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
589
diff
changeset
|
60 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; |
589 | 61 Pad *pad = sgroot->getController(); |
62 | |
63 if (pad->circle.isPush()) { | |
64 node->set_move_collision(ball_move_idle2, ball_collision_idle); | |
65 time = 0; | |
66 } | |
67 | |
68 time++; | |
69 | |
70 if (time > 90) { | |
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); | |
77 time = 0; | |
78 } | |
79 } | |
80 | |
81 static void | |
656
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
589
diff
changeset
|
82 ball_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) |
589 | 83 { |
84 vy += g * dt; | |
85 node->xyz[1] += vy * dt; | |
86 // node->xyz[0] += 10.0f; | |
87 } | |
88 | |
89 static void | |
656
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
589
diff
changeset
|
90 ball_collision_idle(SceneGraphPtr, void *sgroot_, int w, int h, SceneGraphPtr tree) |
589 | 91 { |
92 } | |
93 | |
94 static void | |
656
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
589
diff
changeset
|
95 ball_collision(SceneGraphPtr node, void *sgroot_, int screen_w, |
d0b8860c17f8
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
589
diff
changeset
|
96 int screen_h, SceneGraphPtr tree) |
589 | 97 { |
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 } | |
107 } | |
108 | |
109 char *xmlfile; | |
110 #define MAX_ROOT 100 | |
111 char *parts[MAX_ROOT ]; | |
112 int parts_cnt; | |
113 | |
114 MainLoopPtr | |
115 viewer::init(Viewer *sgroot, int screen_w, int screen_h) | |
116 { | |
117 SceneGraphPtr ball; | |
118 | |
119 // 固定した値で srandom すると、毎回同じ、random() 列が生成される | |
120 // random な値が欲しいなら、man random に方法が書いてあります。 | |
121 srandom(100); | |
122 | |
123 sgroot->createFromXMLfile(xmlfile); | |
124 | |
125 ball = sgroot->createSceneGraph(); | |
126 ball->set_move_collision(ball_move, ball_collision); | |
127 | |
128 h0 = screen_h/2; | |
129 h0 = -1000; | |
130 | |
131 ball->xyz[0] = screen_w/2; | |
132 //ball->xyz[0] = 0.0f; | |
133 ball->xyz[1] = h0; | |
134 ball->xyz[2] = 30.0f; | |
135 | |
136 for(int i=0;i<parts_cnt; i++) { | |
137 ball->addChild(sgroot->createSceneGraph(parts[i])); | |
138 } | |
139 sgroot->setSceneData(ball); | |
140 | |
141 return sgroot; | |
142 } | |
143 | |
144 extern Application * | |
145 application() { | |
146 return new viewer(); | |
147 } | |
148 | |
149 const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n"; | |
150 | |
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 | |
161 for(int i=0;i<argc;i++) { | |
162 if (strcmp(argv[i],"-sg") == 0 && i+1<=argc) { | |
163 xmlfile = argv[i+1]; | |
164 } else if (strcmp(argv[i],"-name") == 0 && i+1<=argc) { | |
165 parts[parts_cnt++] = argv[i+1]; | |
166 } | |
167 } | |
168 return init(manager, argc, argv); | |
169 | |
170 } | |
171 | |
172 void | |
173 TMend(TaskManager *manager) | |
174 { | |
175 printf("test_nogl end\n"); | |
176 } | |
177 | |
178 /* end */ | |
179 |