changeset 1094:f10ec9bbd3f6 draft

separate scale matrix
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 25 Dec 2010 18:38:53 +0900
parents 3e1caef39798
children 652791a4a324
files Renderer/Engine/SceneGraphRoot.cc Renderer/Engine/matrix_calc.cc Renderer/Engine/matrix_calc.h Renderer/Engine/task/update_sgp.cc
diffstat 4 files changed, 40 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/SceneGraphRoot.cc	Thu Dec 23 11:21:52 2010 +0900
+++ b/Renderer/Engine/SceneGraphRoot.cc	Sat Dec 25 18:38:53 2010 +0900
@@ -290,7 +290,7 @@
     int light_num = 4;
     for (int i = 0; i < light_num; i++) {
 
-	get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, light[i]->scale, camera->matrix);
+	get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, camera->matrix);
       
 	light_vector[i*4] = 0.0f;
 	light_vector[i*4+1] = 0.0f;
@@ -381,9 +381,9 @@
 	    cur_parent->addChild(c);
 	    c->frame = t->frame;
 	    /*親の回転、座標から、子の回転、座標を算出*/
-	    get_matrix(c->matrix, c->angle, c->xyz, c->scale, cur_parent->matrix);
+	    get_matrix(c->matrix, c->angle, c->xyz, cur_parent->matrix);
 	    /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/
-	    get_matrix(c->real_matrix, c->angle, c->xyz, c->scale, cur_parent->real_matrix);
+	    get_matrix(c->real_matrix, c->angle, c->xyz, cur_parent->real_matrix);
 	    //get_matrix(c->real_matrix, c->angle, c->xyz, camera->real_matrix);
 
 	} 
@@ -428,7 +428,7 @@
     int light_num = 4;
     for (int i = 0; i < light_num; i++) {
 
-	get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, light[i]->scale, camera->matrix);
+	get_matrix(light[i]->matrix, light[i]->angle, light[i]->xyz, camera->matrix);
       
 	light_vector[i*4] = 0.0f;
 	light_vector[i*4+1] = 0.0f;
--- a/Renderer/Engine/matrix_calc.cc	Thu Dec 23 11:21:52 2010 +0900
+++ b/Renderer/Engine/matrix_calc.cc	Sat Dec 25 18:38:53 2010 +0900
@@ -135,6 +135,9 @@
     return (v0[0]*v1[0] + v0[1]*v1[1] + v0[2]*v1[2]);
 }
 
+/**
+ *     xyz = xyz1 * xyz2
+ */
 void matrix4x4(float *xyz, float *xyz1, float *xyz2) //xyz[16]
 {
   for(int t=0; t<16; t+=4)
@@ -147,11 +150,39 @@
 }
 
 /**
+ *   c_xyz を中心に sacle 倍する
+ */
+void
+scale_matrix(float *xyz, float *scale, float *c_xyz) 
+{
+  float xyz2[16] = {
+        scale[0],  0,         0,         scale[0]*(-c_xyz[0]) + c_xyz[0],
+        0,         scale[1],  1,         scale[1]*(-c_xyz[1]) + c_xyz[1],
+        0,         0,         scale[2],  scale[2]*(-c_xyz[2]) + c_xyz[2],
+        0,         0,         0,         1
+
+  };
+  float xyz1[16]  = {  
+    xyz[0], xyz[1], xyz[2], xyz[3],
+    xyz[4], xyz[5], xyz[6], xyz[7],
+    xyz[8], xyz[9], xyz[10], xyz[11],
+    xyz[12], xyz[13], xyz[14], xyz[15]};
+
+  for(int t=0; t<16; t+=4)
+    {
+      for(int i=0; i<4; i++)
+	{
+	  xyz[t+i] = xyz1[t]*xyz2[i] + xyz1[t+1]*xyz2[4+i] + xyz1[t+2]*xyz2[8+i] + xyz1[t+3]*xyz2[12+i];
+	}
+    }
+}
+
+/**
        stack 上の変換行列に、相対的に、rxyz の回転、txyz の平行移動、scale の拡大を
        行ったものを matrix に代入する
  */
 void
-get_matrix( float *matrix, float *rxyz, float *txyz, float *scale, float *stack)
+get_matrix( float *matrix, float *rxyz, float *txyz, float *stack)
 {
   float radx,rady,radz;
   radx = rxyz[0]*3.14/180;
@@ -191,16 +222,6 @@
 	matrix4x4(matrix, m, stack);
     }
 
-    matrix[0] *= scale[0];
-    matrix[1] *= scale[0];
-    matrix[2] *= scale[0];
-    matrix[4] *= scale[1];
-    matrix[5] *= scale[1];
-    matrix[6] *= scale[1];
-    matrix[8] *= scale[2];
-    matrix[9] *= scale[2];
-    matrix[10] *= scale[2];
-
 }
 
 void rotate_x(float *xyz, float r)
--- a/Renderer/Engine/matrix_calc.h	Thu Dec 23 11:21:52 2010 +0900
+++ b/Renderer/Engine/matrix_calc.h	Sat Dec 25 18:38:53 2010 +0900
@@ -2,13 +2,14 @@
 #define CR_SYS_H
 
 void noMoreMemory();
-void get_matrix(float *matrix, float *rxyz, float *txyz, float *scale, float *stack);
+void get_matrix(float *matrix, float *rxyz, float *txyz, float *stack);
 void rotate_x(float *xyz, float r);
 void rotate_y(float *xyz, float r);
 void rotate_z(float *xyz, float r);
 //void rotate(float *xyz, float *matrix, float *rxyz, float *txyz, float *stack[]);
 void rotate(float *xyz, float *matrix);
 void translate(float *xyz, float x, float y, float z);
+void scale_matrix(float *xyz, float *scale, float *c_xyz);
 void matrix4x4(float *, float *, float *);
 
 void normalize(float *v0, float *v1);
--- a/Renderer/Engine/task/update_sgp.cc	Thu Dec 23 11:21:52 2010 +0900
+++ b/Renderer/Engine/task/update_sgp.cc	Sat Dec 25 18:38:53 2010 +0900
@@ -16,7 +16,6 @@
     SceneGraphPack *_sgp = (SceneGraphPack*)s->get_output(wbuf, 0);
     //int screen_width = get_param(0);
     //int screen_height = get_param(1);
-    float scale[] = {1,1,1};
 
     // 本当はここでやるもんじゃないんだが。。。
     for (int i = 0; i < sgp->info.size && i < 3; i++) {
@@ -25,11 +24,11 @@
 	do {
 	    if (node->pn != -1) {
 		get_matrix(node->translation,
-			   node->angle, node->obj_pos, scale,
+			   node->angle, node->obj_pos, 
 			   sgp->node[node->pn].translation);
 	    } else {
 		get_matrix(node->translation,
-			   node->angle, node->obj_pos, scale,
+			   node->angle, node->obj_pos, 
 			   NULL);
 	    }