comparison Renderer/Test/aquarium.cc @ 902:fb23a3cce848

[aquarium] add direction of fish
author game@zeus.cr.ie.u-ryukyu.ac.jp
date Sat, 17 Jul 2010 01:07:30 +0900
parents c81744aaa3ef
children 04bf33e8e324
comparison
equal deleted inserted replaced
901:56a752736db2 902:fb23a3cce848
50 50
51 void 51 void
52 aquarium::set_position(SceneGraphPtr node, unsigned char *reply) { 52 aquarium::set_position(SceneGraphPtr node, unsigned char *reply) {
53 aqua::Position *pos = new aqua::Position(); 53 aqua::Position *pos = new aqua::Position();
54 pos->ParseFromArray(reply + LINDA_HEADER_SIZE, psx_get_datalength(reply)); 54 pos->ParseFromArray(reply + LINDA_HEADER_SIZE, psx_get_datalength(reply));
55 node->stack_xyz[0] = node->xyz[0] = pos->x() - start_x; 55 node->xyz[0] = pos->x() - start_x;
56 node->stack_xyz[1] = node->xyz[1] = pos->y(); 56 node->xyz[1] = pos->y();
57 57 node->angle[0] = pos->angle_x();
58 node->angle[1] = pos->angle_y();
58 delete pos; 59 delete pos;
59 } 60 }
60 61
61 static void 62 static void
62 update_position_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) 63 update_position_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
146 int pos_id = serial_id * 10 + 1; 147 int pos_id = serial_id * 10 + 1;
147 psx_callback_in(linda, pos_id, callback_free, NULL); 148 psx_callback_in(linda, pos_id, callback_free, NULL);
148 aqua::Position *pos = new aqua::Position(); 149 aqua::Position *pos = new aqua::Position();
149 pos->set_x(node->xyz[0] + start_x); 150 pos->set_x(node->xyz[0] + start_x);
150 pos->set_y(node->xyz[1]); 151 pos->set_y(node->xyz[1]);
152 pos->set_angle_x(node->angle[0]);
153 pos->set_angle_y(node->angle[1]);
151 int size = pos->ByteSize(); 154 int size = pos->ByteSize();
152 unsigned char *msg = (unsigned char *) sgroot->manager->allocate(sizeof(char) * size); 155 unsigned char *msg = (unsigned char *) sgroot->manager->allocate(sizeof(char) * size);
153 pos->SerializeToArray(msg, size); // 更新したデータを再度シリアライズ 156 pos->SerializeToArray(msg, size); // 更新したデータを再度シリアライズ
154 delete pos; 157 delete pos;
155 psx_out(linda, pos_id, msg, size); 158 psx_out(linda, pos_id, msg, size);
162 Pad *pad = sgroot->getController(); 165 Pad *pad = sgroot->getController();
163 int flag = 0; 166 int flag = 0;
164 if (pad->right.isHold() || pad->left.isHold()) { 167 if (pad->right.isHold() || pad->left.isHold()) {
165 if (pad->right.isHold()) { 168 if (pad->right.isHold()) {
166 node->xyz[0] += 5.0f; 169 node->xyz[0] += 5.0f;
170 node->angle[0] = 0.0f;
167 flag = 1; 171 flag = 1;
168 } else if (pad->left.isHold()) { 172 } else if (pad->left.isHold()) {
169 node->xyz[0] -= 5.0f; 173 node->xyz[0] -= 5.0f;
174 node->angle[0] = 180.0f;
170 flag = 1; 175 flag = 1;
171 } 176 }
172 } 177 }
173 178
174 if (pad->down.isHold() || pad->up.isHold() ) { 179 if (pad->down.isHold() || pad->up.isHold() ) {
179 node->xyz[1] -= 5.0f; 184 node->xyz[1] -= 5.0f;
180 flag = 1; 185 flag = 1;
181 } 186 }
182 } 187 }
183 188
184 /* ここで座標を送信 */ 189 /* ここで座標を送信 */
185 if (flag || node->resend_flag) { 190 if (flag || node->resend_flag) {
186 aquarium::send_position(node); 191 aquarium::send_position(node);
187 } 192 }
188 } 193 }
189 194
195 SceneGraphPtr sgp = viewer->createSceneGraph(); 200 SceneGraphPtr sgp = viewer->createSceneGraph();
196 viewer->createFromXMLmemory(sgp, (char *)addr, size); 201 viewer->createFromXMLmemory(sgp, (char *)addr, size);
197 sgp->set_move_collision(my_move, null_collision); 202 sgp->set_move_collision(my_move, null_collision);
198 203
199 par->addChild(sgp); 204 par->addChild(sgp);
205 sgp->c_xyz[0] = 0.0f;
206 sgp->c_xyz[1] = 0.0f;
207 sgp->c_xyz[2] = 0.0f;
200 208
201 int xml_id = serial_id * 10; 209 int xml_id = serial_id * 10;
202 psx_out(linda, xml_id, (unsigned char *)addr, size); 210 psx_out(linda, xml_id, (unsigned char *)addr, size);
203 int pos_id = serial_id * 10 + 1; 211 int pos_id = serial_id * 10 + 1;
204 212
205 aqua::Position *pos = new aqua::Position(); 213 aqua::Position *pos = new aqua::Position();
206 pos->set_x(0.0f + start_x); 214 pos->set_x(0.0f + start_x);
207 pos->set_y(0.0f); 215 pos->set_y(0.0f);
208 unsigned char *msg = (unsigned char *) viewer->manager->allocate(sizeof(unsigned char *) * size); 216 pos->set_angle_x(0.0f);
209 pos->SerializeToArray(msg, size); 217 pos->set_angle_y(0.0f);
218 unsigned char *msg = (unsigned char *) viewer->manager->allocate(sizeof(unsigned char *) * size);
219 pos->SerializeToArray(msg, size);
210 psx_out(linda, pos_id, (unsigned char *)msg, pos->ByteSize()); 220 psx_out(linda, pos_id, (unsigned char *)msg, pos->ByteSize());
211 delete pos; 221 delete pos;
212 sgp->seq = 0; 222 sgp->seq = 0;
213 sgp->resend_flag = 0; 223 sgp->resend_flag = 0;
214 } 224 }
215 225
216 MainLoopPtr 226 MainLoopPtr
217 aquarium::init(Viewer *sgroot, int screen_w, int screen_h) 227 aquarium::init(Viewer *sgroot, int screen_w, int screen_h)
218 { 228 {