CCAffineTransform.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /****************************************************************************
  2. Copyright (c) 2010-2012 cocos2d-x.org
  3. Copyright (c) 2013-2017 Chukong Technologies Inc.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #ifndef __MATH_CCAFFINETRANSFORM_H__
  22. #define __MATH_CCAFFINETRANSFORM_H__
  23. #include "platform/CCPlatformMacros.h"
  24. #include "math/CCGeometry.h"
  25. #include "math/CCMath.h"
  26. /**
  27. * @addtogroup base
  28. * @{
  29. */
  30. NS_CC_BEGIN
  31. /**@{
  32. Affine transform
  33. a b 0
  34. c d 0
  35. tx ty 1
  36. Identity
  37. 1 0 0
  38. 0 1 0
  39. 0 0 1
  40. */
  41. struct CC_DLL AffineTransform {
  42. float a, b, c, d;
  43. float tx, ty;
  44. static const AffineTransform IDENTITY;
  45. };
  46. /**@}*/
  47. /**Make affine transform.*/
  48. CC_DLL AffineTransform __CCAffineTransformMake(float a, float b, float c, float d, float tx, float ty);
  49. #define AffineTransformMake __CCAffineTransformMake
  50. /**Multiply point (x,y,1) by a affine transform.*/
  51. CC_DLL Vec2 __CCPointApplyAffineTransform(const Vec2& point, const AffineTransform& t);
  52. #define PointApplyAffineTransform __CCPointApplyAffineTransform
  53. /**Multiply size (width,height,0) by a affine transform.*/
  54. CC_DLL Size __CCSizeApplyAffineTransform(const Size& size, const AffineTransform& t);
  55. #define SizeApplyAffineTransform __CCSizeApplyAffineTransform
  56. /**Make identity affine transform.*/
  57. CC_DLL AffineTransform AffineTransformMakeIdentity();
  58. /**Transform Rect, which will transform the four vertices of the point.*/
  59. CC_DLL Rect RectApplyAffineTransform(const Rect& rect, const AffineTransform& anAffineTransform);
  60. /**@{
  61. Transform vec2 and Rect by Mat4.
  62. */
  63. CC_DLL Rect RectApplyTransform(const Rect& rect, const Mat4& transform);
  64. CC_DLL Vec2 PointApplyTransform(const Vec2& point, const Mat4& transform);
  65. /**@}*/
  66. /**
  67. Translation, equals
  68. 1 0 1
  69. 0 1 0 * affine transform
  70. tx ty 1
  71. */
  72. CC_DLL AffineTransform AffineTransformTranslate(const AffineTransform& t, float tx, float ty);
  73. /**
  74. Rotation, equals
  75. cos(angle) sin(angle) 0
  76. -sin(angle) cos(angle) 0 * AffineTransform
  77. 0 0 1
  78. */
  79. CC_DLL AffineTransform AffineTransformRotate(const AffineTransform& aTransform, float anAngle);
  80. /**
  81. Scale, equals
  82. sx 0 0
  83. 0 sy 0 * affineTransform
  84. 0 0 1
  85. */
  86. CC_DLL AffineTransform AffineTransformScale(const AffineTransform& t, float sx, float sy);
  87. /**Concat two affine transform, t1 * t2*/
  88. CC_DLL AffineTransform AffineTransformConcat(const AffineTransform& t1, const AffineTransform& t2);
  89. /**Compare affine transform.*/
  90. CC_DLL bool AffineTransformEqualToTransform(const AffineTransform& t1, const AffineTransform& t2);
  91. /**Get the inverse of affine transform.*/
  92. CC_DLL AffineTransform AffineTransformInvert(const AffineTransform& t);
  93. /**Concat Mat4, return t1 * t2.*/
  94. CC_DLL Mat4 TransformConcat(const Mat4& t1, const Mat4& t2);
  95. extern CC_DLL const AffineTransform AffineTransformIdentity;
  96. NS_CC_END
  97. // end of base transform
  98. /// @}
  99. #endif // __MATH_CCAFFINETRANSFORM_H__