diff --git a/cocos/2d/ccShader_PositionTextureColor_noMVP_vert.h b/cocos/2d/ccShader_PositionTextureColor_noMVP_vert.h index fb511ba1dd..bae95bcfea 100644 --- a/cocos/2d/ccShader_PositionTextureColor_noMVP_vert.h +++ b/cocos/2d/ccShader_PositionTextureColor_noMVP_vert.h @@ -38,7 +38,7 @@ varying vec2 v_texCoord; \n\ \n\ void main() \n\ { \n\ - gl_Position = a_position; \n\ + gl_Position = CC_PMatrix * a_position; \n\ v_fragmentColor = a_color; \n\ v_texCoord = a_texCoord; \n\ } \n\ diff --git a/cocos/2d/renderer/CCQuadCommand.cpp b/cocos/2d/renderer/CCQuadCommand.cpp index bbb7ba018c..b69fd075d3 100644 --- a/cocos/2d/renderer/CCQuadCommand.cpp +++ b/cocos/2d/renderer/CCQuadCommand.cpp @@ -58,12 +58,6 @@ void QuadCommand::init(int viewport, int32_t depth, GLuint textureID, GLProgram* _capacity = quadCount; } - kmMat4 p, mvp; - kmGLGetMatrix(KM_GL_PROJECTION, &p); - - kmMat4Multiply(&mvp, &p, &mv); - - _quadCount = quadCount; memcpy(_quad, quad, sizeof(V3F_C4B_T2F_Quad) * quadCount); @@ -74,7 +68,7 @@ void QuadCommand::init(int viewport, int32_t depth, GLuint textureID, GLProgram* vec1.x = q->bl.vertices.x; vec1.y = q->bl.vertices.y; vec1.z = q->bl.vertices.z; - kmVec3TransformCoord(&out1, &vec1, &mvp); + kmVec3Transform(&out1, &vec1, &mv); q->bl.vertices.x = out1.x; q->bl.vertices.y = out1.y; q->bl.vertices.z = out1.z; @@ -83,7 +77,7 @@ void QuadCommand::init(int viewport, int32_t depth, GLuint textureID, GLProgram* vec2.x = q->br.vertices.x; vec2.y = q->br.vertices.y; vec2.z = q->br.vertices.z; - kmVec3TransformCoord(&out2, &vec2, &mvp); + kmVec3Transform(&out2, &vec2, &mv); q->br.vertices.x = out2.x; q->br.vertices.y = out2.y; q->br.vertices.z = out2.z; @@ -92,7 +86,7 @@ void QuadCommand::init(int viewport, int32_t depth, GLuint textureID, GLProgram* vec3.x = q->tr.vertices.x; vec3.y = q->tr.vertices.y; vec3.z = q->tr.vertices.z; - kmVec3TransformCoord(&out3, &vec3, &mvp); + kmVec3Transform(&out3, &vec3, &mv); q->tr.vertices.x = out3.x; q->tr.vertices.y = out3.y; q->tr.vertices.z = out3.z; @@ -101,7 +95,7 @@ void QuadCommand::init(int viewport, int32_t depth, GLuint textureID, GLProgram* vec4.x = q->tl.vertices.x; vec4.y = q->tl.vertices.y; vec4.z = q->tl.vertices.z; - kmVec3TransformCoord(&out4, &vec4, &mvp); + kmVec3Transform(&out4, &vec4, &mv); q->tl.vertices.x = out4.x; q->tl.vertices.y = out4.y; q->tl.vertices.z = out4.z; diff --git a/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.cpp b/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.cpp index 5c2534dee0..843b72bbb6 100644 --- a/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.cpp +++ b/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.cpp @@ -25,6 +25,7 @@ static int sceneIdx = -1; static std::function createFunctions[] = { + CL(CameraTest1), CL(CameraTest2), CL(CameraCenterTest), CL(Test2), @@ -34,6 +35,7 @@ static std::function createFunctions[] = CL(StressTest1), CL(StressTest2), CL(NodeToWorld), + CL(NodeToWorld3D), CL(SchedulerTest1), CL(CameraOrbitTest), CL(CameraZoomTest), @@ -492,6 +494,56 @@ std::string NodeToWorld::title() const return "nodeToParent transform"; } +//------------------------------------------------------------------ +// +// NodeToWorld3D +// +//------------------------------------------------------------------ +NodeToWorld3D::NodeToWorld3D() +{ + // + // This code tests that nodeToParent works OK: + // - It tests different anchor Points + // - It tests different children anchor points + + Size s = Director::getInstance()->getWinSize(); + auto parent = Node::create(); + parent->setContentSize(s); + parent->setAnchorPoint(Point(0.5, 0.5)); + parent->setPosition(s.width/2, s.height/2); + this->addChild(parent); + + auto back = Sprite::create(s_back3); + parent->addChild( back, -10); + back->setAnchorPoint( Point(0,0) ); + auto backSize = back->getContentSize(); + + auto item = MenuItemImage::create(s_PlayNormal, s_PlaySelect); + auto menu = Menu::create(item, NULL); + menu->alignItemsVertically(); + menu->setPosition( Point(backSize.width/2, backSize.height/2)); + back->addChild(menu); + + auto rot = RotateBy::create(5, 360); + auto fe = RepeatForever::create( rot); + item->runAction( fe ); + + auto move = MoveBy::create(3, Point(200,0)); + auto move_back = move->reverse(); + auto seq = Sequence::create( move, move_back, NULL); + auto fe2 = RepeatForever::create(seq); + back->runAction(fe2); + + auto orbit = OrbitCamera::create(10, 0, 1, 0, 360, 0, 90); + parent->runAction(orbit); +} + +std::string NodeToWorld3D::title() const +{ + return "nodeToParent transform in 3D"; +} + + //------------------------------------------------------------------ // // CameraOrbitTest @@ -828,12 +880,10 @@ std::string NodeNonOpaqueTest::subtitle() const return "Node rendered with GL_BLEND enabled"; } -//------------------------------------------------------------------ -// -// CameraTest2 -// -//------------------------------------------------------------------ +// +// MySprite: Used by CameraTest1 and CameraTest2 +// class MySprite : public Sprite { public: @@ -852,6 +902,7 @@ public: protected: CustomCommand _customCommand; + }; void MySprite::draw() @@ -891,6 +942,58 @@ void MySprite::onDraw() CHECK_GL_ERROR_DEBUG(); CC_INCREMENT_GL_DRAWS(1); } +//------------------------------------------------------------------ +// +// CameraTest1 +// +//------------------------------------------------------------------ + +void CameraTest1::onEnter() +{ + TestCocosNodeDemo::onEnter(); + Director::getInstance()->setProjection(Director::Projection::_3D); + Director::getInstance()->setDepthTest(true); +} + +void CameraTest1::onExit() +{ + Director::getInstance()->setProjection(Director::Projection::_2D); + TestCocosNodeDemo::onExit(); +} + +CameraTest1::CameraTest1() +{ + auto s = Director::getInstance()->getWinSize(); + + _sprite1 = MySprite::create(s_back3); + addChild( _sprite1 ); + _sprite1->setPosition( Point(1*s.width/4, s.height/2) ); + _sprite1->setScale(0.5); + + _sprite2 = Sprite::create(s_back3); + addChild( _sprite2 ); + _sprite2->setPosition( Point(3*s.width/4, s.height/2) ); + _sprite2->setScale(0.5); + + auto camera = OrbitCamera::create(10, 0, 1, 0, 360, 0, 0); + _sprite1->runAction( camera ); + _sprite2->runAction( camera->clone() ); +} + +std::string CameraTest1::title() const +{ + return "Camera Test 1"; +} + +std::string CameraTest1::subtitle() const +{ + return "Both images should rotate with a 3D effect"; +} +//------------------------------------------------------------------ +// +// CameraTest2 +// +//------------------------------------------------------------------ void CameraTest2::onEnter() { TestCocosNodeDemo::onEnter(); @@ -928,7 +1031,7 @@ std::string CameraTest2::title() const std::string CameraTest2::subtitle() const { - return "Background image should be rotated in 3D"; + return "Both images should look the same"; } void CameraTest2::update(float dt) @@ -948,6 +1051,7 @@ void CameraTest2::update(float dt) } /// +/// main /// void CocosNodeTestScene::runThisTest() { diff --git a/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.h b/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.h index 50959ced5a..7a6a63d7c2 100644 --- a/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.h +++ b/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.h @@ -110,6 +110,16 @@ protected: NodeToWorld(); }; +class NodeToWorld3D : public TestCocosNodeDemo +{ +public: + CREATE_FUNC(NodeToWorld3D); + virtual std::string title() const override; + +protected: + NodeToWorld3D(); +}; + class CameraOrbitTest : public TestCocosNodeDemo { public: @@ -148,6 +158,22 @@ protected: CameraCenterTest(); }; +class CameraTest1 : public TestCocosNodeDemo +{ +public: + CREATE_FUNC(CameraTest1); + virtual std::string title() const override; + virtual std::string subtitle() const override; + virtual void onEnter() override; + virtual void onExit() override; + +protected: + CameraTest1(); + + Sprite *_sprite1; + Sprite *_sprite2; +}; + class CameraTest2 : public TestCocosNodeDemo { public: @@ -163,7 +189,6 @@ protected: Sprite *_sprite1; Sprite *_sprite2; - }; class ConvertToNode : public TestCocosNodeDemo