diff --git a/cocos/editor-support/cocostudio/CCBone.cpp b/cocos/editor-support/cocostudio/CCBone.cpp index 3e6524e22b..d7b06e2617 100644 --- a/cocos/editor-support/cocostudio/CCBone.cpp +++ b/cocos/editor-support/cocostudio/CCBone.cpp @@ -72,7 +72,7 @@ Bone::Bone() _displayManager = nullptr; _ignoreMovementBoneData = false; // _worldTransform = AffineTransformMake(1, 0, 0, 1, 0, 0); - kmMat4Identity(&_worldTransform); + _worldTransform = Matrix::identity(); _boneTransformDirty = true; _blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED; _blendDirty = false; @@ -238,8 +238,8 @@ void Bone::applyParentTransform(Bone *parent) { float x = _worldInfo->x; float y = _worldInfo->y; - _worldInfo->x = x * parent->_worldTransform.mat[0] + y * parent->_worldTransform.mat[4] + parent->_worldInfo->x; - _worldInfo->y = x * parent->_worldTransform.mat[1] + y * parent->_worldTransform.mat[5] + parent->_worldInfo->y; + _worldInfo->x = x * parent->_worldTransform.m[0] + y * parent->_worldTransform.m[4] + parent->_worldInfo->x; + _worldInfo->y = x * parent->_worldTransform.m[1] + y * parent->_worldTransform.m[5] + parent->_worldInfo->y; _worldInfo->scaleX = _worldInfo->scaleX * parent->_worldInfo->scaleX; _worldInfo->scaleY = _worldInfo->scaleY * parent->_worldInfo->scaleY; _worldInfo->skewX = _worldInfo->skewX + parent->_worldInfo->skewX; @@ -380,7 +380,7 @@ void Bone::setLocalZOrder(int zOrder) Node::setLocalZOrder(zOrder); } -kmMat4 Bone::getNodeToArmatureTransform() const +Matrix Bone::getNodeToArmatureTransform() const { return _worldTransform; } diff --git a/cocos/editor-support/cocostudio/CCBone.h b/cocos/editor-support/cocostudio/CCBone.h index d4cf673b3f..24de7068f5 100644 --- a/cocos/editor-support/cocostudio/CCBone.h +++ b/cocos/editor-support/cocostudio/CCBone.h @@ -156,7 +156,7 @@ public: virtual void setTransformDirty(bool dirty) { _boneTransformDirty = dirty; } virtual bool isTransformDirty() { return _boneTransformDirty; } - virtual kmMat4 getNodeToArmatureTransform() const; + virtual Matrix getNodeToArmatureTransform() const; virtual Matrix getNodeToWorldTransform() const override; Node *getDisplayRenderNode(); @@ -250,7 +250,7 @@ protected: bool _boneTransformDirty; //! Whether or not transform dirty //! self Transform, use this to change display's state - kmMat4 _worldTransform; + Matrix _worldTransform; BaseData *_worldInfo; diff --git a/cocos/editor-support/cocostudio/CCColliderDetector.cpp b/cocos/editor-support/cocostudio/CCColliderDetector.cpp index 838b2a97be..33d8cee9ad 100644 --- a/cocos/editor-support/cocostudio/CCColliderDetector.cpp +++ b/cocos/editor-support/cocostudio/CCColliderDetector.cpp @@ -334,7 +334,7 @@ ColliderFilter *ColliderDetector::getColliderFilter() Point helpPoint; -void ColliderDetector::updateTransform(kmMat4 &t) +void ColliderDetector::updateTransform(Matrix &t) { if (!_active) { diff --git a/cocos/editor-support/cocostudio/CCColliderDetector.h b/cocos/editor-support/cocostudio/CCColliderDetector.h index 8c4335c741..2b32a4ea44 100644 --- a/cocos/editor-support/cocostudio/CCColliderDetector.h +++ b/cocos/editor-support/cocostudio/CCColliderDetector.h @@ -42,6 +42,8 @@ THE SOFTWARE. namespace cocostudio { +USING_NS_CC_MATH; + class Bone; /** @@ -155,7 +157,7 @@ public: void removeContourData(ContourData *contourData); void removeAll(); - void updateTransform(kmMat4 &t); + void updateTransform(Matrix &t); void setActive(bool active); bool getActive(); diff --git a/cocos/editor-support/cocostudio/CCDisplayFactory.cpp b/cocos/editor-support/cocostudio/CCDisplayFactory.cpp index d4fa0aabec..fc422981c2 100644 --- a/cocos/editor-support/cocostudio/CCDisplayFactory.cpp +++ b/cocos/editor-support/cocostudio/CCDisplayFactory.cpp @@ -118,7 +118,7 @@ void DisplayFactory::updateDisplay(Bone *bone, float dt, bool dirty) anchorPoint = PointApplyTransform(anchorPoint, displayTransform); displayTransform.mat[12] = anchorPoint.x; displayTransform.mat[13] = anchorPoint.y; - kmMat4 t = TransformConcat( bone->getArmature()->getNodeToParentTransform(),displayTransform); + Matrix t = TransformConcat( bone->getArmature()->getNodeToParentTransform(),displayTransform); detector->updateTransform(t); } while (0); diff --git a/cocos/editor-support/cocostudio/CCSkin.cpp b/cocos/editor-support/cocostudio/CCSkin.cpp index ca32d48f4b..ee803568ea 100644 --- a/cocos/editor-support/cocostudio/CCSkin.cpp +++ b/cocos/editor-support/cocostudio/CCSkin.cpp @@ -86,7 +86,7 @@ Skin::Skin() , _armature(nullptr) , _displayName("") { - kmMat4Identity(&_skinTransform); + _skinTransform = Matrix::identity(); } bool Skin::initWithSpriteFrameName(const std::string& spriteFrameName) @@ -206,7 +206,7 @@ Matrix Skin::getNodeToWorldTransform() const return TransformConcat( _bone->getArmature()->getNodeToWorldTransform(), _transform); } -kmMat4 Skin::getNodeToWorldTransformAR() const +Matrix Skin::getNodeToWorldTransformAR() const { kmMat4 displayTransform = _transform; Point anchorPoint = _anchorPointInPoints; diff --git a/cocos/editor-support/cocostudio/CCSkin.h b/cocos/editor-support/cocostudio/CCSkin.h index 2e0ec59fc6..dba784f70c 100644 --- a/cocos/editor-support/cocostudio/CCSkin.h +++ b/cocos/editor-support/cocostudio/CCSkin.h @@ -52,7 +52,7 @@ public: void updateTransform() override; Matrix getNodeToWorldTransform() const override; - kmMat4 getNodeToWorldTransformAR() const; + Matrix getNodeToWorldTransformAR() const; virtual void draw(cocos2d::Renderer *renderer, const Matrix &transform, bool transformUpdated) override; @@ -75,7 +75,7 @@ protected: BaseData _skinData; Bone *_bone; Armature *_armature; - kmMat4 _skinTransform; + Matrix _skinTransform; std::string _displayName; cocos2d::QuadCommand _quadCommand; // quad command }; diff --git a/cocos/editor-support/cocostudio/CCTransformHelp.cpp b/cocos/editor-support/cocostudio/CCTransformHelp.cpp index 6979285cff..4412cff2c2 100644 --- a/cocos/editor-support/cocostudio/CCTransformHelp.cpp +++ b/cocos/editor-support/cocostudio/CCTransformHelp.cpp @@ -118,30 +118,30 @@ void TransformHelp::nodeToMatrix(const BaseData &node, AffineTransform &matrix) matrix.ty = node.y; } -void TransformHelp::nodeToMatrix(const BaseData &node, kmMat4 &matrix) +void TransformHelp::nodeToMatrix(const BaseData &node, Matrix &matrix) { - kmMat4Identity(&matrix); + matrix = Matrix::identity(); if (node.skewX == -node.skewY) { double sine = sin(node.skewX); double cosine = cos(node.skewX); - matrix.mat[0] = node.scaleX * cosine; - matrix.mat[1] = node.scaleX * -sine; - matrix.mat[4] = node.scaleY * sine; - matrix.mat[5] = node.scaleY * cosine; + matrix.m[0] = node.scaleX * cosine; + matrix.m[1] = node.scaleX * -sine; + matrix.m[4] = node.scaleY * sine; + matrix.m[5] = node.scaleY * cosine; } else { - matrix.mat[0] = node.scaleX * cos(node.skewY); - matrix.mat[1] = node.scaleX * sin(node.skewY); - matrix.mat[4] = node.scaleY * sin(node.skewX); - matrix.mat[5] = node.scaleY * cos(node.skewX); + matrix.m[0] = node.scaleX * cos(node.skewY); + matrix.m[1] = node.scaleX * sin(node.skewY); + matrix.m[4] = node.scaleY * sin(node.skewX); + matrix.m[5] = node.scaleY * cos(node.skewX); } - matrix.mat[12] = node.x; - matrix.mat[13] = node.y; + matrix.m[12] = node.x; + matrix.m[13] = node.y; } @@ -171,7 +171,7 @@ void TransformHelp::matrixToNode(const AffineTransform &matrix, BaseData &node) node.y = matrix.ty; } -void TransformHelp::matrixToNode(const kmMat4 &matrix, BaseData &node) +void TransformHelp::matrixToNode(const Matrix &matrix, BaseData &node) { /* * In as3 language, there is a function called "deltaTransformPoint", it calculate a point used give Transform @@ -180,21 +180,21 @@ void TransformHelp::matrixToNode(const kmMat4 &matrix, BaseData &node) helpPoint1.x = 0; helpPoint1.y = 1; helpPoint1 = PointApplyTransform(helpPoint1, matrix); - helpPoint1.x -= matrix.mat[12]; - helpPoint1.y -= matrix.mat[13]; + helpPoint1.x -= matrix.m[12]; + helpPoint1.y -= matrix.m[13]; helpPoint2.x = 1; helpPoint2.y = 0; helpPoint2 = PointApplyTransform(helpPoint2, matrix); - helpPoint2.x -= matrix.mat[12]; - helpPoint2.y -= matrix.mat[13]; + helpPoint2.x -= matrix.m[12]; + helpPoint2.y -= matrix.m[13]; node.skewX = -(atan2f(helpPoint1.y, helpPoint1.x) - 1.5707964f); node.skewY = atan2f(helpPoint2.y, helpPoint2.x); - node.scaleX = sqrt(matrix.mat[0] * matrix.mat[0] + matrix.mat[1] * matrix.mat[1]); - node.scaleY = sqrt(matrix.mat[4] * matrix.mat[4] + matrix.mat[5] * matrix.mat[5]); - node.x = matrix.mat[12]; - node.y = matrix.mat[13]; + node.scaleX = sqrt(matrix.m[0] * matrix.m[0] + matrix.m[1] * matrix.m[1]); + node.scaleY = sqrt(matrix.m[4] * matrix.m[4] + matrix.m[5] * matrix.m[5]); + node.x = matrix.m[12]; + node.y = matrix.m[13]; } diff --git a/cocos/editor-support/cocostudio/CCTransformHelp.h b/cocos/editor-support/cocostudio/CCTransformHelp.h index 3dedccbebe..858888532e 100644 --- a/cocos/editor-support/cocostudio/CCTransformHelp.h +++ b/cocos/editor-support/cocostudio/CCTransformHelp.h @@ -30,6 +30,8 @@ THE SOFTWARE. namespace cocostudio { +USING_NS_CC_MATH; + /* * use to calculate the matrix of node from parent node * @js NA @@ -47,9 +49,9 @@ public: static void transformToParentWithoutScale(BaseData &node, const BaseData &parentNode); static void nodeToMatrix(const BaseData &_node, cocos2d::AffineTransform &_matrix); - static void nodeToMatrix(const BaseData &node, kmMat4 &matrix); + static void nodeToMatrix(const BaseData &node, Matrix &matrix); static void matrixToNode(const cocos2d::AffineTransform &_matrix, BaseData &_node); - static void matrixToNode(const kmMat4 &_matrix, BaseData &_node); + static void matrixToNode(const Matrix &_matrix, BaseData &_node); static void nodeConcat(BaseData &target, BaseData &source); static void nodeSub(BaseData &target, BaseData &source); diff --git a/cocos/editor-support/spine/CCSkeleton.cpp b/cocos/editor-support/spine/CCSkeleton.cpp index 5d1dcdf688..42fe236d97 100644 --- a/cocos/editor-support/spine/CCSkeleton.cpp +++ b/cocos/editor-support/spine/CCSkeleton.cpp @@ -133,7 +133,7 @@ void Skeleton::draw(cocos2d::Renderer *renderer, const Matrix &transform, bool t renderer->addCommand(&_customCommand); } -void Skeleton::onDraw(const kmMat4 &transform, bool transformUpdated) +void Skeleton::onDraw(const Matrix &transform, bool transformUpdated) { getShaderProgram()->use(); getShaderProgram()->setUniformsForBuiltins(transform); diff --git a/cocos/editor-support/spine/CCSkeleton.h b/cocos/editor-support/spine/CCSkeleton.h index ba2b0bac74..f10fd76df8 100644 --- a/cocos/editor-support/spine/CCSkeleton.h +++ b/cocos/editor-support/spine/CCSkeleton.h @@ -70,7 +70,7 @@ public: virtual void update (float deltaTime) override; virtual void draw(cocos2d::Renderer *renderer, const Matrix &transform, bool transformUpdated) override; - void onDraw(const kmMat4 &transform, bool transformUpdated); + void onDraw(const Matrix &transform, bool transformUpdated); void onEnter() override; void onExit() override; virtual cocos2d::Rect getBoundingBox () const override; diff --git a/cocos/ui/UILayout.cpp b/cocos/ui/UILayout.cpp index 66afaa03db..00dfcc4ca8 100644 --- a/cocos/ui/UILayout.cpp +++ b/cocos/ui/UILayout.cpp @@ -744,7 +744,7 @@ void Layout::sortAllChildren() doLayout(); } -void Layout::stencilClippingVisit(Renderer *renderer, const kmMat4 &parentTransform, bool parentTransformUpdated) +void Layout::stencilClippingVisit(Renderer *renderer, const Matrix &parentTransform, bool parentTransformUpdated) { if(!_visible) return; @@ -902,7 +902,7 @@ void Layout::onAfterVisitScissor() glDisable(GL_SCISSOR_TEST); } -void Layout::scissorClippingVisit(Renderer *renderer, const kmMat4& parentTransform, bool parentTransformUpdated) +void Layout::scissorClippingVisit(Renderer *renderer, const Matrix& parentTransform, bool parentTransformUpdated) { _beforeVisitCmdScissor.init(_globalZOrder); _beforeVisitCmdScissor.func = CC_CALLBACK_0(Layout::onBeforeVisitScissor, this); diff --git a/cocos/ui/UILayout.h b/cocos/ui/UILayout.h index 8df850d708..ea725fb79d 100644 --- a/cocos/ui/UILayout.h +++ b/cocos/ui/UILayout.h @@ -284,8 +284,8 @@ protected: virtual void copySpecialProperties(Widget* model) override; virtual void copyClonedWidgetChildren(Widget* model) override; - void stencilClippingVisit(Renderer *renderer, const kmMat4& parentTransform, bool parentTransformUpdated); - void scissorClippingVisit(Renderer *renderer, const kmMat4& parentTransform, bool parentTransformUpdated); + void stencilClippingVisit(Renderer *renderer, const Matrix& parentTransform, bool parentTransformUpdated); + void scissorClippingVisit(Renderer *renderer, const Matrix& parentTransform, bool parentTransformUpdated); void setStencilClippingSize(const Size& size); const Rect& getClippingRect();