Mercurial > hg > Game > Cerium
annotate Renderer/Test/property_universe.cc @ 1767:1a68c05eeadf draft
minor fix
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 23 Nov 2013 01:28:59 +0900 |
parents | f40558ec00a8 |
children |
rev | line source |
---|---|
766 | 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" | |
1070 | 7 #include "MyFunc.h" |
8 #include "matrix_calc.h" | |
766 | 9 #include "SgChange.h" |
10 | |
768
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
11 static const int PROPERTY_LENGTH = 2; |
766 | 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); | |
768
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
19 static void set_property(Property *p, SceneGraphPtr sg, int index); |
766 | 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 | |
1412
f40558ec00a8
remove duplicated spe task code source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1393
diff
changeset
|
30 property_task->set_inData(0,property, sizeof(Property)*PROPERTY_LENGTH); |
f40558ec00a8
remove duplicated spe task code source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1393
diff
changeset
|
31 property_task->set_outData(0,update_property, sizeof(Property)*PROPERTY_LENGTH); |
766 | 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; | |
768
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
49 |
766 | 50 // ここが allExecute の tree をたどって clone して行くところに相当する |
51 Property *p; | |
768
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
52 |
766 | 53 for (int i = 0; i < PROPERTY_LENGTH; i++) { |
54 p = &update_property[i]; | |
768
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
55 SceneGraphPtr node = sgroot->createSceneGraph(p->name); |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
56 if (strcmp(node->name, "Earth") == 0) { |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
57 node->set_move_collision(move, collision); |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
58 } |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
59 apply_property(node, p); |
766 | 60 } |
61 | |
62 for (int j = 0; j < PROPERTY_LENGTH; j++) { | |
63 p = &update_property[j]; | |
768
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
64 p_node = (SceneGraphPtr)p->node; |
1115 | 65 //float scale[] = {1,1,1}; |
768
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
66 if (p->have_parent) { |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
67 SceneGraphPtr parent = (SceneGraphPtr)update_property[p->parent_index].node; |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
68 parent->addChild(p_node); |
1109 | 69 get_matrix(p_node->matrix, p_node->angle, p_node->xyz, parent->matrix); |
766 | 70 } else { |
1109 | 71 get_matrix(p_node->matrix, p_node->angle, p_node->xyz, camera->matrix); |
766 | 72 } |
73 } | |
74 | |
768
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
75 sgroot->setSceneData((SceneGraphPtr)update_property[0].node); |
766 | 76 |
77 Property *tmp = property; | |
78 property = update_property; | |
79 update_property = tmp; | |
80 | |
81 sgroot->move_finish(); | |
82 } | |
83 | |
84 static void | |
85 apply_property(SceneGraphPtr node, Property *p) | |
86 { | |
87 for (int i = 0; i < 3; i++) { | |
88 node->xyz[i] = p->xyz[i]; | |
89 node->angle[i] = p->angle[i]; | |
90 node->stack_xyz[i] = p->stack_xyz[i]; | |
91 } | |
768
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
92 p->node = (memaddr)node; |
766 | 93 node->property = (memaddr)p; |
94 } | |
95 | |
96 /* | |
97 ここで必要な値をプロパティに格納 | |
98 */ | |
99 static void | |
100 set_property(Property *p, SceneGraphPtr node, int index) | |
101 { | |
102 for (int i = 0; i < 3; i++) { | |
103 p->xyz[i] = node->xyz[i]; | |
104 p->angle[i] = node->angle[i]; | |
105 p->stack_xyz[i] = node->stack_xyz[i]; | |
106 } | |
768
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
107 p->parent = (memaddr)node->parent; |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
108 p->children = (memaddr)node->children; |
766 | 109 p->name = node->name; |
110 p->property_index = index; | |
111 | |
768
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
112 p->node = (memaddr)node; |
766 | 113 node->property = (memaddr)p; |
114 } | |
115 | |
116 static void | |
117 regist_task(SceneGraphRoot *sgroot) | |
118 { | |
119 TaskManager *manager = sgroot->tmanager; | |
768
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
120 HTaskPtr task = manager->create_task(UniverseTask); |
766 | 121 // sgroot->setExecTask(task); とやるべき? |
122 sgroot->move_exec_task = task; | |
123 } | |
124 | |
125 static void | |
126 set_relation(SceneGraphPtr parent, SceneGraphPtr child) | |
127 { | |
768
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
128 /* |
766 | 129 child->property->parent_index = parent->property->property_index; |
130 child->property->have_parent = 1; | |
768
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
131 */ |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
132 |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
133 Property *p = (Property *)parent->property; |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
134 Property *c = (Property *)child->property; |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
135 c->parent_index = p->property_index; |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
136 c->have_parent = 1; |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
137 |
766 | 138 } |
139 | |
140 MainLoopPtr | |
141 property_universe::init(Viewer *viewer, int screen_w, int screen_h) | |
142 { | |
143 // SgChange を使うための2行 | |
144 SgChange *sgroot = new SgChange(viewer); | |
145 sgroot->run_init(); | |
146 // 上で書いた regist_task() を登録 | |
147 // sgroot->appTaskRegist(regist_task); がいいかな | |
148 sgroot->sgroot_A->appTaskRegist(regist_task); | |
149 | |
150 int root_obj_index = 0; | |
151 property = (Property *)sgroot->manager->allocate(sizeof(Property)*PROPERTY_LENGTH); | |
152 update_property = (Property *)sgroot->manager->allocate(sizeof(Property)*PROPERTY_LENGTH); | |
153 | |
154 SceneGraphPtr earth; | |
155 sgroot->createFromXMLfile("xml_file/universe.xml"); | |
156 earth = sgroot->createSceneGraph("Earth"); | |
768
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
157 earth->set_move_collision(move, collision); |
766 | 158 earth->xyz[0] = screen_w / 2; |
159 earth->xyz[1] = screen_h / 2; | |
160 | |
161 SceneGraphPtr moon; | |
162 moon = sgroot->createSceneGraph("Moon"); | |
163 | |
164 earth->addChild(moon); | |
165 | |
768
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
166 set_property(&property[root_obj_index], earth, 0); |
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
167 set_property(&property[1], moon, 1); |
766 | 168 set_relation(earth, moon); |
169 | |
170 sgroot->setSceneData(earth); | |
171 | |
172 return sgroot; | |
173 } | |
174 | |
175 extern Application * | |
176 application() { | |
768
06302c1dc87d
add add spe/chain_move Test/property_chain, not workd
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
766
diff
changeset
|
177 return new property_universe(); |
766 | 178 } |
179 | |
180 const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n"; | |
181 | |
182 extern int init(TaskManager *manager, int argc, char *argv[]); | |
183 extern void task_initialize(); | |
184 static void TMend(TaskManager *manager); | |
185 | |
186 int | |
187 TMmain(TaskManager *manager, int argc, char *argv[]) | |
188 { | |
189 task_initialize(); | |
190 manager->set_TMend(TMend); | |
191 return init(manager, argc, argv); | |
192 | |
193 } | |
194 | |
195 void | |
196 TMend(TaskManager *manager) | |
197 { | |
198 printf("test_nogl end\n"); | |
199 } | |
200 | |
201 /* end */ |