mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-10 00:58:43 +08:00
[c][cpp][sfml] Fixes #2154
This commit is contained in:
parent
975a3fa30a
commit
531e256d6d
@ -595,7 +595,8 @@ _spAnimationState_setAttachment(spAnimationState *self, spSkeleton *skeleton, sp
|
||||
|
||||
/* @param target After the first and before the last entry. */
|
||||
static int binarySearch1(float *values, int valuesLength, float target) {
|
||||
for (int i = 1; i < valuesLength; i++) {
|
||||
int i;
|
||||
for (i = 1; i < valuesLength; i++) {
|
||||
if (values[i] > target) return (int) (i - 1);
|
||||
}
|
||||
return (int) valuesLength - 1;
|
||||
|
||||
@ -79,22 +79,39 @@ spRegionAttachment *spRegionAttachment_create(const char *name) {
|
||||
}
|
||||
|
||||
void spRegionAttachment_updateRegion(spRegionAttachment *self) {
|
||||
float regionScaleX = self->width / self->region->originalWidth * self->scaleX;
|
||||
float regionScaleY = self->height / self->region->originalHeight * self->scaleY;
|
||||
float localX = -self->width / 2 * self->scaleX + self->region->offsetX * regionScaleX;
|
||||
float localY = -self->height / 2 * self->scaleY + self->region->offsetY * regionScaleY;
|
||||
float localX2 = localX + self->region->width * regionScaleX;
|
||||
float localY2 = localY + self->region->height * regionScaleY;
|
||||
float radians = self->rotation * DEG_RAD;
|
||||
float cosine = COS(radians), sine = SIN(radians);
|
||||
float localXCos = localX * cosine + self->x;
|
||||
float localXSin = localX * sine;
|
||||
float localYCos = localY * cosine + self->y;
|
||||
float localYSin = localY * sine;
|
||||
float localX2Cos = localX2 * cosine + self->x;
|
||||
float localX2Sin = localX2 * sine;
|
||||
float localY2Cos = localY2 * cosine + self->y;
|
||||
float localY2Sin = localY2 * sine;
|
||||
float regionScaleX, regionScaleY, localX, localY, localX2, localY2;
|
||||
float radians, cosine, sine;
|
||||
float localXCos, localXSin, localYCos, localYSin, localX2Cos, localX2Sin, localY2Cos, localY2Sin;
|
||||
|
||||
if (self->region == NULL) {
|
||||
self->uvs[0] = 0;
|
||||
self->uvs[1] = 0;
|
||||
self->uvs[2] = 1;
|
||||
self->uvs[3] = 1;
|
||||
self->uvs[4] = 1;
|
||||
self->uvs[5] = 0;
|
||||
self->uvs[6] = 0;
|
||||
self->uvs[7] = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
regionScaleX = self->width / self->region->originalWidth * self->scaleX;
|
||||
regionScaleY = self->height / self->region->originalHeight * self->scaleY;
|
||||
localX = -self->width / 2 * self->scaleX + self->region->offsetX * regionScaleX;
|
||||
localY = -self->height / 2 * self->scaleY + self->region->offsetY * regionScaleY;
|
||||
localX2 = localX + self->region->width * regionScaleX;
|
||||
localY2 = localY + self->region->height * regionScaleY;
|
||||
radians = self->rotation * DEG_RAD;
|
||||
cosine = COS(radians), sine = SIN(radians);
|
||||
localXCos = localX * cosine + self->x;
|
||||
localXSin = localX * sine;
|
||||
localYCos = localY * cosine + self->y;
|
||||
localYSin = localY * sine;
|
||||
localX2Cos = localX2 * cosine + self->x;
|
||||
localX2Sin = localX2 * sine;
|
||||
localY2Cos = localY2 * cosine + self->y;
|
||||
localY2Sin = localY2 * sine;
|
||||
|
||||
self->offset[BLX] = localXCos - localYSin;
|
||||
self->offset[BLY] = localYCos + localXSin;
|
||||
self->offset[ULX] = localXCos - localY2Sin;
|
||||
|
||||
@ -437,7 +437,6 @@ void spSkeleton_updateWorldTransformWith(const spSkeleton *self, const spBone *p
|
||||
/* Apply the parent bone transform to the root bone. The root bone always inherits scale, rotation and reflection. */
|
||||
int i;
|
||||
float rotationY, la, lb, lc, ld;
|
||||
_spUpdate *updateCache;
|
||||
_spSkeleton *internal = SUB_CAST(_spSkeleton, self);
|
||||
spBone *rootBone = self->root;
|
||||
float pa = parent->a, pb = parent->b, pc = parent->c, pd = parent->d;
|
||||
@ -455,7 +454,6 @@ void spSkeleton_updateWorldTransformWith(const spSkeleton *self, const spBone *p
|
||||
CONST_CAST(float, rootBone->d) = (pc * lb + pd * ld) * self->scaleY;
|
||||
|
||||
/* Update everything except root bone. */
|
||||
updateCache = internal->updateCache;
|
||||
for (i = 0; i < internal->updateCacheCount; ++i) {
|
||||
_spUpdate *update = internal->updateCache + i;
|
||||
switch (update->type) {
|
||||
|
||||
@ -68,6 +68,18 @@ RegionAttachment::~RegionAttachment() {
|
||||
}
|
||||
|
||||
void RegionAttachment::updateRegion() {
|
||||
if (_region == NULL) {
|
||||
_uvs[BLX] = 0;
|
||||
_uvs[BLY] = 0;
|
||||
_uvs[ULX] = 0;
|
||||
_uvs[ULY] = 1;
|
||||
_uvs[URX] = 1;
|
||||
_uvs[URY] = 1;
|
||||
_uvs[BRX] = 1;
|
||||
_uvs[BRY] = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
float regionScaleX = _width / _region->originalWidth * _scaleX;
|
||||
float regionScaleY = _height / _region->originalHeight * _scaleY;
|
||||
float localX = -_width / 2 * _scaleX + _region->offsetX * regionScaleX;
|
||||
|
||||
@ -211,12 +211,12 @@ namespace spine {
|
||||
}
|
||||
|
||||
if (mesh->super.worldVerticesLength > SPINE_MESH_VERTEX_COUNT_MAX) continue;
|
||||
texture = (Texture *) ((spAtlasRegion *) mesh->rendererObject)->page->rendererObject;
|
||||
spVertexAttachment_computeWorldVertices(SUPER(mesh), slot, 0, mesh->super.worldVerticesLength, worldVertices, 0, 2);
|
||||
verticesCount = mesh->super.worldVerticesLength >> 1;
|
||||
uvs = mesh->uvs;
|
||||
indices = mesh->triangles;
|
||||
indicesCount = mesh->trianglesCount;
|
||||
texture = (Texture *) ((spAtlasRegion *) mesh->rendererObject)->page->rendererObject;
|
||||
|
||||
} else if (attachment->type == SP_ATTACHMENT_CLIPPING) {
|
||||
spClippingAttachment *clip = (spClippingAttachment *) slot->attachment;
|
||||
|
||||
@ -103,7 +103,6 @@ namespace spine {
|
||||
}
|
||||
|
||||
Vector<float> *vertices = &worldVertices;
|
||||
int verticesCount = 0;
|
||||
Vector<float> *uvs = NULL;
|
||||
Vector<unsigned short> *indices = NULL;
|
||||
int indicesCount = 0;
|
||||
@ -121,7 +120,6 @@ namespace spine {
|
||||
|
||||
worldVertices.setSize(8, 0);
|
||||
regionAttachment->computeWorldVertices(slot, worldVertices, 0, 2);
|
||||
verticesCount = 4;
|
||||
uvs = ®ionAttachment->getUVs();
|
||||
indices = &quadIndices;
|
||||
indicesCount = 6;
|
||||
@ -138,12 +136,11 @@ namespace spine {
|
||||
}
|
||||
|
||||
worldVertices.setSize(mesh->getWorldVerticesLength(), 0);
|
||||
texture = (Texture *) ((AtlasRegion *) mesh->getRendererObject())->page->getRendererObject();
|
||||
mesh->computeWorldVertices(slot, 0, mesh->getWorldVerticesLength(), worldVertices.buffer(), 0, 2);
|
||||
verticesCount = mesh->getWorldVerticesLength() >> 1;
|
||||
mesh->computeWorldVertices(slot, 0, mesh->getWorldVerticesLength(), worldVertices.buffer(), 0, 2);
|
||||
uvs = &mesh->getUVs();
|
||||
indices = &mesh->getTriangles();
|
||||
indicesCount = mesh->getTriangles().size();
|
||||
texture = (Texture *) ((AtlasRegion *) mesh->getRendererObject())->page->getRendererObject();
|
||||
|
||||
} else if (attachment->getRTTI().isExactly(ClippingAttachment::rtti)) {
|
||||
ClippingAttachment *clip = (ClippingAttachment *) slot.getAttachment();
|
||||
@ -216,7 +213,6 @@ namespace spine {
|
||||
if (clipper.isClipping()) {
|
||||
clipper.clipTriangles(worldVertices, *indices, *uvs, 2);
|
||||
vertices = &clipper.getClippedVertices();
|
||||
verticesCount = clipper.getClippedVertices().size() >> 1;
|
||||
uvs = &clipper.getClippedUVs();
|
||||
indices = &clipper.getClippedTriangles();
|
||||
indicesCount = clipper.getClippedTriangles().size();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user