comparison Renderer/Test/cube_action.cc @ 508:f6daf964f483

reorganization
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 12 Oct 2009 09:43:07 +0900
parents Renderer/Application/cube_action.cc@735f76483bb2
children
comparison
equal deleted inserted replaced
507:735f76483bb2 508:f6daf964f483
1 #include <math.h>
2 #include "SceneGraphRoot.h"
3 #include "SGList.h"
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
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
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];
31
32 node->angle[0] = fmodf(node->angle[0], 360.0f);
33 node->angle[1] = fmodf(node->angle[1], 360.0f);
34 node->angle[2] = fmodf(node->angle[2], 360.0f);
35
36 if (node->frame > 10 && sgroot->controller->circle.isPush()) {
37 cube_split(node);
38 }
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
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
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];
59
60 node->angle[0] = fmodf(node->angle[0], 360.0f);
61 node->angle[1] = fmodf(node->angle[1], 360.0f);
62 node->angle[2] = fmodf(node->angle[2], 360.0f);
63
64 if (node->frame > 10 && sgroot->controller->circle.isPush()) {
65 cube_split(node);
66 }
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);
77
78 p->xyz[0] = root->xyz[0] + 2;
79 p->xyz[1] = root->xyz[1];
80 p->xyz[2] = root->xyz[2];
81
82 p->stack_xyz[0] = 2.0f;
83 p->stack_xyz[1] = random()%3-1;
84 p->stack_xyz[2] = random()%3-1;
85
86 root->xyz[0] -= 2;
87 root->stack_xyz[0] = 2.0f;
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;
98 //node->xyz[2] = -300.0f;
99
100 if (sgroot->controller->circle.isPush()) {
101 cube_split(node);
102 }
103 }
104
105 static void
106 cube_collision(SceneGraphPtr node, int screen_w, int screen_h,
107 SceneGraphPtr tree)
108 {
109 }
110
111 void
112 create_cube_split(TaskManager *manager, int number)
113 {
114 SceneGraphPtr cube;
115 SceneGraphPtr back;
116
117 sgroot->createFromXMLfile(manager, "xml_file/cube.xml");
118
119 // 何もしない親
120 // cube は brother として繋がっていくので
121 // 親が居ないとだめ。
122 back = sgroot->createSceneGraph();
123
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
129 back->addChild(cube);
130
131 sgroot->setSceneData(back);
132 }