Mercurial > hg > Members > kono > Cerium
annotate Renderer/Test/property_universe.cc @ 1006:443c01049702
correct code.
author | koba <koba@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 26 Oct 2010 17:41:41 +0900 |
parents | 2a00c1f470b7 |
children |
rev | line source |
---|---|
767 | 1 #include <math.h> |
2 #include <stdlib.h> | |
3 #include "SceneGraphRoot.h" | |
4 #include "MainLoop.h" | |
5 #include "property_universe.h" | |
6 #include "types.h" | |
7 #include "Func.h" | |
8 #include "sys.h" | |
9 #include "SgChange.h" | |
10 | |
769
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
11 static const int PROPERTY_LENGTH = 2; |
767 | 12 |
13 Property *property, *update_property; | |
14 | |
15 // prototype | |
16 static void collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, SceneGraphPtr tree); | |
17 static void move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h); | |
18 static void createSceneGraphFromProperty(SchedTask *s, void *sgroot, void *arg1); | |
769
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
19 static void set_property(Property *p, SceneGraphPtr sg, int index); |
767 | 20 static void apply_property(SceneGraphPtr sg, Property *p); |
21 static void regist_task(SceneGraphRoot *sgroot); | |
22 static void set_relation(SceneGraphPtr parent, SceneGraphPtr child); | |
23 | |
24 static void | |
25 move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) | |
26 { | |
27 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; | |
28 HTaskPtr property_task = sgroot->move_exec_task; | |
29 | |
769
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
30 property_task->add_inData(property, sizeof(Property)*PROPERTY_LENGTH); |
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
31 property_task->add_outData(update_property, sizeof(Property)*PROPERTY_LENGTH); |
767 | 32 property_task->set_cpu(SPE_ANY); |
33 property_task->set_post(createSceneGraphFromProperty, (void *)sgroot, 0); | |
34 property_task->spawn(); | |
35 } | |
36 | |
37 static void | |
38 collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, | |
39 SceneGraphPtr tree) | |
40 { | |
41 } | |
42 | |
43 static void | |
44 createSceneGraphFromProperty(SchedTask *s, void *sgroot_, void *arg1) | |
45 { | |
46 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; | |
47 SceneGraphPtr camera = sgroot->camera; | |
48 SceneGraphPtr p_node; | |
769
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
49 |
767 | 50 // ここが allExecute の tree をたどって clone して行くところに相当する |
51 Property *p; | |
769
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
52 |
767 | 53 for (int i = 0; i < PROPERTY_LENGTH; i++) { |
54 p = &update_property[i]; | |
769
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
55 SceneGraphPtr node = sgroot->createSceneGraph(p->name); |
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
56 if (strcmp(node->name, "Earth") == 0) { |
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
57 node->set_move_collision(move, collision); |
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
58 } |
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
59 apply_property(node, p); |
767 | 60 } |
61 | |
62 for (int j = 0; j < PROPERTY_LENGTH; j++) { | |
63 p = &update_property[j]; | |
769
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
64 p_node = (SceneGraphPtr)p->node; |
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
65 if (p->have_parent) { |
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
66 SceneGraphPtr parent = (SceneGraphPtr)update_property[p->parent_index].node; |
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
67 parent->addChild(p_node); |
767 | 68 get_matrix(p_node->matrix, p_node->angle, p_node->xyz, parent->matrix); |
69 get_matrix(p_node->real_matrix, p_node->angle, p_node->xyz, parent->real_matrix); | |
70 } else { | |
71 get_matrix(p_node->matrix, p_node->angle, p_node->xyz, camera->matrix); | |
72 get_matrix(p_node->real_matrix, p_node->angle, p_node->xyz, camera->real_matrix); | |
73 } | |
74 } | |
75 | |
769
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
76 sgroot->setSceneData((SceneGraphPtr)update_property[0].node); |
767 | 77 |
78 Property *tmp = property; | |
79 property = update_property; | |
80 update_property = tmp; | |
81 | |
82 sgroot->move_finish(); | |
83 } | |
84 | |
85 static void | |
86 apply_property(SceneGraphPtr node, Property *p) | |
87 { | |
88 for (int i = 0; i < 3; i++) { | |
89 node->xyz[i] = p->xyz[i]; | |
90 node->angle[i] = p->angle[i]; | |
91 node->stack_xyz[i] = p->stack_xyz[i]; | |
92 } | |
769
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
93 p->node = (memaddr)node; |
767 | 94 node->property = (memaddr)p; |
95 } | |
96 | |
97 /* | |
98 ここで必要な値をプロパティに格納 | |
99 */ | |
100 static void | |
101 set_property(Property *p, SceneGraphPtr node, int index) | |
102 { | |
103 for (int i = 0; i < 3; i++) { | |
104 p->xyz[i] = node->xyz[i]; | |
105 p->angle[i] = node->angle[i]; | |
106 p->stack_xyz[i] = node->stack_xyz[i]; | |
107 } | |
769
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
108 p->parent = (memaddr)node->parent; |
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
109 p->children = (memaddr)node->children; |
767 | 110 p->name = node->name; |
111 p->property_index = index; | |
112 | |
769
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
113 p->node = (memaddr)node; |
767 | 114 node->property = (memaddr)p; |
115 } | |
116 | |
117 static void | |
118 regist_task(SceneGraphRoot *sgroot) | |
119 { | |
120 TaskManager *manager = sgroot->tmanager; | |
769
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
121 HTaskPtr task = manager->create_task(UniverseTask); |
767 | 122 // sgroot->setExecTask(task); とやるべき? |
123 sgroot->move_exec_task = task; | |
124 } | |
125 | |
126 static void | |
127 set_relation(SceneGraphPtr parent, SceneGraphPtr child) | |
128 { | |
769
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
129 /* |
767 | 130 child->property->parent_index = parent->property->property_index; |
131 child->property->have_parent = 1; | |
769
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
132 */ |
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
133 |
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
134 Property *p = (Property *)parent->property; |
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
135 Property *c = (Property *)child->property; |
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
136 c->parent_index = p->property_index; |
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
137 c->have_parent = 1; |
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
138 |
767 | 139 } |
140 | |
141 MainLoopPtr | |
142 property_universe::init(Viewer *viewer, int screen_w, int screen_h) | |
143 { | |
144 // SgChange を使うための2行 | |
145 SgChange *sgroot = new SgChange(viewer); | |
146 sgroot->run_init(); | |
147 // 上で書いた regist_task() を登録 | |
148 // sgroot->appTaskRegist(regist_task); がいいかな | |
149 sgroot->sgroot_A->appTaskRegist(regist_task); | |
150 | |
151 int root_obj_index = 0; | |
152 property = (Property *)sgroot->manager->allocate(sizeof(Property)*PROPERTY_LENGTH); | |
153 update_property = (Property *)sgroot->manager->allocate(sizeof(Property)*PROPERTY_LENGTH); | |
154 | |
155 SceneGraphPtr earth; | |
156 sgroot->createFromXMLfile("xml_file/universe.xml"); | |
157 earth = sgroot->createSceneGraph("Earth"); | |
769
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
158 earth->set_move_collision(move, collision); |
767 | 159 earth->xyz[0] = screen_w / 2; |
160 earth->xyz[1] = screen_h / 2; | |
161 | |
162 SceneGraphPtr moon; | |
163 moon = sgroot->createSceneGraph("Moon"); | |
164 | |
165 earth->addChild(moon); | |
166 | |
769
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
167 set_property(&property[root_obj_index], earth, 0); |
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
168 set_property(&property[1], moon, 1); |
767 | 169 set_relation(earth, moon); |
170 | |
171 sgroot->setSceneData(earth); | |
172 | |
173 return sgroot; | |
174 } | |
175 | |
176 extern Application * | |
177 application() { | |
769
2a00c1f470b7
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
767
diff
changeset
|
178 return new property_universe(); |
767 | 179 } |
180 | |
181 const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n"; | |
182 | |
183 extern int init(TaskManager *manager, int argc, char *argv[]); | |
184 extern void task_initialize(); | |
185 static void TMend(TaskManager *manager); | |
186 | |
187 int | |
188 TMmain(TaskManager *manager, int argc, char *argv[]) | |
189 { | |
190 task_initialize(); | |
191 manager->set_TMend(TMend); | |
192 return init(manager, argc, argv); | |
193 | |
194 } | |
195 | |
196 void | |
197 TMend(TaskManager *manager) | |
198 { | |
199 printf("test_nogl end\n"); | |
200 } | |
201 | |
202 /* end */ |