Mercurial > hg > Game > Cerium
changeset 1226:636dfdc30176 draft
new API for SceneGraph
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 31 Jul 2011 10:20:46 +0900 |
parents | 2f4d45cc4aff |
children | bb75ee244826 |
files | Renderer/Engine/SceneGraph.cc Renderer/Engine/SceneGraph.h Renderer/Engine/SceneGraphRoot.cc Renderer/Engine/SceneGraphRoot.h Renderer/Engine/TODO Renderer/Engine/matrix_calc.cc Renderer/Test/icon.png |
diffstat | 7 files changed, 102 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/Renderer/Engine/SceneGraph.cc Sat Jul 30 16:06:59 2011 +0900 +++ b/Renderer/Engine/SceneGraph.cc Sun Jul 31 10:20:46 2011 +0900 @@ -188,8 +188,8 @@ init(); - matrix = (float*)manager->allocate(sizeof(float)*16); - real_matrix = (float*)manager->allocate(sizeof(float)*16); + matrix = (float*)manager->allocate(sizeof(float)*16*2); + real_matrix = matrix+16; texture_info = (texture_list*)manager->allocate(sizeof(texture_list)); texture_info->texture_id = -1; @@ -202,6 +202,10 @@ matrix[i] = 0; real_matrix[i] = 0; } + for (int i = 0; i < 4; i++) { + matrix[i*4+i] = 1; + real_matrix[i*4+i] = 1; + } if (size % 3 != 0) { printf("vertex size is error. size %% 3 = %lld\n", size % 3); @@ -226,7 +230,7 @@ init(); this->matrix = (float*)manager->allocate(sizeof(float)*16); - this->real_matrix = (float*)manager->allocate(sizeof(float)*16); + this->real_matrix = this->matrix+16; this->texture_info = (texture_list*)manager->allocate(sizeof(texture_list)); texture_info->texture_id = -1; @@ -238,6 +242,10 @@ matrix[i] = 0; real_matrix[i] = 0; } + for (int i = 0; i < 4; i++) { + matrix[i*4+i] = 1; + real_matrix[i*4+i] = 1; + } if (size % 3 != 0) { printf("vertex size is error. size %% 3 = %lld\n", size % 3); @@ -1059,9 +1067,9 @@ void SceneGraph::translate(float x, float y, float z) { - this->xyz[0] = x; - this->xyz[1] = y; - this->xyz[2] = z; + this->matrix[3] += x; + this->matrix[4+3] += y; + this->matrix[8+3] += z; } /** @@ -1072,7 +1080,7 @@ void SceneGraph::translateX(float x) { - this->xyz[0] = x; + this->matrix[3] += x; } /** @@ -1083,7 +1091,7 @@ void SceneGraph::translateY(float y) { - this->xyz[1] = y; + this->matrix[4+3] += y; } /** @@ -1094,7 +1102,28 @@ void SceneGraph::translateZ(float z) { - this->xyz[2] = z; + this->matrix[8+3] += z; +} + +void +SceneGraph::angleIt(float *angle) +{ + float m[16]; + float t[4] = {0,0,0,0}; + for(int i=0;i<16;i++) m[i] = matrix[i]; + get_matrix(matrix, angle, t, m); + get_matrix(real_matrix, angle, t, m); +} + +void +SceneGraph::scaleIt(float *scale) +{ + for(int i=0;i<4;i++) { + for(int j=0;i<3;j++) { + matrix[i*4+j] = matrix[i*4+j]*scale[i]; + real_matrix[i*4+j] = real_matrix[i*4+j]*scale[i]; + } + } } /* end */
--- a/Renderer/Engine/SceneGraph.h Sat Jul 30 16:06:59 2011 +0900 +++ b/Renderer/Engine/SceneGraph.h Sun Jul 31 10:20:46 2011 +0900 @@ -117,6 +117,8 @@ void translateX(float x); void translateY(float y); void translateZ(float z); + void scaleIt(float *scale); + void angleIt(float *angle); void tree_check(void);
--- a/Renderer/Engine/SceneGraphRoot.cc Sat Jul 30 16:06:59 2011 +0900 +++ b/Renderer/Engine/SceneGraphRoot.cc Sun Jul 31 10:20:46 2011 +0900 @@ -471,6 +471,48 @@ } +/** + * 破壊的に変換行列の親子関係を計算する + */ +void +SceneGraphRoot::transTree(SceneGraphPtr t, SceneGraphPtr cur_parent) +{ + // SceneGraphPtr t = sg_draw_tree; + + /*removeのflagをもとにtreeを形成*/ + while (t) { + SceneGraphPtr c = NULL; + if (!t->isRemoved()) { + /*親の回転、座標から、子の回転、座標を算出*/ + matrix4x4(t->matrix,t->matrix,cur_parent->matrix); + /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ + matrix4x4(t->real_matrix,t->real_matrix,cur_parent->real_matrix); + } + + if (t->children != NULL && c != NULL) { + cur_parent = t; + t = t->children; + } else if (t->brother != NULL) { + t = t->brother; + } else { + while (t) { + if (t->brother != NULL) { + t = t->brother; + break; + } else { + if (t->parent == NULL) { + t = NULL; + break; + } else { + cur_parent = cur_parent->parent; + t = t->parent; + } + } + } + } + } + +} /* ExecMove task の post func として呼んでやる
--- a/Renderer/Engine/SceneGraphRoot.h Sat Jul 30 16:06:59 2011 +0900 +++ b/Renderer/Engine/SceneGraphRoot.h Sun Jul 31 10:20:46 2011 +0900 @@ -126,6 +126,7 @@ void lightCalc(); void flip(); void copyTree(SceneGraphPtr from, SceneGraphPtr to); + void transTree(SceneGraphPtr t, SceneGraphPtr cur_parent); // void oneExecute(int screen_w, int screen_h); void checkRemove();
--- a/Renderer/Engine/TODO Sat Jul 30 16:06:59 2011 +0900 +++ b/Renderer/Engine/TODO Sun Jul 31 10:20:46 2011 +0900 @@ -3,8 +3,10 @@ SceneGraph Node の angle/scale はアホなので廃止 - matrix <- local transpose matrix - real_matrix <- global transpose matrix + matrix <- transpose matrix + real_matrix <- transpose matrix for normal vector + + 両方同じじゃないの? 片方は不要 angle/scale は matrix への操作として実装する @@ -35,6 +37,18 @@ defSprite putSprite +createPolygonFromSceneGraph + + 親の行列から計算してない + 既に行列は計算されている前提 + + ここで親子の行列のかけ算を行うべき + + なんだけど、互換性はどーする? (そんなのいるの?) + + SceneGraphRoot::setSceneData(SceneGraphPtr sg) + + で計算するか。いや、計算 method を別に用意するか。 Tue Sep 22 21:32:17 JST 2009
--- a/Renderer/Engine/matrix_calc.cc Sat Jul 30 16:06:59 2011 +0900 +++ b/Renderer/Engine/matrix_calc.cc Sun Jul 31 10:20:46 2011 +0900 @@ -185,9 +185,9 @@ get_matrix( float *matrix, float *rxyz, float *txyz, float *stack) { float radx,rady,radz; - radx = rxyz[0]*3.14/180; - rady = rxyz[1]*3.14/180; - radz = rxyz[2]*3.14/180; + radx = rxyz[0]*3.141562/180; + rady = rxyz[1]*3.141562/180; + radz = rxyz[2]*3.141562/180; float sinx = sin(radx); float cosx = cos(radx);