VertexEffect.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /******************************************************************************
  2. * Spine Runtimes License Agreement
  3. * Last updated January 1, 2020. Replaces all prior versions.
  4. *
  5. * Copyright (c) 2013-2020, Esoteric Software LLC
  6. *
  7. * Integration of the Spine Runtimes into software or otherwise creating
  8. * derivative works of the Spine Runtimes is permitted under the terms and
  9. * conditions of Section 2 of the Spine Editor License Agreement:
  10. * http://esotericsoftware.com/spine-editor-license
  11. *
  12. * Otherwise, it is permitted to integrate the Spine Runtimes into software
  13. * or otherwise create derivative works of the Spine Runtimes (collectively,
  14. * "Products"), provided that each user of the Products must obtain their own
  15. * Spine Editor license and redistribution of the Products in any form must
  16. * include this license and copyright notice.
  17. *
  18. * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
  19. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
  24. * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *****************************************************************************/
  29. #ifdef SPINE_UE4
  30. #include "SpinePluginPrivatePCH.h"
  31. #endif
  32. #include <spine/VertexEffect.h>
  33. #include <spine/MathUtil.h>
  34. #include <spine/Skeleton.h>
  35. using namespace spine;
  36. JitterVertexEffect::JitterVertexEffect(float jitterX, float jitterY): _jitterX(jitterX), _jitterY(jitterY) {
  37. }
  38. void JitterVertexEffect::begin(Skeleton &skeleton) {
  39. SP_UNUSED(skeleton);
  40. }
  41. void JitterVertexEffect::transform(float &x, float &y, float &u, float &v, Color &light, Color &dark) {
  42. SP_UNUSED(u);
  43. SP_UNUSED(v);
  44. SP_UNUSED(light);
  45. SP_UNUSED(dark);
  46. float jitterX = _jitterX;
  47. float jitterY = _jitterY;
  48. x += MathUtil::randomTriangular(-jitterX, jitterX);
  49. y += MathUtil::randomTriangular(-jitterX, jitterY);
  50. }
  51. void JitterVertexEffect::end() {
  52. }
  53. void JitterVertexEffect::setJitterX(float jitterX) {
  54. _jitterX = jitterX;
  55. }
  56. float JitterVertexEffect::getJitterX() {
  57. return _jitterX;
  58. }
  59. void JitterVertexEffect::setJitterY(float jitterY) {
  60. _jitterY = jitterY;
  61. }
  62. float JitterVertexEffect::getJitterY() {
  63. return _jitterY;
  64. }
  65. SwirlVertexEffect::SwirlVertexEffect(float radius, Interpolation &interpolation):
  66. _centerX(0),
  67. _centerY(0),
  68. _radius(radius),
  69. _angle(0),
  70. _worldX(0),
  71. _worldY(0),
  72. _interpolation(interpolation) {
  73. }
  74. void SwirlVertexEffect::begin(Skeleton &skeleton) {
  75. _worldX = skeleton.getX() + _centerX;
  76. _worldY = skeleton.getY() + _centerY;
  77. }
  78. void SwirlVertexEffect::transform(float &positionX, float &positionY, float &u, float &v, Color &light, Color &dark) {
  79. SP_UNUSED(u);
  80. SP_UNUSED(v);
  81. SP_UNUSED(light);
  82. SP_UNUSED(dark);
  83. float x = positionX - _worldX;
  84. float y = positionY - _worldY;
  85. float dist = (float)MathUtil::sqrt(x * x + y * y);
  86. if (dist < _radius) {
  87. float theta = _interpolation.interpolate(0, _angle, (_radius - dist) / _radius);
  88. float cos = MathUtil::cos(theta), sin = MathUtil::sin(theta);
  89. positionX = cos * x - sin * y + _worldX;
  90. positionY = sin * x + cos * y + _worldY;
  91. }
  92. }
  93. void SwirlVertexEffect::end() {
  94. }
  95. void SwirlVertexEffect::setCenterX(float centerX) {
  96. _centerX = centerX;
  97. }
  98. float SwirlVertexEffect::getCenterX() {
  99. return _centerX;
  100. }
  101. void SwirlVertexEffect::setCenterY(float centerY) {
  102. _centerY = centerY;
  103. }
  104. float SwirlVertexEffect::getCenterY() {
  105. return _centerY;
  106. }
  107. void SwirlVertexEffect::setRadius(float radius) {
  108. _radius = radius;
  109. }
  110. float SwirlVertexEffect::getRadius() {
  111. return _radius;
  112. }
  113. void SwirlVertexEffect::setAngle(float angle) {
  114. _angle = angle * MathUtil::Deg_Rad;
  115. }
  116. float SwirlVertexEffect::getAngle() {
  117. return _angle;
  118. }
  119. void SwirlVertexEffect::setWorldX(float worldX) {
  120. _worldX = worldX;
  121. }
  122. float SwirlVertexEffect::getWorldX() {
  123. return _worldX;
  124. }
  125. void SwirlVertexEffect::setWorldY(float worldY) {
  126. _worldY = worldY;
  127. }
  128. float SwirlVertexEffect::getWorldY() {
  129. return _worldY;
  130. }