Extra "ports" of juce-based plugins using the distrho build system
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.

120 lines
3.2KB

  1. --- A geometric transformation.
  2. -- Is converted to a [JUCE AffineTransform](http://www.juce.com/api/classAffineTransform.html).
  3. --
  4. -- The default constructor makes an `identity` transform, so all kinds of
  5. -- transformations can be created as follows :
  6. -- rot180 = juce.AffineTransform():rotated(math.pi)
  7. -- chainey = juce.AffineTransform():scaled(2.5):translated(140,140)
  8. -- @classmod juce.AffineTransform
  9. --- Constuctor.
  10. -- parameters thusly define a transformation matrix :
  11. --
  12. -- (mat00 mat01 mat02)
  13. -- (mat10 mat11 mat12)
  14. -- (0 0 1)
  15. -- @param mat00
  16. -- @param mat01
  17. -- @param mat02
  18. -- @param mat10
  19. -- @param mat11
  20. -- @param mat12
  21. -- @within Constructors
  22. -- @constructor
  23. -- @function AffineTransform
  24. local AffineTransform = setmetatable({}, {
  25. __call = function(self, ...)
  26. if select("#", ...)==0 then
  27. return ffi.new("AffineTransform", 1,0,0, 0,1,0)
  28. end
  29. return ffi.new("AffineTransform", ...)
  30. end;
  31. })
  32. local AffineTransform_mt = {
  33. -- methods
  34. __index = {
  35. --- Translated.
  36. -- @param dx the horizontal offset
  37. -- @param dy the vertical offset
  38. -- @return a translated version of this transform
  39. -- @function translated
  40. translated = function (self, dx, dy)
  41. return AffineTransform(
  42. self.mat00, self.mat01, self.mat02 + dx,
  43. self.mat10, self.mat11, self.mat12 + dy)
  44. end;
  45. --- Rotated.
  46. -- @param rad the degree of rotation in radians
  47. -- @return a rotated version of this transform
  48. -- @function rotated
  49. rotated = function (self, rad)
  50. local cosRad = math.cos (rad)
  51. local sinRad = math.sin (rad)
  52. return AffineTransform(
  53. cosRad * self.mat00 + -sinRad * self.mat10,
  54. cosRad * self.mat01 + -sinRad * self.mat11,
  55. cosRad * self.mat02 + -sinRad * self.mat12,
  56. sinRad * self.mat00 + cosRad * self.mat10,
  57. sinRad * self.mat01 + cosRad * self.mat11,
  58. sinRad * self.mat02 + cosRad * self.mat12)
  59. end;
  60. --- Scaled.
  61. -- @param scaleX
  62. -- @param[opt=scaleX] scaleY
  63. -- @return a scaled version of this transform
  64. -- @function scaled
  65. scaled = function (self, scaleX, scaleY)
  66. scaleY = scaleY or scaleX
  67. return AffineTransform(
  68. scaleX * self.mat00, scaleX * self.mat01, scaleX * self.mat02,
  69. scaleY * self.mat10, scaleY * self.mat11, scaleY * self.mat12)
  70. end;
  71. --- Followed by.
  72. -- @param other
  73. -- @return a version of this transform followed by another
  74. -- @function followedBy
  75. followedBy = function (self, other)
  76. return AffineTransform(
  77. other.mat00 * self.mat00 + other.mat01 * self.mat10,
  78. other.mat00 * self.mat01 + other.mat01 * self.mat11,
  79. other.mat00 * self.mat02 + other.mat01 * self.mat12 + other.mat02,
  80. other.mat10 * self.mat00 + other.mat11 * self.mat10,
  81. other.mat10 * self.mat01 + other.mat11 * self.mat11,
  82. other.mat10 * self.mat02 + other.mat11 * self.mat12 + other.mat12)
  83. end;
  84. };
  85. }
  86. ffi.metatype("AffineTransform", AffineTransform_mt)
  87. --- Matrix [0] [0]
  88. -- @simplefield mat00
  89. --- Matrix [0] [1]
  90. -- @simplefield mat01
  91. --- Matrix [0] [2]
  92. -- @simplefield mat02
  93. --- Matrix [1] [0]
  94. -- @simplefield mat10
  95. --- Matrix [1] [1]
  96. -- @simplefield mat11
  97. --- Matrix [1] [2]
  98. -- @simplefield mat12
  99. --- Identity.
  100. -- The non-transform.
  101. -- @predefined juce.AffineTransform.identity
  102. AffineTransform.identity = AffineTransform(1,0,0, 0,1,0)
  103. return AffineTransform