Matrix.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #ifndef CORE_MATRIX_H
  2. #define CORE_MATRIX_H
  3. #include "math/Quaternion.h"
  4. #include "utils/ArrayString.h"
  5. namespace Core {
  6. class Matrix final {
  7. Vector4 data[4];
  8. public:
  9. Matrix();
  10. Matrix& unit();
  11. Matrix& set(int index, const Vector4& v);
  12. Matrix transpose();
  13. const float* getValues() const;
  14. Matrix& operator*=(const Matrix& other);
  15. Matrix operator*(const Matrix& other) const;
  16. Vector3 operator*(const Vector3& v) const;
  17. Matrix& scale(const Vector3& v);
  18. Matrix& scale(float f);
  19. Matrix& translate(const Vector3& v);
  20. Matrix& translateX(float tx);
  21. Matrix& translateY(float ty);
  22. Matrix& translateZ(float tz);
  23. Matrix& translateTo(const Vector3& v);
  24. Matrix& rotateX(float degrees);
  25. Matrix& rotateY(float degrees);
  26. Matrix& rotateZ(float degrees);
  27. Matrix& rotate(const Quaternion& q);
  28. // returns true on error and calls the error callback
  29. template<int L>
  30. check_return bool toString(ArrayString<L>& s) const {
  31. return s.append('[') || s.append(data[0]) || s.append(", ") ||
  32. s.append(data[1]) || s.append(", ") || s.append(data[2]) ||
  33. s.append(", ") || s.append(data[3]) || s.append("]");
  34. }
  35. private:
  36. Matrix& rotate(float degrees, int a, int b);
  37. };
  38. }
  39. #endif