Mercurial > hg > Members > kono > Cerium
view TaskManager/Test/test_render/task/CreatePolygonFromSceneGraph.cpp @ 215:7ca6a2ef5be9
fix SceneGraph Constructor, Destructor
author | gongo@gendarme.local |
---|---|
date | Sun, 01 Feb 2009 22:14:44 +0900 |
parents | fe2cc32cd94d |
children | 0f1ff7b06157 |
line wrap: on
line source
/** * SceneGraph が増えてくると動かなくなるかもしれない。 * 一応 mainMem とかで動くようになるとは思うけど。 * だめだったら、そこら辺が怪しいと思うべき */ #include "CreatePolygonFromSceneGraph.h" #include "polygon_pack.h" #include "scene_graph_pack.h" SchedDefineTask(CreatePolygonFromSceneGraph); #define SG_PACK_LOAD 10 #define SG_NODE_LOAD 11 #define PP_LOAD 12 #define PP_STORE 13 /** * ベクトルに行列を乗算する * @param[out] v vector (float[4]) * @param[in] m matrix (float[16]) */ static void ApplyMatrix(float *v, float *m) { float t[4]; t[0] = v[0]; t[1] = v[1]; t[2] = v[2]; t[3] = v[3]; for (int i = 0; i < 4; i++) { v[i] = t[0]*m[i] + t[1]*m[i+4] + t[2]*m[i+8] + t[3]*m[i+12]; } } /** * 行列の積 * * @param[out] m0 output matrix * @param[in] m1 input left matrix * @param[in] m2 input right matrix */ static void MulMatrix(float *m0, float *m1, float *m2) //xyz[16] { for(int t = 0; t < 16; t += 4) { for (int i = 0; i < 4; i++) { m0[t+i] = m1[t+0]*m2[ i ] + m1[t+1]*m2[i+ 4] + m1[t+2]*m2[i+8] + m1[t+3]*m2[i+12]; } } } int CreatePolygonFromSceneGraph::run(void *rbuf, void *wbuf) { float xyz1[4], xyz2[4], xyz3[4]; SceneGraphPtr sg_top = (SceneGraphPtr)smanager->get_param(0); SceneGraphPtr sg = sg_top; PolygonPackPtr pp = (PolygonPackPtr)smanager->allocate(sizeof(PolygonPack)); PolygonPackPtr send_pp = (PolygonPackPtr)smanager->allocate(sizeof(PolygonPack)); PolygonPackPtr pp_addr = (PolygonPackPtr)smanager->get_param(1); PolygonPackPtr tmp_pp; pp->init(); send_pp->init(); while (sg) { if (sg->flag_drawable) { // sg->isDrawable() とかの方がよくね? for (int i = 0; i < sg->size; i += 3) { if (pp->info.size >= MAX_SIZE_TRIANGLE) { PolygonPackPtr next; smanager->mainMem_alloc(0, sizeof(PolygonPack)); smanager->mainMem_wait(); next = (PolygonPackPtr)smanager->mainMem_get(0); pp->next = next; tmp_pp = pp; pp = send_pp; send_pp = tmp_pp; smanager->dma_wait(PP_STORE); smanager->dma_store(send_pp, (uint32)pp_addr, sizeof(PolygonPack), PP_STORE); pp_addr = next; smanager->dma_wait(PP_LOAD); smanager->dma_load(pp, (uint32)pp_addr, sizeof(PolygonPack), PP_LOAD); smanager->dma_wait(PP_LOAD); pp->init(); } TrianglePack *triangle = &pp->tri[pp->info.size++]; xyz1[0] = sg->data[(i+0)*3]; xyz1[1] = sg->data[(i+0)*3+1]; xyz1[2] = sg->data[(i+0)*3+2]*-1; xyz1[3] = 1; xyz2[0] = sg->data[(i+1)*3]; xyz2[1] = sg->data[(i+1)*3+1]; xyz2[2] = sg->data[(i+1)*3+2]*-1; xyz2[3] = 1; xyz3[0] = sg->data[(i+2)*3]; xyz3[1] = sg->data[(i+2)*3+1]; xyz3[2] = sg->data[(i+2)*3+2]*-1; xyz3[3] = 1; // sg->matrix = 回転行列*透視変換行列 ApplyMatrix(xyz1, sg->matrix); ApplyMatrix(xyz2, sg->matrix); ApplyMatrix(xyz3, sg->matrix); #if 1 xyz1[0] /= xyz1[2]; xyz1[1] /= xyz1[2]; xyz2[0] /= xyz2[2]; xyz2[1] /= xyz2[2]; xyz3[0] /= xyz3[2]; xyz3[1] /= xyz3[2]; #endif triangle->ver1.x = xyz1[0]; triangle->ver1.y = xyz1[1]; triangle->ver1.z = xyz1[2]; triangle->ver1.tex_x = sg->data[(i+0)*3 + sg->size*6]; triangle->ver1.tex_y = sg->data[(i+0)*3 + sg->size*6+1]; triangle->ver2.x = xyz2[0]; triangle->ver2.y = xyz2[1]; triangle->ver2.z = xyz2[2]; triangle->ver2.tex_x = sg->data[(i+1)*3 + sg->size*6]; triangle->ver2.tex_y = sg->data[(i+1)*3 + sg->size*6+1]; triangle->ver3.x = xyz3[0]; triangle->ver3.y = xyz3[1]; triangle->ver3.z = xyz3[2]; triangle->ver3.tex_x = sg->data[(i+2)*3 + sg->size*6]; triangle->ver3.tex_y = sg->data[(i+2)*3 + sg->size*6+1]; triangle->tex_info.addr = sg->texture_info.pixels; triangle->tex_info.width = sg->texture_info.t_w; triangle->tex_info.height = sg->texture_info.t_h; triangle->tex_info.scale_max = sg->texture_info.scale_max; } } if (sg->children != NULL) { sg = sg->children; } else if (sg->brother != NULL) { sg = sg->brother; } else { while (sg) { if (sg->brother != NULL) { sg = sg->brother; break; } else { if (sg->parent == NULL) { sg = NULL; break; } else { sg = sg->parent; } } } } } smanager->dma_wait(PP_STORE); smanager->dma_store(pp, (uint32)pp_addr, sizeof(PolygonPack), PP_STORE); smanager->dma_wait(PP_STORE); free(pp); free(send_pp); return 0; }