mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-19 08:16:41 +08:00
[cpp] Added toString method for SpineObjects, fixed up math, fixed up IKConstraint.
This commit is contained in:
parent
e55818a561
commit
7a18b81226
@ -81,6 +81,8 @@ namespace Spine {
|
||||
float getDuration();
|
||||
|
||||
void setDuration(float inValue);
|
||||
|
||||
String toString() const;
|
||||
|
||||
private:
|
||||
Vector<Timeline*> _timelines;
|
||||
|
||||
@ -213,7 +213,8 @@ namespace Spine {
|
||||
void resetRotationDirections();
|
||||
|
||||
void setOnAnimationEventFunc(OnAnimationEventFunc inValue);
|
||||
|
||||
|
||||
String toString() const;
|
||||
private:
|
||||
Animation* _animation;
|
||||
|
||||
@ -249,6 +250,8 @@ namespace Spine {
|
||||
Event* _event;
|
||||
|
||||
EventQueueEntry(EventType eventType, TrackEntry* trackEntry, Event* event = NULL);
|
||||
|
||||
String toString() const;
|
||||
};
|
||||
|
||||
class EventQueue : public SpineObject {
|
||||
@ -282,6 +285,8 @@ namespace Spine {
|
||||
|
||||
/// Raises all events in the queue and drains the queue.
|
||||
void drain();
|
||||
|
||||
String toString() const ;
|
||||
};
|
||||
|
||||
class AnimationState : public SpineObject {
|
||||
@ -373,6 +378,8 @@ namespace Spine {
|
||||
void setOnAnimationEventFunc(OnAnimationEventFunc inValue);
|
||||
void setRendererObject(void* inValue);
|
||||
void* getRendererObject();
|
||||
|
||||
String toString() const;
|
||||
|
||||
private:
|
||||
static const int Subsequent, First, Dip, DipMix;
|
||||
|
||||
@ -67,7 +67,9 @@ namespace Spine {
|
||||
/// or the DefaultMix if no mix duration has been set.
|
||||
///
|
||||
float getMix(Animation* from, Animation* to);
|
||||
|
||||
|
||||
String toString() const;
|
||||
|
||||
private:
|
||||
class AnimationPair : public SpineObject {
|
||||
public:
|
||||
@ -77,6 +79,8 @@ namespace Spine {
|
||||
explicit AnimationPair(Animation* a1 = NULL, Animation* a2 = NULL);
|
||||
|
||||
bool operator==(const AnimationPair &other) const;
|
||||
|
||||
String toString() const;
|
||||
};
|
||||
|
||||
struct HashAnimationPair : public SpineObject {
|
||||
|
||||
@ -78,6 +78,15 @@ namespace Spine {
|
||||
magFilter(TextureFilter_Nearest), uWrap(TextureWrap_ClampToEdge),
|
||||
vWrap(TextureWrap_ClampToEdge) {
|
||||
}
|
||||
|
||||
String toString() const {
|
||||
String str;
|
||||
str.append("AtlasPage { name: ").appendString(name)
|
||||
.append(", width: ").append(width)
|
||||
.append(", height: ").append(height)
|
||||
.append(" }");
|
||||
return str;
|
||||
}
|
||||
};
|
||||
|
||||
class AtlasRegion : public SpineObject {
|
||||
@ -92,6 +101,12 @@ namespace Spine {
|
||||
bool rotate;
|
||||
Vector<int> splits;
|
||||
Vector<int> pads;
|
||||
|
||||
String toString() const {
|
||||
String str;
|
||||
str.append("AtlasRegion { name: ").appendString(name).append(" }");
|
||||
return str;
|
||||
}
|
||||
};
|
||||
|
||||
class TextureLoader;
|
||||
@ -112,6 +127,8 @@ namespace Spine {
|
||||
AtlasRegion* findRegion(const String& name);
|
||||
|
||||
void dispose();
|
||||
|
||||
String toString() const;
|
||||
|
||||
private:
|
||||
Vector<AtlasPage*> _pages;
|
||||
|
||||
@ -63,6 +63,8 @@ namespace Spine {
|
||||
virtual ClippingAttachment* newClippingAttachment(Skin& skin, const String& name);
|
||||
|
||||
AtlasRegion* findRegion(const String& name);
|
||||
|
||||
String toString() const;
|
||||
|
||||
private:
|
||||
Atlas* _atlas;
|
||||
|
||||
@ -43,7 +43,7 @@ namespace Spine {
|
||||
explicit Attachment(const String& name);
|
||||
virtual ~Attachment();
|
||||
|
||||
const String& getName();
|
||||
const String& getName() const;
|
||||
|
||||
private:
|
||||
const String _name;
|
||||
|
||||
@ -66,7 +66,6 @@ namespace Spine {
|
||||
const Vector<String>& getAttachmentNames();
|
||||
void setAttachmentNames(Vector<String>& inValue);
|
||||
int getFrameCount();
|
||||
|
||||
private:
|
||||
int _slotIndex;
|
||||
Vector<float> _frames;
|
||||
|
||||
@ -180,7 +180,8 @@ namespace Spine {
|
||||
|
||||
/// Returns the magnitide (always positive) of the world scale Y.
|
||||
float getWorldScaleY();
|
||||
|
||||
|
||||
String toString() const;
|
||||
private:
|
||||
static bool yDown;
|
||||
|
||||
|
||||
@ -93,6 +93,8 @@ namespace Spine {
|
||||
/// The transform mode for how parent world transforms affect this bone.
|
||||
TransformMode getTransformMode();
|
||||
void setTransformMode(TransformMode inValue);
|
||||
|
||||
String toString() const;
|
||||
|
||||
private:
|
||||
const int _index;
|
||||
|
||||
@ -40,6 +40,8 @@ namespace Spine {
|
||||
RTTI_DECL
|
||||
|
||||
explicit BoundingBoxAttachment(const String& name);
|
||||
|
||||
String toString() const;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -49,6 +49,8 @@ namespace Spine {
|
||||
|
||||
SlotData* getEndSlot();
|
||||
void setEndSlot(SlotData* inValue);
|
||||
|
||||
String toString() const;
|
||||
|
||||
private:
|
||||
SlotData* _endSlot;
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
#include <spine/MathUtil.h>
|
||||
|
||||
namespace Spine {
|
||||
class Color {
|
||||
class Color : public SpineObject {
|
||||
public:
|
||||
Color() : _r(0), _g(0), _b(0), _a(0) {
|
||||
}
|
||||
@ -87,6 +87,12 @@ namespace Spine {
|
||||
}
|
||||
|
||||
float _r, _g, _b, _a;
|
||||
|
||||
inline String toString() const {
|
||||
String str;
|
||||
str.append("Color { r: ").append(_r).append(", g: ").append(_g).append(", b: ").append(_b).append(", a: ").append(_a).append(" }");
|
||||
return str;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -59,6 +59,8 @@ namespace Spine {
|
||||
|
||||
const String& getStringValue();
|
||||
void setStringValue(const String& inValue);
|
||||
|
||||
String toString() const;
|
||||
|
||||
private:
|
||||
const EventData& _data;
|
||||
|
||||
@ -55,7 +55,9 @@ namespace Spine {
|
||||
|
||||
const String& getStringValue();
|
||||
void setStringValue(const String& inValue);
|
||||
|
||||
|
||||
String toString() const;
|
||||
|
||||
private:
|
||||
const String _name;
|
||||
int _intValue;
|
||||
|
||||
@ -34,6 +34,7 @@
|
||||
#include <spine/Extension.h>
|
||||
#include <spine/Vector.h>
|
||||
#include <spine/SpineObject.h>
|
||||
#include <spine/String.h>
|
||||
|
||||
namespace Spine {
|
||||
template <typename K, typename V>
|
||||
@ -144,9 +145,25 @@ namespace Spine {
|
||||
else assert(false);
|
||||
}
|
||||
|
||||
Entries getEntries() {
|
||||
Entries getEntries() const {
|
||||
return Entries(_head);
|
||||
}
|
||||
|
||||
String toString() const {
|
||||
String str;
|
||||
|
||||
str.append("{");
|
||||
Entries entries = getEntries();
|
||||
|
||||
while(entries.hasNext()) {
|
||||
Pair pair = entries.next();
|
||||
str.append(pair.key);
|
||||
str.append("->");
|
||||
str.append(pair.value);
|
||||
}
|
||||
str.append("}");
|
||||
return str;
|
||||
}
|
||||
|
||||
private:
|
||||
Entry* find(const K& key) {
|
||||
@ -165,6 +182,12 @@ namespace Spine {
|
||||
Entry* prev;
|
||||
|
||||
Entry () : next(NULL), prev(NULL) {}
|
||||
|
||||
String toString() const {
|
||||
String str;
|
||||
str.append("Entry { key: ").append(_key).append(" -> ").append(_value);
|
||||
return str;
|
||||
}
|
||||
};
|
||||
|
||||
Entry* _head;
|
||||
|
||||
@ -77,6 +77,8 @@ namespace Spine {
|
||||
|
||||
float getMix();
|
||||
void setMix(float inValue);
|
||||
|
||||
String toString() const;
|
||||
|
||||
private:
|
||||
IkConstraintData& _data;
|
||||
|
||||
@ -67,7 +67,9 @@ namespace Spine {
|
||||
|
||||
float getMix();
|
||||
void setMix(float inValue);
|
||||
|
||||
|
||||
String toString() const;
|
||||
|
||||
private:
|
||||
const String _name;
|
||||
int _order;
|
||||
|
||||
@ -68,7 +68,8 @@ namespace Spine {
|
||||
explicit Json(const char* value);
|
||||
|
||||
~Json();
|
||||
|
||||
|
||||
String toString() const;
|
||||
private:
|
||||
static const char* _error;
|
||||
|
||||
|
||||
@ -43,7 +43,8 @@ namespace Spine {
|
||||
|
||||
public:
|
||||
LinkedMesh(MeshAttachment* mesh, const String& skin, int slotIndex, const String& parent);
|
||||
|
||||
|
||||
String toString() const;
|
||||
private:
|
||||
MeshAttachment* _mesh;
|
||||
String _skin;
|
||||
|
||||
@ -36,27 +36,20 @@
|
||||
#include <float.h>
|
||||
#include <string.h>
|
||||
|
||||
#define SPINE_PI 3.1415927f
|
||||
#define SPINE_PI_2 (SPINE_PI * 2)
|
||||
#define RadDeg (180.0f / SPINE_PI)
|
||||
#define DegRad (SPINE_PI / 180.0f)
|
||||
#define SIN_BITS 14 // 16KB. Adjust for accuracy.
|
||||
#define SIN_MASK (~(-(1 << SIN_BITS)))
|
||||
#define SIN_COUNT (SIN_MASK + 1)
|
||||
#define RadFull (SPINE_PI * 2)
|
||||
#define DegFull 360
|
||||
#define RadToIndex (SIN_COUNT / RadFull)
|
||||
#define DegToIndex (SIN_COUNT / DegFull)
|
||||
#define MAX(a, b) ((((a) > (b)) ? (a) : (b)))
|
||||
#define MIN(a, b) ((((a) < (b)) ? (a) : (b)))
|
||||
|
||||
|
||||
namespace Spine {
|
||||
|
||||
static const float PI = 3.1415927f;
|
||||
static const float PI_2 = PI * 2;
|
||||
static const float RAD_DEG = (180.0f / PI);
|
||||
static const float DEG_RAD = (PI / 180.0f);
|
||||
|
||||
class MathUtil : public SpineObject {
|
||||
public:
|
||||
MathUtil();
|
||||
|
||||
template <typename T> static inline T min(T a, T b) { return a < b ? a : b; }
|
||||
|
||||
template <typename T> static inline T max(T a, T b) { return a > b ? a : b; }
|
||||
|
||||
static int sign(float val);
|
||||
|
||||
static bool areFloatsPracticallyEqual(float A, float B, float maxDiff = 0.0000000000000001f, float maxRelDiff = FLT_EPSILON);
|
||||
@ -88,9 +81,6 @@ namespace Spine {
|
||||
static float fmod(float a, float b);
|
||||
|
||||
static bool isNan(float v);
|
||||
|
||||
private:
|
||||
static float SIN_TABLE[SIN_COUNT];
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -122,6 +122,8 @@ namespace Spine {
|
||||
float getHeight();
|
||||
void setHeight(float inValue);
|
||||
|
||||
String toString() const;
|
||||
|
||||
private:
|
||||
float _regionOffsetX, _regionOffsetY, _regionWidth, _regionHeight, _regionOriginalWidth, _regionOriginalHeight;
|
||||
MeshAttachment* _parentMesh;
|
||||
|
||||
@ -50,6 +50,8 @@ namespace Spine {
|
||||
void setClosed(bool inValue);
|
||||
bool isConstantSpeed();
|
||||
void setConstantSpeed(bool inValue);
|
||||
|
||||
String toString() const;
|
||||
|
||||
private:
|
||||
Vector<float> _lengths;
|
||||
|
||||
@ -78,6 +78,8 @@ namespace Spine {
|
||||
void setTarget(Slot* inValue);
|
||||
|
||||
PathConstraintData& getData();
|
||||
|
||||
String toString() const;
|
||||
|
||||
private:
|
||||
static const float EPSILON;
|
||||
|
||||
@ -88,7 +88,8 @@ namespace Spine {
|
||||
|
||||
float getTranslateMix();
|
||||
void setTranslateMix(float inValue);
|
||||
|
||||
|
||||
String toString() const;
|
||||
private:
|
||||
const String _name;
|
||||
int _order;
|
||||
|
||||
@ -64,6 +64,8 @@ namespace Spine {
|
||||
|
||||
float getRotation();
|
||||
void setRotation(float inValue);
|
||||
|
||||
String toString() const;
|
||||
|
||||
private:
|
||||
float _x, _y, _rotation;
|
||||
|
||||
@ -67,6 +67,12 @@ namespace Spine {
|
||||
_objects.add(object);
|
||||
}
|
||||
}
|
||||
|
||||
String toString () const {
|
||||
String str;
|
||||
str.append("Pool { size: ").append((int)_objects.size()).append(" }");
|
||||
return str;
|
||||
}
|
||||
|
||||
private:
|
||||
Vector<T*> _objects;
|
||||
|
||||
@ -47,7 +47,8 @@ namespace Spine {
|
||||
bool isExactly(const RTTI& rtti) const;
|
||||
|
||||
bool instanceOf(const RTTI &rtti) const;
|
||||
|
||||
|
||||
String toString() const;
|
||||
private:
|
||||
// Prevent copying
|
||||
RTTI(const RTTI& obj);
|
||||
@ -61,15 +62,15 @@ namespace Spine {
|
||||
#define RTTI_DECL \
|
||||
public: \
|
||||
static const Spine::RTTI rtti; \
|
||||
virtual const Spine::RTTI& getRTTI();
|
||||
virtual const Spine::RTTI& getRTTI() const;
|
||||
|
||||
#define RTTI_IMPL_NOPARENT(name) \
|
||||
const Spine::RTTI name::rtti(#name); \
|
||||
const Spine::RTTI& name::getRTTI() { return rtti; }
|
||||
const Spine::RTTI& name::getRTTI() const { return rtti; }
|
||||
|
||||
#define RTTI_IMPL(name,parent) \
|
||||
const Spine::RTTI name::rtti(#name, parent::rtti); \
|
||||
const Spine::RTTI& name::getRTTI() { return rtti; }
|
||||
const Spine::RTTI& name::getRTTI() const { return rtti; }
|
||||
|
||||
#endif /* Spine_RTTI_h */
|
||||
|
||||
|
||||
@ -106,6 +106,8 @@ namespace Spine {
|
||||
|
||||
Vector<float>& getOffset();
|
||||
Vector<float>& getUVs();
|
||||
|
||||
String toString() const;
|
||||
|
||||
private:
|
||||
static const int BLX;
|
||||
|
||||
@ -169,7 +169,9 @@ namespace Spine {
|
||||
void setFlipX(bool inValue);
|
||||
bool getFlipY();
|
||||
void setFlipY(bool inValue);
|
||||
|
||||
|
||||
String toString() const;
|
||||
|
||||
private:
|
||||
SkeletonData* _data;
|
||||
Vector<Bone*> _bones;
|
||||
|
||||
@ -80,11 +80,15 @@ namespace Spine {
|
||||
void setScale(float scale) { _scale = scale; }
|
||||
|
||||
String& getError() { return _error; }
|
||||
|
||||
String toString() const;
|
||||
|
||||
private:
|
||||
struct DataInput : public SpineObject {
|
||||
const unsigned char* cursor;
|
||||
const unsigned char* end;
|
||||
|
||||
String toString() const { return String("DataInput"); }
|
||||
};
|
||||
|
||||
AttachmentLoader* _attachmentLoader;
|
||||
|
||||
@ -85,6 +85,8 @@ namespace Spine {
|
||||
|
||||
float getWidth();
|
||||
float getHeight();
|
||||
|
||||
String toString() const;
|
||||
|
||||
private:
|
||||
Vector<Polygon*> _polygonPool;
|
||||
@ -103,6 +105,8 @@ namespace Spine {
|
||||
Polygon() : _count(0) {
|
||||
_vertices.ensureCapacity(16);
|
||||
}
|
||||
|
||||
String toString() const;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -55,6 +55,8 @@ namespace Spine {
|
||||
Vector<float>& getClippedVertices();
|
||||
Vector<unsigned short>& getClippedTriangles();
|
||||
Vector<float>& getClippedUVs();
|
||||
|
||||
String toString() const;
|
||||
|
||||
private:
|
||||
Triangulator _triangulator;
|
||||
|
||||
@ -140,7 +140,9 @@ namespace Spine {
|
||||
/// The dopesheet FPS in Spine. Available only when nonessential data was exported.
|
||||
float getFps();
|
||||
void setFps(float inValue);
|
||||
|
||||
|
||||
String toString() const;
|
||||
|
||||
private:
|
||||
String _name;
|
||||
Vector<BoneData*> _bones; // Ordered parents first
|
||||
|
||||
@ -61,6 +61,8 @@ namespace Spine {
|
||||
void setScale (float scale) { _scale = scale; }
|
||||
|
||||
String& getError() { return _error; }
|
||||
|
||||
String toString() const;
|
||||
|
||||
private:
|
||||
AttachmentLoader* _attachmentLoader;
|
||||
|
||||
@ -46,7 +46,7 @@ namespace Spine {
|
||||
friend class Skeleton;
|
||||
|
||||
public:
|
||||
class AttachmentKey {
|
||||
class AttachmentKey: public SpineObject {
|
||||
public:
|
||||
int _slotIndex;
|
||||
String _name;
|
||||
@ -59,6 +59,8 @@ namespace Spine {
|
||||
}
|
||||
|
||||
bool operator==(const AttachmentKey &other) const;
|
||||
|
||||
String toString() const;
|
||||
};
|
||||
|
||||
struct HashAttachmentKey : public SpineObject {
|
||||
@ -87,6 +89,8 @@ namespace Spine {
|
||||
|
||||
const String& getName();
|
||||
HashMap<AttachmentKey, Attachment*>& getAttachments();
|
||||
|
||||
String toString() const;
|
||||
|
||||
private:
|
||||
const String _name;
|
||||
|
||||
@ -88,7 +88,9 @@ namespace Spine {
|
||||
|
||||
Vector<float>& getAttachmentVertices();
|
||||
void setAttachmentVertices(Vector<float> inValue);
|
||||
|
||||
|
||||
String toString() const;
|
||||
|
||||
private:
|
||||
SlotData& _data;
|
||||
Bone& _bone;
|
||||
|
||||
@ -79,7 +79,9 @@ namespace Spine {
|
||||
|
||||
BlendMode getBlendMode();
|
||||
void setBlendMode(BlendMode inValue);
|
||||
|
||||
|
||||
String toString() const;
|
||||
|
||||
private:
|
||||
const int _index;
|
||||
String _name;
|
||||
|
||||
@ -42,6 +42,7 @@ namespace Spine {
|
||||
void* operator new(size_t sz, void* ptr);
|
||||
void operator delete(void* p);
|
||||
virtual ~SpineObject();
|
||||
virtual String toString() const = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -35,6 +35,7 @@
|
||||
#include <spine/Extension.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
namespace Spine {
|
||||
class String : public SpineObject {
|
||||
@ -138,7 +139,7 @@ namespace Spine {
|
||||
return *this;
|
||||
}
|
||||
|
||||
String& operator+ (const char* chars) {
|
||||
String& append (const char* chars) {
|
||||
size_t len = strlen(chars);
|
||||
size_t thisLen = _length;
|
||||
_length = _length + len;
|
||||
@ -148,7 +149,7 @@ namespace Spine {
|
||||
return *this;
|
||||
}
|
||||
|
||||
String& operator+= (const String& other) {
|
||||
String& appendString (const String& other) {
|
||||
size_t len = other.length();
|
||||
size_t thisLen = _length;
|
||||
_length = _length + len;
|
||||
@ -158,8 +159,28 @@ namespace Spine {
|
||||
return *this;
|
||||
}
|
||||
|
||||
friend String operator+ (const String& a, const String& b) {
|
||||
return String(a) += b;
|
||||
String& append (int other) {
|
||||
char str[100];
|
||||
sprintf(str, "%i", other);
|
||||
append(str);
|
||||
return *this;
|
||||
}
|
||||
|
||||
String& append (float other) {
|
||||
char str[100];
|
||||
sprintf(str, "%f", other);
|
||||
append(str);
|
||||
return *this;
|
||||
}
|
||||
|
||||
String& append(const SpineObject& object) {
|
||||
appendString(object.toString());
|
||||
return *this;
|
||||
}
|
||||
|
||||
String& append(const SpineObject* object) {
|
||||
appendString(object->toString());
|
||||
return *this;
|
||||
}
|
||||
|
||||
friend bool operator== (const String& a, const String& b) {
|
||||
@ -181,6 +202,10 @@ namespace Spine {
|
||||
SpineExtension::free(_buffer, __FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
|
||||
String toString () const {
|
||||
return *this;
|
||||
}
|
||||
private:
|
||||
mutable size_t _length;
|
||||
mutable char* _buffer;
|
||||
|
||||
@ -63,6 +63,8 @@ namespace Spine {
|
||||
virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction) = 0;
|
||||
|
||||
virtual int getPropertyId() = 0;
|
||||
|
||||
virtual String toString() const;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -73,6 +73,8 @@ namespace Spine {
|
||||
|
||||
float getShearMix();
|
||||
void setShearMix(float inValue);
|
||||
|
||||
String toString() const;
|
||||
|
||||
private:
|
||||
TransformConstraintData& _data;
|
||||
|
||||
@ -67,6 +67,8 @@ namespace Spine {
|
||||
|
||||
bool isRelative();
|
||||
bool isLocal();
|
||||
|
||||
String toString() const;
|
||||
|
||||
private:
|
||||
const String _name;
|
||||
|
||||
@ -40,6 +40,8 @@ namespace Spine {
|
||||
Vector<int>& triangulate(Vector<float>& vertices);
|
||||
|
||||
Vector< Vector<float>* > decompose(Vector<float>& vertices, Vector<int>& triangles);
|
||||
|
||||
String toString() const;
|
||||
|
||||
private:
|
||||
Vector< Vector<float>* > _convexPolygons;
|
||||
|
||||
@ -32,12 +32,11 @@
|
||||
#define Spine_Vector_h
|
||||
|
||||
#include <spine/Extension.h>
|
||||
|
||||
#include <spine/SpineObject.h>
|
||||
#include <spine/String.h>
|
||||
#include <stdlib.h>
|
||||
#include <memory>
|
||||
#include <assert.h>
|
||||
#include <spine/SpineObject.h>
|
||||
#include <spine/Extension.h>
|
||||
|
||||
namespace Spine {
|
||||
template <typename T>
|
||||
@ -109,13 +108,13 @@ namespace Spine {
|
||||
}
|
||||
|
||||
inline void add(const T &inValue) {
|
||||
if (_size == _capacity) {
|
||||
if (_size == _capacity) {
|
||||
_capacity = (int)(_size * 1.75f);
|
||||
if (_capacity < 8) _capacity = 8;
|
||||
_buffer = Spine::SpineExtension::realloc<T>(_buffer, _capacity, __FILE__, __LINE__);
|
||||
}
|
||||
construct(_buffer + _size++, inValue);
|
||||
}
|
||||
}
|
||||
construct(_buffer + _size++, inValue);
|
||||
}
|
||||
|
||||
inline void removeAt(size_t inIndex) {
|
||||
assert(inIndex < _size);
|
||||
@ -179,6 +178,18 @@ namespace Spine {
|
||||
return _buffer;
|
||||
}
|
||||
|
||||
String toString () const {
|
||||
String str;
|
||||
str.append("Vector { size: ").append((int)_size).append(", items: [\n");
|
||||
for (size_t i = 0; i < _size; i++) {
|
||||
str.append(" ").append(_buffer[i]);
|
||||
if (i != _size - 1) str.append(",\n");
|
||||
else str.append("\n");
|
||||
}
|
||||
str.append("] }");
|
||||
return str;
|
||||
}
|
||||
|
||||
private:
|
||||
size_t _size;
|
||||
size_t _capacity;
|
||||
|
||||
@ -38,6 +38,10 @@ namespace Spine {
|
||||
public:
|
||||
Vector<int> _bones;
|
||||
Vector<float> _vertices;
|
||||
|
||||
String toString() const {
|
||||
return String("Vertices");
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -142,4 +142,12 @@ namespace Spine {
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
String Animation::toString() const {
|
||||
String str;
|
||||
str.append("Animation { name: ").appendString(_name).append(", duration: ").append(_duration);
|
||||
str.append(",\n timelines: ").appendString(_timelines.toString());
|
||||
str.append("}");
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ namespace Spine {
|
||||
return MathUtil::fmod(_trackTime, duration) + _animationStart;
|
||||
}
|
||||
|
||||
return MIN(_trackTime + _animationStart, _animationEnd);
|
||||
return MathUtil::min(_trackTime + _animationStart, _animationEnd);
|
||||
}
|
||||
|
||||
float TrackEntry::getTimeScale() { return _timeScale; }
|
||||
@ -203,13 +203,21 @@ namespace Spine {
|
||||
|
||||
_onAnimationEventFunc = dummyOnAnimationEventFunc;
|
||||
}
|
||||
|
||||
|
||||
String TrackEntry::toString() const {
|
||||
return String("TrackEntry");
|
||||
}
|
||||
|
||||
EventQueueEntry::EventQueueEntry(EventType eventType, TrackEntry* trackEntry, Event* event) :
|
||||
_type(eventType),
|
||||
_entry(trackEntry),
|
||||
_event(event) {
|
||||
}
|
||||
|
||||
|
||||
String EventQueueEntry::toString() const {
|
||||
return String("EventQueueEntry");
|
||||
}
|
||||
|
||||
EventQueue* EventQueue::newEventQueue(AnimationState& state, Pool<TrackEntry>& trackEntryPool) {
|
||||
return new (__FILE__, __LINE__) EventQueue(state, trackEntryPool);
|
||||
}
|
||||
@ -292,7 +300,11 @@ namespace Spine {
|
||||
|
||||
_drainDisabled = false;
|
||||
}
|
||||
|
||||
|
||||
String EventQueue::toString() const {
|
||||
return String("EventQueue");
|
||||
}
|
||||
|
||||
const int AnimationState::Subsequent = 0;
|
||||
const int AnimationState::First = 1;
|
||||
const int AnimationState::Dip = 2;
|
||||
@ -804,7 +816,7 @@ namespace Spine {
|
||||
default:
|
||||
pose = MixPose_Setup;
|
||||
TrackEntry* dipMix = timelineDipMix[i];
|
||||
alpha = alphaDip * MAX(0, 1 - dipMix->_mixTime / dipMix->_mixDuration);
|
||||
alpha = alphaDip * MathUtil::max(0.0f, 1 - dipMix->_mixTime / dipMix->_mixDuration);
|
||||
break;
|
||||
}
|
||||
from->_totalAlpha += alpha;
|
||||
@ -882,7 +894,7 @@ namespace Spine {
|
||||
|
||||
// Store interrupted mix percentage.
|
||||
if (from->_mixingFrom != NULL && from->_mixDuration > 0) {
|
||||
current->_interruptAlpha *= MIN(1, from->_mixTime / from->_mixDuration);
|
||||
current->_interruptAlpha *= MathUtil::min(1.0f, from->_mixTime / from->_mixDuration);
|
||||
}
|
||||
|
||||
from->_timelinesRotation.clear(); // Reset rotation for mixing out, in case entry was mixed in.
|
||||
@ -956,4 +968,8 @@ namespace Spine {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String AnimationState::toString() const {
|
||||
return String("AnimationState");
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,14 +73,24 @@ namespace Spine {
|
||||
void AnimationStateData::setDefaultMix(float inValue) {
|
||||
_defaultMix = inValue;
|
||||
}
|
||||
|
||||
|
||||
String AnimationStateData::toString() const {
|
||||
return String("AnimationStateData");
|
||||
}
|
||||
|
||||
AnimationStateData::AnimationPair::AnimationPair(Animation* a1, Animation* a2) : _a1(a1), _a2(a2) {
|
||||
}
|
||||
|
||||
bool AnimationStateData::AnimationPair::operator==(const AnimationPair &other) const {
|
||||
return _a1->_name == other._a1->_name && _a2->_name == other._a2->_name;
|
||||
}
|
||||
|
||||
|
||||
String AnimationStateData::AnimationPair::toString() const {
|
||||
String str;
|
||||
str.append("AnimationPair { ").append(_a1->_name).append(" -> ").append(_a2->_name).append(" } ");
|
||||
return str;
|
||||
}
|
||||
|
||||
std::size_t AnimationStateData::HashAnimationPair::operator()(const Spine::AnimationStateData::AnimationPair& val) const {
|
||||
std::size_t h1 = 7;
|
||||
size_t strlen = val._a1->_name.length();
|
||||
|
||||
@ -352,4 +352,8 @@ namespace Spine {
|
||||
int Atlas::toInt(Str* str) {
|
||||
return (int)strtol(str->begin, (char**)&str->end, 10);
|
||||
}
|
||||
|
||||
String Atlas::toString() const {
|
||||
return String("Atlas");
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,4 +111,8 @@ namespace Spine {
|
||||
AtlasRegion* ret;
|
||||
return _atlas->findRegion(name);
|
||||
}
|
||||
|
||||
String AtlasAttachmentLoader::toString() const {
|
||||
return String("AtlasAttachmentLoader");
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ namespace Spine {
|
||||
Attachment::~Attachment() {
|
||||
}
|
||||
|
||||
const String& Attachment::getName() {
|
||||
const String& Attachment::getName() const {
|
||||
return _name;
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,12 +164,12 @@ namespace Spine {
|
||||
s = MathUtil::abs(pa * pd - pb * pc) / s;
|
||||
pb = pc * s;
|
||||
pd = pa * s;
|
||||
prx = MathUtil::atan2(pc, pa) * RadDeg;
|
||||
prx = MathUtil::atan2(pc, pa) * RAD_DEG;
|
||||
}
|
||||
else {
|
||||
pa = 0;
|
||||
pc = 0;
|
||||
prx = 90 - MathUtil::atan2(pd, pb) * RadDeg;
|
||||
prx = 90 - MathUtil::atan2(pd, pb) * RAD_DEG;
|
||||
}
|
||||
float rx = rotation + shearX - prx;
|
||||
float ry = rotation + shearY - prx + 90;
|
||||
@ -199,7 +199,7 @@ namespace Spine {
|
||||
za *= s;
|
||||
zc *= s;
|
||||
s = MathUtil::sqrt(za * za + zc * zc);
|
||||
float r = SPINE_PI / 2 + MathUtil::atan2(zc, za);
|
||||
float r = PI / 2 + MathUtil::atan2(zc, za);
|
||||
float zb = MathUtil::cos(r) * s;
|
||||
float zd = MathUtil::sin(r) * s;
|
||||
float la = MathUtil::cosDeg(shearX) * scaleX;
|
||||
@ -266,14 +266,14 @@ namespace Spine {
|
||||
float sin = MathUtil::sinDeg(worldRotation);
|
||||
float cos = MathUtil::cosDeg(worldRotation);
|
||||
|
||||
return MathUtil::atan2(_a * sin - _c * cos, _d * cos - _b * sin) * RadDeg;
|
||||
return MathUtil::atan2(_a * sin - _c * cos, _d * cos - _b * sin) * RAD_DEG;
|
||||
}
|
||||
|
||||
float Bone::localToWorldRotation(float localRotation) {
|
||||
float sin = MathUtil::sinDeg(localRotation);
|
||||
float cos = MathUtil::cosDeg(localRotation);
|
||||
|
||||
return MathUtil::atan2(cos * _c + sin * _d, cos * _a + sin * _b) * RadDeg;
|
||||
return MathUtil::atan2(cos * _c + sin * _d, cos * _a + sin * _b) * RAD_DEG;
|
||||
}
|
||||
|
||||
void Bone::rotateWorld(float degrees) {
|
||||
@ -306,7 +306,7 @@ namespace Spine {
|
||||
float a = _a;
|
||||
float c = _c;
|
||||
|
||||
return MathUtil::atan2(pa * c - pc * a, pd * a - pb * c) * RadDeg;
|
||||
return MathUtil::atan2(pa * c - pc * a, pd * a - pb * c) * RAD_DEG;
|
||||
}
|
||||
|
||||
float Bone::getWorldToLocalRotationY() {
|
||||
@ -322,7 +322,7 @@ namespace Spine {
|
||||
float b = _b;
|
||||
float d = _d;
|
||||
|
||||
return MathUtil::atan2(pa * d - pc * b, pd * b - pb * d) * RadDeg;
|
||||
return MathUtil::atan2(pa * d - pc * b, pd * b - pb * d) * RAD_DEG;
|
||||
}
|
||||
|
||||
BoneData& Bone::getData() {
|
||||
@ -502,11 +502,11 @@ namespace Spine {
|
||||
}
|
||||
|
||||
float Bone::getWorldRotationX() {
|
||||
return MathUtil::atan2(_c, _a) * RadDeg;
|
||||
return MathUtil::atan2(_c, _a) * RAD_DEG;
|
||||
}
|
||||
|
||||
float Bone::getWorldRotationY() {
|
||||
return MathUtil::atan2(_d, _b) * RadDeg;
|
||||
return MathUtil::atan2(_d, _b) * RAD_DEG;
|
||||
}
|
||||
|
||||
float Bone::getWorldScaleX() {
|
||||
@ -523,11 +523,11 @@ namespace Spine {
|
||||
if (!parent) {
|
||||
_ax = _worldX;
|
||||
_ay = _worldY;
|
||||
_arotation = MathUtil::atan2(_c, _a) * RadDeg;
|
||||
_arotation = MathUtil::atan2(_c, _a) * RAD_DEG;
|
||||
_ascaleX = MathUtil::sqrt(_a * _a + _c * _c);
|
||||
_ascaleY = MathUtil::sqrt(_b * _b + _d * _d);
|
||||
_ashearX = 0;
|
||||
_ashearY = MathUtil::atan2(_a * _b + _c * _d, _a * _d - _b * _c) * RadDeg;
|
||||
_ashearY = MathUtil::atan2(_a * _b + _c * _d, _a * _d - _b * _c) * RAD_DEG;
|
||||
|
||||
return;
|
||||
}
|
||||
@ -560,14 +560,22 @@ namespace Spine {
|
||||
if (_ascaleX > 0.0001f) {
|
||||
float det = ra * rd - rb * rc;
|
||||
_ascaleY = det / _ascaleX;
|
||||
_ashearY = MathUtil::atan2(ra * rb + rc * rd, det) * RadDeg;
|
||||
_arotation = MathUtil::atan2(rc, ra) * RadDeg;
|
||||
_ashearY = MathUtil::atan2(ra * rb + rc * rd, det) * RAD_DEG;
|
||||
_arotation = MathUtil::atan2(rc, ra) * RAD_DEG;
|
||||
}
|
||||
else {
|
||||
_ascaleX = 0;
|
||||
_ascaleY = MathUtil::sqrt(rb * rb + rd * rd);
|
||||
_ashearY = 0;
|
||||
_arotation = 90 - MathUtil::atan2(rd, rb) * RadDeg;
|
||||
_arotation = 90 - MathUtil::atan2(rd, rb) * RAD_DEG;
|
||||
}
|
||||
}
|
||||
|
||||
String Bone::toString() const {
|
||||
String str;
|
||||
str.append("Bone { name: ").appendString(_data.getName());
|
||||
str.append(", a: ").append(_a).append(", b: ").append(_b).append(", c").append(_c).append(", d: ").append(_d);
|
||||
str.append(", worldX: ").append(_worldX).append(", worldY: ").append(_worldY).append(" }");
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,4 +133,8 @@ namespace Spine {
|
||||
void BoneData::setTransformMode(TransformMode inValue) {
|
||||
_transformMode = inValue;
|
||||
}
|
||||
|
||||
String BoneData::toString() const {
|
||||
return String("BoneData");
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,4 +35,11 @@ namespace Spine {
|
||||
|
||||
BoundingBoxAttachment::BoundingBoxAttachment(const String& name) : VertexAttachment(name) {
|
||||
}
|
||||
|
||||
String BoundingBoxAttachment::toString() const {
|
||||
String str;
|
||||
str.append("BoundingBoxAttachment { name: ").appendString(getName()).append(", worldVerticesLength: ").append(_worldVerticesLength);
|
||||
str.append(",\n bones: ").append(_bones).append(",\n weights: ").append(_vertices).append(" }");
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,4 +45,12 @@ namespace Spine {
|
||||
void ClippingAttachment::setEndSlot(SlotData* inValue) {
|
||||
_endSlot = inValue;
|
||||
}
|
||||
|
||||
String ClippingAttachment::toString() const {
|
||||
String str;
|
||||
str.append("Clipping { name: ").appendString(getName());
|
||||
str.append(", worldVerticesLength: ").append(_worldVerticesLength);
|
||||
str.append(", bones: ").append(_bones).append(", weights: ").append(_vertices).append(" }");
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,4 +72,8 @@ namespace Spine {
|
||||
void Event::setStringValue(const String& inValue) {
|
||||
_stringValue = inValue;
|
||||
}
|
||||
|
||||
String Event::toString() const {
|
||||
return String("Event");
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,4 +69,8 @@ namespace Spine {
|
||||
void EventData::setStringValue(const String& inValue) {
|
||||
_stringValue = inValue;
|
||||
}
|
||||
|
||||
String EventData::toString() const {
|
||||
return String("EventData");
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,204 +41,143 @@ namespace Spine {
|
||||
RTTI_IMPL(IkConstraint, Constraint);
|
||||
|
||||
void IkConstraint::apply(Bone& bone, float targetX, float targetY, float alpha) {
|
||||
if (!bone._appliedValid) {
|
||||
bone.updateAppliedTransform();
|
||||
}
|
||||
|
||||
Bone* parent = bone.getParent();
|
||||
Bone& p = *parent;
|
||||
|
||||
float id = 1 / (p._a * p._d - p._b * p._c);
|
||||
float x = targetX - p._worldX, y = targetY - p._worldY;
|
||||
float tx = (x * p._d - y * p._b) * id - bone._ax, ty = (y * p._a - x * p._c) * id - bone._ay;
|
||||
float rotationIK = MathUtil::atan2(ty, tx) * RadDeg - bone._ashearX - bone._arotation;
|
||||
|
||||
if (bone._ascaleX < 0) {
|
||||
rotationIK += 180;
|
||||
}
|
||||
|
||||
if (rotationIK > 180) {
|
||||
rotationIK -= 360;
|
||||
}
|
||||
else if (rotationIK < -180) {
|
||||
rotationIK += 360;
|
||||
}
|
||||
|
||||
bone.updateWorldTransform(bone._ax, bone._ay, bone._arotation + rotationIK * alpha, bone._ascaleX, bone._ascaleY, bone._ashearX, bone._ashearY);
|
||||
Bone* p = bone.getParent();
|
||||
float id, x, y, tx, ty, rotationIK;
|
||||
if (!bone._appliedValid) bone.updateAppliedTransform();
|
||||
id = 1 / (p->_a * p->_d - p->_b * p->_c);
|
||||
x = targetX - p->_worldX, y = targetY - p->_worldY;
|
||||
tx = (x * p->_d - y * p->_b) * id - bone._ax; ty = (y * p->_a - x * p->_c) * id - bone._ay;
|
||||
rotationIK = MathUtil::atan2(ty, tx) * RAD_DEG - bone._ashearX - bone._arotation;
|
||||
if (bone._ascaleX < 0) rotationIK += 180;
|
||||
if (rotationIK > 180) rotationIK -= 360;
|
||||
else if (rotationIK < -180) rotationIK += 360;
|
||||
bone.updateWorldTransform(bone._ax, bone._ay, bone._arotation + rotationIK * alpha, bone._ascaleX,
|
||||
bone._ascaleY, bone._ashearX, bone._ashearY);
|
||||
}
|
||||
|
||||
void IkConstraint::apply(Bone& parent, Bone& child, float targetX, float targetY, int bendDir, float alpha) {
|
||||
if (MathUtil::areFloatsPracticallyEqual(alpha, 0)) {
|
||||
float px, py, psx, psy;
|
||||
float cx, cy, csx, cwx, cwy;
|
||||
int o1, o2, s2, u;
|
||||
Bone* pp = parent.getParent();
|
||||
float tx, ty, dx, dy, l1, l2, a1, a2, r;
|
||||
float id, x, y;
|
||||
if (alpha == 0) {
|
||||
child.updateWorldTransform();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!parent._appliedValid) {
|
||||
parent.updateAppliedTransform();
|
||||
}
|
||||
|
||||
if (!child._appliedValid) {
|
||||
child.updateAppliedTransform();
|
||||
}
|
||||
|
||||
float px = parent._ax;
|
||||
float py = parent._ay;
|
||||
float psx = parent._ascaleX;
|
||||
float psy = parent._ascaleY;
|
||||
float csx = child._ascaleX;
|
||||
|
||||
int os1, os2, s2;
|
||||
if (!parent._appliedValid) parent.updateAppliedTransform();
|
||||
if (!child._appliedValid) child.updateAppliedTransform();
|
||||
px = parent._ax; py = parent._ay; psx = parent._ascaleX; psy = parent._ascaleY; csx = child._ascaleX;
|
||||
if (psx < 0) {
|
||||
psx = -psx;
|
||||
os1 = 180;
|
||||
o1 = 180;
|
||||
s2 = -1;
|
||||
}
|
||||
else {
|
||||
os1 = 0;
|
||||
} else {
|
||||
o1 = 0;
|
||||
s2 = 1;
|
||||
}
|
||||
|
||||
if (psy < 0) {
|
||||
psy = -psy;
|
||||
s2 = -s2;
|
||||
}
|
||||
|
||||
if (csx < 0) {
|
||||
csx = -csx;
|
||||
os2 = 180;
|
||||
}
|
||||
else {
|
||||
os2 = 0;
|
||||
}
|
||||
|
||||
float cx = child._ax;
|
||||
float cy;
|
||||
float cwx;
|
||||
float cwy;
|
||||
float a = parent._a;
|
||||
float b = parent._b;
|
||||
float c = parent._c;
|
||||
float d = parent._d;
|
||||
|
||||
bool u = MathUtil::abs(psx - psy) <= 0.0001f;
|
||||
o2 = 180;
|
||||
} else
|
||||
o2 = 0;
|
||||
r = psx - psy;
|
||||
cx = child._ax;
|
||||
u = (r < 0 ? -r : r) <= 0.0001f;
|
||||
if (!u) {
|
||||
cy = 0;
|
||||
cwx = a * cx + parent._worldX;
|
||||
cwy = c * cx + parent._worldY;
|
||||
}
|
||||
else {
|
||||
cwx = parent._a * cx + parent._worldX;
|
||||
cwy = parent._c * cx + parent._worldY;
|
||||
} else {
|
||||
cy = child._ay;
|
||||
cwx = a * cx + b * cy + parent._worldX;
|
||||
cwy = c * cx + d * cy + parent._worldY;
|
||||
cwx = parent._a * cx + parent._b * cy + parent._worldX;
|
||||
cwy = parent._c * cx + parent._d * cy + parent._worldY;
|
||||
}
|
||||
|
||||
Bone* parentparent = parent._parent;
|
||||
Bone& pp = *parentparent;
|
||||
|
||||
a = pp._a;
|
||||
b = pp._b;
|
||||
c = pp._c;
|
||||
d = pp._d;
|
||||
|
||||
float id = 1 / (a * d - b * c), x = targetX - pp._worldX, y = targetY - pp._worldY;
|
||||
float tx = (x * d - y * b) * id - px, ty = (y * a - x * c) * id - py;
|
||||
x = cwx - pp._worldX;
|
||||
y = cwy - pp._worldY;
|
||||
float dx = (x * d - y * b) * id - px, dy = (y * a - x * c) * id - py;
|
||||
float l1 = MathUtil::sqrt(dx * dx + dy * dy), l2 = child._data.getLength() * csx, a1, a2;
|
||||
id = 1 / (pp->_a * pp->_d - pp->_b * pp->_c);
|
||||
x = targetX - pp->_worldX;
|
||||
y = targetY - pp->_worldY;
|
||||
tx = (x * pp->_d - y * pp->_b) * id - px;
|
||||
ty = (y * pp->_a - x * pp->_c) * id - py;
|
||||
x = cwx - pp->_worldX;
|
||||
y = cwy - pp->_worldY;
|
||||
dx = (x * pp->_d - y * pp->_b) * id - px;
|
||||
dy = (y * pp->_a - x * pp->_c) * id - py;
|
||||
l1 = MathUtil::sqrt(dx * dx + dy * dy);
|
||||
l2 = child.getData().getLength() * csx;
|
||||
if (u) {
|
||||
float cosine, a, b;
|
||||
l2 *= psx;
|
||||
float cos = (tx * tx + ty * ty - l1 * l1 - l2 * l2) / (2 * l1 * l2);
|
||||
if (cos < -1) {
|
||||
cos = -1;
|
||||
}
|
||||
else if (cos > 1) {
|
||||
cos = 1;
|
||||
}
|
||||
|
||||
a2 = MathUtil::acos(cos) * bendDir;
|
||||
a = l1 + l2 * cos;
|
||||
cosine = (tx * tx + ty * ty - l1 * l1 - l2 * l2) / (2 * l1 * l2);
|
||||
if (cosine < -1) cosine = -1;
|
||||
else if (cosine > 1) cosine = 1;
|
||||
a2 = MathUtil::acos(cosine) * bendDir;
|
||||
a = l1 + l2 * cosine;
|
||||
b = l2 * MathUtil::sin(a2);
|
||||
a1 = MathUtil::atan2(ty * a - tx * b, tx * a + ty * b);
|
||||
}
|
||||
else {
|
||||
a = psx * l2;
|
||||
b = psy * l2;
|
||||
float aa = a * a, bb = b * b, dd = tx * tx + ty * ty, ta = MathUtil::atan2(ty, tx);
|
||||
c = bb * l1 * l1 + aa * dd - aa * bb;
|
||||
float c1 = -2 * bb * l1, c2 = bb - aa;
|
||||
d = c1 * c1 - 4 * c2 * c;
|
||||
} else {
|
||||
float a = psx * l2, b = psy * l2;
|
||||
float aa = a * a, bb = b * b, ll = l1 * l1, dd = tx * tx + ty * ty, ta = MathUtil::atan2(ty, tx);
|
||||
float c0 = bb * ll + aa * dd - aa * bb, c1 = -2 * bb * l1, c2 = bb - aa;
|
||||
float d = c1 * c1 - 4 * c2 * c0;
|
||||
if (d >= 0) {
|
||||
float q = MathUtil::sqrt(d);
|
||||
float q = MathUtil::sqrt(d), r0, r1;
|
||||
if (c1 < 0) q = -q;
|
||||
q = -(c1 + q) / 2;
|
||||
float r0 = q / c2, r1 = c / q;
|
||||
float r = MathUtil::abs(r0) < MathUtil::abs(r1) ? r0 : r1;
|
||||
r0 = q / c2; r1 = c0 / q;
|
||||
r = MathUtil::abs(r0) < MathUtil::abs(r1) ? r0 : r1;
|
||||
if (r * r <= dd) {
|
||||
y = MathUtil::sqrt(dd - r * r) * bendDir;
|
||||
a1 = ta - MathUtil::atan2(y, r);
|
||||
a2 = MathUtil::atan2(y / psy, (r - l1) / psx);
|
||||
|
||||
float os = MathUtil::atan2(cy, cx) * s2;
|
||||
float rotation = parent._arotation;
|
||||
a1 = (a1 - os) * RadDeg + os1 - rotation;
|
||||
if (a1 > 180) {
|
||||
a1 -= 360;
|
||||
}
|
||||
else if (a1 < -180) {
|
||||
a1 += 360;
|
||||
}
|
||||
|
||||
parent.updateWorldTransform(px, py, rotation + a1 * alpha, parent._scaleX, parent._ascaleY, 0, 0);
|
||||
rotation = child._arotation;
|
||||
a2 = ((a2 + os) * RadDeg - child._ashearX) * s2 + os2 - rotation;
|
||||
|
||||
if (a2 > 180) {
|
||||
a2 -= 360;
|
||||
}
|
||||
else if (a2 < -180) {
|
||||
a2 += 360;
|
||||
}
|
||||
|
||||
child.updateWorldTransform(cx, cy, rotation + a2 * alpha, child._ascaleX, child._ascaleY, child._ashearX, child._ashearY);
|
||||
|
||||
return;
|
||||
goto break_outer;
|
||||
}
|
||||
}
|
||||
|
||||
float minAngle = SPINE_PI, minX = l1 - a, minDist = minX * minX, minY = 0;
|
||||
float maxAngle = 0, maxX = l1 + a, maxDist = maxX * maxX, maxY = 0;
|
||||
c = -a * l1 / (aa - bb);
|
||||
if (c >= -1 && c <= 1) {
|
||||
c = MathUtil::acos(c);
|
||||
x = a * MathUtil::cos(c) + l1;
|
||||
y = b * (float)MathUtil::sin(c);
|
||||
d = x * x + y * y;
|
||||
|
||||
if (d < minDist) {
|
||||
minAngle = c;
|
||||
minDist = d;
|
||||
minX = x;
|
||||
minY = y;
|
||||
{
|
||||
float minAngle = PI, minX = l1 - a, minDist = minX * minX, minY = 0;
|
||||
float maxAngle = 0, maxX = l1 + a, maxDist = maxX * maxX, maxY = 0;
|
||||
c0 = -a * l1 / (aa - bb);
|
||||
if (c0 >= -1 && c0 <= 1) {
|
||||
c0 = MathUtil::acos(c0);
|
||||
x = a * MathUtil::cos(c0) + l1;
|
||||
y = b * MathUtil::sin(c0);
|
||||
d = x * x + y * y;
|
||||
if (d < minDist) {
|
||||
minAngle = c0;
|
||||
minDist = d;
|
||||
minX = x;
|
||||
minY = y;
|
||||
}
|
||||
if (d > maxDist) {
|
||||
maxAngle = c0;
|
||||
maxDist = d;
|
||||
maxX = x;
|
||||
maxY = y;
|
||||
}
|
||||
}
|
||||
|
||||
if (d > maxDist) {
|
||||
maxAngle = c;
|
||||
maxDist = d;
|
||||
maxX = x;
|
||||
maxY = y;
|
||||
if (dd <= (minDist + maxDist) / 2) {
|
||||
a1 = ta - MathUtil::atan2(minY * bendDir, minX);
|
||||
a2 = minAngle * bendDir;
|
||||
} else {
|
||||
a1 = ta - MathUtil::atan2(maxY * bendDir, maxX);
|
||||
a2 = maxAngle * bendDir;
|
||||
}
|
||||
}
|
||||
|
||||
if (dd <= (minDist + maxDist) / 2) {
|
||||
a1 = ta - MathUtil::atan2(minY * bendDir, minX);
|
||||
a2 = minAngle * bendDir;
|
||||
}
|
||||
else {
|
||||
a1 = ta - MathUtil::atan2(maxY * bendDir, maxX);
|
||||
a2 = maxAngle * bendDir;
|
||||
}
|
||||
}
|
||||
break_outer: {
|
||||
float os = MathUtil::atan2(cy, cx) * s2;
|
||||
a1 = (a1 - os) * RAD_DEG + o1 - parent._arotation;
|
||||
if (a1 > 180) a1 -= 360;
|
||||
else if (a1 < -180) a1 += 360;
|
||||
parent.updateWorldTransform(px, py, parent._rotation + a1 * alpha, parent._ascaleX, parent._ascaleY, 0, 0);
|
||||
a2 = ((a2 + os) * RAD_DEG - child._ashearX) * s2 + o2 - child._arotation;
|
||||
if (a2 > 180) a2 -= 360;
|
||||
else if (a2 < -180) a2 += 360;
|
||||
child.updateWorldTransform(cx, cy, child._arotation + a2 * alpha, child._ascaleX, child._ascaleY, child._ashearX, child._ashearY);
|
||||
}
|
||||
}
|
||||
|
||||
@ -310,4 +249,11 @@ namespace Spine {
|
||||
void IkConstraint::setMix(float inValue) {
|
||||
_mix = inValue;
|
||||
}
|
||||
|
||||
String IkConstraint::toString() const {
|
||||
String str;
|
||||
str.append("IkConstraint { name: ").appendString(_data.getName());
|
||||
str.append("}");
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,4 +80,8 @@ namespace Spine {
|
||||
void IkConstraintData::setMix(float inValue) {
|
||||
_mix = inValue;
|
||||
}
|
||||
|
||||
String IkConstraintData::toString() const {
|
||||
return String("IkConstraintData");
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,6 +42,8 @@
|
||||
#endif
|
||||
|
||||
#include <spine/Json.h>
|
||||
#include <spine/Extension.h>
|
||||
#include <spine/String.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
@ -49,7 +51,6 @@
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h> /* strtod (C89), strtof (C99) */
|
||||
#include <string.h> /* strcasecmp (4.4BSD - compatibility), _stricmp (_WIN32) */
|
||||
#include <spine/Extension.h>
|
||||
#include <new>
|
||||
|
||||
namespace Spine {
|
||||
@ -549,4 +550,8 @@ namespace Spine {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String Json::toString() const {
|
||||
return String("Json");
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,4 +39,8 @@ namespace Spine {
|
||||
_slotIndex(slotIndex),
|
||||
_parent(parent) {
|
||||
}
|
||||
|
||||
String LinkedMesh::toString() const {
|
||||
return String("LinkedMesh");
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,12 +72,12 @@ namespace Spine {
|
||||
|
||||
/// Returns the sine in radians from a lookup table.
|
||||
float MathUtil::sinDeg(float degrees) {
|
||||
return ::sin(degrees * DegRad);
|
||||
return ::sin(degrees * DEG_RAD);
|
||||
}
|
||||
|
||||
/// Returns the cosine in radians from a lookup table.
|
||||
float MathUtil::cosDeg(float degrees) {
|
||||
return ::cos(degrees * DegRad);
|
||||
return ::cos(degrees * DEG_RAD);
|
||||
}
|
||||
|
||||
/// Returns atan2 in radians, faster but less accurate than Math.Atan2. Average error of 0.00231 radians (0.1323
|
||||
|
||||
@ -270,4 +270,10 @@
|
||||
Spine::Color& MeshAttachment::getColor() {
|
||||
return _color;
|
||||
}
|
||||
|
||||
String MeshAttachment::toString() const {
|
||||
String str;
|
||||
str.append("RegionAttachment { name: ").appendString(getName()).append(", path: ").appendString(_path).append(" }");
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,4 +59,12 @@ namespace Spine {
|
||||
void PathAttachment::setConstantSpeed(bool inValue) {
|
||||
_constantSpeed = inValue;
|
||||
}
|
||||
|
||||
String PathAttachment::toString() const {
|
||||
String str;
|
||||
str.append("PathAttachment { name: ").appendString(getName()).append(", closed: ").append(_closed).append(", constantSpeed: ").append(_constantSpeed);
|
||||
str.append(", worldVerticesLength: ").append(_worldVerticesLength);
|
||||
str.append(", bones: ").append(_bones).append(", weights: ").append(_vertices).append(" }");
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,8 +139,8 @@ namespace Spine {
|
||||
}
|
||||
else {
|
||||
tip = false;
|
||||
Bone p = _target->getBone();
|
||||
offsetRotation *= p.getA() * p.getD() - p.getB() * p.getC() > 0 ? DegRad : -DegRad;
|
||||
Bone& p = _target->getBone();
|
||||
offsetRotation *= p.getA() * p.getD() - p.getB() * p.getC() > 0 ? DEG_RAD : -DEG_RAD;
|
||||
}
|
||||
|
||||
for (int i = 0, p = 3; i < boneCount; i++, p += 3) {
|
||||
@ -189,11 +189,11 @@ namespace Spine {
|
||||
r += offsetRotation;
|
||||
}
|
||||
|
||||
if (r > SPINE_PI) {
|
||||
r -= SPINE_PI_2;
|
||||
if (r > PI) {
|
||||
r -= PI_2;
|
||||
}
|
||||
else if (r < -SPINE_PI) {
|
||||
r += SPINE_PI_2;
|
||||
else if (r < -PI) {
|
||||
r += PI_2;
|
||||
}
|
||||
|
||||
r *= rotateMix;
|
||||
@ -557,4 +557,10 @@ namespace Spine {
|
||||
output[o + 2] = MathUtil::atan2(y - (y1 * uu + cy1 * ut * 2 + cy2 * tt), x - (x1 * uu + cx1 * ut * 2 + cx2 * tt));
|
||||
}
|
||||
}
|
||||
|
||||
String PathConstraint::toString() const {
|
||||
String str;
|
||||
str.append("TransformConstraint { name: ").appendString(_data.getName()).append(" }");
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,4 +138,10 @@ namespace Spine {
|
||||
void PathConstraintData::setTranslateMix(float inValue) {
|
||||
_translateMix = inValue;
|
||||
}
|
||||
|
||||
String PathConstraintData::toString() const {
|
||||
String str;
|
||||
str.append("PathConstraintData { name: ").appendString(_name).append(" }");
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ namespace Spine {
|
||||
float ix = cos * bone._a + sin * bone._b;
|
||||
float iy = cos * bone._c + sin * bone._d;
|
||||
|
||||
return MathUtil::atan2(iy, ix) * RadDeg;
|
||||
return MathUtil::atan2(iy, ix) * RAD_DEG;
|
||||
}
|
||||
|
||||
float PointAttachment::getX() {
|
||||
@ -76,4 +76,10 @@ namespace Spine {
|
||||
void PointAttachment::setRotation(float inValue) {
|
||||
_rotation = inValue;
|
||||
}
|
||||
|
||||
String PointAttachment::toString() const {
|
||||
String str;
|
||||
str.append("PointAttachment { name: ").appendString(getName()).append(" }");
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,4 +59,10 @@ namespace Spine {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
String RTTI::toString() const {
|
||||
String str;
|
||||
str.append("RTTI { name: ").append(_className.c_str()).append(" }");
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
@ -287,4 +287,10 @@ namespace Spine {
|
||||
Spine::Color& RegionAttachment::getColor() {
|
||||
return _color;
|
||||
}
|
||||
|
||||
String RegionAttachment::toString() const {
|
||||
String str;
|
||||
str.append("RegionAttachment { name: ").appendString(getName()).append(", path: ").appendString(_path).append(" }");
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
@ -431,10 +431,10 @@ namespace Spine {
|
||||
float vx = outVertexBuffer[ii];
|
||||
float vy = outVertexBuffer[ii + 1];
|
||||
|
||||
minX = MIN(minX, vx);
|
||||
minY = MIN(minY, vy);
|
||||
maxX = MAX(maxX, vx);
|
||||
maxY = MAX(maxY, vy);
|
||||
minX = MathUtil::min(minX, vx);
|
||||
minY = MathUtil::min(minY, vy);
|
||||
maxX = MathUtil::max(maxX, vx);
|
||||
maxY = MathUtil::max(maxY, vy);
|
||||
}
|
||||
}
|
||||
|
||||
@ -649,4 +649,16 @@ namespace Spine {
|
||||
bone->_sorted = false;
|
||||
}
|
||||
}
|
||||
|
||||
String Skeleton::toString() const {
|
||||
String str;
|
||||
|
||||
str.append("Skeleton {\n");
|
||||
str.append(" bones: ").append(_bones);
|
||||
str.append(",\n slots: ").append(_slots);
|
||||
str.append(",\n drawOrder: ").append(_drawOrder);
|
||||
str.append(",\n animations: ").append(_data->getAnimations());
|
||||
str.append(" }");
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
@ -646,7 +646,7 @@ namespace Spine {
|
||||
timeline->setFrame(frameIndex, readFloat(input), String(readString(input), true));
|
||||
}
|
||||
timelines.add(timeline);
|
||||
duration = MAX(duration, timeline->_frames[frameCount - 1]);
|
||||
duration = MathUtil::max(duration, timeline->_frames[frameCount - 1]);
|
||||
break;
|
||||
}
|
||||
case SLOT_COLOR: {
|
||||
@ -665,7 +665,7 @@ namespace Spine {
|
||||
}
|
||||
}
|
||||
timelines.add(timeline);
|
||||
duration = MAX(duration, timeline->_frames[(frameCount - 1) * ColorTimeline::ENTRIES]);
|
||||
duration = MathUtil::max(duration, timeline->_frames[(frameCount - 1) * ColorTimeline::ENTRIES]);
|
||||
break;
|
||||
}
|
||||
case SLOT_TWO_COLOR: {
|
||||
@ -689,7 +689,7 @@ namespace Spine {
|
||||
}
|
||||
}
|
||||
timelines.add(timeline);
|
||||
duration = MAX(duration, timeline->_frames[(frameCount - 1) * TwoColorTimeline::ENTRIES]);
|
||||
duration = MathUtil::max(duration, timeline->_frames[(frameCount - 1) * TwoColorTimeline::ENTRIES]);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@ -718,7 +718,7 @@ namespace Spine {
|
||||
}
|
||||
}
|
||||
timelines.add(timeline);
|
||||
duration = MAX(duration, timeline->_frames[(frameCount - 1) * RotateTimeline::ENTRIES]);
|
||||
duration = MathUtil::max(duration, timeline->_frames[(frameCount - 1) * RotateTimeline::ENTRIES]);
|
||||
break;
|
||||
}
|
||||
case BONE_TRANSLATE:
|
||||
@ -744,7 +744,7 @@ namespace Spine {
|
||||
}
|
||||
}
|
||||
timelines.add(timeline);
|
||||
duration = MAX(duration, timeline->_frames[(frameCount - 1) * TranslateTimeline::ENTRIES]);
|
||||
duration = MathUtil::max(duration, timeline->_frames[(frameCount - 1) * TranslateTimeline::ENTRIES]);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@ -769,7 +769,7 @@ namespace Spine {
|
||||
}
|
||||
}
|
||||
timelines.add(timeline);
|
||||
duration = MAX(duration, timeline->_frames[(frameCount - 1) * IkConstraintTimeline::ENTRIES]);
|
||||
duration = MathUtil::max(duration, timeline->_frames[(frameCount - 1) * IkConstraintTimeline::ENTRIES]);
|
||||
}
|
||||
|
||||
// Transform constraint timelines.
|
||||
@ -785,7 +785,7 @@ namespace Spine {
|
||||
}
|
||||
}
|
||||
timelines.add(timeline);
|
||||
duration = MAX(duration, timeline->_frames[(frameCount - 1) * TransformConstraintTimeline::ENTRIES]);
|
||||
duration = MathUtil::max(duration, timeline->_frames[(frameCount - 1) * TransformConstraintTimeline::ENTRIES]);
|
||||
}
|
||||
|
||||
// Path constraint timelines.
|
||||
@ -822,7 +822,7 @@ namespace Spine {
|
||||
}
|
||||
}
|
||||
timelines.add(timeline);
|
||||
duration = MAX(duration, timeline->_frames[(frameCount - 1) * PathConstraintPositionTimeline::ENTRIES]);
|
||||
duration = MathUtil::max(duration, timeline->_frames[(frameCount - 1) * PathConstraintPositionTimeline::ENTRIES]);
|
||||
break;
|
||||
}
|
||||
case PATH_MIX: {
|
||||
@ -836,7 +836,7 @@ namespace Spine {
|
||||
}
|
||||
}
|
||||
timelines.add(timeline);
|
||||
duration = MAX(duration, timeline->_frames[(frameCount - 1) * PathConstraintMixTimeline::ENTRIES]);
|
||||
duration = MathUtil::max(duration, timeline->_frames[(frameCount - 1) * PathConstraintMixTimeline::ENTRIES]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -915,7 +915,7 @@ namespace Spine {
|
||||
}
|
||||
|
||||
timelines.add(timeline);
|
||||
duration = MAX(duration, timeline->_frames[frameCount - 1]);
|
||||
duration = MathUtil::max(duration, timeline->_frames[frameCount - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -964,7 +964,7 @@ namespace Spine {
|
||||
timeline->setFrame(i, time, drawOrder);
|
||||
}
|
||||
timelines.add(timeline);
|
||||
duration = MAX(duration, timeline->_frames[drawOrderCount - 1]);
|
||||
duration = MathUtil::max(duration, timeline->_frames[drawOrderCount - 1]);
|
||||
}
|
||||
|
||||
// Event timeline.
|
||||
@ -989,7 +989,7 @@ namespace Spine {
|
||||
}
|
||||
|
||||
timelines.add(timeline);
|
||||
duration = MAX(duration, timeline->_frames[eventCount - 1]);
|
||||
duration = MathUtil::max(duration, timeline->_frames[eventCount - 1]);
|
||||
}
|
||||
|
||||
return new (__FILE__, __LINE__) Animation(String(name), timelines, duration);
|
||||
@ -1011,4 +1011,8 @@ namespace Spine {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String SkeletonBinary::toString() const {
|
||||
return String("SkeletonBinary");
|
||||
}
|
||||
}
|
||||
|
||||
@ -222,10 +222,10 @@ namespace Spine {
|
||||
for (int ii = 0, nn = polygon->_count; ii < nn; ii += 2) {
|
||||
float x = vertices[ii];
|
||||
float y = vertices[ii + 1];
|
||||
minX = MIN(minX, x);
|
||||
minY = MIN(minY, y);
|
||||
maxX = MAX(maxX, x);
|
||||
maxY = MAX(maxY, y);
|
||||
minX = MathUtil::min(minX, x);
|
||||
minY = MathUtil::min(minY, y);
|
||||
maxX = MathUtil::max(maxX, x);
|
||||
maxY = MathUtil::max(maxY, y);
|
||||
}
|
||||
}
|
||||
_minX = minX;
|
||||
@ -233,5 +233,15 @@ namespace Spine {
|
||||
_maxX = maxX;
|
||||
_maxY = maxY;
|
||||
}
|
||||
|
||||
String SkeletonBounds::toString() const {
|
||||
return String("SkeletonBounds");
|
||||
}
|
||||
|
||||
String Polygon::toString() const {
|
||||
String str;
|
||||
str.append("Polygon { count: ").append(_count).append(", vertices: ").append(_vertices).append(" }");
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -96,8 +96,10 @@ namespace Spine {
|
||||
clippedVertices.clear();
|
||||
_clippedUVs.clear();
|
||||
clippedTriangles.clear();
|
||||
|
||||
for (int i = 0; i < trianglesLength; i += 3) {
|
||||
|
||||
int i = 0;
|
||||
continue_outer:
|
||||
for (; i < trianglesLength; i += 3) {
|
||||
int vertexOffset = triangles[i] << 1;
|
||||
float x1 = vertices[vertexOffset], y1 = vertices[vertexOffset + 1];
|
||||
float u1 = uvs[vertexOffset], v1 = uvs[vertexOffset + 1];
|
||||
@ -170,7 +172,8 @@ namespace Spine {
|
||||
clippedTriangles[s + 1] = index + 1;
|
||||
clippedTriangles[s + 2] = index + 2;
|
||||
index += 3;
|
||||
break;
|
||||
i += 3;
|
||||
goto continue_outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -312,4 +315,8 @@ namespace Spine {
|
||||
polygon[other + 1] = y;
|
||||
}
|
||||
}
|
||||
|
||||
String SkeletonClipping::toString() const {
|
||||
return String("SkeletonClipping");
|
||||
}
|
||||
}
|
||||
|
||||
@ -232,4 +232,8 @@ namespace Spine {
|
||||
void SkeletonData::setFps(float inValue) {
|
||||
_fps = inValue;
|
||||
}
|
||||
|
||||
String SkeletonData::toString() const {
|
||||
return String("SkeletonData");
|
||||
}
|
||||
}
|
||||
|
||||
@ -810,7 +810,7 @@ namespace Spine {
|
||||
}
|
||||
timelines.add(timeline);
|
||||
timelinesCount++;
|
||||
duration = MAX(duration, timeline->_frames[timelineMap->_size - 1]);
|
||||
duration = MathUtil::max(duration, timeline->_frames[timelineMap->_size - 1]);
|
||||
|
||||
}
|
||||
else if (strcmp(timelineMap->_name, "color") == 0) {
|
||||
@ -825,7 +825,7 @@ namespace Spine {
|
||||
}
|
||||
timelines.add(timeline);
|
||||
timelinesCount++;
|
||||
duration = MAX(duration, timeline->_frames[(timelineMap->_size - 1) * ColorTimeline::ENTRIES]);
|
||||
duration = MathUtil::max(duration, timeline->_frames[(timelineMap->_size - 1) * ColorTimeline::ENTRIES]);
|
||||
|
||||
}
|
||||
else if (strcmp(timelineMap->_name, "twoColor") == 0) {
|
||||
@ -842,7 +842,7 @@ namespace Spine {
|
||||
}
|
||||
timelines.add(timeline);
|
||||
timelinesCount++;
|
||||
duration = MAX(duration, timeline->_frames[(timelineMap->_size - 1) * TwoColorTimeline::ENTRIES]);
|
||||
duration = MathUtil::max(duration, timeline->_frames[(timelineMap->_size - 1) * TwoColorTimeline::ENTRIES]);
|
||||
}
|
||||
else {
|
||||
ContainerUtil::cleanUpVectorOfPointers(timelines);
|
||||
@ -875,7 +875,7 @@ namespace Spine {
|
||||
}
|
||||
timelines.add(timeline);
|
||||
timelinesCount++;
|
||||
duration = MAX(duration, timeline->_frames[(timelineMap->_size - 1) * RotateTimeline::ENTRIES]);
|
||||
duration = MathUtil::max(duration, timeline->_frames[(timelineMap->_size - 1) * RotateTimeline::ENTRIES]);
|
||||
}
|
||||
else {
|
||||
int isScale = strcmp(timelineMap->_name, "scale") == 0;
|
||||
@ -902,7 +902,7 @@ namespace Spine {
|
||||
|
||||
timelines.add(timeline);
|
||||
timelinesCount++;
|
||||
duration = MAX(duration, timeline->_frames[(timelineMap->_size - 1) * TranslateTimeline::ENTRIES]);
|
||||
duration = MathUtil::max(duration, timeline->_frames[(timelineMap->_size - 1) * TranslateTimeline::ENTRIES]);
|
||||
}
|
||||
else {
|
||||
ContainerUtil::cleanUpVectorOfPointers(timelines);
|
||||
@ -930,7 +930,7 @@ namespace Spine {
|
||||
}
|
||||
timelines.add(timeline);
|
||||
timelinesCount++;
|
||||
duration = MAX(duration, timeline->_frames[(constraintMap->_size - 1) * IkConstraintTimeline::ENTRIES]);
|
||||
duration = MathUtil::max(duration, timeline->_frames[(constraintMap->_size - 1) * IkConstraintTimeline::ENTRIES]);
|
||||
}
|
||||
|
||||
/** Transform constraint timelines. */
|
||||
@ -950,7 +950,7 @@ namespace Spine {
|
||||
}
|
||||
timelines.add(timeline);
|
||||
timelinesCount++;
|
||||
duration = MAX(duration, timeline->_frames[(constraintMap->_size - 1) * TransformConstraintTimeline::ENTRIES]);
|
||||
duration = MathUtil::max(duration, timeline->_frames[(constraintMap->_size - 1) * TransformConstraintTimeline::ENTRIES]);
|
||||
}
|
||||
|
||||
/** Path constraint timelines. */
|
||||
@ -999,7 +999,7 @@ namespace Spine {
|
||||
}
|
||||
timelines.add(timeline);
|
||||
timelinesCount++;
|
||||
duration = MAX(duration, timeline->_frames[(timelineMap->_size - 1) * PathConstraintPositionTimeline::ENTRIES]);
|
||||
duration = MathUtil::max(duration, timeline->_frames[(timelineMap->_size - 1) * PathConstraintPositionTimeline::ENTRIES]);
|
||||
}
|
||||
else if (strcmp(timelineName, "mix") == 0) {
|
||||
PathConstraintMixTimeline* timeline = new (__FILE__, __LINE__) PathConstraintMixTimeline(timelineMap->_size);
|
||||
@ -1010,7 +1010,7 @@ namespace Spine {
|
||||
}
|
||||
timelines.add(timeline);
|
||||
timelinesCount++;
|
||||
duration = MAX(duration, timeline->_frames[(timelineMap->_size - 1) * PathConstraintMixTimeline::ENTRIES]);
|
||||
duration = MathUtil::max(duration, timeline->_frames[(timelineMap->_size - 1) * PathConstraintMixTimeline::ENTRIES]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1085,7 +1085,7 @@ namespace Spine {
|
||||
|
||||
timelines.add(timeline);
|
||||
timelinesCount++;
|
||||
duration = MAX(duration, timeline->_frames[timelineMap->_size - 1]);
|
||||
duration = MathUtil::max(duration, timeline->_frames[timelineMap->_size - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1141,7 +1141,7 @@ namespace Spine {
|
||||
}
|
||||
timelines.add(timeline);
|
||||
timelinesCount++;
|
||||
duration = MAX(duration, timeline->_frames[drawOrder->_size - 1]);
|
||||
duration = MathUtil::max(duration, timeline->_frames[drawOrder->_size - 1]);
|
||||
}
|
||||
|
||||
/** Event timeline. */
|
||||
@ -1165,7 +1165,7 @@ namespace Spine {
|
||||
}
|
||||
timelines.add(timeline);
|
||||
timelinesCount++;
|
||||
duration = MAX(duration, timeline->_frames[events->_size - 1]);
|
||||
duration = MathUtil::max(duration, timeline->_frames[events->_size - 1]);
|
||||
}
|
||||
|
||||
return new (__FILE__, __LINE__) Animation(String(root->_name), timelines, duration);
|
||||
@ -1217,8 +1217,12 @@ namespace Spine {
|
||||
}
|
||||
|
||||
void SkeletonJson::setError(Json* root, const String& value1, const String& value2) {
|
||||
_error = String(value1 + value2);
|
||||
_error = String(value1).append(value2);
|
||||
|
||||
delete root;
|
||||
}
|
||||
|
||||
String SkeletonJson::toString() const {
|
||||
return String("SkeletonJson");
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,8 +46,14 @@ namespace Spine {
|
||||
bool Skin::AttachmentKey::operator==(const AttachmentKey &other) const {
|
||||
return _slotIndex == other._slotIndex && _name == other._name;
|
||||
}
|
||||
|
||||
std::size_t Skin::HashAttachmentKey::operator()(const Spine::Skin::AttachmentKey& val) const {
|
||||
|
||||
String Skin::AttachmentKey::toString() const {
|
||||
String str;
|
||||
str.append("AttachmentKey { slotIndex: ").append(_slotIndex).append(", name: ").appendString(_name).append(" }");
|
||||
return str;
|
||||
}
|
||||
|
||||
std::size_t Skin::HashAttachmentKey::operator()(const Spine::Skin::AttachmentKey& val) const {
|
||||
std::size_t h1 = val._slotIndex;
|
||||
return h1;
|
||||
}
|
||||
@ -122,4 +128,12 @@ namespace Spine {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String Skin::toString() const {
|
||||
String str;
|
||||
str.append("Skin { name: ").appendString(_name);
|
||||
str.append(",\n attachments: ").append(_attachments);
|
||||
str.append(" }");
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,4 +118,13 @@ namespace Spine {
|
||||
void Slot::setAttachmentVertices(Vector<float> inValue) {
|
||||
_attachmentVertices = inValue;
|
||||
}
|
||||
|
||||
String Slot::toString() const {
|
||||
String str;
|
||||
str.append("Slot { name: ").appendString(_data.getName());
|
||||
str.append(", color: ").appendString(_color.toString());
|
||||
if (_hasDarkColor) str.append(", darkColor: ").appendString(_darkColor.toString());
|
||||
str.append("}");
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,4 +89,8 @@ namespace Spine {
|
||||
void SlotData::setBlendMode(BlendMode inValue) {
|
||||
_blendMode = inValue;
|
||||
}
|
||||
|
||||
String SlotData::toString() const {
|
||||
return String("SlotData");
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,4 +41,10 @@ namespace Spine {
|
||||
|
||||
Timeline::~Timeline() {
|
||||
}
|
||||
|
||||
String Timeline::toString() const {
|
||||
String str;
|
||||
str.appendString(getRTTI().toString());
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,7 +134,7 @@ namespace Spine {
|
||||
float rotateMix = _rotateMix, translateMix = _translateMix, scaleMix = _scaleMix, shearMix = _shearMix;
|
||||
Bone& target = *_target;
|
||||
float ta = target._a, tb = target._b, tc = target._c, td = target._d;
|
||||
float degRadReflect = ta * td - tb * tc > 0 ? DegRad : -DegRad;
|
||||
float degRadReflect = ta * td - tb * tc > 0 ? DEG_RAD : -DEG_RAD;
|
||||
float offsetRotation = _data._offsetRotation * degRadReflect, offsetShearY = _data._offsetShearY * degRadReflect;
|
||||
|
||||
for (size_t i = 0; i < _bones.size(); ++i) {
|
||||
@ -146,11 +146,11 @@ namespace Spine {
|
||||
if (rotateMix != 0) {
|
||||
float a = bone._a, b = bone._b, c = bone._c, d = bone._d;
|
||||
float r = MathUtil::atan2(tc, ta) - MathUtil::atan2(c, a) + offsetRotation;
|
||||
if (r > SPINE_PI) {
|
||||
r -= SPINE_PI_2;
|
||||
if (r > PI) {
|
||||
r -= PI_2;
|
||||
}
|
||||
else if (r < -SPINE_PI) {
|
||||
r += SPINE_PI_2;
|
||||
else if (r < -PI) {
|
||||
r += PI_2;
|
||||
}
|
||||
|
||||
r *= rotateMix;
|
||||
@ -192,11 +192,11 @@ namespace Spine {
|
||||
float b = bone._b, d = bone._d;
|
||||
float by = MathUtil::atan2(d, b);
|
||||
float r = MathUtil::atan2(td, tb) - MathUtil::atan2(tc, ta) - (by - MathUtil::atan2(bone._c, bone._a));
|
||||
if (r > SPINE_PI) {
|
||||
r -= SPINE_PI_2;
|
||||
if (r > PI) {
|
||||
r -= PI_2;
|
||||
}
|
||||
else if (r < -SPINE_PI) {
|
||||
r += SPINE_PI_2;
|
||||
else if (r < -PI) {
|
||||
r += PI_2;
|
||||
}
|
||||
|
||||
r = by + (r + offsetShearY) * shearMix;
|
||||
@ -216,7 +216,7 @@ namespace Spine {
|
||||
float rotateMix = _rotateMix, translateMix = _translateMix, scaleMix = _scaleMix, shearMix = _shearMix;
|
||||
Bone& target = *_target;
|
||||
float ta = target._a, tb = target._b, tc = target._c, td = target._d;
|
||||
float degRadReflect = ta * td - tb * tc > 0 ? DegRad : -DegRad;
|
||||
float degRadReflect = ta * td - tb * tc > 0 ? DEG_RAD : -DEG_RAD;
|
||||
float offsetRotation = _data._offsetRotation * degRadReflect, offsetShearY = _data._offsetShearY * degRadReflect;
|
||||
for (size_t i = 0; i < _bones.size(); ++i) {
|
||||
Bone* item = _bones[i];
|
||||
@ -227,11 +227,11 @@ namespace Spine {
|
||||
if (rotateMix != 0) {
|
||||
float a = bone._a, b = bone._b, c = bone._c, d = bone._d;
|
||||
float r = MathUtil::atan2(tc, ta) + offsetRotation;
|
||||
if (r > SPINE_PI) {
|
||||
r -= SPINE_PI_2;
|
||||
if (r > PI) {
|
||||
r -= PI_2;
|
||||
}
|
||||
else if (r < -SPINE_PI) {
|
||||
r += SPINE_PI_2;
|
||||
else if (r < -PI) {
|
||||
r += PI_2;
|
||||
}
|
||||
|
||||
r *= rotateMix;
|
||||
@ -263,15 +263,15 @@ namespace Spine {
|
||||
|
||||
if (shearMix > 0) {
|
||||
float r = MathUtil::atan2(td, tb) - MathUtil::atan2(tc, ta);
|
||||
if (r > SPINE_PI) {
|
||||
r -= SPINE_PI_2;
|
||||
if (r > PI) {
|
||||
r -= PI_2;
|
||||
}
|
||||
else if (r < -SPINE_PI) {
|
||||
r += SPINE_PI_2;
|
||||
else if (r < -PI) {
|
||||
r += PI_2;
|
||||
}
|
||||
|
||||
float b = bone._b, d = bone._d;
|
||||
r = MathUtil::atan2(d, b) + (r - SPINE_PI / 2 + offsetShearY) * shearMix;
|
||||
r = MathUtil::atan2(d, b) + (r - PI / 2 + offsetShearY) * shearMix;
|
||||
float s = MathUtil::sqrt(b * b + d * d);
|
||||
bone._b = MathUtil::cos(r) * s;
|
||||
bone._d = MathUtil::sin(r) * s;
|
||||
@ -379,4 +379,10 @@ namespace Spine {
|
||||
bone.updateWorldTransform(x, y, rotation, scaleX, scaleY, bone._ashearX, shearY);
|
||||
}
|
||||
}
|
||||
|
||||
String TransformConstraint::toString() const {
|
||||
String str;
|
||||
str.append("TransformConstraint { name: ").appendString(_data.getName()).append(" }");
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,4 +116,8 @@ namespace Spine {
|
||||
bool TransformConstraintData::isLocal() {
|
||||
return _local;
|
||||
}
|
||||
|
||||
String TransformConstraintData::toString() const {
|
||||
return String("TransformConstraintData");
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ namespace Spine {
|
||||
|
||||
Vector<int>& triangles = _triangles;
|
||||
triangles.clear();
|
||||
triangles.ensureCapacity(MAX(0, vertexCount - 2) << 2);
|
||||
triangles.ensureCapacity(MathUtil::max(0, vertexCount - 2) << 2);
|
||||
|
||||
while (vertexCount > 3) {
|
||||
// Find ear tip.
|
||||
@ -293,4 +293,8 @@ namespace Spine {
|
||||
|
||||
return p3x * py - p3y * px + px * p1y - p1x * py >= 0 ? 1 : -1;
|
||||
}
|
||||
|
||||
String Triangulator::toString() const {
|
||||
return String("Triangulator");
|
||||
}
|
||||
}
|
||||
|
||||
@ -340,6 +340,7 @@ void coin (SkeletonData* skeletonData, Atlas* atlas) {
|
||||
skeleton->updateWorldTransform();
|
||||
|
||||
drawable->state->setAnimation(0, "rotate", true);
|
||||
drawable->update(0.1);
|
||||
|
||||
sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - vine");
|
||||
window.setFramerateLimit(60);
|
||||
@ -353,7 +354,7 @@ void coin (SkeletonData* skeletonData, Atlas* atlas) {
|
||||
float delta = deltaClock.getElapsedTime().asSeconds();
|
||||
deltaClock.restart();
|
||||
|
||||
drawable->update(delta);
|
||||
// drawable->update(delta);
|
||||
|
||||
window.clear();
|
||||
window.draw(*drawable);
|
||||
@ -394,12 +395,12 @@ void owl (SkeletonData* skeletonData, Atlas* atlas) {
|
||||
if (event.type == sf::Event::Closed) window.close();
|
||||
if (event.type == sf::Event::MouseMoved) {
|
||||
float x = event.mouseMove.x / 640.0f;
|
||||
left->setAlpha((MAX(x, 0.5f) - 0.5f) * 2);
|
||||
right->setAlpha((0.5 - MIN(x, 0.5)) * 2);
|
||||
left->setAlpha((MathUtil::max(x, 0.5f) - 0.5f) * 2);
|
||||
right->setAlpha((0.5 - MathUtil::min(x, 0.5f)) * 2);
|
||||
|
||||
float y = event.mouseMove.y / 640.0f;
|
||||
down->setAlpha((MAX(y, 0.5f) - 0.5f) * 2);
|
||||
up->setAlpha((0.5 - MIN(y, 0.5)) * 2);
|
||||
down->setAlpha((MathUtil::max(y, 0.5f) - 0.5f) * 2);
|
||||
up->setAlpha((0.5 - MathUtil::min(y, 0.5f)) * 2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -425,14 +426,10 @@ void test (SkeletonData* skeletonData, Atlas* atlas) {
|
||||
|
||||
float d = 3;
|
||||
for (int i = 0; i < 1; i++) {
|
||||
skeleton->update(d);
|
||||
animState->update(d);
|
||||
animState->apply(*skeleton);
|
||||
skeleton->updateWorldTransform();
|
||||
for (int ii = 0; ii < skeleton->getBones().size(); ii++) {
|
||||
Bone* bone = skeleton->getBones()[ii];
|
||||
printf("%s %f %f %f %f %f %f\n", bone->getData().getName().buffer(), bone->getA(), bone->getB(), bone->getC(), bone->getD(), bone->getWorldX(), bone->getWorldY());
|
||||
}
|
||||
printf("%s\n", skeleton->toString().buffer());
|
||||
printf("========================================\n");
|
||||
d += 0.1f;
|
||||
}
|
||||
@ -444,15 +441,16 @@ void test (SkeletonData* skeletonData, Atlas* atlas) {
|
||||
|
||||
int main () {
|
||||
DebugExtension dbgExtension;
|
||||
SpineExtension::setInstance(&dbgExtension);
|
||||
/*testcase(test, "data/tank-pro.json", "data/tank-pro.skel", "data/tank.atlas", 1.0f);
|
||||
// SpineExtension::setInstance(&dbgExtension);
|
||||
testcase(test, "data/tank-pro.json", "data/tank-pro.skel", "data/tank.atlas", 1.0f);
|
||||
testcase(coin, "data/coin-pro.json", "data/coin-pro.skel", "data/coin.atlas", 0.5f);
|
||||
testcase(spineboy, "data/spineboy-ess.json", "data/spineboy-ess.skel", "data/spineboy.atlas", 0.6f);
|
||||
testcase(owl, "data/owl-pro.json", "data/owl-pro.skel", "data/owl.atlas", 0.5f);
|
||||
testcase(coin, "data/coin-pro.json", "data/coin-pro.skel", "data/coin.atlas", 0.5f);
|
||||
testcase(vine, "data/vine-pro.json", "data/vine-pro.skel", "data/vine.atlas", 0.5f);
|
||||
testcase(tank, "data/tank-pro.json", "data/tank-pro.skel", "data/tank.atlas", 0.2f);
|
||||
testcase(raptor, "data/raptor-pro.json", "data/raptor-pro.skel", "data/raptor.atlas", 0.5f);
|
||||
testcase(goblins, "data/goblins-pro.json", "data/goblins-pro.skel", "data/goblins.atlas", 1.4f);*/
|
||||
testcase(goblins, "data/goblins-pro.json", "data/goblins-pro.skel", "data/goblins.atlas", 1.4f);
|
||||
testcase(stretchyman, "data/stretchyman-pro.json", "data/stretchyman-pro.skel", "data/stretchyman.atlas", 0.6f);
|
||||
dbgExtension.reportLeaks();
|
||||
return 0;
|
||||
|
||||
@ -296,4 +296,8 @@ void SFMLTextureLoader::load(AtlasPage &page, const String &path) {
|
||||
void SFMLTextureLoader::unload(void *texture) {
|
||||
delete (Texture*)texture;
|
||||
}
|
||||
|
||||
String SFMLTextureLoader::toString() const {
|
||||
return String("SFMLTextureLoader");
|
||||
}
|
||||
} /* namespace spine */
|
||||
|
||||
@ -71,6 +71,8 @@ public:
|
||||
virtual void load(AtlasPage& page, const String& path);
|
||||
|
||||
virtual void unload(void* texture);
|
||||
|
||||
String toString() const;
|
||||
};
|
||||
|
||||
} /* namespace spine */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user