Mercurial > hg > Members > kono > Cerium
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 |
rev | line source |
---|---|
219
0f1ff7b06157
allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents:
215
diff
changeset
|
1 #include <math.h> |
212 | 2 #include "SceneGraphRoot.h" |
3 #include "SGList.h" | |
142 | 4 |
5 static void cube_move_left(SceneGraphPtr node, int screen_w, int screen_h); | |
6 static void cube_move_right(SceneGraphPtr node, int screen_w, int screen_h); | |
7 static void cube_move_idle(SceneGraphPtr node, int screen_w, int screen_h); | |
8 static void cube_collision(SceneGraphPtr node, int screen_w, int screen_h, | |
9 SceneGraphPtr tree); | |
10 | |
11 static void cube_split(SceneGraphPtr root); | |
12 | |
13 static void | |
14 cube_move_left(SceneGraphPtr node, int screen_w, int screen_h) | |
15 { | |
16 node->xyz[0] -= node->stack_xyz[0]; | |
17 node->xyz[1] -= node->stack_xyz[0] * node->stack_xyz[1]; | |
18 node->xyz[2] -= node->stack_xyz[0] * node->stack_xyz[2]; | |
19 | |
144 | 20 if (node->xyz[0] < 0) { |
21 node->set_move_collision(cube_move_right, cube_collision); | |
22 } | |
23 | |
24 if (node->xyz[1] < 0 || node->xyz[1] > screen_h) { | |
25 node->stack_xyz[1] = -node->stack_xyz[1]; | |
26 } | |
27 | |
143 | 28 node->angle[0] += 2.0f; |
29 node->angle[1] += 2.0f * node->stack_xyz[1]; | |
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 | 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 | 39 } |
40 | |
41 static void | |
42 cube_move_right(SceneGraphPtr node, int screen_w, int screen_h) | |
43 { | |
44 node->xyz[0] += node->stack_xyz[0]; | |
45 node->xyz[1] -= node->stack_xyz[0] * node->stack_xyz[1]; | |
46 node->xyz[2] -= node->stack_xyz[0] * node->stack_xyz[2]; | |
47 | |
144 | 48 if (node->xyz[0] > screen_w) { |
49 node->set_move_collision(cube_move_left, cube_collision); | |
50 } | |
51 | |
52 if (node->xyz[1] < 0 || node->xyz[1] > screen_h) { | |
53 node->stack_xyz[1] = -node->stack_xyz[1]; | |
54 } | |
55 | |
143 | 56 node->angle[0] += 2.0f; |
57 node->angle[1] += 2.0f * node->stack_xyz[1]; | |
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 | 67 } |
68 | |
69 static void | |
70 cube_split(SceneGraphPtr root) | |
71 { | |
72 SceneGraphPtr p = root->clone(); | |
73 root->addBrother(p); | |
74 | |
75 root->set_move_collision(cube_move_left, cube_collision); | |
76 p->set_move_collision(cube_move_right, cube_collision); | |
219
0f1ff7b06157
allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents:
215
diff
changeset
|
77 |
142 | 78 p->xyz[0] = root->xyz[0] + 2; |
79 p->xyz[1] = root->xyz[1]; | |
80 p->xyz[2] = root->xyz[2]; | |
81 | |
143 | 82 p->stack_xyz[0] = 2.0f; |
142 | 83 p->stack_xyz[1] = random()%3-1; |
84 p->stack_xyz[2] = random()%3-1; | |
85 | |
86 root->xyz[0] -= 2; | |
143 | 87 root->stack_xyz[0] = 2.0f; |
142 | 88 root->stack_xyz[1] = random()%3-1; |
89 root->stack_xyz[2] = random()%3-1; | |
90 } | |
91 | |
92 | |
93 static void | |
94 cube_move_idle(SceneGraphPtr node, int screen_w, int screen_h) | |
95 { | |
96 node->xyz[0] = screen_w/2; | |
97 node->xyz[1] = screen_h/2; | |
212 | 98 //node->xyz[2] = -300.0f; |
142 | 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 | 103 } |
104 | |
105 static void | |
106 cube_collision(SceneGraphPtr node, int screen_w, int screen_h, | |
107 SceneGraphPtr tree) | |
108 { | |
109 } | |
110 | |
111 void | |
144 | 112 create_cube_split(int number) |
142 | 113 { |
212 | 114 SceneGraphPtr cube; |
219
0f1ff7b06157
allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents:
215
diff
changeset
|
115 SceneGraphPtr back; |
212 | 116 |
117 sgroot->createFromXMLfile("xml_file/cube.xml"); | |
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 | 124 cube = sgroot->createSceneGraph(Cube); |
125 cube->xyz[0] = 960.0f; | |
126 cube->xyz[1] = 540.0f; | |
127 cube->set_move_collision(cube_move_idle, cube_collision); | |
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 | 132 } |