annotate TaskManager/Test/test_render/cube_action.cpp @ 224:ebfb9e389716

SceneGraph.cpp xmlcreate
author tkaito@nw0534.st.ie.u-ryukyu.ac.jp
date Tue, 10 Feb 2009 20:45:51 +0900
parents 0f1ff7b06157
children a4f690f44842
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
219
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
1 #include <math.h>
212
gongo@localhost.localdomain
parents: 195
diff changeset
2 #include "SceneGraphRoot.h"
gongo@localhost.localdomain
parents: 195
diff changeset
3 #include "SGList.h"
142
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
4
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
5 static void cube_move_left(SceneGraphPtr node, int screen_w, int screen_h);
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
6 static void cube_move_right(SceneGraphPtr node, int screen_w, int screen_h);
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
7 static void cube_move_idle(SceneGraphPtr node, int screen_w, int screen_h);
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
8 static void cube_collision(SceneGraphPtr node, int screen_w, int screen_h,
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
9 SceneGraphPtr tree);
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
10
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
11 static void cube_split(SceneGraphPtr root);
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
12
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
13 static void
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
14 cube_move_left(SceneGraphPtr node, int screen_w, int screen_h)
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
15 {
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
16 node->xyz[0] -= node->stack_xyz[0];
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
17 node->xyz[1] -= node->stack_xyz[0] * node->stack_xyz[1];
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
18 node->xyz[2] -= node->stack_xyz[0] * node->stack_xyz[2];
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
19
144
gongo@localhost.localdomain
parents: 143
diff changeset
20 if (node->xyz[0] < 0) {
gongo@localhost.localdomain
parents: 143
diff changeset
21 node->set_move_collision(cube_move_right, cube_collision);
gongo@localhost.localdomain
parents: 143
diff changeset
22 }
gongo@localhost.localdomain
parents: 143
diff changeset
23
gongo@localhost.localdomain
parents: 143
diff changeset
24 if (node->xyz[1] < 0 || node->xyz[1] > screen_h) {
gongo@localhost.localdomain
parents: 143
diff changeset
25 node->stack_xyz[1] = -node->stack_xyz[1];
gongo@localhost.localdomain
parents: 143
diff changeset
26 }
gongo@localhost.localdomain
parents: 143
diff changeset
27
143
58eacf676bb5 add xml
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 142
diff changeset
28 node->angle[0] += 2.0f;
58eacf676bb5 add xml
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 142
diff changeset
29 node->angle[1] += 2.0f * node->stack_xyz[1];
58eacf676bb5 add xml
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 142
diff changeset
30 node->angle[2] += 2.0f * node->stack_xyz[2];
219
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
31
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
32 node->angle[0] = fmodf(node->angle[0], 360.0f);
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
33 node->angle[1] = fmodf(node->angle[1], 360.0f);
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
34 node->angle[2] = fmodf(node->angle[2], 360.0f);
142
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
35
215
7ca6a2ef5be9 fix SceneGraph Constructor, Destructor
gongo@gendarme.local
parents: 213
diff changeset
36 if (node->frame > 10 && sgroot->controller->circle.isPush()) {
7ca6a2ef5be9 fix SceneGraph Constructor, Destructor
gongo@gendarme.local
parents: 213
diff changeset
37 cube_split(node);
213
159519cdca1f add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
38 }
142
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
39 }
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
40
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
41 static void
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
42 cube_move_right(SceneGraphPtr node, int screen_w, int screen_h)
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
43 {
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
44 node->xyz[0] += node->stack_xyz[0];
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
45 node->xyz[1] -= node->stack_xyz[0] * node->stack_xyz[1];
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
46 node->xyz[2] -= node->stack_xyz[0] * node->stack_xyz[2];
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
47
144
gongo@localhost.localdomain
parents: 143
diff changeset
48 if (node->xyz[0] > screen_w) {
gongo@localhost.localdomain
parents: 143
diff changeset
49 node->set_move_collision(cube_move_left, cube_collision);
gongo@localhost.localdomain
parents: 143
diff changeset
50 }
gongo@localhost.localdomain
parents: 143
diff changeset
51
gongo@localhost.localdomain
parents: 143
diff changeset
52 if (node->xyz[1] < 0 || node->xyz[1] > screen_h) {
gongo@localhost.localdomain
parents: 143
diff changeset
53 node->stack_xyz[1] = -node->stack_xyz[1];
gongo@localhost.localdomain
parents: 143
diff changeset
54 }
gongo@localhost.localdomain
parents: 143
diff changeset
55
143
58eacf676bb5 add xml
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 142
diff changeset
56 node->angle[0] += 2.0f;
58eacf676bb5 add xml
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 142
diff changeset
57 node->angle[1] += 2.0f * node->stack_xyz[1];
58eacf676bb5 add xml
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 142
diff changeset
58 node->angle[2] += 2.0f * node->stack_xyz[2];
219
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
59
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
60 node->angle[0] = fmodf(node->angle[0], 360.0f);
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
61 node->angle[1] = fmodf(node->angle[1], 360.0f);
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
62 node->angle[2] = fmodf(node->angle[2], 360.0f);
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
63
215
7ca6a2ef5be9 fix SceneGraph Constructor, Destructor
gongo@gendarme.local
parents: 213
diff changeset
64 if (node->frame > 10 && sgroot->controller->circle.isPush()) {
7ca6a2ef5be9 fix SceneGraph Constructor, Destructor
gongo@gendarme.local
parents: 213
diff changeset
65 cube_split(node);
213
159519cdca1f add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
66 }
142
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
67 }
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
68
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
69 static void
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
70 cube_split(SceneGraphPtr root)
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
71 {
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
72 SceneGraphPtr p = root->clone();
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
73 root->addBrother(p);
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
74
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
75 root->set_move_collision(cube_move_left, cube_collision);
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
76 p->set_move_collision(cube_move_right, cube_collision);
219
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
77
142
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
78 p->xyz[0] = root->xyz[0] + 2;
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
79 p->xyz[1] = root->xyz[1];
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
80 p->xyz[2] = root->xyz[2];
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
81
143
58eacf676bb5 add xml
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 142
diff changeset
82 p->stack_xyz[0] = 2.0f;
142
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
83 p->stack_xyz[1] = random()%3-1;
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
84 p->stack_xyz[2] = random()%3-1;
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
85
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
86 root->xyz[0] -= 2;
143
58eacf676bb5 add xml
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 142
diff changeset
87 root->stack_xyz[0] = 2.0f;
142
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
88 root->stack_xyz[1] = random()%3-1;
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
89 root->stack_xyz[2] = random()%3-1;
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
90 }
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
91
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
92
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
93 static void
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
94 cube_move_idle(SceneGraphPtr node, int screen_w, int screen_h)
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
95 {
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
96 node->xyz[0] = screen_w/2;
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
97 node->xyz[1] = screen_h/2;
212
gongo@localhost.localdomain
parents: 195
diff changeset
98 //node->xyz[2] = -300.0f;
142
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
99
213
159519cdca1f add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
100 if (sgroot->controller->circle.isPush()) {
215
7ca6a2ef5be9 fix SceneGraph Constructor, Destructor
gongo@gendarme.local
parents: 213
diff changeset
101 cube_split(node);
213
159519cdca1f add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
102 }
142
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
103 }
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
104
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
105 static void
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
106 cube_collision(SceneGraphPtr node, int screen_w, int screen_h,
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
107 SceneGraphPtr tree)
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
108 {
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
109 }
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
110
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
111 void
144
gongo@localhost.localdomain
parents: 143
diff changeset
112 create_cube_split(int number)
142
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
113 {
212
gongo@localhost.localdomain
parents: 195
diff changeset
114 SceneGraphPtr cube;
219
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
115 SceneGraphPtr back;
212
gongo@localhost.localdomain
parents: 195
diff changeset
116
gongo@localhost.localdomain
parents: 195
diff changeset
117 sgroot->createFromXMLfile("xml_file/cube.xml");
gongo@localhost.localdomain
parents: 195
diff changeset
118
219
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
119 // 何もしない親
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
120 // cube は brother として繋がっていくので
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
121 // 親が居ないとだめ。
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
122 back = sgroot->createSceneGraph();
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
123
212
gongo@localhost.localdomain
parents: 195
diff changeset
124 cube = sgroot->createSceneGraph(Cube);
gongo@localhost.localdomain
parents: 195
diff changeset
125 cube->xyz[0] = 960.0f;
gongo@localhost.localdomain
parents: 195
diff changeset
126 cube->xyz[1] = 540.0f;
gongo@localhost.localdomain
parents: 195
diff changeset
127 cube->set_move_collision(cube_move_idle, cube_collision);
gongo@localhost.localdomain
parents: 195
diff changeset
128
219
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
129 back->addChild(cube);
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
130
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
131 sgroot->setSceneData(back);
142
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
132 }