Mercurial > hg > Members > kono > Cerium
annotate Renderer/Test/property_test.cc @ 758:e615e552efa5
change Test/create_task
author | hiroki |
---|---|
date | Sat, 30 Jan 2010 19:33:16 +0900 |
parents | 2575791a333a |
children | 4455e7b0caf3 |
rev | line source |
---|---|
754 | 1 #include <iostream> |
2 #include <math.h> | |
3 #include "SceneGraphRoot.h" | |
4 #include "SceneGraph.h" | |
5 #include "TaskManager.h" | |
6 #include "property_test.h" | |
7 #include "Func.h" | |
8 | |
9 ChainPropertyPtr properties[2]; | |
10 ChainProperty cv[CHAIN_LEN]; | |
11 | |
755 | 12 // |
756
2575791a333a
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
755
diff
changeset
|
13 //void createSceneGraphFromProperty(SceneGraphPtr root, ChainPropertyPtr cv, Viewer *sgroot); |
2575791a333a
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
755
diff
changeset
|
14 void createSceneGraphFromProperty(SceneGraphPtr root, ChainPropertyPtr cv, SgChange *sgroot); |
754 | 15 |
16 void | |
17 init_chainold_vars(ChainPropertyPtr cv) { | |
18 cv->x = 0, cv->y = 0, cv->next_x = 0, cv->next_y = 0; | |
19 cv->vx = 0, cv->vy = 0, cv->next_vx = 0, cv->next_vy = 0; | |
20 cv->can_move = TRUE; | |
21 } | |
22 | |
23 void | |
24 set_old_vector(ChainPropertyPtr cv, SceneGraphPtr sg) { | |
25 sg->xyz[0] = (float)cv->next_x; | |
26 sg->xyz[1] = (float)cv->next_y; | |
27 sg->xyz[2] = 0.0f; | |
28 } | |
29 | |
30 | |
31 static void | |
32 chain_old_move_ope(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) | |
33 { | |
34 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; | |
35 Pad *pad = sgroot->getController(); | |
36 | |
37 if (pad->cross.isHold()) { | |
38 cv[CHAIN_LEN-1].can_move = FALSE; | |
39 if (pad->left.isHold()) { | |
40 cv[CHAIN_LEN-1].x += -5.0; | |
41 } else if (pad->right.isHold()) { | |
42 cv[CHAIN_LEN-1].x += 5.0; | |
43 } | |
44 | |
45 if (pad->up.isHold()) { | |
46 cv[CHAIN_LEN-1].y += -5.0; | |
47 } else if (pad->down.isHold()) { | |
48 cv[CHAIN_LEN-1].y += 5.0; | |
49 } | |
50 } else { | |
51 cv[CHAIN_LEN-1].can_move = TRUE; | |
52 } | |
53 } | |
54 | |
55 void | |
56 chain_old_move(SceneGraphPtr sg, void *sgroot_, int w, int h) | |
57 { | |
58 int id = sg->id; | |
59 if(id == 0) { | |
60 for(int cnt = 0; cnt < 600; cnt++) { | |
61 for(int i = 0; i < CHAIN_LEN; i++) { | |
62 if(cv[i].can_move) { | |
63 double dx = cv[i-1].x - cv[i].x; | |
64 double dy = cv[i-1].y - cv[i].y; | |
65 double l = sqrt(dx * dx + dy * dy); | |
66 double a = k * (l - chain_width) / m; | |
67 double ax = a * dx / l; | |
68 double ay = a * dy / l; | |
69 if(i < CHAIN_LEN - 1) { | |
70 dx = cv[i+1].x - cv[i].x; | |
71 dy = cv[i+1].y - cv[i].y; | |
72 l = sqrt(dx * dx + dy * dy); | |
73 a = k * (l - chain_width) / m; | |
74 ax += a * dx / l; | |
75 ay += a * dy / l; | |
76 } | |
77 ay += g; | |
78 cv[i].vx *= safe; | |
79 cv[i].vy *= safe; | |
80 cv[i].next_vx = cv[i].vx + ax * dt; | |
81 cv[i].next_vy = cv[i].vy + ay * dt; | |
82 cv[i].next_x = cv[i].x + cv[i].vx * dt; | |
83 cv[i].next_y = cv[i].y + cv[i].vy * dt; | |
84 } else { | |
85 cv[i].next_x = cv[i].x; | |
86 cv[i].next_y = cv[i].y; | |
87 } | |
88 } | |
89 for(int i = 0; i < CHAIN_LEN; i++) { | |
90 cv[i].vx = cv[i].next_vx; | |
91 cv[i].vy = cv[i].next_vy; | |
92 cv[i].x = cv[i].next_x; | |
93 cv[i].y = cv[i].next_y; | |
94 } | |
95 } | |
96 // cout << id << ", " << sg->xyz[1] << endl; | |
97 } | |
98 set_old_vector(&cv[id], sg); | |
99 int p, n; | |
100 p = n = id; | |
101 if(p != 0) { | |
102 p--; | |
103 } | |
104 if(n != CHAIN_LEN - 1) { | |
105 n++; | |
106 } | |
107 sg->angle[2-(id%2)*2] | |
108 = 90 + atan((cv[p].next_y - cv[n].next_y) / (cv[p].next_x - cv[n].next_x)) * 180 / M_PI; | |
109 } | |
110 | |
111 /* | |
112 void | |
113 chain_old_collision(SceneGraphPtr sg, int w, int h, SceneGraphPtr osg) | |
114 { | |
115 | |
116 } | |
117 */ | |
118 | |
119 void | |
120 spe_move_collision(ChainProperty cv, void *sgroot_,spe_move_func new_move, spe_move_func new_collision) | |
121 { | |
122 | |
123 cv.move = new_move; | |
124 cv.collision = new_collision; | |
125 | |
126 } | |
127 | |
128 | |
129 void | |
130 chain_old_collision(SceneGraphPtr node, void *sgroot_, int w, int h, SceneGraphPtr ocv) | |
131 { | |
132 //createSceneGraphFromProperty(cv, cv); | |
133 } | |
134 | |
135 | |
136 void | |
137 property_swich() | |
138 { | |
139 | |
140 } | |
141 | |
142 | |
143 void | |
756
2575791a333a
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
755
diff
changeset
|
144 #if 1 |
754 | 145 createSceneGraphFromProperty(SceneGraphPtr root, ChainPropertyPtr cv, Viewer *sgroot) |
756
2575791a333a
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
755
diff
changeset
|
146 #else |
2575791a333a
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
755
diff
changeset
|
147 createSceneGraphFromProperty(SceneGraphPtr root, ChainPropertyPtr cv, SgChange *sgroot) |
2575791a333a
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
755
diff
changeset
|
148 #endif |
754 | 149 { |
150 SceneGraphPtr node; | |
151 | |
152 for(int i = 0; i < CHAIN_LEN; i++) { | |
153 node = sgroot->createSceneGraph(cv[i].objname); | |
154 /** | |
155 * move, collision は spe で実行される, task taskID を持たせればよい | |
156 * property が 対応する taskID を持つので set_move_collision() は不要 | |
157 * set_task_propety(move_taskID, collision_taskID) のようなものを作る | |
158 */ | |
159 node->set_move_collision(chain_old_move, chain_old_collision); | |
160 //spe_move_collision(cv[i], chain_old_move, chain_old_collision); | |
161 node->id = cv[i].id; | |
162 node->angle[1] = cv[i].angle[1]; | |
163 set_old_vector(&cv[i], node); | |
164 cv[i].parent->addChild(node); | |
165 } | |
166 sgroot->setSceneData(root); | |
167 } | |
168 | |
169 | |
170 void | |
171 set_properties(ChainPropertyPtr cv) | |
172 { | |
173 properties[0] = cv; | |
174 properties[1] = cv; | |
175 } | |
176 | |
177 MainLoopPtr | |
178 Chain::init(Viewer *sgroot, int w, int h) | |
179 { | |
756
2575791a333a
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
755
diff
changeset
|
180 #if 0 |
2575791a333a
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
755
diff
changeset
|
181 SgChange *sgroot = new SgChange(sgroot_); |
2575791a333a
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
755
diff
changeset
|
182 sgroot->run_init(); |
2575791a333a
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
755
diff
changeset
|
183 #endif |
2575791a333a
add Test/create_task {spe, task}/Property
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
755
diff
changeset
|
184 |
754 | 185 SceneGraphPtr root, chain; |
186 sgroot->createFromXMLfile("xml_file/chain.xml"); | |
187 | |
188 ChainProperty rcv; | |
189 init_chainold_vars(&rcv); | |
190 rcv.next_x = w / 2; | |
191 rcv.next_y = 0.0; | |
192 rcv.id = CHAIN_LEN; | |
193 | |
194 root = sgroot->createSceneGraph("CHAIN"); | |
195 root->set_move_collision(chain_old_move_ope, chain_old_collision); | |
196 set_old_vector(&rcv, root); | |
197 | |
198 chain = sgroot->createSceneGraph("CHAIN"); | |
199 chain->set_move_collision(chain_old_move, chain_old_collision); | |
200 | |
201 set_properties(cv); | |
202 | |
203 for(int i = 0; i < CHAIN_LEN; i++) { | |
204 init_chainold_vars(&cv[i]); | |
205 cv[i].x = 0; | |
206 cv[i].y = chain_width * i; | |
207 cv[i].angle[1] = -90 * (i % 2); | |
208 | |
209 chain->id = cv[i].id; | |
210 chain->angle[1] = cv[i].angle[1]; | |
211 set_old_vector(&cv[i], chain); | |
212 | |
213 cv[i].root = root; | |
214 cv[i].objname = "CHAIN"; | |
215 cv[i].id = i; | |
216 | |
217 cv[i].parent = root; | |
218 | |
219 } | |
220 | |
221 createSceneGraphFromProperty(root, cv, sgroot); | |
222 cv[0].can_move = FALSE; | |
223 //sgroot->setSceneData(root); | |
224 | |
225 return sgroot; | |
226 } | |
227 | |
228 extern Application * | |
229 application() { | |
230 return new Chain(); | |
231 } | |
232 | |
233 const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n"; | |
234 | |
235 extern int init(TaskManager *manager, int argc, char *argv[]); | |
236 extern void task_initialize(); | |
237 static void TMend(TaskManager *manager); | |
238 | |
239 int | |
240 TMmain(TaskManager *manager, int argc, char *argv[]) | |
241 { | |
242 task_initialize(); | |
243 manager->set_TMend(TMend); | |
244 return init(manager, argc, argv); | |
245 | |
246 } | |
247 | |
248 void | |
249 TMend(TaskManager *manager) | |
250 { | |
251 printf("test_nogl end\n"); | |
252 } | |
253 | |
254 /* end */ | |
255 |