def transform_vec3(self, v): """Transforms a vector and returns the result as a Vector3. v -- Vector to transform """ m = self._m x, y, z = v return Vector3.from_floats(x * m[0] + y * m[4] + z * m[8] + m[12], x * m[1] + y * m[5] + z * m[9] + m[13], x * m[2] + y * m[6] + z * m[10] + m[14])
def rotate_vec3(self, v): """Rotates a Vector3 and returns the result. The translation part of the Matrix44 is ignored. v -- Vector to rotate """ m = self._m x, y, z = v return Vector3.from_floats(x * m[0] + y * m[4] + z * m[8], x * m[1] + y * m[5] + z * m[9], x * m[2] + y * m[6] + z * m[10])
def transform_sequence_vec3(self, points): m_0, m_1, m_2, m_3, \ m_4, m_5, m_6, m_7, \ m_8, m_9, m_10, m_11, \ m_12, m_13, m_14, m_15 = self._m return [ Vector3.from_floats(x * m_0 + y * m_4 + z * m_8 + m_12, x * m_1 + y * m_5 + z * m_9 + m_13, x * m_2 + y * m_6 + z * m_10 + m_14) for x, y, z in points ]
def get_row_vec3(self, row_no): """Returns a Vector3 for a given row. row_no -- The row index """ try: r = row_no * 4 x, y, z = self._m[r:r + 3] return Vector3.from_floats(x, y, z) except IndexError: raise IndexError("Row and Column should be 0, 1, 2 or 3")
def iter_transform_vec3(self, points): """Transforms a sequence of points, and yields the result as Vector3s points -- A sequence of vectors """ m_0, m_1, m_2, m_3, \ m_4, m_5, m_6, m_7, \ m_8, m_9, m_10, m_11, \ m_12, m_13, m_14, m_15 = self._m for x, y, z in points: yield Vector3.from_floats(x * m_0 + y * m_4 + z * m_8 + m_12, x * m_1 + y * m_5 + z * m_9 + m_13, x * m_2 + y * m_6 + z * m_10 + m_14)