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