Mercurial > hg > Game > Cerium
diff Renderer/Engine/matrix_calc.cc @ 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 | 2a291e6ac2fc |
children | 1ef561eb1ef5 |
line wrap: on
line diff
--- 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)