Transform.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * Copyright (c) 2006-2017 LOVE Development Team
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. *
  8. * Permission is granted to anyone to use this software for any purpose,
  9. * including commercial applications, and to alter it and redistribute it
  10. * freely, subject to the following restrictions:
  11. *
  12. * 1. The origin of this software must not be misrepresented; you must not
  13. * claim that you wrote the original software. If you use this software
  14. * in a product, an acknowledgment in the product documentation would be
  15. * appreciated but is not required.
  16. * 2. Altered source versions must be plainly marked as such, and must not be
  17. * misrepresented as being the original software.
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. **/
  20. #pragma once
  21. // LOVE
  22. #include "common/Object.h"
  23. #include "common/Matrix.h"
  24. #include "common/Vector.h"
  25. #include "common/StringMap.h"
  26. namespace love
  27. {
  28. namespace math
  29. {
  30. class Transform : public Object
  31. {
  32. public:
  33. enum MatrixLayout
  34. {
  35. MATRIX_ROW_MAJOR,
  36. MATRIX_COLUMN_MAJOR,
  37. MATRIX_MAX_ENUM
  38. };
  39. static love::Type type;
  40. Transform();
  41. Transform(const Matrix4 &m);
  42. Transform(float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky);
  43. virtual ~Transform();
  44. Transform *clone();
  45. Transform *inverse();
  46. void apply(Transform *other);
  47. void translate(float x, float y);
  48. void rotate(float angle);
  49. void scale(float x, float y);
  50. void shear(float x, float y);
  51. void reset();
  52. void setTransformation(float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky);
  53. love::Vector2 transformPoint(love::Vector2 p) const;
  54. love::Vector2 inverseTransformPoint(love::Vector2 p);
  55. const Matrix4 &getMatrix() const;
  56. void setMatrix(const Matrix4 &m);
  57. static bool getConstant(const char *in, MatrixLayout &out);
  58. static bool getConstant(MatrixLayout in, const char *&out);
  59. private:
  60. inline const Matrix4 &getInverseMatrix()
  61. {
  62. if (inverseDirty)
  63. {
  64. inverseDirty = false;
  65. inverseMatrix = matrix.inverse();
  66. }
  67. return inverseMatrix;
  68. }
  69. Matrix4 matrix;
  70. bool inverseDirty;
  71. Matrix4 inverseMatrix;
  72. static StringMap<MatrixLayout, MATRIX_MAX_ENUM>::Entry matrixLayoutEntries[];
  73. static StringMap<MatrixLayout, MATRIX_MAX_ENUM> matrixLayouts;
  74. }; // Transform
  75. } // math
  76. } // love