109
|
1 #include <stdio.h>
|
|
2 #include <string.h>
|
|
3 #include <unistd.h>
|
|
4 #include <math.h>
|
|
5 #include "scene_graph_pack.h"
|
|
6 #include "sys.h"
|
|
7 #include "update_sgp.hpp"
|
|
8
|
|
9 SchedDefineTask(Update_SGP);
|
|
10
|
|
11 typedef void (*moveFunc)(SceneGraphNodePtr, int, int);
|
|
12 typedef void (*collFunc)(SceneGraphNodePtr, int, int);
|
|
13
|
|
14 static moveFunc moveList[3];
|
|
15 static collFunc collList[3];
|
|
16
|
|
17 static void
|
|
18 move0(SceneGraphNodePtr node, int w, int h)
|
|
19 {
|
|
20 static float dest_x = 0.3f;
|
|
21 static float dest_y = 0.5f;
|
|
22
|
|
23 node->angle[1] += 1.0f;
|
|
24 if (node->angle[1] > 360.0f) {
|
|
25 node->angle[1] = 0.0f;
|
|
26 }
|
|
27
|
|
28 node->obj_pos[0] += dest_x;
|
|
29 if ((int)node->obj_pos[0] > w || (int)node->obj_pos[0] < 0) {
|
|
30 dest_x = -dest_x;
|
|
31 }
|
|
32
|
|
33 node->obj_pos[1] += dest_y;
|
|
34 if ((int)node->obj_pos[1] > h || (int)node->obj_pos[1] < 0) {
|
|
35 dest_y = -dest_y;
|
|
36 }
|
|
37 }
|
|
38
|
|
39 static void
|
|
40 move1(SceneGraphNodePtr node, int w, int h)
|
|
41 {
|
|
42 node->angle[1] += 1.0f;
|
|
43 if (node->angle[1] > 360.0f) {
|
|
44 node->angle[1] = 0.0f;
|
|
45 }
|
|
46
|
|
47 static float dest_x = 0.5f;
|
|
48 static float dest_y = 1.3f;
|
|
49
|
|
50 node->obj_pos[0] += dest_x;
|
|
51 if ((int)node->obj_pos[0] > w || (int)node->obj_pos[0] < 0) {
|
|
52 dest_x = -dest_x;
|
|
53 }
|
|
54
|
|
55 node->obj_pos[1] += dest_y;
|
|
56 if ((int)node->obj_pos[1] > h || (int)node->obj_pos[1] < 0) {
|
|
57 dest_y = -dest_y;
|
|
58 }
|
|
59 }
|
|
60
|
|
61 static void
|
|
62 move2(SceneGraphNodePtr node, int w, int h)
|
|
63 {
|
|
64 node->angle[1] += 1.0f;
|
|
65 if (node->angle[1] > 360.0f) {
|
|
66 node->angle[1] = 0.0f;
|
|
67 }
|
|
68
|
|
69 static float dest_x = 1.0f;
|
|
70 static float dest_y = 0.8f;
|
|
71
|
|
72 node->obj_pos[0] += dest_x;
|
|
73 if ((int)node->obj_pos[0] > w || (int)node->obj_pos[0] < 0) {
|
|
74 dest_x = -dest_x;
|
|
75 }
|
|
76
|
|
77 node->obj_pos[1] += dest_y;
|
|
78 if ((int)node->obj_pos[1] > h || (int)node->obj_pos[1] < 0) {
|
|
79 dest_y = -dest_y;
|
|
80 }
|
|
81 }
|
|
82
|
|
83
|
|
84 static void
|
|
85 coll(SceneGraphNodePtr node, int w, int h)
|
|
86 {
|
|
87 }
|
|
88
|
|
89 static void
|
|
90 init(void)
|
|
91 {
|
|
92 moveList[0] = move0;
|
|
93 moveList[1] = move1;
|
|
94 moveList[2] = move2;
|
|
95
|
|
96 collList[0] = coll;
|
|
97 collList[1] = coll;
|
|
98 collList[2] = coll;
|
|
99 }
|
|
100
|
|
101 int
|
|
102 Update_SGP::run(void *rbuf, void *wbuf)
|
|
103 {
|
|
104 SceneGraphNodePtr node;
|
|
105 SceneGraphPack *sgp = (SceneGraphPack*)get_input(rbuf, 0);
|
|
106 SceneGraphPack *_sgp = (SceneGraphPack*)get_output(wbuf, 0);
|
|
107 int screen_width = get_param(0);
|
|
108 int screen_height = get_param(1);
|
|
109
|
|
110 init();
|
|
111
|
|
112 // 本当はここでやるもんじゃないんだが。。。
|
|
113 for (int i = 0; i < sgp->info.size && i < 3; i++) {
|
|
114 node = &sgp->node[i];
|
|
115
|
|
116 do {
|
|
117 moveList[i](node, screen_width, screen_height);
|
|
118 collList[i](node, screen_width, screen_height);
|
|
119
|
|
120 if (node->pn != -1) {
|
|
121 get_matrix(node->translation,
|
|
122 node->angle, node->obj_pos,
|
|
123 sgp->node[node->pn].translation);
|
|
124 } else {
|
|
125 get_matrix(node->translation,
|
|
126 node->angle, node->obj_pos,
|
|
127 NULL);
|
|
128 }
|
|
129
|
|
130 node = node->next;
|
|
131 } while (node);
|
|
132 }
|
|
133
|
|
134 memcpy(_sgp, sgp, sizeof(SceneGraphPack));
|
|
135
|
|
136 return 0;
|
|
137 }
|