The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
3.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef JUCE_MATRIX3D_H_INCLUDED
  18. #define JUCE_MATRIX3D_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A 4x4 transformation matrix.
  22. @see AffineTransform
  23. */
  24. template <typename Type>
  25. class Matrix3D
  26. {
  27. public:
  28. Matrix3D() noexcept
  29. {
  30. zeromem (mat, sizeof (mat));
  31. mat[0] = mat[1 + 1 * 4] = mat[2 + 2 * 4] = mat[3 + 3 * 4] = (Type) 1;
  32. }
  33. Matrix3D (const Matrix3D& other) noexcept
  34. {
  35. memcpy (mat, other.mat, sizeof (mat));
  36. }
  37. Matrix3D (const AffineTransform& transform) noexcept
  38. {
  39. mat[0] = transform.mat00; mat[1] = transform.mat10; mat[2] = 0; mat[3] = 0;
  40. mat[4] = transform.mat01; mat[5] = transform.mat11; mat[6] = 0; mat[7] = 0;
  41. mat[8] = 0; mat[9] = 0; mat[10] = (Type) 1; mat[11] = 0;
  42. mat[12] = transform.mat02; mat[13] = transform.mat12; mat[14] = 0; mat[15] = (Type) 1;
  43. }
  44. Matrix3D (const Type* values) noexcept
  45. {
  46. memcpy (mat, values, sizeof (mat));
  47. }
  48. Matrix3D (const Type& m00, const Type& m10, const Type& m20, const Type& m30,
  49. const Type& m01, const Type& m11, const Type& m21, const Type& m31,
  50. const Type& m02, const Type& m12, const Type& m22, const Type& m32,
  51. const Type& m03, const Type& m13, const Type& m23, const Type& m33) noexcept
  52. {
  53. mat[0] = m00; mat[1] = m10; mat[2] = m20; mat[3] = m30;
  54. mat[4] = m01; mat[5] = m11; mat[6] = m21; mat[7] = m31;
  55. mat[8] = m02; mat[9] = m12; mat[10] = m22; mat[11] = m32;
  56. mat[12] = m03; mat[13] = m13; mat[14] = m23; mat[15] = m33;
  57. }
  58. Matrix3D& operator= (const Matrix3D& other) noexcept
  59. {
  60. memcpy (mat, other.mat, sizeof (mat));
  61. return *this;
  62. }
  63. #if JUCE_USE_OPENGL_FIXED_FUNCTION
  64. /** Multiplies the active OpenGL context's matrix by this one. */
  65. void applyToOpenGL() const noexcept
  66. {
  67. OpenGLHelpers::applyMatrix (mat);
  68. }
  69. #endif
  70. /** The 4x4 matrix values. These are stored in the standard OpenGL order. */
  71. Type mat[16];
  72. };
  73. #endif // JUCE_MATRIX3D_H_INCLUDED