同次座標系で計算

「同次座標系で計算」の編集履歴(バックアップ)一覧はこちら

同次座標系で計算」(2014/04/17 (木) 00:47:51) の最新版変更点

追加された行は緑色になります。

削除された行は赤色になります。

<p><strong>それでは、実際に計算してみます。<br /> 正しく処理されているのがわかると思います。</strong></p> <p><img alt="" src="http://www21.atwiki.jp/opengl?cmd=upload&amp;act=open&amp;pageid=181&amp;file=geo.png" /></p> <table width="600" border="1" cellspacing="1" cellpadding="1"><tbody><tr><td> <p><span style="font-size:small;">//#pragma comment(linker, "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")<br /> #include &lt;GL/freeglut/freeglut.h&gt;<br /> #include &lt;stdio.h&gt;</span></p> <p><span style="font-size:small;">#define WIDTH 640<br /> #define HEIGHT 480</span></p> <p><span style="font-size:small;">//マトリクス構造体<br /> struct MATRIX {<br />     union {<br />         struct {<br />             float _11, _12, _13, _14;<br />             float _21, _22, _23, _24;<br />             float _31, _32, _33, _34;<br />             float _41, _42, _43, _44;<br />         };<br />         float mat_4x4[4][4];<br />         float mat_16[16];<br />     };<br />  MATRIX(){//単位行列に初期化<br />   for(int i=0;i&lt;16;i++){<br />    this-&gt;mat_16[i]=0;<br />   }<br />   this-&gt;_11=this-&gt;_22=this-&gt;_33=this-&gt;_44=1;<br />  }<br />  void PRINT(char* text){<br />   printf("%s\n%f,%f,%f,%f\n%f,%f,%f,%f\n%f,%f,%f,%f\n%f,%f,%f,%f\n\n",<br />    text,<br />    this-&gt;_11,this-&gt;_21,this-&gt;_31,this-&gt;_41,<br />    this-&gt;_12,this-&gt;_22,this-&gt;_32,this-&gt;_42,<br />    this-&gt;_13,this-&gt;_23,this-&gt;_33,this-&gt;_43,<br />    this-&gt;_14,this-&gt;_24,this-&gt;_34,this-&gt;_44);<br />  }<br /> };</span></p> <p><span style="font-size:small;">//4つのベクトル<br /> struct Vector4f{<br />  union {<br />         struct {<br />    float x;<br />    float y;<br />    float z;<br />    float w;<br />   };<br />   float Index[4];<br />  };<br />  Vector4f(){};<br />  Vector4f(float _x,float _y,float _z,float _w){<br />   x=_x;y=_y;z=_z;w=_w;<br />  };<br />  Vector4f GeometricTransform(MATRIX&amp; mat);//幾何変換<br />  void PRINT(char* text){<br />   printf("%s\n%f,%f,%f,%f\n\n",text,this-&gt;x,this-&gt;y,this-&gt;z,this-&gt;w);<br />  }<br /> }vec4d;<br /> Vector4f Vector4f::GeometricTransform(MATRIX &amp;mat){<br />  Vector4f ret;<br />  for(int y=0;y&lt;4;y++){<br />   ret.Index[y]=mat.mat_16[y]*this-&gt;x+mat.mat_16[y+4]*this-&gt;y+mat.mat_16[y+8]*this-&gt;z+mat.mat_16[y+12]*this-&gt;w;<br />  }<br />  return ret;<br /> }</span></p> <p><span style="font-size:small;">void display(void)<br /> {</span></p> <p><span style="font-size:small;">}</span></p> <p><span style="font-size:small;">void Init(){</span></p> <p><span style="font-size:small;"> Vector4f test;<br />  test.x=3.0f;<br />  test.y=1.0f;<br />  test.z=5.0f;<br />  test.w=1.0f;<br />  test.PRINT("同次座標を設定");</span></p> <p><span style="font-size:small;"> MATRIX mat;<br />  mat._41=4.0f;<br />  mat._42=8.0f;<br />  mat._43=2.0f;<br />  mat.PRINT("適当に作成した平行移動行列");</span></p> <p><span style="font-size:small;"> Vector4f ret=test.GeometricTransform(mat);<br />  ret.PRINT("積を行った結果");</span></p> <p><span style="font-size:small;">}<br /> int main(int argc, char *argv[])<br /> {<br />  glutInitWindowPosition(100, 100);<br />  glutInitWindowSize(WIDTH, HEIGHT);<br />  glutInit(&amp;argc, argv);<br />  glutCreateWindow("同次座標で計算");<br />  glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);<br />  glutDisplayFunc(display);<br />  Init();<br />  glutMainLoop();<br />  return 0;<br /> }</span></p> </td> </tr></tbody></table>
<p><strong>それでは、実際に計算してみます。<br /> 正しく処理されているのがわかると思います。</strong></p> <p><img alt="" src="http://cdn21.atwikiimg.com/opengl?cmd=upload&amp;act=open&amp;pageid=181&amp;file=geo.png" /></p> <table border="1" cellpadding="1" cellspacing="1" width="600"><tbody><tr><td> <p>//#pragma comment(linker, "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")<br /> #include &lt;GL/freeglut/freeglut.h&gt;<br /> #include &lt;stdio.h&gt;</p> <p>#define WIDTH 100<br /> #define HEIGHT 50</p> <p>//マトリクス構造体<br /> struct MATRIX {<br />     union {<br />         struct {<br />             float _11, _12, _13, _14;<br />             float _21, _22, _23, _24;<br />             float _31, _32, _33, _34;<br />             float _41, _42, _43, _44;<br />         };<br />         float mat_4x4[4][4];<br />         float mat_16[16];<br />     };<br />  MATRIX(){//単位行列に初期化<br />   for(int i=0;i&lt;16;i++){<br />    this-&gt;mat_16[i]=0;<br />   }<br />   this-&gt;_11=this-&gt;_22=this-&gt;_33=this-&gt;_44=1;<br />  }<br />  void PRINT(char* text){<br />   printf("%s\n%f,%f,%f,%f\n%f,%f,%f,%f\n%f,%f,%f,%f\n%f,%f,%f,%f\n\n",<br />    text,<br />    this-&gt;_11,this-&gt;_21,this-&gt;_31,this-&gt;_41,<br />    this-&gt;_12,this-&gt;_22,this-&gt;_32,this-&gt;_42,<br />    this-&gt;_13,this-&gt;_23,this-&gt;_33,this-&gt;_43,<br />    this-&gt;_14,this-&gt;_24,this-&gt;_34,this-&gt;_44);<br />  }<br /> };</p> <p>//4つのベクトル<br /> struct Vector4f{<br />  union {<br />         struct {<br />    float x;<br />    float y;<br />    float z;<br />    float w;<br />   };<br />   float Index[4];<br />  };<br />  Vector4f(){};<br />  Vector4f(float _x,float _y,float _z,float _w){<br />   x=_x;y=_y;z=_z;w=_w;<br />  };<br />  Vector4f GeometricTransform(MATRIX&amp; mat);//幾何変換<br />  void PRINT(char* text){<br />   printf("%s\n%f,%f,%f,%f\n\n",text,this-&gt;x,this-&gt;y,this-&gt;z,this-&gt;w);<br />  }<br /> }vec4d;<br /> Vector4f Vector4f::GeometricTransform(MATRIX &amp;mat){<br />  Vector4f ret;<br />  for(int y=0;y&lt;4;y++){<br />   ret.Index[y]=mat.mat_16[y]*this-&gt;x+mat.mat_16[y+4]*this-&gt;y+mat.mat_16[y+8]*this-&gt;z+mat.mat_16[y+12]*this-&gt;w;<br />  }<br />  return ret;<br /> }</p> <p>void display(void)<br /> {</p> <p>}</p> <p>void Init(){</p> <p> Vector4f test;<br />  test.x=3.0f;<br />  test.y=1.0f;<br />  test.z=5.0f;<br />  test.w=1.0f;<br />  test.PRINT("同次座標を設定");</p> <p> MATRIX mat;<br />  mat._41=4.0f;<br />  mat._42=8.0f;<br />  mat._43=2.0f;<br />  mat.PRINT("適当に作成した平行移動行列");</p> <p> Vector4f ret=test.GeometricTransform(mat);<br />  ret.PRINT("積を行った結果");</p> <p>}<br /> int main(int argc, char *argv[])<br /> {<br />  glutInitWindowPosition(100, 100);<br />  glutInitWindowSize(WIDTH, HEIGHT);<br />  glutInit(&amp;argc, argv);<br />  glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);<br />  glutCreateWindow("同次座標で計算");<br />  glutDisplayFunc(display);<br />  Init();<br />  glutMainLoop();<br />  return 0;<br /> }</p> </td> </tr></tbody></table>

表示オプション

横に並べて表示:
変化行の前後のみ表示: