SkeletonBounds.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /******************************************************************************
  2. * Spine Runtimes Software License
  3. * Version 2
  4. *
  5. * Copyright (c) 2013, Esoteric Software
  6. * All rights reserved.
  7. *
  8. * You are granted a perpetual, non-exclusive, non-sublicensable and
  9. * non-transferable license to install, execute and perform the Spine Runtimes
  10. * Software (the "Software") solely for internal use. Without the written
  11. * permission of Esoteric Software, you may not (a) modify, translate, adapt or
  12. * otherwise create derivative works, improvements of the Software or develop
  13. * new applications using the Software or (b) remove, delete, alter or obscure
  14. * any trademarks or any copyright, trademark, patent or other intellectual
  15. * property or proprietary rights notices on or in the Software, including
  16. * any copy thereof. Redistributions in binary or source form must include
  17. * this license and terms. THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE
  18. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  19. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTARE BE LIABLE FOR ANY
  21. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *****************************************************************************/
  28. #ifndef SPINE_SKELETONBOUNDS_H_
  29. #define SPINE_SKELETONBOUNDS_H_
  30. #include <spine/BoundingBoxAttachment.h>
  31. #include <spine/Skeleton.h>
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. typedef struct {
  36. float* const vertices;
  37. int count;
  38. int capacity;
  39. } spPolygon;
  40. spPolygon* spPolygon_create (int capacity);
  41. void spPolygon_dispose (spPolygon* self);
  42. int/*bool*/spPolygon_containsPoint (spPolygon* polygon, float x, float y);
  43. int/*bool*/spPolygon_intersectsSegment (spPolygon* polygon, float x1, float y1, float x2, float y2);
  44. #ifdef SPINE_SHORT_NAMES
  45. typedef spPolygon Polygon;
  46. #define Polygon_create(...) spPolygon_create(__VA_ARGS__)
  47. #define Polygon_dispose(...) spPolygon_dispose(__VA_ARGS__)
  48. #define Polygon_containsPoint(...) spPolygon_containsPoint(__VA_ARGS__)
  49. #define Polygon_intersectsSegment(...) spPolygon_intersectsSegment(__VA_ARGS__)
  50. #endif
  51. /**/
  52. typedef struct {
  53. int count;
  54. spBoundingBoxAttachment** boundingBoxes;
  55. spPolygon** polygons;
  56. float minX, minY, maxX, maxY;
  57. } spSkeletonBounds;
  58. spSkeletonBounds* spSkeletonBounds_create ();
  59. void spSkeletonBounds_dispose (spSkeletonBounds* self);
  60. void spSkeletonBounds_update (spSkeletonBounds* self, spSkeleton* skeleton, int/*bool*/updateAabb);
  61. /** Returns true if the axis aligned bounding box contains the point. */
  62. int/*bool*/spSkeletonBounds_aabbContainsPoint (spSkeletonBounds* self, float x, float y);
  63. /** Returns true if the axis aligned bounding box intersects the line segment. */
  64. int/*bool*/spSkeletonBounds_aabbIntersectsSegment (spSkeletonBounds* self, float x1, float y1, float x2, float y2);
  65. /** Returns true if the axis aligned bounding box intersects the axis aligned bounding box of the specified bounds. */
  66. int/*bool*/spSkeletonBounds_aabbIntersectsSkeleton (spSkeletonBounds* self, spSkeletonBounds* bounds);
  67. /** Returns the first bounding box attachment that contains the point, or null. When doing many checks, it is usually more
  68. * efficient to only call this method if spSkeletonBounds_aabbContainsPoint returns true. */
  69. spBoundingBoxAttachment* spSkeletonBounds_containsPoint (spSkeletonBounds* self, float x, float y);
  70. /** Returns the first bounding box attachment that contains the line segment, or null. When doing many checks, it is usually
  71. * more efficient to only call this method if spSkeletonBounds_aabbIntersectsSegment returns true. */
  72. spBoundingBoxAttachment* spSkeletonBounds_intersectsSegment (spSkeletonBounds* self, float x1, float y1, float x2, float y2);
  73. /** Returns the polygon for the specified bounding box, or null. */
  74. spPolygon* spSkeletonBounds_getPolygon (spSkeletonBounds* self, spBoundingBoxAttachment* boundingBox);
  75. #ifdef SPINE_SHORT_NAMES
  76. typedef spSkeletonBounds SkeletonBounds;
  77. #define SkeletonBounds_create(...) spSkeletonBounds_create(__VA_ARGS__)
  78. #define SkeletonBounds_dispose(...) spSkeletonBounds_dispose(__VA_ARGS__)
  79. #define SkeletonBounds_update(...) spSkeletonBounds_update(__VA_ARGS__)
  80. #define SkeletonBounds_aabbContainsPoint(...) spSkeletonBounds_aabbContainsPoint(__VA_ARGS__)
  81. #define SkeletonBounds_aabbIntersectsSegment(...) spSkeletonBounds_aabbIntersectsSegment(__VA_ARGS__)
  82. #define SkeletonBounds_aabbIntersectsSkeleton(...) spSkeletonBounds_aabbIntersectsSkeleton(__VA_ARGS__)
  83. #define SkeletonBounds_containsPoint(...) spSkeletonBounds_containsPoint(__VA_ARGS__)
  84. #define SkeletonBounds_intersectsSegment(...) spSkeletonBounds_intersectsSegment(__VA_ARGS__)
  85. #define SkeletonBounds_getPolygon(...) spSkeletonBounds_getPolygon(__VA_ARGS__)
  86. #endif
  87. #ifdef __cplusplus
  88. }
  89. #endif
  90. #endif /* SPINE_SKELETONBOUNDS_H_ */