- just some cleanup in the Matrix classes
authorAkiko <akiko@linux-addicted.net>
Wed, 23 Oct 2013 08:40:43 +0000 (10:40 +0200)
committerAkiko <akiko@linux-addicted.net>
Wed, 23 Oct 2013 08:40:43 +0000 (10:40 +0200)
engine/Matrix.hxx

index 5aa238f..e4c235c 100644 (file)
 #include <sstream>
 #include "Vector.hxx"
 
-// --- constants ---
-
-enum MatrixIndex : uint8_t {
-    I01 = 0, I02 = 1, I03 = 2, I04 = 3,
-    I05 = 4, I06 = 5, I07 = 6, I08 = 7,
-    I09 = 8, I10 = 9, I11 = 10, I12 = 11,
-    I13 = 12, I14 = 13, I15 = 14, I16 = 15
-};
-
 // --- generic forwarder ---
 
 template <typename MT, size_t C, size_t R>
@@ -146,9 +137,9 @@ public:
             for (size_t row = 0; row < rows; ++row)
             {
                 if (col == row)
-                    m[col][row] = static_cast<const MT>(1);
+                    m[col][row] = 1;
                 else
-                    m[col][row] = static_cast<const MT>(0);
+                    m[col][row] = 0;
             }
         }
     }
@@ -182,32 +173,36 @@ public:
 
     // --- constructors and deconstructors ---
 
+    // default is an identity matrix
     Matrix()
-    : ml{static_cast<const MT>(1), static_cast<const MT>(0), static_cast<const MT>(0), static_cast<const MT>(0),
-         static_cast<const MT>(0), static_cast<const MT>(1), static_cast<const MT>(0), static_cast<const MT>(0),
-         static_cast<const MT>(0), static_cast<const MT>(0), static_cast<const MT>(1), static_cast<const MT>(0),
-         static_cast<const MT>(0), static_cast<const MT>(0), static_cast<const MT>(0), static_cast<const MT>(1)}
+    : ml{1, 0, 0, 0,
+         0, 1, 0, 0,
+         0, 0, 1, 0,
+         0, 0, 0, 1}
     {
     }
 
     Matrix(const MT& val)
-    : ml{val, val, val, val, val, val, val, val, val, val, val, val, val, val, val, val}
+    : ml{val, val, val, val,
+         val, val, val, val,
+         val, val, val, val,
+         val, val, val, val}
     {
     }
 
     Matrix(const MT *mat)
-    : m11(mat[I01]), m21(mat[I02]), m31(mat[I03]), m41(mat[I04]),
-      m12(mat[I05]), m22(mat[I06]), m32(mat[I07]), m42(mat[I08]),
-      m13(mat[I09]), m23(mat[I10]), m33(mat[I11]), m43(mat[I12]),
-      m14(mat[I13]), m24(mat[I14]), m34(mat[I15]), m44(mat[I16])
+    : m11(mat[0]), m21(mat[1]), m31(mat[2]), m41(mat[3]),
+      m12(mat[4]), m22(mat[5]), m32(mat[6]), m42(mat[7]),
+      m13(mat[8]), m23(mat[9]), m33(mat[10]), m43(mat[11]),
+      m14(mat[12]), m24(mat[13]), m34(mat[14]), m44(mat[15])
     {
     }
 
     Matrix(const MT **mat)
-    : m11(mat[I01][I01]), m21(mat[I02][I01]), m31(mat[I03][I01]), m41(mat[I04][I01]),
-      m12(mat[I01][I02]), m22(mat[I02][I02]), m32(mat[I03][I02]), m42(mat[I04][I02]),
-      m13(mat[I01][I03]), m23(mat[I02][I03]), m33(mat[I03][I03]), m43(mat[I04][I03]),
-      m14(mat[I01][I04]), m24(mat[I02][I04]), m34(mat[I03][I04]), m44(mat[I04][I04])
+    : m11(mat[0][0]), m21(mat[1][0]), m31(mat[2][0]), m41(mat[3][0]),
+      m12(mat[0][1]), m22(mat[1][1]), m32(mat[2][1]), m42(mat[3][1]),
+      m13(mat[0][2]), m23(mat[1][2]), m33(mat[2][2]), m43(mat[3][2]),
+      m14(mat[0][3]), m24(mat[1][3]), m34(mat[2][3]), m44(mat[3][3])
     {
     }
 
@@ -275,12 +270,12 @@ public:
         return !(*this == rhs);
     }
 
-    const MT operator[](const MatrixIndex index) const
+    const MT operator[](const size_t& index) const
     {
         return ml[index];
     }
 
-    MT& operator[](const MatrixIndex index)
+    MT& operator[](const size_t& index)
     {
         return ml[index];
     }
@@ -500,7 +495,7 @@ public:
 
     // --- public methods ---
 
-    Vector4<MT> column(const MatrixIndex index) const
+    Vector4<MT> column(const size_t& index) const
     {
         return {ml[index], ml[index + 4], ml[index + 8], ml[index + 12]};
     }