annotate TaskManager/Test/test_render/cube_action.cpp @ 215:7ca6a2ef5be9

fix SceneGraph Constructor, Destructor
author gongo@gendarme.local
date Sun, 01 Feb 2009 22:14:44 +0900
parents 159519cdca1f
children 0f1ff7b06157
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
212
gongo@localhost.localdomain
parents: 195
diff changeset
1 #include "SceneGraphRoot.h"
gongo@localhost.localdomain
parents: 195
diff changeset
2 #include "SGList.h"
142
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
3
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
4 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
5 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
6 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
7 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
8 SceneGraphPtr tree);
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
9
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
10 static void cube_split(SceneGraphPtr root);
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
11
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
12 static void
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
13 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
14 {
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
15 node->xyz[0] -= node->stack_xyz[0];
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
16 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
17 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
18
144
gongo@localhost.localdomain
parents: 143
diff changeset
19 if (node->xyz[0] < 0) {
gongo@localhost.localdomain
parents: 143
diff changeset
20 node->set_move_collision(cube_move_right, cube_collision);
gongo@localhost.localdomain
parents: 143
diff changeset
21 }
gongo@localhost.localdomain
parents: 143
diff changeset
22
gongo@localhost.localdomain
parents: 143
diff changeset
23 if (node->xyz[1] < 0 || node->xyz[1] > screen_h) {
gongo@localhost.localdomain
parents: 143
diff changeset
24 node->stack_xyz[1] = -node->stack_xyz[1];
gongo@localhost.localdomain
parents: 143
diff changeset
25 }
gongo@localhost.localdomain
parents: 143
diff changeset
26
143
58eacf676bb5 add xml
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 142
diff changeset
27 node->angle[0] += 2.0f;
58eacf676bb5 add xml
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 142
diff changeset
28 node->angle[1] += 2.0f * node->stack_xyz[1];
58eacf676bb5 add xml
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 142
diff changeset
29 node->angle[2] += 2.0f * node->stack_xyz[2];
142
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
30
215
7ca6a2ef5be9 fix SceneGraph Constructor, Destructor
gongo@gendarme.local
parents: 213
diff changeset
31 if (node->frame > 10 && sgroot->controller->circle.isPush()) {
7ca6a2ef5be9 fix SceneGraph Constructor, Destructor
gongo@gendarme.local
parents: 213
diff changeset
32 cube_split(node);
213
159519cdca1f add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
33 }
142
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
34 }
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
35
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
36 static void
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
37 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
38 {
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
39 node->xyz[0] += node->stack_xyz[0];
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
40 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
41 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
42
144
gongo@localhost.localdomain
parents: 143
diff changeset
43 if (node->xyz[0] > screen_w) {
gongo@localhost.localdomain
parents: 143
diff changeset
44 node->set_move_collision(cube_move_left, cube_collision);
gongo@localhost.localdomain
parents: 143
diff changeset
45 }
gongo@localhost.localdomain
parents: 143
diff changeset
46
gongo@localhost.localdomain
parents: 143
diff changeset
47 if (node->xyz[1] < 0 || node->xyz[1] > screen_h) {
gongo@localhost.localdomain
parents: 143
diff changeset
48 node->stack_xyz[1] = -node->stack_xyz[1];
gongo@localhost.localdomain
parents: 143
diff changeset
49 }
gongo@localhost.localdomain
parents: 143
diff changeset
50
143
58eacf676bb5 add xml
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 142
diff changeset
51 node->angle[0] += 2.0f;
58eacf676bb5 add xml
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 142
diff changeset
52 node->angle[1] += 2.0f * node->stack_xyz[1];
58eacf676bb5 add xml
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 142
diff changeset
53 node->angle[2] += 2.0f * node->stack_xyz[2];
215
7ca6a2ef5be9 fix SceneGraph Constructor, Destructor
gongo@gendarme.local
parents: 213
diff changeset
54
7ca6a2ef5be9 fix SceneGraph Constructor, Destructor
gongo@gendarme.local
parents: 213
diff changeset
55 if (node->frame > 10 && sgroot->controller->circle.isPush()) {
7ca6a2ef5be9 fix SceneGraph Constructor, Destructor
gongo@gendarme.local
parents: 213
diff changeset
56 cube_split(node);
213
159519cdca1f add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
57 }
142
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
58 }
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
59
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
60 static void
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
61 cube_split(SceneGraphPtr root)
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
62 {
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
63 SceneGraphPtr p = root->clone();
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
64 root->addBrother(p);
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
65
215
7ca6a2ef5be9 fix SceneGraph Constructor, Destructor
gongo@gendarme.local
parents: 213
diff changeset
66 printf("%d %d\n", root->frame, p->frame);
7ca6a2ef5be9 fix SceneGraph Constructor, Destructor
gongo@gendarme.local
parents: 213
diff changeset
67 // TODO
7ca6a2ef5be9 fix SceneGraph Constructor, Destructor
gongo@gendarme.local
parents: 213
diff changeset
68 // 木の作り方変えたらここ消す
7ca6a2ef5be9 fix SceneGraph Constructor, Destructor
gongo@gendarme.local
parents: 213
diff changeset
69 p->frame = 0;
7ca6a2ef5be9 fix SceneGraph Constructor, Destructor
gongo@gendarme.local
parents: 213
diff changeset
70 root->frame = 0;
7ca6a2ef5be9 fix SceneGraph Constructor, Destructor
gongo@gendarme.local
parents: 213
diff changeset
71
142
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
72 root->set_move_collision(cube_move_left, cube_collision);
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
73 p->set_move_collision(cube_move_right, cube_collision);
213
159519cdca1f add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
74
142
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
75 p->xyz[0] = root->xyz[0] + 2;
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
76 p->xyz[1] = root->xyz[1];
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
77 p->xyz[2] = root->xyz[2];
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
78
143
58eacf676bb5 add xml
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 142
diff changeset
79 p->stack_xyz[0] = 2.0f;
142
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
80 p->stack_xyz[1] = random()%3-1;
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
81 p->stack_xyz[2] = random()%3-1;
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
82
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
83 root->xyz[0] -= 2;
143
58eacf676bb5 add xml
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 142
diff changeset
84 root->stack_xyz[0] = 2.0f;
142
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
85 root->stack_xyz[1] = random()%3-1;
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
86 root->stack_xyz[2] = random()%3-1;
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
87 }
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
88
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
89
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
90 static void
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
91 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
92 {
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
93 node->xyz[0] = screen_w/2;
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
94 node->xyz[1] = screen_h/2;
212
gongo@localhost.localdomain
parents: 195
diff changeset
95 //node->xyz[2] = -300.0f;
142
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
96
213
159519cdca1f add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
97 if (sgroot->controller->circle.isPush()) {
215
7ca6a2ef5be9 fix SceneGraph Constructor, Destructor
gongo@gendarme.local
parents: 213
diff changeset
98 cube_split(node);
213
159519cdca1f add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 212
diff changeset
99 }
142
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
100 }
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
101
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
102 static void
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
103 cube_collision(SceneGraphPtr node, int screen_w, int screen_h,
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
104 SceneGraphPtr tree)
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
105 {
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
106 }
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
107
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
108 void
144
gongo@localhost.localdomain
parents: 143
diff changeset
109 create_cube_split(int number)
142
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
110 {
212
gongo@localhost.localdomain
parents: 195
diff changeset
111 SceneGraphPtr cube;
gongo@localhost.localdomain
parents: 195
diff changeset
112
gongo@localhost.localdomain
parents: 195
diff changeset
113 //sgroot->createFromXMLfile("xml_file/cube_split.xml");
gongo@localhost.localdomain
parents: 195
diff changeset
114 sgroot->createFromXMLfile("xml_file/cube.xml");
gongo@localhost.localdomain
parents: 195
diff changeset
115
gongo@localhost.localdomain
parents: 195
diff changeset
116 //if (number == 0) {
gongo@localhost.localdomain
parents: 195
diff changeset
117 //cube = sgroot->createSceneGraph(SmallCube);
gongo@localhost.localdomain
parents: 195
diff changeset
118 //} else {
gongo@localhost.localdomain
parents: 195
diff changeset
119 cube = sgroot->createSceneGraph(Cube);
gongo@localhost.localdomain
parents: 195
diff changeset
120 cube->xyz[0] = 960.0f;
gongo@localhost.localdomain
parents: 195
diff changeset
121 cube->xyz[1] = 540.0f;
gongo@localhost.localdomain
parents: 195
diff changeset
122 //}
gongo@localhost.localdomain
parents: 195
diff changeset
123
gongo@localhost.localdomain
parents: 195
diff changeset
124 cube->set_move_collision(cube_move_idle, cube_collision);
gongo@localhost.localdomain
parents: 195
diff changeset
125
gongo@localhost.localdomain
parents: 195
diff changeset
126 sgroot->setSceneData(cube);
142
ff3fb47c2553 add xml
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
127 }