Matrix.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #ifndef CORE_MATRIX_HPP
  2. #define CORE_MATRIX_HPP
  3. #include "core/math/Quaternion.hpp"
  4. #include "core/utils/ArrayString.hpp"
  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. template<typename String>
  29. check_return Error toString(String& s) const {
  30. CORE_RETURN_ERROR(s.append('['));
  31. CORE_RETURN_ERROR(s.append(data[0]));
  32. CORE_RETURN_ERROR(s.append(", "));
  33. CORE_RETURN_ERROR(s.append(data[1]));
  34. CORE_RETURN_ERROR(s.append(", "));
  35. CORE_RETURN_ERROR(s.append(data[2]));
  36. CORE_RETURN_ERROR(s.append(", "));
  37. CORE_RETURN_ERROR(s.append(data[3]));
  38. CORE_RETURN_ERROR(s.append("]"));
  39. return ErrorCode::NONE;
  40. }
  41. private:
  42. Matrix& rotate(float degrees, int a, int b);
  43. };
  44. }
  45. #endif