comparison Renderer/Test/property_universe.cc @ 767:e4d635b1f018

add spe/univers_move
author hiroki@henri.cr.ie.u-ryukyu.ac.jp
date Sat, 13 Feb 2010 17:33:38 +0900
parents
children 2a00c1f470b7
comparison
equal deleted inserted replaced
764:987d4cced279 767:e4d635b1f018
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
11 #define PROPERTY_LENGTH 2;
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);
19 static void set_property(Property *p, SceneGraphPtr sg);
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
30 property_task->add_inData(property, sizeof(Property));
31 property_task->add_outData(update_property, sizeof(Property));
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;
49 int p_length = sgroot->;
50
51 // ここが allExecute の tree をたどって clone して行くところに相当する
52 //Property *t = update_property;
53 Property *p;
54
55 for (int i = 0; i < PROPERTY_LENGTH; i++) {
56 p = &update_property[i];
57 SceneGraphPtr node = sgroot->createSceneGraph(t->name);
58 node->set_move_collision(t->move_func, t->collision_func);
59 apply_property(node, t);
60 }
61
62 for (int j = 0; j < PROPERTY_LENGTH; j++) {
63 p = &update_property[j];
64 p_node = p->node;
65 if (t->have_parent) {
66 SceneGraphPtr parent = update_property[t->parent_index]->node;
67 parent->addChilde(p_node);
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
76 sgroot->setSceneData(update_property[0]->node);
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 }
93 p->node = node;
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 }
108 p->parent = node->parent;
109 p->children = node->children;
110 p->name = node->name;
111 p->property_index = index;
112
113 p->node = node;
114 node->property = (memaddr)p;
115 }
116
117 static void
118 regist_task(SceneGraphRoot *sgroot)
119 {
120 TaskManager *manager = sgroot->tmanager;
121 HTaskPtr task = manager->create_task(PropertyUniverseTask);
122 // sgroot->setExecTask(task); とやるべき?
123 sgroot->move_exec_task = task;
124 }
125
126 static void
127 set_relation(SceneGraphPtr parent, SceneGraphPtr child)
128 {
129 child->property->parent_index = parent->property->property_index;
130 child->property->have_parent = 1;
131 }
132
133 MainLoopPtr
134 property_universe::init(Viewer *viewer, int screen_w, int screen_h)
135 {
136 // SgChange を使うための2行
137 SgChange *sgroot = new SgChange(viewer);
138 sgroot->run_init();
139 // 上で書いた regist_task() を登録
140 // sgroot->appTaskRegist(regist_task); がいいかな
141 sgroot->sgroot_A->appTaskRegist(regist_task);
142
143 int root_obj_index = 0;
144 property = (Property *)sgroot->manager->allocate(sizeof(Property)*PROPERTY_LENGTH);
145 update_property = (Property *)sgroot->manager->allocate(sizeof(Property)*PROPERTY_LENGTH);
146
147 SceneGraphPtr earth;
148 sgroot->createFromXMLfile("xml_file/universe.xml");
149 earth = sgroot->createSceneGraph("Earth");
150 earth->set_move_collision(earth_move, earth_collision);
151 earth->xyz[0] = screen_w / 2;
152 earth->xyz[1] = screen_h / 2;
153
154 SceneGraphPtr moon;
155 moon = sgroot->createSceneGraph("Moon");
156 moon->set_move_collision(moon_move, moon_collision);
157
158 earth->addChild(moon);
159
160 set_property(property[root_obj_index], earth, 0);
161 set_property(property[1], moon, 1);
162 set_relation(earth, moon);
163
164 sgroot->setSceneData(earth);
165
166 return sgroot;
167 }
168
169 extern Application *
170 application() {
171 return new create_task();
172 }
173
174 const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n";
175
176 extern int init(TaskManager *manager, int argc, char *argv[]);
177 extern void task_initialize();
178 static void TMend(TaskManager *manager);
179
180 int
181 TMmain(TaskManager *manager, int argc, char *argv[])
182 {
183 task_initialize();
184 manager->set_TMend(TMend);
185 return init(manager, argc, argv);
186
187 }
188
189 void
190 TMend(TaskManager *manager)
191 {
192 printf("test_nogl end\n");
193 }
194
195 /* end */