mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
Renamed Polygon struct.
This commit is contained in:
parent
8cec4eb354
commit
c96bdac26f
@ -45,20 +45,20 @@ typedef struct {
|
|||||||
float* const vertices;
|
float* const vertices;
|
||||||
int count;
|
int count;
|
||||||
int capacity;
|
int capacity;
|
||||||
} Polygon;
|
} BoundingPolygon;
|
||||||
|
|
||||||
Polygon* Polygon_create (int capacity);
|
BoundingPolygon* BoundingPolygon_create (int capacity);
|
||||||
void Polygon_dispose (Polygon* self);
|
void BoundingPolygon_dispose (BoundingPolygon* self);
|
||||||
|
|
||||||
int/*bool*/Polygon_containsPoint (Polygon* polygon, float x, float y);
|
int/*bool*/BoundingPolygon_containsPoint (BoundingPolygon* polygon, float x, float y);
|
||||||
int/*bool*/Polygon_intersectsSegment (Polygon* polygon, float x1, float y1, float x2, float y2);
|
int/*bool*/BoundingPolygon_intersectsSegment (BoundingPolygon* polygon, float x1, float y1, float x2, float y2);
|
||||||
|
|
||||||
/**/
|
/**/
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int count;
|
int count;
|
||||||
BoundingBoxAttachment** boundingBoxes;
|
BoundingBoxAttachment** boundingBoxes;
|
||||||
Polygon** polygons;
|
BoundingPolygon** polygons;
|
||||||
|
|
||||||
float minX, minY, maxX, maxY;
|
float minX, minY, maxX, maxY;
|
||||||
} SkeletonBounds;
|
} SkeletonBounds;
|
||||||
@ -85,7 +85,7 @@ BoundingBoxAttachment* SkeletonBounds_containsPoint (SkeletonBounds* self, float
|
|||||||
BoundingBoxAttachment* SkeletonBounds_intersectsSegment (SkeletonBounds* self, float x1, float y1, float x2, float y2);
|
BoundingBoxAttachment* SkeletonBounds_intersectsSegment (SkeletonBounds* self, float x1, float y1, float x2, float y2);
|
||||||
|
|
||||||
/** Returns the polygon for the specified bounding box, or null. */
|
/** Returns the polygon for the specified bounding box, or null. */
|
||||||
Polygon* SkeletonBounds_getPolygon (SkeletonBounds* self, BoundingBoxAttachment* boundingBox);
|
BoundingPolygon* SkeletonBounds_getPolygon (SkeletonBounds* self, BoundingBoxAttachment* boundingBox);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,19 +36,19 @@
|
|||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <spine/extension.h>
|
#include <spine/extension.h>
|
||||||
|
|
||||||
Polygon* Polygon_create (int capacity) {
|
BoundingPolygon* BoundingPolygon_create (int capacity) {
|
||||||
Polygon* self = NEW(Polygon);
|
BoundingPolygon* self = NEW(BoundingPolygon);
|
||||||
self->capacity = capacity;
|
self->capacity = capacity;
|
||||||
CONST_CAST(float*, self->vertices) = MALLOC(float, capacity);
|
CONST_CAST(float*, self->vertices) = MALLOC(float, capacity);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Polygon_dispose (Polygon* self) {
|
void BoundingPolygon_dispose (BoundingPolygon* self) {
|
||||||
FREE(self->vertices);
|
FREE(self->vertices);
|
||||||
FREE(self);
|
FREE(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
int/*bool*/Polygon_containsPoint (Polygon* self, float x, float y) {
|
int/*bool*/BoundingPolygon_containsPoint (BoundingPolygon* self, float x, float y) {
|
||||||
int prevIndex = self->count - 2;
|
int prevIndex = self->count - 2;
|
||||||
int inside = 0;
|
int inside = 0;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -64,7 +64,7 @@ int/*bool*/Polygon_containsPoint (Polygon* self, float x, float y) {
|
|||||||
return inside;
|
return inside;
|
||||||
}
|
}
|
||||||
|
|
||||||
int/*bool*/Polygon_intersectsSegment (Polygon* self, float x1, float y1, float x2, float y2) {
|
int/*bool*/BoundingPolygon_intersectsSegment (BoundingPolygon* self, float x1, float y1, float x2, float y2) {
|
||||||
float width12 = x1 - x2, height12 = y1 - y2;
|
float width12 = x1 - x2, height12 = y1 - y2;
|
||||||
float det1 = x1 * y2 - y1 * x2;
|
float det1 = x1 * y2 - y1 * x2;
|
||||||
float x3 = self->vertices[self->count - 2], y3 = self->vertices[self->count - 1];
|
float x3 = self->vertices[self->count - 2], y3 = self->vertices[self->count - 1];
|
||||||
@ -99,7 +99,7 @@ SkeletonBounds* SkeletonBounds_create () {
|
|||||||
void SkeletonBounds_dispose (SkeletonBounds* self) {
|
void SkeletonBounds_dispose (SkeletonBounds* self) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (; i < SUB_CAST(_Internal, self)->capacity; ++i)
|
for (; i < SUB_CAST(_Internal, self)->capacity; ++i)
|
||||||
Polygon_dispose(self->polygons[i]);
|
if (self->polygons[i]) BoundingPolygon_dispose(self->polygons[i]);
|
||||||
FREE(self->polygons);
|
FREE(self->polygons);
|
||||||
FREE(self->boundingBoxes);
|
FREE(self->boundingBoxes);
|
||||||
FREE(self);
|
FREE(self);
|
||||||
@ -110,12 +110,12 @@ void SkeletonBounds_update (SkeletonBounds* self, Skeleton* skeleton, int/*bool*
|
|||||||
|
|
||||||
_Internal* internal = SUB_CAST(_Internal, self);
|
_Internal* internal = SUB_CAST(_Internal, self);
|
||||||
if (internal->capacity < skeleton->slotCount) {
|
if (internal->capacity < skeleton->slotCount) {
|
||||||
Polygon** newPolygons;
|
BoundingPolygon** newPolygons;
|
||||||
|
|
||||||
FREE(self->boundingBoxes);
|
FREE(self->boundingBoxes);
|
||||||
self->boundingBoxes = MALLOC(BoundingBoxAttachment*, skeleton->slotCount);
|
self->boundingBoxes = MALLOC(BoundingBoxAttachment*, skeleton->slotCount);
|
||||||
|
|
||||||
newPolygons = CALLOC(Polygon*, skeleton->slotCount);
|
newPolygons = CALLOC(BoundingPolygon*, skeleton->slotCount);
|
||||||
memcpy(newPolygons, self->polygons, internal->capacity);
|
memcpy(newPolygons, self->polygons, internal->capacity);
|
||||||
FREE(self->polygons);
|
FREE(self->polygons);
|
||||||
self->polygons = newPolygons;
|
self->polygons = newPolygons;
|
||||||
@ -130,7 +130,7 @@ void SkeletonBounds_update (SkeletonBounds* self, Skeleton* skeleton, int/*bool*
|
|||||||
|
|
||||||
self->count = 0;
|
self->count = 0;
|
||||||
for (i = 0; i < skeleton->slotCount; ++i) {
|
for (i = 0; i < skeleton->slotCount; ++i) {
|
||||||
Polygon* polygon;
|
BoundingPolygon* polygon;
|
||||||
BoundingBoxAttachment* boundingBox;
|
BoundingBoxAttachment* boundingBox;
|
||||||
|
|
||||||
Slot* slot = skeleton->slots[i];
|
Slot* slot = skeleton->slots[i];
|
||||||
@ -141,8 +141,8 @@ void SkeletonBounds_update (SkeletonBounds* self, Skeleton* skeleton, int/*bool*
|
|||||||
|
|
||||||
polygon = self->polygons[self->count];
|
polygon = self->polygons[self->count];
|
||||||
if (!polygon || polygon->capacity < boundingBox->verticesCount) {
|
if (!polygon || polygon->capacity < boundingBox->verticesCount) {
|
||||||
if (polygon) Polygon_dispose(polygon);
|
if (polygon) BoundingPolygon_dispose(polygon);
|
||||||
self->polygons[self->count] = polygon = Polygon_create(boundingBox->verticesCount);
|
self->polygons[self->count] = polygon = BoundingPolygon_create(boundingBox->verticesCount);
|
||||||
}
|
}
|
||||||
polygon->count = boundingBox->verticesCount;
|
polygon->count = boundingBox->verticesCount;
|
||||||
BoundingBoxAttachment_computeWorldVertices(boundingBox, skeleton->x, skeleton->y, slot->bone, polygon->vertices);
|
BoundingBoxAttachment_computeWorldVertices(boundingBox, skeleton->x, skeleton->y, slot->bone, polygon->vertices);
|
||||||
@ -190,18 +190,18 @@ int/*bool*/SkeletonBounds_aabbIntersectsSkeleton (SkeletonBounds* self, Skeleton
|
|||||||
BoundingBoxAttachment* SkeletonBounds_containsPoint (SkeletonBounds* self, float x, float y) {
|
BoundingBoxAttachment* SkeletonBounds_containsPoint (SkeletonBounds* self, float x, float y) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (; i < self->count; ++i)
|
for (; i < self->count; ++i)
|
||||||
if (Polygon_containsPoint(self->polygons[i], x, y)) return self->boundingBoxes[i];
|
if (BoundingPolygon_containsPoint(self->polygons[i], x, y)) return self->boundingBoxes[i];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
BoundingBoxAttachment* SkeletonBounds_intersectsSegment (SkeletonBounds* self, float x1, float y1, float x2, float y2) {
|
BoundingBoxAttachment* SkeletonBounds_intersectsSegment (SkeletonBounds* self, float x1, float y1, float x2, float y2) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (; i < self->count; ++i)
|
for (; i < self->count; ++i)
|
||||||
if (Polygon_intersectsSegment(self->polygons[i], x1, y1, x2, y2)) return self->boundingBoxes[i];
|
if (BoundingPolygon_intersectsSegment(self->polygons[i], x1, y1, x2, y2)) return self->boundingBoxes[i];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Polygon* SkeletonBounds_getPolygon (SkeletonBounds* self, BoundingBoxAttachment* boundingBox) {
|
BoundingPolygon* SkeletonBounds_getPolygon (SkeletonBounds* self, BoundingBoxAttachment* boundingBox) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (; i < self->count; ++i)
|
for (; i < self->count; ++i)
|
||||||
if (self->boundingBoxes[i] == boundingBox) return self->polygons[i];
|
if (self->boundingBoxes[i] == boundingBox) return self->polygons[i];
|
||||||
|
|||||||
@ -109,6 +109,7 @@ void spineboy () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SkeletonData_dispose(skeletonData);
|
SkeletonData_dispose(skeletonData);
|
||||||
|
SkeletonBounds_dispose(bounds);
|
||||||
Atlas_dispose(atlas);
|
Atlas_dispose(atlas);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user