507
|
1 #include "scene_graph_pack.h"
|
|
2 #include "SceneGraph.h"
|
|
3 #include "create_sgp.h"
|
|
4 #include "TaskManager.h"
|
|
5 using namespace std;
|
|
6
|
|
7 SchedDefineTask(Create_SGP);
|
|
8
|
|
9 /**
|
|
10 * TODO
|
|
11 * 入りきらない分は SceneGraphPack を next で繋げてるので
|
|
12 * node->pn をつかって sgp->node[node->pn] とかやって
|
|
13 * 親?の要素を探す事は出来ないかもしれません。
|
|
14 * next を辿って node->pn == とかやるのは確実だけどさ。。。
|
|
15 */
|
|
16 static int
|
|
17 //create_sgp(Polygon *sg, SceneGraphPack *sgp)
|
|
18 run(SchedTask *smanager, void *rbuf, void *wbuf)
|
|
19 {
|
|
20 //SceneGraph *sg = (SceneGraph*)smanager->get_input(rbuf, 0);
|
|
21 SceneGraph *sg = (SceneGraph*)smanager->get_param(0);
|
|
22 SceneGraphPack *sgp = (SceneGraphPack*)smanager->get_param(0);
|
|
23 sgp->init();
|
|
24
|
|
25 int curNumber = 0;
|
|
26 int nnpn = -1;
|
|
27 SceneGraphNodePtr node;
|
|
28
|
|
29 SceneGraph *t = sg;
|
|
30
|
|
31 while(t) {
|
|
32 // blocking はこれでいいのかな?
|
|
33 if (curNumber >= MAX_NODE ){
|
|
34 SceneGraphPack *sgp_new =
|
|
35 //(SceneGraphPack*)manager->malloc(sizeof(SceneGraphPack));
|
|
36 (SceneGraphPack*)smanager->allocate(sizeof(SceneGraphPack));
|
|
37 sgp_new->init();
|
|
38 sgp->info.size = curNumber-1;
|
|
39 curNumber = 0;
|
|
40 sgp->next = sgp_new;
|
|
41 sgp = sgp_new;
|
|
42 }
|
|
43
|
|
44 node = &sgp->node[curNumber];
|
|
45 node->init();
|
|
46
|
|
47 for (int i = 0,d = 0,tex = 0; i < t->size; i++, d += 3, tex += 2) {
|
|
48 if (node->size >= MAX_POLYGON) {
|
|
49 SceneGraphNodePtr node_new = (SceneGraphNodePtr)smanager->allocate(sizeof(SceneGraphNode));
|
|
50 node_new->init();
|
|
51 node->next = node_new;
|
|
52 node = node_new;
|
|
53 d = 0;
|
|
54 tex = 0;
|
|
55 }
|
|
56
|
|
57 /**
|
|
58 * struct texture {
|
|
59 * int texture_id;
|
|
60 * float vertex[3];
|
|
61 * float texture[2];
|
|
62 * }
|
|
63 */
|
|
64
|
|
65 node->vertex[d] = t->coord_xyz[i*3];
|
|
66 node->vertex[d+1] = t->coord_xyz[i*3+1];
|
|
67 node->vertex[d+2] = t->coord_xyz[i*3+2];
|
|
68 node->texture[tex] = t->coord_tex[i*3];
|
|
69 node->texture[tex+1] = t->coord_tex[i*3+1];
|
|
70 node->size++;
|
|
71 }
|
|
72
|
|
73 node = &sgp->node[curNumber];
|
|
74
|
|
75 SceneGraphNode *p = node;
|
|
76 do {
|
|
77 p->obj_pos[0] = 0;
|
|
78 p->obj_pos[1] = 0;
|
|
79 p->obj_pos[2] = 0;
|
|
80 p->obj_pos[3] = 1;
|
|
81 p->angle[0] = 0;
|
|
82 p->angle[1] = 0;
|
|
83 p->angle[2] = 0;
|
|
84 p->angle[3] = 1;
|
|
85
|
|
86 for (int tm = 0; tm < 16; tm++) {
|
|
87 p->translation[tm] = 0;
|
|
88 }
|
|
89
|
|
90 p->id = 0;
|
|
91 p->move = 0;
|
|
92 p->interaction = 0;
|
|
93 p->self = t;
|
|
94 p->tree = scene_graph;
|
|
95
|
|
96 p->pn = nnpn;
|
|
97 //node->tex_addr = t->texture_image->pixels;
|
|
98 p->tex_width = t->texture_image->w;
|
|
99 p->tex_height = t->texture_image->h;
|
|
100 p = p->next;
|
|
101 } while (p);
|
|
102
|
|
103 if (t->children != NULL) {
|
|
104 nnpn = curNumber;
|
|
105 t = t->children;
|
|
106 } else if (t->brother != NULL) {
|
|
107 nnpn = node->pn;
|
|
108 t = t->brother;
|
|
109 } else {
|
|
110 while (t) {
|
|
111 if (t->brother != NULL) {
|
|
112 t = t->brother;
|
|
113 break;
|
|
114 } else {
|
|
115 if (t->parent == NULL) {
|
|
116 t = NULL;
|
|
117 break;
|
|
118 }
|
|
119 nnpn = sgp->node[nnpn].pn;
|
|
120 t = t->parent;
|
|
121 }
|
|
122 }
|
|
123 }
|
|
124 curNumber++;
|
|
125 }
|
|
126 sgp->info.size = curNumber;
|
|
127
|
|
128 return 0;
|
|
129 }
|