//********************************** Banshee Engine (www.banshee3d.com) **************************************************// //**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************// #pragma once #include "Prerequisites/BsPrerequisitesUtil.h" #include "Math/BsVector3.h" namespace bs { /** @addtogroup Math * @{ */ /** * Class representing a NxM matrix. * * @note If you need to use matrices for more than just data storage then * it is suggested you use specialized Matrix3 or Matrix4 classes * as they provide a wide range of functionality. */ template class MatrixNxM { public: MatrixNxM() {} MatrixNxM(float data[N*M]) { memcpy(m, data, N*M * sizeof(float)); } /** Returns a transpose of the matrix (switched columns and rows). */ MatrixNxM transpose() const { MatrixNxM matTranspose; for (UINT32 row = 0; row < N; row++) { for (UINT32 col = 0; col < M; col++) matTranspose[row][col] = m[col][row]; } return matTranspose; } /** Returns a row of the matrix. */ float* operator[] (UINT32 row) const { assert(row < N); return (float*)m[row]; } MatrixNxM& operator= (const MatrixNxM& rhs) { memcpy(m, rhs.m, (N*M)*sizeof(float)); return *this; } bool operator== (const MatrixNxM& rhs) const { for (UINT32 row = 0; row < N; row++) { for (UINT32 col = 0; col < M; col++) { if (m[row][col] != rhs.m[row][col]) return false; } } return true; } bool operator!= (const MatrixNxM& rhs) const { return !operator==(rhs); } float m[N][M]; }; typedef MatrixNxM<2, 2> Matrix2; typedef MatrixNxM<2, 3> Matrix2x3; typedef MatrixNxM<2, 4> Matrix2x4; typedef MatrixNxM<3, 2> Matrix3x2; typedef MatrixNxM<3, 4> Matrix3x4; typedef MatrixNxM<4, 2> Matrix4x2; typedef MatrixNxM<4, 3> Matrix4x3; /** @} */ }