Mercurial > hg > Game > Cerium
annotate TaskManager/Test/test_render/task/update_sgp.cpp @ 132:9550e4ce2868 draft
add XML
author | gongo@charles.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Tue, 25 Nov 2008 18:19:53 +0900 |
parents | 40978d4b608a |
children | 8f1419174cdf |
rev | line source |
---|---|
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 | |
123
e9e12e2088bd
delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
109
diff
changeset
|
40 move3(SceneGraphNodePtr node, int w, int h) |
e9e12e2088bd
delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
109
diff
changeset
|
41 { |
e9e12e2088bd
delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
109
diff
changeset
|
42 node->angle[1] += 1.0f; |
e9e12e2088bd
delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
109
diff
changeset
|
43 if (node->angle[1] > 360.0f) { |
e9e12e2088bd
delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
109
diff
changeset
|
44 node->angle[1] = 0.0f; |
e9e12e2088bd
delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
109
diff
changeset
|
45 } |
e9e12e2088bd
delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
109
diff
changeset
|
46 } |
e9e12e2088bd
delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
109
diff
changeset
|
47 |
e9e12e2088bd
delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
109
diff
changeset
|
48 static void |
128
95e2046eb46f
texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
123
diff
changeset
|
49 no_move(SceneGraphNodePtr node, int w, int h) |
95e2046eb46f
texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
123
diff
changeset
|
50 { |
130
40978d4b608a
テクスチャの大きさを128x128以外にも使えるように。(若干バグ有り)
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
128
diff
changeset
|
51 node->obj_pos[0] = 0; |
40978d4b608a
テクスチャの大きさを128x128以外にも使えるように。(若干バグ有り)
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
128
diff
changeset
|
52 node->obj_pos[1] = 0; |
128
95e2046eb46f
texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
123
diff
changeset
|
53 } |
95e2046eb46f
texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
123
diff
changeset
|
54 |
95e2046eb46f
texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
123
diff
changeset
|
55 static void |
109 | 56 move1(SceneGraphNodePtr node, int w, int h) |
57 { | |
58 node->angle[1] += 1.0f; | |
59 if (node->angle[1] > 360.0f) { | |
60 node->angle[1] = 0.0f; | |
61 } | |
62 | |
63 static float dest_x = 0.5f; | |
64 static float dest_y = 1.3f; | |
65 | |
66 node->obj_pos[0] += dest_x; | |
67 if ((int)node->obj_pos[0] > w || (int)node->obj_pos[0] < 0) { | |
68 dest_x = -dest_x; | |
69 } | |
70 | |
71 node->obj_pos[1] += dest_y; | |
72 if ((int)node->obj_pos[1] > h || (int)node->obj_pos[1] < 0) { | |
73 dest_y = -dest_y; | |
74 } | |
75 } | |
76 | |
77 static void | |
78 move2(SceneGraphNodePtr node, int w, int h) | |
79 { | |
80 static float dest_x = 1.0f; | |
81 static float dest_y = 0.8f; | |
82 | |
83 node->obj_pos[0] += dest_x; | |
84 if ((int)node->obj_pos[0] > w || (int)node->obj_pos[0] < 0) { | |
85 dest_x = -dest_x; | |
86 } | |
87 | |
88 node->obj_pos[1] += dest_y; | |
89 if ((int)node->obj_pos[1] > h || (int)node->obj_pos[1] < 0) { | |
90 dest_y = -dest_y; | |
91 } | |
92 } | |
93 | |
94 | |
95 static void | |
96 coll(SceneGraphNodePtr node, int w, int h) | |
97 { | |
98 } | |
99 | |
100 static void | |
101 init(void) | |
102 { | |
132 | 103 //moveList[0] = no_move; |
104 moveList[0] = move2; | |
123
e9e12e2088bd
delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
109
diff
changeset
|
105 moveList[1] = move3; |
109 | 106 moveList[2] = move2; |
107 | |
108 collList[0] = coll; | |
109 collList[1] = coll; | |
110 collList[2] = coll; | |
111 } | |
112 | |
113 int | |
114 Update_SGP::run(void *rbuf, void *wbuf) | |
115 { | |
116 SceneGraphNodePtr node; | |
117 SceneGraphPack *sgp = (SceneGraphPack*)get_input(rbuf, 0); | |
118 SceneGraphPack *_sgp = (SceneGraphPack*)get_output(wbuf, 0); | |
119 int screen_width = get_param(0); | |
120 int screen_height = get_param(1); | |
121 | |
122 init(); | |
123 | |
124 // ϤǤʤ | |
125 for (int i = 0; i < sgp->info.size && i < 3; i++) { | |
126 node = &sgp->node[i]; | |
127 | |
128 do { | |
129 moveList[i](node, screen_width, screen_height); | |
130 collList[i](node, screen_width, screen_height); | |
131 | |
132 if (node->pn != -1) { | |
133 get_matrix(node->translation, | |
134 node->angle, node->obj_pos, | |
135 sgp->node[node->pn].translation); | |
136 } else { | |
137 get_matrix(node->translation, | |
138 node->angle, node->obj_pos, | |
139 NULL); | |
140 } | |
141 | |
142 node = node->next; | |
143 } while (node); | |
144 } | |
145 | |
146 memcpy(_sgp, sgp, sizeof(SceneGraphPack)); | |
147 | |
148 return 0; | |
149 } |