OSDN Git Service

Merge branch 'mat_fix' of git.sourceforge.jp:/gitroot/moflib/moflib
authoro_ggy <o_ggy@users.sourceforge.jp>
Mon, 6 Sep 2010 01:08:11 +0000 (10:08 +0900)
committero_ggy <o_ggy@users.sourceforge.jp>
Mon, 6 Sep 2010 01:08:11 +0000 (10:08 +0900)
Conflicts:
src/mof/math/basic_matrix.hpp
src/mof/math/basic_vector.hpp
src/mof/math/matrix2.hpp
src/mof/math/matrix3.hpp
src/mof/math/test/matrix3_test.cpp

1  2 
src/mof/math/basic_matrix.hpp
src/mof/math/basic_vector.hpp
src/mof/math/matrix2.hpp
src/mof/math/matrix3.hpp
src/mof/math/test/matrix3_test.cpp

@@@ -107,33 -102,17 +102,43 @@@ namespace mat
                }
  //}}}
  //{{{ operator *=     
++<<<<<<< HEAD
 +              /**
 +               * @brief 行列の積を計算し,最後の要素が1になるように定数倍する.
 +               */
 +              Derived& operator*=(const Derived& rhs)
 +              {
 +                      Derived retval;
 +                      const int SIZE = Dim + 1;
 +
 +                      // calculate the last element previously
 +                      int b = last_index() - Dim;
 +                      int c = Dim;
 +                      float last_sum = 0;
 +                      for (int i = 0; i < SIZE; ++i) {
 +                              last_sum += elements_[b + i] * rhs.elements_[c + i * SIZE];
 +                      }
 +                      retval.elements_[last_index()] = 1;
 +
 +                      for (int a = last_index() - 1; a >= 0; --a) {
 +                              int b = a / SIZE * SIZE;
 +                              int c = a % SIZE;
 +                              float sum = 0;
 +                              for (int i = 0; i < SIZE; ++i) {
 +                                      sum += elements_[b + i] * rhs.elements_[c + i * SIZE];
++=======
+               Derived& operator*=(const Derived& rhs) const
+               {
+                       Derived M;
+                       for (int i = 0; i < Dim; ++i) {
+                               for (int j = 0; j <= Dim; ++j) {
+                                       for (int k = 0; k <= Dim; ++k) {
+                                               M.elements_[i][j] += (*this)[i][k] * rhs[k][j];
+                                       }
++>>>>>>> b5b23396b7e7f34fc19daa767a3cbdad95673d24
                                }
-                               retval.elements_[a] = sum / last_sum;
                        }
-                       *this = retval;
+                       *this = M;
                        return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
                }
  
                        }
                        return Coordinate(arr);
                }
++<<<<<<< HEAD
++=======
+               friend Derived operator*(float rhs1, Derived& rhs2) 
+               {
+                       float arr[last_index() + 1];
+                       for (size_t i = 0; i <= last_index(); ++i) {
+                               arr[i] *= rhs;
+                       }
+                       return Derived(arr);
+               }
++>>>>>>> b5b23396b7e7f34fc19daa767a3cbdad95673d24
  //}}}
  //{{{ operator /=
-               Derived& operator/=(float rhs)
+               Derived& operator/=(float rhs) const
                {
-                       const size_t END = last_index() - 1;// 最後の要素は1で保存
-                       for (size_t i = 0; i <= END; ++i) {
-                               elements_[i] /= rhs;
+                       for (size_t i = 0; i <= last_index(); ++i) {
+                               components_[i] /= rhs;
                        }
                        return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
                }
@@@ -80,9 -87,16 +87,19 @@@ namespace mat
                        for (size_t i = 0; i < Dim; ++i) components_[i] *= rhs;
                        return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
                }
++<<<<<<< HEAD
++=======
+               
+               friend Derived operator*(float rhs1, Derived& rhs2)
+               {
+                       Derived retval;
+                       for (size_t i = 0; i < Dim; ++i) retval.components_[i] = rhs1 * rhs2.components_[i];
+                       return retval;
+               }
++>>>>>>> b5b23396b7e7f34fc19daa767a3cbdad95673d24
  //}}}
  //{{{ operator /=
-               Derived& operator/=(float rhs)
+               Derived& operator/=(float rhs) const
                {
                        for (size_t i = 0; i < Dim; ++i) components_[i] /= rhs;
                        return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
@@@ -73,8 -72,8 +72,13 @@@ namespace mat
  //{{{ operator =
        matrix2& operator = (const matrix2& rhs)
        {
++<<<<<<< HEAD
 +              for (size_t i = 0; i <= last_index() - 1; ++i) {
 +                      elements_[i] = rhs.elements_[i];
++=======
+               for (size_t i = 0; i <= last_index(); ++i) {
+                       components_[i] = rhs.components_[i];
++>>>>>>> b5b23396b7e7f34fc19daa767a3cbdad95673d24
                }
                return *this;
        }
@@@ -67,8 -67,8 +67,13 @@@ namespace mat
  //{{{ copy constructor
        matrix3(const matrix3& rhs)
        {
++<<<<<<< HEAD
 +              for (size_t i = 0; i <= last_index(); ++i) {
 +                      elements_[i] = rhs.elements_[i];
++=======
+               for (size_t i = 0; i < last_index(); ++i) {
+                       components_[i] = rhs.components_[i];
++>>>>>>> b5b23396b7e7f34fc19daa767a3cbdad95673d24
                }
        }
  //}}}
         */
        matrix3& operator = (const matrix3& rhs)
        {
++<<<<<<< HEAD
 +              for (size_t i = 0; i <= last_index() -1; ++i) {
 +                      elements_[i] = rhs.elements_[i];
++=======
+               for (size_t i = 0; i < last_index(); ++i) {
+                       components_[i] = rhs.components_[i];
++>>>>>>> b5b23396b7e7f34fc19daa767a3cbdad95673d24
                }
                return *this;
        }
@@@ -94,11 -92,10 +92,15 @@@ int main(
        }
  
        {
-               matrix3 N1(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0, 0, 0);
-               matrix3 N2(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 0, 0, 0);
+               matrix3 N1(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
+               matrix3 N2(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13);
                matrix3 N = N1 * N2;
++<<<<<<< HEAD
 +              matrix3 A(44, 50, 56, 66, 116, 134, 152, 178, 188, 218, 248, 290, 0, 0, 0);
 +              cout << N << endl;
++=======
+               matrix3 A(44, 50, 56, 66, 116, 134, 152, 178, 188, 218, 248, 290);
++>>>>>>> b5b23396b7e7f34fc19daa767a3cbdad95673d24
                if (N != A) {
                        cerr << "Failed:" << "Affine matrix N1 * N2 test" << endl;      
                        failed_count++;
        }
        
        {
++<<<<<<< HEAD
 +              matrix3 N1(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
 +              matrix3 N2(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
 +              matrix3 N = N1 * N2;
 +              matrix3 A
 +              (
 +                      0.25840f, 0.28424f, 0.31008f, 0.17054f,
 +                      0.58915f, 0.65633f, 0.72351f, 0.45995f,
 +                      0.91990f, 1.02842f, 1.13695f, 0.74935f,
 +                      0.70801f, 0.81912f, 0.93023f
 +              );
 +              if (N != A) {
 +                      cerr << "Failed:" << "Projective matrix N1 * N2 test" << endl;  
 +                      failed_count++;
 +              }
 +      }
 +      
 +      {
 +              matrix3 M(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
++=======
+               matrix3 M(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
++>>>>>>> b5b23396b7e7f34fc19daa767a3cbdad95673d24
                vector3 v(1, 2, 3);
                vector3 w = M * v;
                vector3 a(0.20690f, 0.52874f, 0.85057f);