diff --git a/spine-cpp/spine-cpp/include/spine/Bone.h b/spine-cpp/spine-cpp/include/spine/Bone.h index 46c04d3a5..a0b61867e 100644 --- a/spine-cpp/spine-cpp/include/spine/Bone.h +++ b/spine-cpp/spine-cpp/include/spine/Bone.h @@ -50,6 +50,7 @@ namespace Spine friend class RotateTimeline; friend class IkConstraint; friend class TransformConstraint; + friend class VertexAttachment; public: static void setYDown(bool inValue); diff --git a/spine-cpp/spine-cpp/include/spine/BoneData.h b/spine-cpp/spine-cpp/include/spine/BoneData.h index 9710eda27..e5d82ef31 100644 --- a/spine-cpp/spine-cpp/include/spine/BoneData.h +++ b/spine-cpp/spine-cpp/include/spine/BoneData.h @@ -39,6 +39,8 @@ namespace Spine { class BoneData { + friend class RotateTimeline; + public: BoneData(int index, std::string name, BoneData* parent = NULL); diff --git a/spine-cpp/spine-cpp/include/spine/PathAttachment.h b/spine-cpp/spine-cpp/include/spine/PathAttachment.h new file mode 100644 index 000000000..5eda9a360 --- /dev/null +++ b/spine-cpp/spine-cpp/include/spine/PathAttachment.h @@ -0,0 +1,60 @@ +/****************************************************************************** + * Spine Runtimes Software License v2.5 + * + * Copyright (c) 2013-2016, Esoteric Software + * All rights reserved. + * + * You are granted a perpetual, non-exclusive, non-sublicensable, and + * non-transferable license to use, install, execute, and perform the Spine + * Runtimes software and derivative works solely for personal or internal + * use. Without the written permission of Esoteric Software (see Section 2 of + * the Spine Software License Agreement), you may not (a) modify, translate, + * adapt, or develop new applications using the Spine Runtimes or otherwise + * create derivative works or improvements of the Spine Runtimes or (b) remove, + * delete, alter, or obscure any trademarks or any copyright, trademark, patent, + * or other intellectual property or proprietary rights notices on or in the + * Software, including any copy thereof. Redistributions in binary or source + * form must include this license and terms. + * + * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF + * USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +#ifndef Spine_PathAttachment_h +#define Spine_PathAttachment_h + +#include + +namespace Spine +{ + class PathAttachment : public VertexAttachment + { + public: + PathAttachment(std::string name) : VertexAttachment(name) + { + // Empty + } + + /// The length in the setup pose from the start of the path to the end of each curve. + float[] Lengths { return lengths; } + set { lengths = value; } + bool Closed { return closed; } + set { closed = value; } + bool ConstantSpeed { return constantSpeed; } + set { constantSpeed = value; } + + private: + float[] lengths; + bool closed, constantSpeed; + }; +} + +#endif /* Spine_PathAttachment_h */ diff --git a/spine-cpp/spine-cpp/include/spine/Slot.h b/spine-cpp/spine-cpp/include/spine/Slot.h index 767373056..f9472c9da 100644 --- a/spine-cpp/spine-cpp/include/spine/Slot.h +++ b/spine-cpp/spine-cpp/include/spine/Slot.h @@ -44,14 +44,16 @@ namespace Spine class Slot { + friend class VertexAttachment; + public: Slot(SlotData& data, Bone& bone); void setToSetupPose(); - const SlotData& getSlotData(); - const Bone& getBone(); - const Skeleton& getSkeleton(); + SlotData& getSlotData(); + Bone& getBone(); + Skeleton& getSkeleton(); float getR(); void setR(float inValue); @@ -82,9 +84,9 @@ namespace Spine void setAttachmentVertices(Vector inValue); private: - const SlotData& _slotData; - const Bone& _bone; - const Skeleton& _skeleton; + SlotData& _slotData; + Bone& _bone; + Skeleton& _skeleton; float _r, _g, _b, _a; float _r2, _g2, _b2; bool _hasSecondColor; diff --git a/spine-cpp/spine-cpp/src/spine/PathAttachment.cpp b/spine-cpp/spine-cpp/src/spine/PathAttachment.cpp new file mode 100644 index 000000000..bb4d2ccfe --- /dev/null +++ b/spine-cpp/spine-cpp/src/spine/PathAttachment.cpp @@ -0,0 +1,34 @@ +/****************************************************************************** +* Spine Runtimes Software License v2.5 +* +* Copyright (c) 2013-2016, Esoteric Software +* All rights reserved. +* +* You are granted a perpetual, non-exclusive, non-sublicensable, and +* non-transferable license to use, install, execute, and perform the Spine +* Runtimes software and derivative works solely for personal or internal +* use. Without the written permission of Esoteric Software (see Section 2 of +* the Spine Software License Agreement), you may not (a) modify, translate, +* adapt, or develop new applications using the Spine Runtimes or otherwise +* create derivative works or improvements of the Spine Runtimes or (b) remove, +* delete, alter, or obscure any trademarks or any copyright, trademark, patent, +* or other intellectual property or proprietary rights notices on or in the +* Software, including any copy thereof. Redistributions in binary or source +* form must include this license and terms. +* +* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +* EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF +* USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +*****************************************************************************/ + +namespace Spine +{ + // TODO +} diff --git a/spine-cpp/spine-cpp/src/spine/RotateTimeline.cpp b/spine-cpp/spine-cpp/src/spine/RotateTimeline.cpp index b77b60858..1d2cb4bde 100644 --- a/spine-cpp/spine-cpp/src/spine/RotateTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/RotateTimeline.cpp @@ -34,7 +34,9 @@ #include #include +#include #include +#include namespace Spine { @@ -45,20 +47,29 @@ namespace Spine void RotateTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector& events, float alpha, MixPose pose, MixDirection direction) { - Bone* bone = skeleton.getBones().at(_boneIndex); + Bone* bone = skeleton.getBones()[_boneIndex]; if (time < _frames[0]) { switch (pose) { case MixPose_Setup: - bone->_rotation = bone->_data->_rotation; - return; + { + bone->_rotation = bone->_data._rotation; + break; + } case MixPose_Current: - float rr = bone->_data->_rotation - bone->_rotation; + { + float rr = bone->_data._rotation - bone->_rotation; rr -= (16384 - (int)(16384.499999999996 - rr / 360)) * 360; bone->_rotation += rr * alpha; - return; + break; + } + case MixPose_CurrentLayered: + { + // TODO? + break; + } } return; @@ -69,11 +80,11 @@ namespace Spine // Time is after last frame. if (pose == MixPose_Setup) { - bone->_rotation = bone->_data->_rotation + _frames[_frames.size() + PREV_ROTATION] * alpha; + bone->_rotation = bone->_data._rotation + _frames[_frames.size() + PREV_ROTATION] * alpha; } else { - float rr = bone->_data->_rotation + _frames[_frames.size() + PREV_ROTATION] - bone->_rotation; + float rr = bone->_data._rotation + _frames[_frames.size() + PREV_ROTATION] - bone->_rotation; rr -= (16384 - (int)(16384.499999999996 - rr / 360)) * 360; // Wrap within -180 and 180. bone->_rotation += rr * alpha; } @@ -94,11 +105,11 @@ namespace Spine if (pose == MixPose_Setup) { r -= (16384 - (int)(16384.499999999996 - r / 360)) * 360; - bone->_rotation = bone->_data->_rotation + r * alpha; + bone->_rotation = bone->_data._rotation + r * alpha; } else { - r = bone->_data->_rotation + r - bone->_rotation; + r = bone->_data._rotation + r - bone->_rotation; r -= (16384 - (int)(16384.499999999996 - r / 360)) * 360; bone->_rotation += r * alpha; } diff --git a/spine-cpp/spine-cpp/src/spine/Slot.cpp b/spine-cpp/spine-cpp/src/spine/Slot.cpp index e4bc6b1e7..fa9e1f5d8 100644 --- a/spine-cpp/spine-cpp/src/spine/Slot.cpp +++ b/spine-cpp/spine-cpp/src/spine/Slot.cpp @@ -74,17 +74,17 @@ namespace Spine } } - const SlotData& Slot::getSlotData() + SlotData& Slot::getSlotData() { return _slotData; } - const Bone& Slot::getBone() + Bone& Slot::getBone() { return _bone; } - const Skeleton& Slot::getSkeleton() + Skeleton& Slot::getSkeleton() { return _skeleton; } diff --git a/spine-cpp/spine-cpp/src/spine/VertexAttachment.cpp b/spine-cpp/spine-cpp/src/spine/VertexAttachment.cpp index 02819a18f..7581d360b 100644 --- a/spine-cpp/spine-cpp/src/spine/VertexAttachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/VertexAttachment.cpp @@ -32,6 +32,9 @@ #include +#include +#include + namespace Spine { VertexAttachment::VertexAttachment(std::string name) : Attachment(name), _id(getNextID()), _worldVerticesLength(0) @@ -47,19 +50,25 @@ namespace Spine void VertexAttachment::computeWorldVertices(Slot& slot, int start, int count, Vector& worldVertices, int offset, int stride) { count = offset + (count >> 1) * stride; - Skeleton skeleton = slot.bone.skeleton; - var deformArray = slot.attachmentVertices; - Vector vertices = _vertices; - Vector bones = _bones; - if (bones == NULL) + Skeleton& skeleton = slot._bone._skeleton; + Vector& deformArray = slot.getAttachmentVertices(); + Vector& vertices = _vertices; + Vector& bones = _bones; + if (bones.size() == 0) { - if (deformArray.Count > 0) vertices = deformArray.Items; - Bone bone = slot.bone; - float x = bone.worldX, y = bone.worldY; - float a = bone.a, b = bone.b, c = bone.c, d = bone.d; + 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; for (int vv = start, w = offset; w < count; vv += 2, w += stride) { - float vx = vertices[vv], vy = vertices[vv + 1]; + float vx = vertices[vv]; + float vy = vertices[vv + 1]; worldVertices[w] = vx * a + vy * b + x; worldVertices[w + 1] = vx * c + vy * d + y; } @@ -74,8 +83,8 @@ namespace Spine skip += n; } - var skeletonBones = skeleton.bones.Items; - if (deformArray.Count == 0) + Vector& skeletonBones = skeleton.getBones(); + if (deformArray.size() == 0) { for (int w = offset, b = skip * 3; w < count; w += stride) { @@ -84,10 +93,13 @@ namespace Spine n += v; for (; v < n; v++, b += 3) { - Bone bone = skeletonBones[bones[v]]; - float vx = vertices[b], vy = vertices[b + 1], weight = vertices[b + 2]; - wx += (vx * bone.a + vy * bone.b + bone.worldX) * weight; - wy += (vx * bone.c + vy * bone.d + bone.worldY) * weight; + Bone* boneP = skeletonBones[bones[v]]; + Bone bone = *boneP; + 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; } worldVertices[w] = wx; worldVertices[w + 1] = wy; @@ -95,7 +107,6 @@ namespace Spine } else { - Vector deform = deformArray.Items; for (int w = offset, b = skip * 3, f = skip << 1; w < count; w += stride) { float wx = 0, wy = 0; @@ -103,10 +114,13 @@ namespace Spine n += v; for (; v < n; v++, b += 3, f += 2) { - Bone bone = skeletonBones[bones[v]]; - float vx = vertices[b] + deform[f], vy = vertices[b + 1] + deform[f + 1], weight = vertices[b + 2]; - wx += (vx * bone.a + vy * bone.b + bone.worldX) * weight; - wy += (vx * bone.c + vy * bone.d + bone.worldY) * weight; + Bone* boneP = skeletonBones[bones[v]]; + Bone bone = *boneP; + 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; } worldVertices[w] = wx; worldVertices[w + 1] = wy;