matrix.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * Matrix header
  4. *
  5. * Created by Manoël Trapier
  6. * Copyright (c) 2020 986-Studio.
  7. *
  8. */
  9. #ifndef DORAYME_MATRIX_H
  10. #define DORAYME_MATRIX_H
  11. #include <tuples.h>
  12. class Matrix
  13. {
  14. private:
  15. /* 4x4 is the default */
  16. double data[4*4];
  17. int width;
  18. public:
  19. Matrix(int width);
  20. Matrix(double values[], int width);
  21. double get(int x, int y) const { return this->data[this->width * x + y]; };
  22. void set(int x, int y, double v) { this->data[this->width * x + y] = v; };
  23. Matrix identity();
  24. Matrix transpose();
  25. bool operator==(const Matrix &b) const;
  26. bool operator!=(const Matrix &b) const;
  27. Matrix operator*(const Matrix &b) const;
  28. Tuple operator*(const Tuple &b) const;
  29. };
  30. class Matrix4: public Matrix
  31. {
  32. public:
  33. Matrix4() : Matrix(4) { };
  34. Matrix4(double values[]) : Matrix(values, 4) { };
  35. };
  36. class Matrix2 : public Matrix
  37. {
  38. public:
  39. Matrix2() : Matrix(2) { };
  40. Matrix2(double values[]) : Matrix(values, 2) { };
  41. };
  42. class Matrix3 : public Matrix
  43. {
  44. public:
  45. Matrix3() : Matrix(3) { };
  46. Matrix3(double values[]) : Matrix(values, 3) { };
  47. };
  48. #endif /* DORAYME_MATRIX_H */