From f1b16789002b8e85eb929587beb74391bf4f769c Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Fri, 4 Apr 2014 17:31:21 +0800 Subject: [PATCH] Director::getMatrix returns Matrix instead of kmMat4 --- cocos/2d/CCDirector.cpp | 8 +++---- cocos/2d/CCDirector.h | 2 +- cocos/2d/CCGLProgram.cpp | 4 ++-- cocos/2d/CCNode.cpp | 4 ++-- cocos/2d/CCRenderTexture.cpp | 8 +++---- cocos/2d/CCSprite.cpp | 2 +- cocos/editor-support/cocostudio/CCSkin.cpp | 2 +- .../Classes/ActionsTest/ActionsTest.cpp | 24 +++++++++---------- .../cpp-tests/Classes/Box2DTest/Box2dTest.cpp | 4 ++-- 9 files changed, 29 insertions(+), 29 deletions(-) diff --git a/cocos/2d/CCDirector.cpp b/cocos/2d/CCDirector.cpp index f0e63e6db3..23212c398d 100644 --- a/cocos/2d/CCDirector.cpp +++ b/cocos/2d/CCDirector.cpp @@ -578,7 +578,7 @@ void Director::pushMatrix(MATRIX_STACK_TYPE type) } } -kmMat4 Director::getMatrix(MATRIX_STACK_TYPE type) +Matrix Director::getMatrix(MATRIX_STACK_TYPE type) { Matrix result; if(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW == type) @@ -607,7 +607,7 @@ kmMat4 Director::getMatrix(MATRIX_STACK_TYPE type) // { // CCASSERT(false, "Error in director matrix stack"); // } - return matrixToKmMat4(result); + return result; } void Director::setProjection(Projection projection) @@ -739,7 +739,7 @@ static void GLToClipTransform(kmMat4 *transformOut) CCASSERT(nullptr != director, "Director is null when seting matrix stack"); kmMat4 projection; - projection = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); + projection = matrixToKmMat4(director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION)); #if CC_TARGET_PLATFORM == CC_PLATFORM_WP8 //if needed, we need to undo the rotation for Landscape orientation in order to get the correct positions @@ -747,7 +747,7 @@ static void GLToClipTransform(kmMat4 *transformOut) #endif kmMat4 modelview; - modelview = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + modelview = matrixToKmMat4(director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW)); kmMat4Multiply(transformOut, &projection, &modelview); } diff --git a/cocos/2d/CCDirector.h b/cocos/2d/CCDirector.h index cb546de6e3..4425f486f7 100644 --- a/cocos/2d/CCDirector.h +++ b/cocos/2d/CCDirector.h @@ -111,7 +111,7 @@ public: void loadIdentityMatrix(MATRIX_STACK_TYPE type); void loadMatrix(MATRIX_STACK_TYPE type, const kmMat4& mat); void multiplyMatrix(MATRIX_STACK_TYPE type, const kmMat4& mat); - kmMat4 getMatrix(MATRIX_STACK_TYPE type); + Matrix getMatrix(MATRIX_STACK_TYPE type); void resetMatrixStack(); public: static const char *EVENT_PROJECTION_CHANGED; diff --git a/cocos/2d/CCGLProgram.cpp b/cocos/2d/CCGLProgram.cpp index f65b14ec16..cec848e28f 100644 --- a/cocos/2d/CCGLProgram.cpp +++ b/cocos/2d/CCGLProgram.cpp @@ -633,14 +633,14 @@ void GLProgram::setUniformsForBuiltins() CCASSERT(nullptr != director, "Director is null when seting matrix stack"); kmMat4 matrixMV; - matrixMV = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + matrixMV = matrixToKmMat4(director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW)); setUniformsForBuiltins(matrixMV); } void GLProgram::setUniformsForBuiltins(const kmMat4 &matrixMV) { - kmMat4 matrixP = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); + kmMat4 matrixP = matrixToKmMat4(Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION)); if(_flags.usesP) setUniformLocationWithMatrix4fv(_uniforms[UNIFORM_P_MATRIX], matrixP.mat, 1); diff --git a/cocos/2d/CCNode.cpp b/cocos/2d/CCNode.cpp index 2370ebd305..c658ecfd1e 100644 --- a/cocos/2d/CCNode.cpp +++ b/cocos/2d/CCNode.cpp @@ -933,8 +933,8 @@ void Node::draw(Renderer* renderer, const kmMat4 &transform, bool transformUpdat void Node::visit() { auto renderer = Director::getInstance()->getRenderer(); - kmMat4 parentTransform = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); - visit(renderer, parentTransform, true); + Matrix parentTransform = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + visit(renderer, matrixToKmMat4(parentTransform), true); } void Node::visit(Renderer* renderer, const kmMat4 &parentTransform, bool parentTransformUpdated) diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index 96dd498fcc..c76e9afb93 100644 --- a/cocos/2d/CCRenderTexture.cpp +++ b/cocos/2d/CCRenderTexture.cpp @@ -524,10 +524,10 @@ void RenderTexture::onBegin() // Director *director = Director::getInstance(); Size size = director->getWinSizeInPixels(); - _oldProjMatrix = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); + _oldProjMatrix = matrixToKmMat4(director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION)); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, _projectionMatrix); - _oldTransMatrix = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + _oldTransMatrix = matrixToKmMat4(director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW)); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _transformMatrix); if(!_keepMatrix) @@ -678,10 +678,10 @@ void RenderTexture::begin() CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); - _projectionMatrix = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); + _projectionMatrix = matrixToKmMat4(director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION)); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); - _transformMatrix = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + _transformMatrix = matrixToKmMat4(director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW)); if(!_keepMatrix) { diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index 2afaf6d30d..790ed6cefb 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -610,7 +610,7 @@ void Sprite::drawDebugData() Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); kmMat4 oldModelView; - oldModelView = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + oldModelView = matrixToKmMat4(director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW)); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); // draw bounding box Point vertices[4] = { diff --git a/cocos/editor-support/cocostudio/CCSkin.cpp b/cocos/editor-support/cocostudio/CCSkin.cpp index e35be6bb8f..774ede9715 100644 --- a/cocos/editor-support/cocostudio/CCSkin.cpp +++ b/cocos/editor-support/cocostudio/CCSkin.cpp @@ -221,7 +221,7 @@ kmMat4 Skin::getNodeToWorldTransformAR() const void Skin::draw(Renderer *renderer, const kmMat4 &transform, bool transformUpdated) { - kmMat4 mv = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + kmMat4 mv = matrixToKmMat4(Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW)); //TODO implement z order _quadCommand.init(_globalZOrder, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, mv); diff --git a/tests/cpp-tests/Classes/ActionsTest/ActionsTest.cpp b/tests/cpp-tests/Classes/ActionsTest/ActionsTest.cpp index 0568013de3..5261f8af68 100644 --- a/tests/cpp-tests/Classes/ActionsTest/ActionsTest.cpp +++ b/tests/cpp-tests/Classes/ActionsTest/ActionsTest.cpp @@ -1678,9 +1678,9 @@ void ActionCatmullRomStacked::draw(Renderer *renderer, const kmMat4 &transform, kmMat4Translation(&translation,50,50,0); director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation); - _modelViewMV1 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + _modelViewMV1 = matrixToKmMat4(director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW)); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); - _modelViewMV2 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + _modelViewMV2 = matrixToKmMat4(director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW)); _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(ActionCatmullRomStacked::onDraw, this, transform, transformUpdated); @@ -1693,7 +1693,7 @@ void ActionCatmullRomStacked::onDraw(const kmMat4 &transform, bool transformUpda CCASSERT(nullptr != director, "Director is null when seting matrix stack"); kmMat4 oldMat; - oldMat = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + oldMat = matrixToKmMat4(director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW)); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV1); DrawPrimitives::drawCatmullRom(_array1,50); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV2); @@ -1798,7 +1798,7 @@ void ActionCardinalSplineStacked::draw(Renderer *renderer, const kmMat4 &transfo kmMat4Translation(&translation,50,50,0); director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation); - _modelViewMV1 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + _modelViewMV1 = matrixToKmMat4(director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW)); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); auto s = Director::getInstance()->getWinSize(); @@ -1809,7 +1809,7 @@ void ActionCardinalSplineStacked::draw(Renderer *renderer, const kmMat4 &transfo kmMat4Translation(&translation,s.width/2,50,0); director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation); - _modelViewMV2 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + _modelViewMV2 = matrixToKmMat4(director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW)); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); _customCommand.init(_globalZOrder); @@ -1823,7 +1823,7 @@ void ActionCardinalSplineStacked::onDraw(const kmMat4 &transform, bool transform CCASSERT(nullptr != director, "Director is null when seting matrix stack"); kmMat4 oldMat; - oldMat = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + oldMat = matrixToKmMat4(director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW)); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV1); DrawPrimitives::drawCardinalSpline(_array, 0, 100); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV2); @@ -2179,10 +2179,10 @@ void ActionCatmullRom::draw(Renderer *renderer, const kmMat4 &transform, bool tr //Create a rotation matrix using the axis and the angle kmMat4Translation(&translation,50,50,0); director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation); - _modelViewMV1 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + _modelViewMV1 = matrixToKmMat4(director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW)); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); - _modelViewMV2 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + _modelViewMV2 = matrixToKmMat4(director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW)); _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(ActionCatmullRom::onDraw, this, transform, transformUpdated); @@ -2196,7 +2196,7 @@ void ActionCatmullRom::onDraw(const kmMat4 &transform, bool transformUpdated) CCASSERT(nullptr != director, "Director is null when seting matrix stack"); kmMat4 oldMat; - oldMat = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + oldMat = matrixToKmMat4(director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW)); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV1); DrawPrimitives::drawCatmullRom(_array1, 50); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV2); @@ -2284,7 +2284,7 @@ void ActionCardinalSpline::draw(Renderer *renderer, const kmMat4 &transform, boo //Create a rotation matrix using the axis and the angle kmMat4Translation(&translation,50,50,0); director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation); - _modelViewMV1 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + _modelViewMV1 = matrixToKmMat4(director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW)); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); auto s = Director::getInstance()->getWinSize(); @@ -2294,7 +2294,7 @@ void ActionCardinalSpline::draw(Renderer *renderer, const kmMat4 &transform, boo //Create a rotation matrix using the axis and the angle kmMat4Translation(&translation,s.width/2,50,0); director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation); - _modelViewMV2 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + _modelViewMV2 = matrixToKmMat4(director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW)); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); _customCommand.init(_globalZOrder); @@ -2308,7 +2308,7 @@ void ActionCardinalSpline::onDraw(const kmMat4 &transform, bool transformUpdated CCASSERT(nullptr != director, "Director is null when seting matrix stack"); kmMat4 oldMat; - oldMat = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + oldMat = matrixToKmMat4(director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW)); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV1); DrawPrimitives::drawCardinalSpline(_array, 0, 100); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV2); diff --git a/tests/cpp-tests/Classes/Box2DTest/Box2dTest.cpp b/tests/cpp-tests/Classes/Box2DTest/Box2dTest.cpp index 6e5b5be236..fa219162e8 100644 --- a/tests/cpp-tests/Classes/Box2DTest/Box2dTest.cpp +++ b/tests/cpp-tests/Classes/Box2DTest/Box2dTest.cpp @@ -152,7 +152,7 @@ void Box2DTestLayer::draw(Renderer *renderer, const kmMat4 &transform, bool tran CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); - _modelViewMV = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + _modelViewMV = matrixToKmMat4(director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW)); _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(Box2DTestLayer::onDraw, this); @@ -169,7 +169,7 @@ void Box2DTestLayer::onDraw() CCASSERT(nullptr != director, "Director is null when seting matrix stack"); kmMat4 oldMV; - oldMV = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + oldMV = matrixToKmMat4(director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW)); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV); world->DrawDebugData(); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, oldMV);