mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 07:14:55 +08:00
[cpp] 4.3 porting WIP
This commit is contained in:
parent
205b390195
commit
e5c9f9b86a
@ -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();
|
||||
|
||||
@ -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();
|
||||
|
||||
|
||||
@ -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<float> &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<float> &worldVertices, size_t offset,
|
||||
virtual void computeWorldVertices(Skeleton &skeleton, Slot &slot, size_t start, size_t count, Vector<float> &worldVertices, size_t offset,
|
||||
size_t stride = 2);
|
||||
|
||||
/// Gets a unique ID for this attachment.
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -133,9 +133,9 @@ void RegionAttachment::computeWorldVertices(Slot &slot, Vector<float> &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;
|
||||
|
||||
@ -45,33 +45,25 @@ VertexAttachment::VertexAttachment(const String &name) : Attachment(name), _worl
|
||||
VertexAttachment::~VertexAttachment() {
|
||||
}
|
||||
|
||||
void VertexAttachment::computeWorldVertices(Slot &slot, Vector<float> &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<float> &worldVertices,
|
||||
void VertexAttachment::computeWorldVertices(Skeleton &skeleton, Slot &slot, size_t start, size_t count, Vector<float> &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<float> *deformArray = &slot.getDeform();
|
||||
Vector<float> *deformArray = &slot.getAppliedPose().getDeform();
|
||||
Vector<float> *vertices = &_vertices;
|
||||
Vector<int> &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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user