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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
1 #include <stdio.h>
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
2 #include <string.h>
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
3 #include <unistd.h>
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
4 #include <math.h>
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
5 #include "scene_graph_pack.h"
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
6 #include "sys.h"
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
7 #include "update_sgp.hpp"
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
8
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
9 SchedDefineTask(Update_SGP);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
10
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
11 typedef void (*moveFunc)(SceneGraphNodePtr, int, int);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
12 typedef void (*collFunc)(SceneGraphNodePtr, int, int);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
13
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
14 static moveFunc moveList[3];
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
15 static collFunc collList[3];
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
16
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
17 static void
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
18 move0(SceneGraphNodePtr node, int w, int h)
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
19 {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
20 static float dest_x = 0.3f;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
21 static float dest_y = 0.5f;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
22
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
23 node->angle[1] += 1.0f;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
24 if (node->angle[1] > 360.0f) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
25 node->angle[1] = 0.0f;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
26 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
27
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
28 node->obj_pos[0] += dest_x;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
29 if ((int)node->obj_pos[0] > w || (int)node->obj_pos[0] < 0) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
30 dest_x = -dest_x;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
31 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
32
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
33 node->obj_pos[1] += dest_y;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
34 if ((int)node->obj_pos[1] > h || (int)node->obj_pos[1] < 0) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
35 dest_y = -dest_y;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
36 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
37 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
38
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
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
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
56 move1(SceneGraphNodePtr node, int w, int h)
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
57 {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
58 node->angle[1] += 1.0f;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
59 if (node->angle[1] > 360.0f) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
60 node->angle[1] = 0.0f;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
61 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
62
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
63 static float dest_x = 0.5f;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
64 static float dest_y = 1.3f;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
65
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
66 node->obj_pos[0] += dest_x;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
67 if ((int)node->obj_pos[0] > w || (int)node->obj_pos[0] < 0) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
68 dest_x = -dest_x;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
69 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
70
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
71 node->obj_pos[1] += dest_y;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
72 if ((int)node->obj_pos[1] > h || (int)node->obj_pos[1] < 0) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
73 dest_y = -dest_y;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
74 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
75 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
76
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
77 static void
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
78 move2(SceneGraphNodePtr node, int w, int h)
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
79 {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
80 static float dest_x = 1.0f;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
81 static float dest_y = 0.8f;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
82
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
83 node->obj_pos[0] += dest_x;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
84 if ((int)node->obj_pos[0] > w || (int)node->obj_pos[0] < 0) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
85 dest_x = -dest_x;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
86 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
87
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
88 node->obj_pos[1] += dest_y;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
89 if ((int)node->obj_pos[1] > h || (int)node->obj_pos[1] < 0) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
90 dest_y = -dest_y;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
91 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
92 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
93
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
94
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
95 static void
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
96 coll(SceneGraphNodePtr node, int w, int h)
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
97 {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
98 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
99
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
100 static void
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
101 init(void)
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
102 {
132
9550e4ce2868 add XML
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 130
diff changeset
103 //moveList[0] = no_move;
9550e4ce2868 add XML
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 130
diff changeset
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
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
106 moveList[2] = move2;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
107
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
108 collList[0] = coll;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
109 collList[1] = coll;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
110 collList[2] = coll;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
111 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
112
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
113 int
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
114 Update_SGP::run(void *rbuf, void *wbuf)
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
115 {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
116 SceneGraphNodePtr node;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
117 SceneGraphPack *sgp = (SceneGraphPack*)get_input(rbuf, 0);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
118 SceneGraphPack *_sgp = (SceneGraphPack*)get_output(wbuf, 0);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
119 int screen_width = get_param(0);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
120 int screen_height = get_param(1);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
121
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
122 init();
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
123
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
124 // ϤǤ󤸤ʤ
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
125 for (int i = 0; i < sgp->info.size && i < 3; i++) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
126 node = &sgp->node[i];
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
127
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
128 do {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
129 moveList[i](node, screen_width, screen_height);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
130 collList[i](node, screen_width, screen_height);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
131
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
132 if (node->pn != -1) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
133 get_matrix(node->translation,
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
134 node->angle, node->obj_pos,
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
135 sgp->node[node->pn].translation);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
136 } else {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
137 get_matrix(node->translation,
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
138 node->angle, node->obj_pos,
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
139 NULL);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
140 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
141
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
142 node = node->next;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
143 } while (node);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
144 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
145
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
146 memcpy(_sgp, sgp, sizeof(SceneGraphPack));
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
147
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
148 return 0;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
149 }