283
|
1 #include <stdlib.h>
|
|
2 #include "SceneGraph.h"
|
|
3 #include "xml_file/cube.h"
|
|
4
|
|
5 static void
|
|
6 cube_collision(SceneGraphPtr node, int screen_w, int screen_h,
|
|
7 SceneGraphPtr tree)
|
|
8 {
|
|
9 }
|
|
10
|
|
11 static void
|
|
12 cube_move2(SceneGraphPtr node, int screen_w, int screen_h)
|
|
13 {
|
|
14 node->angle[1] += 1.0f;
|
|
15 if (node->angle[1] > 360.0f) {
|
|
16 node->angle[1] = 0.0f;
|
|
17 }
|
|
18
|
|
19 node->xyz[0] += node->stack_xyz[0];
|
|
20 if ((int)node->xyz[0] > screen_w || (int)node->xyz[0] < 0) {
|
|
21 node->stack_xyz[0] = -node->stack_xyz[0];
|
|
22 }
|
|
23
|
|
24 node->xyz[1] += node->stack_xyz[1];
|
|
25 if ((int)node->xyz[1] > screen_h || (int)node->xyz[1] < 0) {
|
|
26 node->stack_xyz[1] = -node->stack_xyz[1];
|
|
27 }
|
|
28 }
|
|
29
|
|
30 static void
|
|
31 cube_move(SceneGraphPtr node, int screen_w, int screen_h)
|
|
32 {
|
|
33 node->angle[1] += 1.0f;
|
|
34 if (node->angle[1] > 360.0f) {
|
|
35 node->angle[1] = 0.0f;
|
|
36 }
|
|
37
|
|
38 node->xyz[0] += node->stack_xyz[0];
|
|
39 if ((int)node->xyz[0] > screen_w || (int)node->xyz[0] < 0) {
|
|
40 node->stack_xyz[0] = -node->stack_xyz[0];
|
|
41 }
|
|
42
|
|
43 node->xyz[1] += node->stack_xyz[1];
|
|
44 if ((int)node->xyz[1] > screen_h || (int)node->xyz[1] < 0) {
|
|
45
|
|
46 // 実は微妙に意味が無い
|
|
47 srandom(random());
|
|
48
|
|
49 SceneGraphPtr p = node->clone();
|
|
50 p->position_init();
|
|
51 node->addBrother(p);
|
|
52 p->set_move_collision(cube_move2, cube_collision);
|
|
53 p->stack_xyz[0] = (float)(random() % 5);
|
|
54 p->stack_xyz[1] = (float)(random() % 5);
|
|
55 //p->xyz[0] = screen_w/2;
|
|
56 //p->xyz[1] = screen_h/2;
|
|
57 p->xyz[2] = node->xyz[2]+1000.0f;
|
|
58
|
|
59 node->stack_xyz[1] = -node->stack_xyz[1];
|
|
60 }
|
|
61 }
|
|
62
|
|
63 void
|
|
64 node_init(void)
|
|
65 {
|
|
66 SceneGraph::createFromXMLfile("xml_file/cube.xml");
|
|
67 Cube->set_move_collision(cube_move, cube_collision);
|
|
68 Cube->stack_xyz[0] = 2.0f;
|
|
69 Cube->stack_xyz[1] = 2.0f;
|
|
70 }
|