Commits

Anonymous committed e83851c

Added a function that checks if a matrix is affine.

  • Participants
  • Parent commits 1c42e27

Comments (0)

Files changed (2)

File neglect/cpplib/include/neglect/matrix.hpp

         m[3] = vector<T, 4>(T(), T(), T(), T(1));
         return m;
     }
+
+    /* checks a 4x4 matrix if it represents an affine transformation.
+       (last row is 0, 0, 0, 1) */
+    template <typename T>
+    bool is_affine(const matrix<T, 4, 4> &mat)
+    {
+        return mat[0][3] == T() &&
+               mat[1][3] == T() &&
+               mat[2][3] == T() &&
+               mat[3][3] == T(1);
+    }
 }
 
 #endif

File neglect/tests/src/test_matrix.cpp

         m2expected[2] = vec3(1, -1, 0);
         NUT_CHECK_EQUAL(inverse(m2), m2expected);
     }
+
+    NUT_TESTCASE(matrix_is_afffine)
+    {
+        mat4 m = translation_matrix(2.0f, 0.0f, 2.0f);
+        NUT_CHECK(is_affine(m));
+        m[3][3] = 25.0f;
+        NUT_CHECK(!is_affine(m));
+    }
 }