annotate TaskManager/Test/test_render/task/update_sgp.cpp @ 109:5c194c71eca8

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