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.

94 lines
3.4KB

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