diff --git a/spine-cpp/spine-cpp/include/spine/MeshAttachment.h b/spine-cpp/spine-cpp/include/spine/MeshAttachment.h index a553766c9..c03b3fec5 100644 --- a/spine-cpp/spine-cpp/include/spine/MeshAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/MeshAttachment.h @@ -55,7 +55,7 @@ namespace spine { using VertexAttachment::computeWorldVertices; - virtual void computeWorldVertices(Slot &slot, size_t start, size_t count, float *worldVertices, size_t offset, + virtual void computeWorldVertices(Skeleton &skeleton, Slot &slot, size_t start, size_t count, float *worldVertices, size_t offset, size_t stride = 2); void updateRegion(); diff --git a/spine-cpp/spine-cpp/include/spine/PointAttachment.h b/spine-cpp/spine-cpp/include/spine/PointAttachment.h index 9dab04e6b..a34fc2c69 100644 --- a/spine-cpp/spine-cpp/include/spine/PointAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/PointAttachment.h @@ -35,6 +35,7 @@ namespace spine { class Bone; + class BonePose; /// An attachment which is a single point and a rotation. This can be used to spawn projectiles, particles, etc. A bone can be /// used in similar ways, but a PointAttachment is slightly less expensive to compute and can be hidden, shown, and placed in a @@ -66,9 +67,9 @@ namespace spine { Color &getColor(); - void computeWorldPosition(Bone &bone, float &ox, float &oy); + void computeWorldPosition(BonePose &bone, float &ox, float &oy); - float computeWorldRotation(Bone &bone); + float computeWorldRotation(BonePose &bone); virtual Attachment *copy(); diff --git a/spine-cpp/spine-cpp/include/spine/VertexAttachment.h b/spine-cpp/spine-cpp/include/spine/VertexAttachment.h index e4957a9f1..3d8fd508a 100644 --- a/spine-cpp/spine-cpp/include/spine/VertexAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/VertexAttachment.h @@ -36,6 +36,7 @@ namespace spine { class Slot; + class Skeleton; /// An attachment with vertices that are transformed by one or more bones and can be deformed by a slot's vertices. class SP_API VertexAttachment : public Attachment { @@ -52,9 +53,6 @@ namespace spine { virtual ~VertexAttachment(); - void computeWorldVertices(Slot &slot, float *worldVertices); - - void computeWorldVertices(Slot &slot, Vector &worldVertices); /// Transforms local vertices to world coordinates. /// @param start The index of the first Vertices value to transform. Each vertex has 2 values, x and y. @@ -62,10 +60,10 @@ namespace spine { /// @param worldVertices The output world vertices. Must have a length greater than or equal to offset + count. /// @param offset The worldVertices index to begin writing values. /// @param stride The number of worldVertices entries between the value pairs written. - virtual void computeWorldVertices(Slot &slot, size_t start, size_t count, float *worldVertices, size_t offset, + virtual void computeWorldVertices(Skeleton &skeleton, Slot &slot, size_t start, size_t count, float *worldVertices, size_t offset, size_t stride = 2); - virtual void computeWorldVertices(Slot &slot, size_t start, size_t count, Vector &worldVertices, size_t offset, + virtual void computeWorldVertices(Skeleton &skeleton, Slot &slot, size_t start, size_t count, Vector &worldVertices, size_t offset, size_t stride = 2); /// Gets a unique ID for this attachment. diff --git a/spine-cpp/spine-cpp/src/spine/MeshAttachment.cpp b/spine-cpp/spine-cpp/src/spine/MeshAttachment.cpp index e40bc6e28..304cfce83 100644 --- a/spine-cpp/spine-cpp/src/spine/MeshAttachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/MeshAttachment.cpp @@ -234,8 +234,8 @@ MeshAttachment *MeshAttachment::newLinkedMesh() { return copy; } -void MeshAttachment::computeWorldVertices(Slot &slot, size_t start, size_t count, float *worldVertices, size_t offset, +void MeshAttachment::computeWorldVertices(Skeleton &skeleton, Slot &slot, size_t start, size_t count, float *worldVertices, size_t offset, size_t stride) { - if (_sequence) _sequence->apply(&slot, this); - VertexAttachment::computeWorldVertices(slot, start, count, worldVertices, offset, stride); + if (_sequence) _sequence->apply(slot.getAppliedPose(), this); + VertexAttachment::computeWorldVertices(skeleton, slot, start, count, worldVertices, offset, stride); } diff --git a/spine-cpp/spine-cpp/src/spine/PointAttachment.cpp b/spine-cpp/spine-cpp/src/spine/PointAttachment.cpp index 8c9605fc2..d37be3cba 100644 --- a/spine-cpp/spine-cpp/src/spine/PointAttachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/PointAttachment.cpp @@ -68,15 +68,15 @@ Color &PointAttachment::getColor() { return _color; } -void PointAttachment::computeWorldPosition(Bone &bone, float &ox, float &oy) { - ox = _x * bone._a + _y * bone._b + bone._worldX; - oy = _x * bone._c + _y * bone._d + bone._worldY; +void PointAttachment::computeWorldPosition(BonePose &bone, float &ox, float &oy) { + ox = _x * bone.getA() + _y * bone.getB() + bone.getWorldX(); + oy = _x * bone.getC() + _y * bone.getD() + bone.getWorldY(); } -float PointAttachment::computeWorldRotation(Bone &bone) { +float PointAttachment::computeWorldRotation(BonePose &bone) { float r = _rotation * MathUtil::Deg_Rad, cosine = MathUtil::cos(r), sine = MathUtil::sin(r); - float x = cosine * bone._a + sine * bone._b; - float y = cosine * bone._c + sine * bone._d; + float x = cosine * bone.getA() + sine * bone.getB(); + float y = cosine * bone.getC() + sine * bone.getD(); return MathUtil::atan2Deg(y, x); } diff --git a/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp b/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp index 65e1423e5..875db9591 100644 --- a/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp @@ -133,9 +133,9 @@ void RegionAttachment::computeWorldVertices(Slot &slot, Vector &worldVert } void RegionAttachment::computeWorldVertices(Slot &slot, float *worldVertices, size_t offset, size_t stride) { - if (_sequence) _sequence->apply(&slot, this); + if (_sequence) _sequence->apply(slot.getAppliedPose(), this); - Bone &bone = slot.getBone(); + BonePose &bone = slot.getBone().getAppliedPose(); float x = bone.getWorldX(), y = bone.getWorldY(); float a = bone.getA(), b = bone.getB(), c = bone.getC(), d = bone.getD(); float offsetX, offsetY; diff --git a/spine-cpp/spine-cpp/src/spine/VertexAttachment.cpp b/spine-cpp/spine-cpp/src/spine/VertexAttachment.cpp index a84f9a7f4..3cf4f6d85 100644 --- a/spine-cpp/spine-cpp/src/spine/VertexAttachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/VertexAttachment.cpp @@ -45,33 +45,25 @@ VertexAttachment::VertexAttachment(const String &name) : Attachment(name), _worl VertexAttachment::~VertexAttachment() { } -void VertexAttachment::computeWorldVertices(Slot &slot, Vector &worldVertices) { - computeWorldVertices(slot, 0, _worldVerticesLength, worldVertices, 0); -} -void VertexAttachment::computeWorldVertices(Slot &slot, float *worldVertices) { - computeWorldVertices(slot, 0, _worldVerticesLength, worldVertices, 0); -} - -void VertexAttachment::computeWorldVertices(Slot &slot, size_t start, size_t count, Vector &worldVertices, +void VertexAttachment::computeWorldVertices(Skeleton &skeleton, Slot &slot, size_t start, size_t count, Vector &worldVertices, size_t offset, size_t stride) { - computeWorldVertices(slot, start, count, worldVertices.buffer(), offset, stride); + computeWorldVertices(skeleton, slot, start, count, worldVertices.buffer(), offset, stride); } -void VertexAttachment::computeWorldVertices(Slot &slot, size_t start, size_t count, float *worldVertices, size_t offset, +void VertexAttachment::computeWorldVertices(Skeleton &skeleton, Slot &slot, size_t start, size_t count, float *worldVertices, size_t offset, size_t stride) { count = offset + (count >> 1) * stride; - Skeleton &skeleton = slot._bone._skeleton; - Vector *deformArray = &slot.getDeform(); + Vector *deformArray = &slot.getAppliedPose().getDeform(); Vector *vertices = &_vertices; Vector &bones = _bones; if (bones.size() == 0) { if (deformArray->size() > 0) vertices = deformArray; - Bone &bone = slot._bone; - float x = bone._worldX; - float y = bone._worldY; - float a = bone._a, b = bone._b, c = bone._c, d = bone._d; + BonePose &bone = slot.getBone().getAppliedPose(); + float x = bone.getWorldX(); + float y = bone.getWorldY(); + float a = bone.getA(), b = bone.getB(), c = bone.getC(), d = bone.getD(); for (size_t vv = start, w = offset; w < count; vv += 2, w += stride) { float vx = (*vertices)[vv]; float vy = (*vertices)[vv + 1]; @@ -96,12 +88,12 @@ void VertexAttachment::computeWorldVertices(Slot &slot, size_t start, size_t cou n += v; for (; v < n; v++, b += 3) { Bone *boneP = skeletonBones[bones[v]]; - Bone &bone = *boneP; + BonePose &bonePose = boneP->getAppliedPose(); float vx = (*vertices)[b]; float vy = (*vertices)[b + 1]; float weight = (*vertices)[b + 2]; - wx += (vx * bone._a + vy * bone._b + bone._worldX) * weight; - wy += (vx * bone._c + vy * bone._d + bone._worldY) * weight; + wx += (vx * bonePose.getA() + vy * bonePose.getB() + bonePose.getWorldX()) * weight; + wy += (vx * bonePose.getC() + vy * bonePose.getD() + bonePose.getWorldY()) * weight; } worldVertices[w] = wx; worldVertices[w + 1] = wy; @@ -113,12 +105,12 @@ void VertexAttachment::computeWorldVertices(Slot &slot, size_t start, size_t cou n += v; for (; v < n; v++, b += 3, f += 2) { Bone *boneP = skeletonBones[bones[v]]; - Bone &bone = *boneP; + BonePose &bonePose = boneP->getAppliedPose(); float vx = (*vertices)[b] + (*deformArray)[f]; float vy = (*vertices)[b + 1] + (*deformArray)[f + 1]; float weight = (*vertices)[b + 2]; - wx += (vx * bone._a + vy * bone._b + bone._worldX) * weight; - wy += (vx * bone._c + vy * bone._d + bone._worldY) * weight; + wx += (vx * bonePose.getA() + vy * bonePose.getB() + bonePose.getWorldX()) * weight; + wy += (vx * bonePose.getC() + vy * bonePose.getD() + bonePose.getWorldY()) * weight; } worldVertices[w] = wx; worldVertices[w + 1] = wy;