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 {
|
860
|
20
|
|
21 #if !SPE_CREATE_POLYGON
|
|
22
|
507
|
23 //SceneGraph *sg = (SceneGraph*)smanager->get_input(rbuf, 0);
|
|
24 SceneGraph *sg = (SceneGraph*)smanager->get_param(0);
|
|
25 SceneGraphPack *sgp = (SceneGraphPack*)smanager->get_param(0);
|
|
26 sgp->init();
|
|
27
|
|
28 int curNumber = 0;
|
|
29 int nnpn = -1;
|
|
30 SceneGraphNodePtr node;
|
|
31
|
|
32 SceneGraph *t = sg;
|
|
33
|
|
34 while(t) {
|
|
35 // blocking はこれでいいのかな?
|
|
36 if (curNumber >= MAX_NODE ){
|
|
37 SceneGraphPack *sgp_new =
|
|
38 //(SceneGraphPack*)manager->malloc(sizeof(SceneGraphPack));
|
|
39 (SceneGraphPack*)smanager->allocate(sizeof(SceneGraphPack));
|
|
40 sgp_new->init();
|
|
41 sgp->info.size = curNumber-1;
|
|
42 curNumber = 0;
|
|
43 sgp->next = sgp_new;
|
|
44 sgp = sgp_new;
|
|
45 }
|
|
46
|
|
47 node = &sgp->node[curNumber];
|
|
48 node->init();
|
|
49
|
|
50 for (int i = 0,d = 0,tex = 0; i < t->size; i++, d += 3, tex += 2) {
|
|
51 if (node->size >= MAX_POLYGON) {
|
|
52 SceneGraphNodePtr node_new = (SceneGraphNodePtr)smanager->allocate(sizeof(SceneGraphNode));
|
|
53 node_new->init();
|
|
54 node->next = node_new;
|
|
55 node = node_new;
|
|
56 d = 0;
|
|
57 tex = 0;
|
|
58 }
|
|
59
|
|
60 /**
|
|
61 * struct texture {
|
|
62 * int texture_id;
|
|
63 * float vertex[3];
|
|
64 * float texture[2];
|
|
65 * }
|
|
66 */
|
|
67
|
|
68 node->vertex[d] = t->coord_xyz[i*3];
|
|
69 node->vertex[d+1] = t->coord_xyz[i*3+1];
|
|
70 node->vertex[d+2] = t->coord_xyz[i*3+2];
|
|
71 node->texture[tex] = t->coord_tex[i*3];
|
|
72 node->texture[tex+1] = t->coord_tex[i*3+1];
|
|
73 node->size++;
|
|
74 }
|
|
75
|
|
76 node = &sgp->node[curNumber];
|
|
77
|
|
78 SceneGraphNode *p = node;
|
|
79 do {
|
|
80 p->obj_pos[0] = 0;
|
|
81 p->obj_pos[1] = 0;
|
|
82 p->obj_pos[2] = 0;
|
|
83 p->obj_pos[3] = 1;
|
|
84 p->angle[0] = 0;
|
|
85 p->angle[1] = 0;
|
|
86 p->angle[2] = 0;
|
|
87 p->angle[3] = 1;
|
|
88
|
|
89 for (int tm = 0; tm < 16; tm++) {
|
|
90 p->translation[tm] = 0;
|
|
91 }
|
|
92
|
|
93 p->id = 0;
|
|
94 p->move = 0;
|
|
95 p->interaction = 0;
|
|
96 p->self = t;
|
|
97 p->tree = scene_graph;
|
|
98
|
|
99 p->pn = nnpn;
|
|
100 //node->tex_addr = t->texture_image->pixels;
|
|
101 p->tex_width = t->texture_image->w;
|
|
102 p->tex_height = t->texture_image->h;
|
|
103 p = p->next;
|
|
104 } while (p);
|
|
105
|
|
106 if (t->children != NULL) {
|
|
107 nnpn = curNumber;
|
|
108 t = t->children;
|
|
109 } else if (t->brother != NULL) {
|
|
110 nnpn = node->pn;
|
|
111 t = t->brother;
|
|
112 } else {
|
|
113 while (t) {
|
|
114 if (t->brother != NULL) {
|
|
115 t = t->brother;
|
|
116 break;
|
|
117 } else {
|
|
118 if (t->parent == NULL) {
|
|
119 t = NULL;
|
|
120 break;
|
|
121 }
|
|
122 nnpn = sgp->node[nnpn].pn;
|
|
123 t = t->parent;
|
|
124 }
|
|
125 }
|
|
126 }
|
|
127 curNumber++;
|
|
128 }
|
|
129 sgp->info.size = curNumber;
|
|
130
|
860
|
131 #endif
|
|
132
|
507
|
133 return 0;
|
|
134 }
|