annotate TaskManager/Test/test_render/universe.cpp @ 198:b832e6cff83e draft

rename snake_bg to panel
author gongo@gendarme.cr.ie.u-ryukyu.ac.jp
date Mon, 26 Jan 2009 10:38:29 +0900
parents 4e66b3327c50
children 1fd0107ebb25
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
1 #include <stdlib.h>
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
2 #include "SceneGraphRoot.h"
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
3 #include "SGList.h"
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
4
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
5 int moonrem = 0;
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
6
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
7 static void
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
8 cube_collision(SceneGraphPtr node, int screen_w, int screen_h,
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
9 SceneGraphPtr tree)
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
10 {
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
11 }
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
12
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
13 static void
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
14 moon_collision(SceneGraphPtr node, int screen_w, int screen_h,
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
15 SceneGraphPtr tree)
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
16 {
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
17 }
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
18
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
19 static void
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
20 moon_move(SceneGraphPtr node, int screen_w, int screen_h)
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
21 {
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
22 node->angle[0] += 3.0f;
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
23 printf("%f\n", node->angle[0]);
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
24 if (node->angle[0] > 360.0f) {
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
25 node->remove();
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
26 //node->angle[0] = 0.0f;
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
27 moonrem = 1;
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
28 }
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
29 }
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
30
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
31
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
32 static void
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
33 cube_move(SceneGraphPtr node, int screen_w, int screen_h)
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
34 {
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
35 node->angle[1] += 1.0f;
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
36 if (node->angle[1] > 360.0f) {
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
37 node->angle[1] = 0.0f;
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
38 if (moonrem) {
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
39 SceneGraphPtr moon = sgroot->createSceneGraph(Moon);
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
40 moon->set_move_collision(moon_move, moon_collision);
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
41 node->addChild(moon);
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
42 moonrem = 0;
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
43 }
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
44 }
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
45
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
46 node->xyz[0] += node->stack_xyz[0];
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
47 if ((int)node->xyz[0] > screen_w || (int)node->xyz[0] < 0) {
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
48 node->stack_xyz[0] = -node->stack_xyz[0];
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
49 }
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
50
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
51 node->xyz[1] += node->stack_xyz[1];
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
52 if ((int)node->xyz[1] > screen_h || (int)node->xyz[1] < 0) {
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
53 node->stack_xyz[1] = -node->stack_xyz[1];
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
54 }
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
55 }
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
56
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
57 void
198
b832e6cff83e rename snake_bg to panel
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 195
diff changeset
58 universe_init(void)
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
59 {
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
60 SceneGraphPtr earth;
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
61 SceneGraphPtr moon;
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
62
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
63 sgroot->createFromXMLfile("xml_file/universe.xml");
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
64
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
65 // SGList.h にある SceneGraph ID から SceneGraph を生成する
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
66 earth = sgroot->createSceneGraph(Earth);
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
67 moon = sgroot->createSceneGraph(Moon);
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
68
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
69 // SceneGraph の move と collision を設定
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
70 earth->set_move_collision(cube_move, cube_collision);
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
71 earth->stack_xyz[0] = 3.0f;
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
72 earth->stack_xyz[1] = 3.0f;
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
73 moon->set_move_collision(moon_move, moon_collision);
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
74
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
75 // SceneGraph 同士の親子関係を設定 (今回は 親 earth、子 moon)
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
76 earth->addChild(moon);
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
77
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
78 // SceneGraphRoot に、使用する SceneGraph を設定する
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
79 // このとき、ユーザーが記述した SceneGraph の root を渡す。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
80 sgroot->setSceneData(earth);
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
81 }