初始化

This commit is contained in:
SmallMain
2022-06-25 00:23:03 +08:00
commit ef0589e8e5
2264 changed files with 617829 additions and 0 deletions

View File

@@ -0,0 +1,80 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2012-2018 DragonBones team and other contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef DRAGONBONES_COLOR_TRANSFORM_H
#define DRAGONBONES_COLOR_TRANSFORM_H
#include "../core/DragonBones.h"
DRAGONBONES_NAMESPACE_BEGIN
/**
* @internal
*/
class ColorTransform
{
public:
float alphaMultiplier;
float redMultiplier;
float greenMultiplier;
float blueMultiplier;
int alphaOffset;
int redOffset;
int greenOffset;
int blueOffset;
ColorTransform():
alphaMultiplier(1.0f),
redMultiplier(1.0f),
greenMultiplier(1.0f),
blueMultiplier(1.0f),
alphaOffset(0),
redOffset(0),
greenOffset(0),
blueOffset(0)
{}
ColorTransform(const ColorTransform &value)
{
operator=(value);
}
~ColorTransform() {}
inline void operator=(const ColorTransform &value)
{
alphaMultiplier = value.alphaMultiplier;
redMultiplier = value.redMultiplier;
greenMultiplier = value.greenMultiplier;
blueMultiplier = value.blueMultiplier;
alphaOffset = value.alphaOffset;
redOffset = value.redOffset;
greenOffset = value.greenOffset;
blueOffset = value.blueOffset;
}
inline void identity()
{
alphaMultiplier = redMultiplier = greenMultiplier = blueMultiplier = 1.0f;
alphaOffset = redOffset = greenOffset = blueOffset = 0;
}
};
DRAGONBONES_NAMESPACE_END
#endif // DRAGONBONES_COLOR_TRANSFORM_H

View File

@@ -0,0 +1,317 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2012-2018 DragonBones team and other contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef DRAGONBONES_MATRIX_H
#define DRAGONBONES_MATRIX_H
#include "../core/DragonBones.h"
#include "Point.h"
#include "Rectangle.h"
DRAGONBONES_NAMESPACE_BEGIN
/**
* - 2D Transform matrix.
* @version DragonBones 3.0
* @language en_US
*/
/**
* - 2D 转换矩阵。
* @version DragonBones 3.0
* @language zh_CN
*/
class Matrix
{
public:
/**
* - The value that affects the positioning of pixels along the x axis when scaling or rotating an image.
* @default 1.0
* @version DragonBones 3.0
* @language en_US
*/
/**
* - 缩放或旋转图像时影响像素沿 x 轴定位的值。
* @default 1.0
* @version DragonBones 3.0
* @language zh_CN
*/
float a;
/**
* - The value that affects the positioning of pixels along the y axis when rotating or skewing an image.
* @default 0.0
* @version DragonBones 3.0
* @language en_US
*/
/**
* - 旋转或倾斜图像时影响像素沿 y 轴定位的值。
* @default 0.0
* @version DragonBones 3.0
* @language zh_CN
*/
float b;
/**
* - The value that affects the positioning of pixels along the x axis when rotating or skewing an image.
* @default 0.0
* @version DragonBones 3.0
* @language en_US
*/
/**
* - 旋转或倾斜图像时影响像素沿 x 轴定位的值。
* @default 0.0
* @version DragonBones 3.0
* @language zh_CN
*/
float c;
/**
* - The value that affects the positioning of pixels along the y axis when scaling or rotating an image.
* @default 1.0
* @version DragonBones 3.0
* @language en_US
*/
/**
* - 缩放或旋转图像时影响像素沿 y 轴定位的值。
* @default 1.0
* @version DragonBones 3.0
* @language zh_CN
*/
float d;
/**
* - The distance by which to translate each point along the x axis.
* @default 0.0
* @version DragonBones 3.0
* @language en_US
*/
/**
* - 沿 x 轴平移每个点的距离。
* @default 0.0
* @version DragonBones 3.0
* @language zh_CN
*/
float tx;
/**
* - The distance by which to translate each point along the y axis.
* @default 0.0
* @version DragonBones 3.0
* @language en_US
*/
/**
* - 沿 y 轴平移每个点的距离。
* @default 0.0
* @version DragonBones 3.0
* @language zh_CN
*/
float ty;
Matrix():
a(1.0f),
b(0.0f),
c(0.0f),
d(1.0f),
tx(0.0f),
ty(0.0f)
{}
/**
* @private
*/
Matrix(const Matrix& value)
{
operator=(value);
}
~Matrix() {}
inline void operator=(const Matrix& value)
{
a = value.a;
b = value.b;
c = value.c;
d = value.d;
tx = value.tx;
ty = value.ty;
}
/**
* - Convert to unit matrix.
* The resulting matrix has the following properties: a=1, b=0, c=0, d=1, tx=0, ty=0.
* @version DragonBones 3.0
* @language en_US
*/
/**
* - 转换为单位矩阵。
* 该矩阵具有以下属性a=1、b=0、c=0、d=1、tx=0、ty=0。
* @version DragonBones 3.0
* @language zh_CN
*/
inline void identity()
{
a = d = 1.0f;
b = c = 0.0f;
tx = ty = 0.0f;
}
/**
* - Multiplies the current matrix with another matrix.
* @param value - The matrix that needs to be multiplied.
* @version DragonBones 3.0
* @language en_US
*/
/**
* - 将当前矩阵与另一个矩阵相乘。
* @param value - 需要相乘的矩阵。
* @version DragonBones 3.0
* @language zh_CN
*/
inline void concat(const Matrix& value)
{
const auto aA = a;
const auto bA = b;
const auto cA = c;
const auto dA = d;
const auto txA = tx;
const auto tyA = ty;
const auto aB = value.a;
const auto bB = value.b;
const auto cB = value.c;
const auto dB = value.d;
const auto txB = value.tx;
const auto tyB = value.ty;
a = aA * aB + bA * cB;
b = aA * bB + bA * dB;
c = cA * aB + dA * cB;
d = cA * bB + dA * dB;
tx = aB * txA + cB * tyA + txB;
ty = dB * tyA + bB * txA + tyB;
}
/**
* - Convert to inverse matrix.
* @version DragonBones 3.0
* @language en_US
*/
/**
* - 转换为逆矩阵。
* @version DragonBones 3.0
* @language zh_CN
*/
inline void invert()
{
const auto aA = a;
const auto bA = b;
const auto cA = c;
const auto dA = d;
const auto txA = tx;
const auto tyA = ty;
const auto n = aA * dA - bA * cA;
a = dA / n;
b = -bA / n;
c = -cA / n;
d = aA / n;
tx = (cA * tyA - dA * txA) / n;
ty = -(aA * tyA - bA * txA) / n;
}
/**
* - Apply a matrix transformation to a specific point.
* @param x - X coordinate.
* @param y - Y coordinate.
* @param result - The point after the transformation is applied.
* @param delta - Whether to ignore tx, ty's conversion to point.
* @version DragonBones 3.0
* @language en_US
*/
/**
* - 将矩阵转换应用于特定点。
* @param x - 横坐标。
* @param y - 纵坐标。
* @param result - 应用转换之后的点。
* @param delta - 是否忽略 txty 对点的转换。
* @version DragonBones 3.0
* @language zh_CN
*/
inline void transformPoint(float x, float y, Point& result, bool delta = false) const
{
result.x = a * x + c * y;
result.y = b * x + d * y;
if (!delta)
{
result.x += tx;
result.y += ty;
}
}
/**
* @private
*/
inline void transformRectangle(Rectangle& rectangle, bool delta = false) const
{
const auto offsetX = delta ? 0.0f : this->tx;
const auto offsetY = delta ? 0.0f : this->ty;
const auto x = rectangle.x;
const auto y = rectangle.y;
const auto xMax = x + rectangle.width;
const auto yMax = y + rectangle.height;
auto x0 = a * x + c * y + offsetX;
auto y0 = b * x + d * y + offsetY;
auto x1 = a * xMax + c * y + offsetX;
auto y1 = b * xMax + d * y + offsetY;
auto x2 = a * xMax + c * yMax + offsetX;
auto y2 = b * xMax + d * yMax + offsetY;
auto x3 = a * x + c * yMax + offsetX;
auto y3 = b * x + d * yMax + offsetY;
auto tmp = 0.0f;
if (x0 > x1)
{
tmp = x0;
x0 = x1;
x1 = tmp;
}
if (x2 > x3)
{
tmp = x2;
x2 = x3;
x3 = tmp;
}
rectangle.x = std::floor(x0 < x2 ? x0 : x2);
rectangle.width = std::ceil((x1 > x3 ? x1 : x3) - rectangle.x);
if (y0 > y1)
{
tmp = y0;
y0 = y1;
y1 = tmp;
}
if (y2 > y3)
{
tmp = y2;
y2 = y3;
y3 = tmp;
}
rectangle.y = std::floor(y0 < y2 ? y0 : y2);
rectangle.height = std::ceil((y1 > y3 ? y1 : y3) - rectangle.y);
}
};
DRAGONBONES_NAMESPACE_END
#endif // DRAGONBONES_MATRIX_H

View File

@@ -0,0 +1,10 @@
#include "Point.h"
DRAGONBONES_NAMESPACE_BEGIN
Point Point::helpPointA;
Point Point::helpPointB;
Point Point::helpPointC;
Point Point::helpPointD;
DRAGONBONES_NAMESPACE_END

View File

@@ -0,0 +1,121 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2012-2018 DragonBones team and other contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef DRAGONBONES_POINT_H
#define DRAGONBONES_POINT_H
#include "../core/DragonBones.h"
DRAGONBONES_NAMESPACE_BEGIN
/**
* - The Point object represents a location in a two-dimensional coordinate system.
* @version DragonBones 3.0
* @language en_US
*/
/**
* - Point 对象表示二维坐标系统中的某个位置。
* @version DragonBones 3.0
* @language zh_CN
*/
class Point
{
public:
static Point helpPointA;
static Point helpPointB;
static Point helpPointC;
static Point helpPointD;
public:
/**
* - The horizontal coordinate.
* @default 0.0
* @version DragonBones 3.0
* @language en_US
*/
/**
* - 该点的水平坐标。
* @default 0.0
* @version DragonBones 3.0
* @language zh_CN
*/
float x;
/**
* - The vertical coordinate.
* @default 0.0
* @version DragonBones 3.0
* @language en_US
*/
/**
* - 该点的垂直坐标。
* @default 0.0
* @version DragonBones 3.0
* @language zh_CN
*/
float y;
Point():
x(0.0f),
y(0.0f)
{}
/**
* - Creates a new point. If you pass no parameters to this method, a point is created at (0,0).
* @param x - The horizontal coordinate.
* @param y - The vertical coordinate.
* @version DragonBones 3.0
* @language en_US
*/
/**
* - 创建一个 egret.Point 对象.若不传入任何参数将会创建一个位于00位置的点。
* @param x - 该对象的x属性值默认为 0.0。
* @param y - 该对象的y属性值默认为 0.0。
* @version DragonBones 3.0
* @language zh_CN
*/
Point(const Point& value)
{
operator=(value);
}
~Point() {}
inline void operator=(const Point& value)
{
x = value.x;
y = value.y;
}
/**
* @private
*/
inline void clear()
{
x = y = 0.0f;
}
public: // For WebAssembly.
static Point* getHelpPointA() { return &helpPointA; }
static Point* getHelpPointB() { return &helpPointB; }
static Point* getHelpPointC() { return &helpPointC; }
static Point* getHelpPointD() { return &helpPointD; }
};
DRAGONBONES_NAMESPACE_END
#endif // DRAGONBONES_POINT_H

View File

@@ -0,0 +1,137 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2012-2018 DragonBones team and other contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef DRAGONBONES_RECTANGLE_H
#define DRAGONBONES_RECTANGLE_H
#include "../core/DragonBones.h"
DRAGONBONES_NAMESPACE_BEGIN
/**
* - A Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its
* width and its height.<br/>
* The x, y, width, and height properties of the Rectangle class are independent of each other; changing the value of
* one property has no effect on the others. However, the right and bottom properties are integrally related to those
* four properties. For example, if you change the value of the right property, the value of the width property changes;
* if you change the bottom property, the value of the height property changes.
* @version DragonBones 3.0
* @language en_US
*/
/**
* - Rectangle 对象是按其位置(由它左上角的点 (x, y) 确定)以及宽度和高度定义的区域。<br/>
* Rectangle 类的 x、y、width 和 height 属性相互独立;更改一个属性的值不会影响其他属性。
* 但是right 和 bottom 属性与这四个属性是整体相关的。例如,如果更改 right 属性的值,则 width
* 属性的值将发生变化;如果更改 bottom 属性,则 height 属性的值将发生变化。
* @version DragonBones 3.0
* @language zh_CN
*/
class Rectangle
{
public:
/**
* - The x coordinate of the top-left corner of the rectangle.
* @default 0.0
* @version DragonBones 3.0
* @language en_US
*/
/**
* - 矩形左上角的 x 坐标。
* @default 0.0
* @version DragonBones 3.0
* @language zh_CN
*/
float x;
/**
* - The y coordinate of the top-left corner of the rectangle.
* @default 0.0
* @version DragonBones 3.0
* @language en_US
*/
/**
* - 矩形左上角的 y 坐标。
* @default 0.0
* @version DragonBones 3.0
* @language zh_CN
*/
float y;
/**
* - The width of the rectangle, in pixels.
* @default 0.0
* @version DragonBones 3.0
* @language en_US
*/
/**
* - 矩形的宽度(以像素为单位)。
* @default 0.0
* @version DragonBones 3.0
* @language zh_CN
*/
float width;
/**
* - 矩形的高度(以像素为单位)。
* @default 0.0
* @version DragonBones 3.0
* @language en_US
*/
/**
* - The height of the rectangle, in pixels.
* @default 0.0
* @version DragonBones 3.0
* @language zh_CN
*/
float height;
Rectangle():
x(0.0f),
y(0.0f),
width(0.0f),
height(0.0f)
{}
/**
* @private
*/
Rectangle(const Rectangle& value)
{
operator=(value);
}
~Rectangle() {}
inline void operator=(const Rectangle& value)
{
x = value.x;
y = value.y;
width = value.width;
height = value.height;
}
/**
* @private
*/
void clear()
{
x = y = 0.0f;
width = height = 0.0f;
}
};
DRAGONBONES_NAMESPACE_END
#endif // DRAGONBONES_RECTANGLE_H

View File

@@ -0,0 +1,13 @@
#include "Transform.h"
DRAGONBONES_NAMESPACE_BEGIN
const float Transform::PI = 3.14159265358979323846f;
const float Transform::PI_D = PI * 2.0f;
const float Transform::PI_H = PI * 0.5f;
const float Transform::PI_Q = PI * 0.25f;
const float Transform::DEG_RAD = PI / 180.f;
const float Transform::RAD_DEG = 180.f / PI;
DRAGONBONES_NAMESPACE_END

View File

@@ -0,0 +1,289 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2012-2018 DragonBones team and other contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef DRAGONBONES_TRANSFORM_H
#define DRAGONBONES_TRANSFORM_H
#include "../core/DragonBones.h"
#include "Matrix.h"
DRAGONBONES_NAMESPACE_BEGIN
/**
* - 2D Transform.
* @version DragonBones 3.0
* @language en_US
*/
/**
* - 2D 变换。
* @version DragonBones 3.0
* @language zh_CN
*/
class Transform final
{
public:
/**
* @private
*/
static const float PI;
/**
* @private
*/
static const float PI_D;
/**
* @private
*/
static const float PI_H;
/**
* @private
*/
static const float PI_Q;
/**
* @private
*/
static const float DEG_RAD;
/**
* @private
*/
static const float RAD_DEG;
/**
* @private
*/
static float normalizeRadian(float value)
{
value = fmod(value + Transform::PI, Transform::PI * 2.0f);
value += value > 0.0f ? -Transform::PI : Transform::PI;
return value;
}
public:
/**
* - Horizontal translate.
* @version DragonBones 3.0
* @language en_US
*/
/**
* - 水平位移。
* @version DragonBones 3.0
* @language zh_CN
*/
float x;
/**
* - Vertical translate.
* @version DragonBones 3.0
* @language en_US
*/
/**
* - 垂直位移。
* @version DragonBones 3.0
* @language zh_CN
*/
float y;
/**
* - Skew. (In radians)
* @version DragonBones 3.0
* @language en_US
*/
/**
* - 倾斜。 (以弧度为单位)
* @version DragonBones 3.0
* @language zh_CN
*/
float skew;
/**
* - rotation. (In radians)
* @version DragonBones 3.0
* @language en_US
*/
/**
* - 旋转。 (以弧度为单位)
* @version DragonBones 3.0
* @language zh_CN
*/
float rotation;
/**
* - Horizontal Scaling.
* @version DragonBones 3.0
* @language en_US
*/
/**
* - 水平缩放。
* @version DragonBones 3.0
* @language zh_CN
*/
float scaleX;
/**
* - Vertical scaling.
* @version DragonBones 3.0
* @language en_US
*/
/**
* - 垂直缩放。
* @version DragonBones 3.0
* @language zh_CN
*/
float scaleY;
Transform():
x(0.0f),
y(0.0f),
skew(0.0f),
rotation(0.0f),
scaleX(1.0f),
scaleY(1.0f)
{}
/**
* @private
*/
Transform(const Transform& value)
{
operator=(value);
}
~Transform() {}
inline void operator=(const Transform& value)
{
x = value.x;
y = value.y;
skew = value.skew;
rotation = value.rotation;
scaleX = value.scaleX;
scaleY = value.scaleY;
}
/**
* @private
*/
inline Transform& identity()
{
x = y = skew = rotation = 0.0f;
scaleX = scaleY = 1.0f;
return *this;
}
/**
* @private
*/
inline Transform& add(const Transform& value)
{
x += value.x;
y += value.y;
skew += value.skew;
rotation += value.rotation;
scaleX *= value.scaleX;
scaleY *= value.scaleY;
return *this;
}
/**
* @private
*/
inline Transform& minus(const Transform& value)
{
x -= value.x;
y -= value.y;
skew -= value.skew;
rotation -= value.rotation;
scaleX /= value.scaleX;
scaleY /= value.scaleY;
return *this;
}
/**
* @private
*/
inline Transform& fromMatrix(const Matrix& matrix)
{
const auto backupScaleX = scaleX, backupScaleY = scaleY;
x = matrix.tx;
y = matrix.ty;
rotation = std::atan(matrix.b / matrix.a);
auto skewX = std::atan(-matrix.c / matrix.d);
scaleX = (rotation > -PI_Q && rotation < PI_Q) ? matrix.a / std::cos(rotation) : matrix.b / std::sin(rotation);
scaleY = (skewX > -PI_Q && skewX < PI_Q) ? matrix.d / std::cos(skewX) : -matrix.c / std::sin(skewX);
if (backupScaleX >= 0.0f && scaleX < 0.0f)
{
scaleX = -scaleX;
rotation = rotation - PI;
}
if (backupScaleY >= 0.0f && scaleY < 0.0f)
{
scaleY = -scaleY;
skewX = skewX - PI;
}
skew = skewX - rotation;
return *this;
}
/**
* @private
*/
inline Transform& toMatrix(Matrix& matrix)
{
if (rotation == 0.0f)
{
matrix.a = 1.0f;
matrix.b = 0.0f;
}
else
{
matrix.a = std::cos(rotation);
matrix.b = std::sin(rotation);
}
if (skew == 0.0f)
{
matrix.c = -matrix.b;
matrix.d = matrix.a;
}
else {
matrix.c = -std::sin(skew + rotation);
matrix.d = std::cos(skew + rotation);
}
if (scaleX != 1.0f)
{
matrix.a *= scaleX;
matrix.b *= scaleX;
}
if (scaleY != 1.0f)
{
matrix.c *= scaleY;
matrix.d *= scaleY;
}
matrix.tx = x;
matrix.ty = y;
return *this;
}
};
DRAGONBONES_NAMESPACE_END
#endif // DRAGONBONES_TRANSFORM_H