axmol/tests/cpp-tests/Classes/NodeTest/NodeTest.cpp

1523 lines
42 KiB
C++
Raw Normal View History

/****************************************************************************
Copyright (c) 2012 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
2022-10-01 16:24:52 +08:00
https://axmolengine.github.io/
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.
****************************************************************************/
#include "NodeTest.h"
#include <regex>
#include "../testResource.h"
USING_NS_AX;
2021-12-28 16:06:23 +08:00
enum
2010-08-26 15:09:02 +08:00
{
kTagSprite1 = 1,
kTagSprite2 = 2,
kTagSprite3 = 3,
kTagSlider,
};
2010-08-26 15:09:02 +08:00
//------------------------------------------------------------------
//
// TestCocosNodeDemo
//
//------------------------------------------------------------------
CocosNodeTests::CocosNodeTests()
{
ADD_TEST_CASE(CameraTest1);
ADD_TEST_CASE(CameraTest2);
ADD_TEST_CASE(CameraCenterTest);
ADD_TEST_CASE(NodeTest2);
ADD_TEST_CASE(NodeTest4);
ADD_TEST_CASE(NodeTest5);
ADD_TEST_CASE(NodeTest6);
ADD_TEST_CASE(StressTest1);
ADD_TEST_CASE(StressTest2);
ADD_TEST_CASE(NodeToWorld);
ADD_TEST_CASE(NodeToWorld3D);
ADD_TEST_CASE(SchedulerTest1);
ADD_TEST_CASE(SchedulerCallbackTest);
2019-02-20 17:07:31 +08:00
ADD_TEST_CASE(CameraOrbitTest);
// TODO: Camera has been removed from CCNode; add new feature to support it
2021-12-28 16:06:23 +08:00
// ADD_TEST_CASE(CameraZoomTest);
ADD_TEST_CASE(ConvertToNode);
ADD_TEST_CASE(NodeOpaqueTest);
ADD_TEST_CASE(NodeNonOpaqueTest);
ADD_TEST_CASE(NodeGlobalZValueTest);
ADD_TEST_CASE(NodeNormalizedPositionTest1);
ADD_TEST_CASE(NodeNormalizedPositionTest2);
ADD_TEST_CASE(NodeNormalizedPositionBugTest);
ADD_TEST_CASE(NodeNameTest);
ADD_TEST_CASE(Issue16100Test);
ADD_TEST_CASE(Issue16735Test);
2010-08-26 15:09:02 +08:00
}
2021-12-28 16:06:23 +08:00
TestCocosNodeDemo::TestCocosNodeDemo(void) {}
2021-12-28 16:06:23 +08:00
TestCocosNodeDemo::~TestCocosNodeDemo(void) {}
std::string TestCocosNodeDemo::title() const
2010-08-26 15:09:02 +08:00
{
return "Node Test";
2010-08-26 15:09:02 +08:00
}
//------------------------------------------------------------------
//
// NodeTest2
2010-08-26 15:09:02 +08:00
//
//------------------------------------------------------------------
void NodeTest2::onEnter()
{
TestCocosNodeDemo::onEnter();
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
auto sp1 = Sprite::create(s_pathSister1);
auto sp2 = Sprite::create(s_pathSister2);
auto sp3 = Sprite::create(s_pathSister1);
auto sp4 = Sprite::create(s_pathSister2);
2021-12-28 16:06:23 +08:00
sp1->setPosition(Vec2(100.0f, s.height / 2));
sp2->setPosition(Vec2(380.0f, s.height / 2));
addChild(sp1);
addChild(sp2);
2021-12-28 16:06:23 +08:00
sp3->setScale(0.25f);
sp4->setScale(0.25f);
2021-12-28 16:06:23 +08:00
sp1->addChild(sp3);
sp2->addChild(sp4);
2021-12-28 16:06:23 +08:00
auto a1 = RotateBy::create(2, 360);
auto a2 = ScaleBy::create(2, 2);
2021-12-28 16:06:23 +08:00
auto action1 = RepeatForever::create(Sequence::create(a1, a2, a2->reverse(), nullptr));
auto action2 = RepeatForever::create(Sequence::create(a1->clone(), a2->clone(), a2->reverse(), nullptr));
sp2->setAnchorPoint(Vec2(0, 0));
sp1->runAction(action1);
sp2->runAction(action2);
2010-08-26 15:09:02 +08:00
}
std::string NodeTest2::subtitle() const
2010-08-26 15:09:02 +08:00
{
return "anchorPoint and children";
2010-08-26 15:09:02 +08:00
}
//------------------------------------------------------------------
//
// NodeTest4
2010-08-26 15:09:02 +08:00
//
//------------------------------------------------------------------
2021-12-28 16:06:23 +08:00
#define SID_DELAY2 1
#define SID_DELAY4 2
2010-08-26 15:09:02 +08:00
NodeTest4::NodeTest4()
{
auto sp1 = Sprite::create(s_pathSister1);
auto sp2 = Sprite::create(s_pathSister2);
2021-12-28 16:06:23 +08:00
sp1->setPosition(Vec2(100, 160));
sp2->setPosition(Vec2(380, 160));
addChild(sp1, 0, 2);
addChild(sp2, 0, 3);
2021-12-28 16:06:23 +08:00
2022-07-15 19:17:01 +08:00
schedule(AX_CALLBACK_1(NodeTest4::delay2, this), 2.0f, "delay2_key");
schedule(AX_CALLBACK_1(NodeTest4::delay4, this), 4.0f, "delay4_key");
}
2010-08-26 15:09:02 +08:00
void NodeTest4::delay2(float dt)
2010-08-26 15:09:02 +08:00
{
2021-12-28 16:06:23 +08:00
auto node = static_cast<Sprite*>(getChildByTag(2));
auto action1 = RotateBy::create(1, 360);
node->runAction(action1);
2010-08-26 15:09:02 +08:00
}
void NodeTest4::delay4(float dt)
2010-08-26 15:09:02 +08:00
{
unschedule("delay4_key");
removeChildByTag(3, false);
2010-08-26 15:09:02 +08:00
}
std::string NodeTest4::subtitle() const
2010-08-26 15:09:02 +08:00
{
return "tags";
2010-08-26 15:09:02 +08:00
}
//------------------------------------------------------------------
//
// NodeTest5
2010-08-26 15:09:02 +08:00
//
//------------------------------------------------------------------
NodeTest5::NodeTest5()
{
auto sp1 = Sprite::create(s_pathSister1);
auto sp2 = Sprite::create(s_pathSister2);
2021-12-28 16:06:23 +08:00
sp1->setPosition(Vec2(100.0f, 160.0f));
sp2->setPosition(Vec2(380.0f, 160.0f));
auto rot = RotateBy::create(2.0f, 360.0f);
auto rot_back = rot->reverse();
2021-12-28 16:06:23 +08:00
auto forever = RepeatForever::create(Sequence::create(rot, rot_back, nullptr));
auto forever2 = forever->clone();
forever->setTag(101);
forever2->setTag(102);
2021-12-28 16:06:23 +08:00
addChild(sp1, 0, kTagSprite1);
addChild(sp2, 0, kTagSprite2);
2021-12-28 16:06:23 +08:00
sp1->runAction(forever);
sp2->runAction(forever2);
2021-12-28 16:06:23 +08:00
2022-07-15 19:17:01 +08:00
schedule(AX_CALLBACK_1(NodeTest5::addAndRemove, this), 2.0f, "add_and_remove_key");
}
2010-08-26 15:09:02 +08:00
void NodeTest5::addAndRemove(float dt)
2010-08-26 15:09:02 +08:00
{
auto sp1 = getChildByTag(kTagSprite1);
auto sp2 = getChildByTag(kTagSprite2);
2010-08-26 15:09:02 +08:00
sp1->retain();
sp2->retain();
2021-12-28 16:06:23 +08:00
removeChild(sp1, false);
removeChild(sp2, true);
2021-12-28 16:06:23 +08:00
addChild(sp1, 0, kTagSprite1);
addChild(sp2, 0, kTagSprite2);
2021-12-28 16:06:23 +08:00
sp1->release();
sp2->release();
2010-08-26 15:09:02 +08:00
}
std::string NodeTest5::subtitle() const
2010-08-26 15:09:02 +08:00
{
return "remove and cleanup";
2010-08-26 15:09:02 +08:00
}
2010-08-26 15:09:02 +08:00
//------------------------------------------------------------------
//
// NodeTest6
2010-08-26 15:09:02 +08:00
//
//------------------------------------------------------------------
NodeTest6::NodeTest6()
{
2021-12-28 16:06:23 +08:00
auto sp1 = Sprite::create(s_pathSister1);
auto sp11 = Sprite::create(s_pathSister1);
2021-12-28 16:06:23 +08:00
auto sp2 = Sprite::create(s_pathSister2);
auto sp21 = Sprite::create(s_pathSister2);
2021-12-28 16:06:23 +08:00
sp1->setPosition(Vec2(100.0f, 160.0f));
sp2->setPosition(Vec2(380.0f, 160.0f));
auto rot = RotateBy::create(2.0f, 360.0f);
auto rot_back = rot->reverse();
auto forever1 = RepeatForever::create(Sequence::create(rot, rot_back, nullptr));
auto forever11 = forever1->clone();
2021-12-28 16:06:23 +08:00
auto forever2 = forever1->clone();
auto forever21 = forever1->clone();
2021-12-28 16:06:23 +08:00
addChild(sp1, 0, kTagSprite1);
sp1->addChild(sp11);
addChild(sp2, 0, kTagSprite2);
sp2->addChild(sp21);
2021-12-28 16:06:23 +08:00
sp1->runAction(forever1);
sp11->runAction(forever11);
sp2->runAction(forever2);
sp21->runAction(forever21);
2021-12-28 16:06:23 +08:00
2022-07-15 19:17:01 +08:00
schedule(AX_CALLBACK_1(NodeTest6::addAndRemove, this), 2.0f, "add_and_remove_key");
}
2010-08-26 15:09:02 +08:00
void NodeTest6::addAndRemove(float dt)
2010-08-26 15:09:02 +08:00
{
auto sp1 = getChildByTag(kTagSprite1);
auto sp2 = getChildByTag(kTagSprite2);
2010-08-26 15:09:02 +08:00
sp1->retain();
sp2->retain();
2021-12-28 16:06:23 +08:00
removeChild(sp1, false);
removeChild(sp2, true);
2021-12-28 16:06:23 +08:00
addChild(sp1, 0, kTagSprite1);
addChild(sp2, 0, kTagSprite2);
2021-12-28 16:06:23 +08:00
sp1->release();
sp2->release();
2010-08-26 15:09:02 +08:00
}
std::string NodeTest6::subtitle() const
2010-08-26 15:09:02 +08:00
{
return "remove/cleanup with children";
2010-08-26 15:09:02 +08:00
}
//------------------------------------------------------------------
2010-08-26 15:09:02 +08:00
//
// StressTest1
//
//------------------------------------------------------------------
StressTest1::StressTest1()
{
auto s = Director::getInstance()->getWinSize();
2010-08-26 15:09:02 +08:00
auto sp1 = Sprite::create(s_pathSister1);
addChild(sp1, 0, kTagSprite1);
2021-12-28 16:06:23 +08:00
sp1->setPosition(Vec2(s.width / 2, s.height / 2));
2010-08-26 15:09:02 +08:00
2022-07-15 19:17:01 +08:00
schedule(AX_CALLBACK_1(StressTest1::shouldNotCrash, this), 1.0f, "should_not_crash_key");
}
2010-08-26 15:09:02 +08:00
2012-06-08 13:55:28 +08:00
void StressTest1::shouldNotCrash(float dt)
2010-08-26 15:09:02 +08:00
{
unschedule("should_not_crash_key");
2010-08-26 15:09:02 +08:00
auto s = Director::getInstance()->getWinSize();
2010-08-26 15:09:02 +08:00
// if the node has timers, it crashes
auto explosion = ParticleSun::create();
explosion->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png"));
2021-12-28 16:06:23 +08:00
// if it doesn't, it works Ok.
2021-12-28 16:06:23 +08:00
// auto explosion = [Sprite create:@"grossinis_sister2.png");
explosion->setPosition(Vec2(s.width / 2, s.height / 2));
2022-07-15 19:17:01 +08:00
runAction(Sequence::create(RotateBy::create(2, 360), CallFuncN::create(AX_CALLBACK_1(StressTest1::removeMe, this)),
2021-12-28 16:06:23 +08:00
nullptr));
addChild(explosion);
2010-08-26 15:09:02 +08:00
}
// remove
void StressTest1::removeMe(Node* node)
{
getTestSuite()->enterNextTest();
2010-08-26 15:09:02 +08:00
}
2014-02-28 23:02:22 +08:00
std::string StressTest1::subtitle() const
2010-08-26 15:09:02 +08:00
{
return "stress test #1: no crashes";
2010-08-26 15:09:02 +08:00
}
//------------------------------------------------------------------
//
// StressNodeTest2
2010-08-26 15:09:02 +08:00
//
//------------------------------------------------------------------
StressTest2::StressTest2()
{
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
auto sublayer = Layer::create();
2021-12-28 16:06:23 +08:00
auto sp1 = Sprite::create(s_pathSister1);
2021-12-28 16:06:23 +08:00
sp1->setPosition(Vec2(80.0f, s.height / 2));
auto move = MoveBy::create(3, Vec2(350.0f, 0.0f));
auto move_ease_inout3 = EaseInOut::create(move->clone(), 2.0f);
auto move_ease_inout_back3 = move_ease_inout3->reverse();
2021-12-28 16:06:23 +08:00
auto seq3 = Sequence::create(move_ease_inout3, move_ease_inout_back3, nullptr);
sp1->runAction(RepeatForever::create(seq3));
sublayer->addChild(sp1, 1);
auto fire = ParticleFire::create();
fire->setTexture(Director::getInstance()->getTextureCache()->addImage("Images/fire.png"));
2021-12-28 16:06:23 +08:00
fire->setPosition(Vec2(80.0f, s.height / 2 - 50));
auto copy_seq3 = seq3->clone();
2021-12-28 16:06:23 +08:00
fire->runAction(RepeatForever::create(copy_seq3));
sublayer->addChild(fire, 2);
2021-12-28 16:06:23 +08:00
2022-07-15 19:17:01 +08:00
schedule(AX_CALLBACK_1(StressTest2::shouldNotLeak, this), 6.0f, "should_not_leak_key");
2021-12-28 16:06:23 +08:00
addChild(sublayer, 0, kTagSprite1);
}
2010-08-26 15:09:02 +08:00
2012-06-08 13:55:28 +08:00
void StressTest2::shouldNotLeak(float dt)
2010-08-26 15:09:02 +08:00
{
unschedule("should_not_leak_key");
2021-12-28 16:06:23 +08:00
auto sublayer = static_cast<Layer*>(getChildByTag(kTagSprite1));
sublayer->removeAllChildrenWithCleanup(true);
2010-08-26 15:09:02 +08:00
}
2014-02-28 23:02:22 +08:00
std::string StressTest2::subtitle() const
2010-08-26 15:09:02 +08:00
{
return "stress test #2: no leaks";
2010-08-26 15:09:02 +08:00
}
//------------------------------------------------------------------
//
// SchedulerTest1
//
//------------------------------------------------------------------
SchedulerTest1::SchedulerTest1()
{
auto layer = Layer::create();
2022-07-16 10:43:05 +08:00
// AXLOG("retain count after init is %d", layer->getReferenceCount()); // 1
2021-12-28 16:06:23 +08:00
addChild(layer, 0);
2022-07-16 10:43:05 +08:00
// AXLOG("retain count after addChild is %d", layer->getReferenceCount()); // 2
2021-12-28 16:06:23 +08:00
2022-07-15 19:17:01 +08:00
layer->schedule(AX_CALLBACK_1(SchedulerTest1::doSomething, this), "do_something_key");
2022-07-16 10:43:05 +08:00
// AXLOG("retain count after schedule is %d", layer->getReferenceCount()); // 3 : (objective-c version), but
2021-12-28 16:06:23 +08:00
// win32 version is still 2, because Timer class don't save target.
layer->unschedule("do_something_key");
2022-07-16 10:43:05 +08:00
// AXLOG("retain count after unschedule is %d", layer->getReferenceCount()); // STILL 3! (win32 is '2')
}
2010-08-26 15:09:02 +08:00
2021-12-28 16:06:23 +08:00
void SchedulerTest1::doSomething(float dt) {}
2010-08-26 15:09:02 +08:00
2014-02-28 23:02:22 +08:00
std::string SchedulerTest1::subtitle() const
2010-08-26 15:09:02 +08:00
{
return "cocosnode scheduler test #1";
2010-08-26 15:09:02 +08:00
}
//------------------------------------------------------------------
//
// SchedulerCallbackTest
//
//------------------------------------------------------------------
SchedulerCallbackTest::SchedulerCallbackTest()
{
auto node = Node::create();
addChild(node, 0);
node->setName("a node");
_total = 0;
2021-12-28 16:06:23 +08:00
node->schedule(
[&](float dt) {
_total += dt;
log("hello world: %f - total: %f", dt, _total);
},
0.5, "some_key");
node->scheduleOnce(
[&](float dt) {
// the local variable "node" will go out of scope, so I have to get it from "this"
auto anode = this->getChildByName("a node");
anode->unschedule("some_key");
},
5, "ignore_key");
}
void SchedulerCallbackTest::onEnter()
{
TestCocosNodeDemo::onEnter();
log("--onEnter-- Must be called before the scheduled lambdas");
}
std::string SchedulerCallbackTest::subtitle() const
{
return "Node scheduler with lambda";
}
2010-08-26 15:09:02 +08:00
//------------------------------------------------------------------
//
// NodeToWorld
//
//------------------------------------------------------------------
NodeToWorld::NodeToWorld()
{
//
// This code tests that nodeToParent works OK:
// - It tests different anchor Points
// - It tests different children anchor points
auto back = Sprite::create(s_back3);
2021-12-28 16:06:23 +08:00
addChild(back, -10);
back->setAnchorPoint(Vec2(0, 0));
auto backSize = back->getContentSize();
2021-12-28 16:06:23 +08:00
auto item = MenuItemImage::create(s_PlayNormal, s_PlaySelect);
auto menu = Menu::create(item, nullptr);
menu->alignItemsVertically();
2021-12-28 16:06:23 +08:00
menu->setPosition(Vec2(backSize.width / 2, backSize.height / 2));
back->addChild(menu);
2021-12-28 16:06:23 +08:00
auto rot = RotateBy::create(5.0f, 360.0f);
2021-12-28 16:06:23 +08:00
auto fe = RepeatForever::create(rot);
item->runAction(fe);
auto move = MoveBy::create(3.0f, Vec2(200.0f, 0.0f));
auto move_back = move->reverse();
2021-12-28 16:06:23 +08:00
auto seq = Sequence::create(move, move_back, nullptr);
auto fe2 = RepeatForever::create(seq);
back->runAction(fe2);
}
2014-02-28 23:02:22 +08:00
std::string NodeToWorld::subtitle() 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
2021-12-28 16:06:23 +08:00
Size s = Director::getInstance()->getWinSize();
auto parent = Node::create();
parent->setContentSize(s);
parent->setAnchorPoint(Vec2(0.5f, 0.5f));
2021-12-28 16:06:23 +08:00
parent->setPosition(s.width / 2, s.height / 2);
this->addChild(parent);
auto back = Sprite::create(s_back3);
2021-12-28 16:06:23 +08:00
parent->addChild(back, -10);
back->setAnchorPoint(Vec2(0.0f, 0.0f));
auto backSize = back->getContentSize();
auto item = MenuItemImage::create(s_PlayNormal, s_PlaySelect);
auto menu = Menu::create(item, nullptr);
menu->alignItemsVertically();
2021-12-28 16:06:23 +08:00
menu->setPosition(Vec2(backSize.width / 2, backSize.height / 2));
back->addChild(menu);
auto rot = RotateBy::create(5, 360);
2021-12-28 16:06:23 +08:00
auto fe = RepeatForever::create(rot);
item->runAction(fe);
2021-12-28 16:06:23 +08:00
auto move = MoveBy::create(3, Vec2(200.0f, 0.0f));
auto move_back = move->reverse();
2021-12-28 16:06:23 +08:00
auto seq = Sequence::create(move, move_back, nullptr);
auto fe2 = RepeatForever::create(seq);
back->runAction(fe2);
auto orbit = OrbitCamera::create(10, 0, 1, 0, 360, 0, 90);
parent->runAction(orbit);
}
2014-02-28 23:02:22 +08:00
std::string NodeToWorld3D::subtitle() const
{
return "nodeToParent transform in 3D";
}
2010-08-26 15:09:02 +08:00
//------------------------------------------------------------------
//
// CameraOrbitTest
//
//------------------------------------------------------------------
void CameraOrbitTest::onEnter()
{
TestCocosNodeDemo::onEnter();
_preProjection = Director::getInstance()->getProjection();
2019-06-30 11:36:52 +08:00
Director::getInstance()->getRenderer()->setDepthTest(true);
2019-09-04 10:02:03 +08:00
Director::getInstance()->getRenderer()->setDepthWrite(true);
Director::getInstance()->setProjection(Director::Projection::_3D);
}
void CameraOrbitTest::onExit()
{
2019-06-30 11:36:52 +08:00
Director::getInstance()->getRenderer()->setDepthTest(false);
2019-09-04 10:02:03 +08:00
Director::getInstance()->getRenderer()->setDepthWrite(false);
Director::getInstance()->setProjection(_preProjection);
TestCocosNodeDemo::onExit();
}
CameraOrbitTest::CameraOrbitTest()
{
auto s = Director::getInstance()->getWinSize();
auto p = Sprite::create(s_back3);
2021-12-28 16:06:23 +08:00
addChild(p, 0);
p->setPosition(Vec2(s.width / 2, s.height / 2));
p->setOpacity(128);
Sprite* sprite;
OrbitCamera* orbit;
Size ss;
// LEFT
2021-12-28 16:06:23 +08:00
s = p->getContentSize();
sprite = Sprite::create(s_pathGrossini);
sprite->setScale(0.5f);
2021-12-28 16:06:23 +08:00
p->addChild(sprite, 0);
sprite->setPosition(Vec2(s.width / 4 * 1, s.height / 2));
orbit = OrbitCamera::create(2, 1, 0, 0, 360, 0, 0);
2021-12-28 16:06:23 +08:00
sprite->runAction(RepeatForever::create(orbit));
// CENTER
sprite = Sprite::create(s_pathGrossini);
2021-12-28 16:06:23 +08:00
sprite->setScale(1.0f);
p->addChild(sprite, 0);
sprite->setPosition(Vec2(s.width / 4 * 2, s.height / 2));
orbit = OrbitCamera::create(2, 1, 0, 0, 360, 45, 0);
2021-12-28 16:06:23 +08:00
sprite->runAction(RepeatForever::create(orbit));
// RIGHT
sprite = Sprite::create(s_pathGrossini);
2021-12-28 16:06:23 +08:00
sprite->setScale(2.0f);
p->addChild(sprite, 0);
sprite->setPosition(Vec2(s.width / 4 * 3, s.height / 2));
ss = sprite->getContentSize();
orbit = OrbitCamera::create(2, 1, 0, 0, 360, 90, -45), sprite->runAction(RepeatForever::create(orbit));
// PARENT
orbit = OrbitCamera::create(10, 1, 0, 0, 360, 0, 90);
2021-12-28 16:06:23 +08:00
p->runAction(RepeatForever::create(orbit));
2021-12-28 16:06:23 +08:00
setScale(1);
}
2014-02-28 23:02:22 +08:00
std::string CameraOrbitTest::subtitle() const
{
return "Camera Orbit test";
}
2010-08-26 15:09:02 +08:00
//------------------------------------------------------------------
//
// CameraZoomTest
//
//------------------------------------------------------------------
void CameraZoomTest::onEnter()
{
TestCocosNodeDemo::onEnter();
_preProjection = Director::getInstance()->getProjection();
Director::getInstance()->setProjection(Director::Projection::_3D);
}
void CameraZoomTest::onExit()
{
Director::getInstance()->setProjection(_preProjection);
TestCocosNodeDemo::onExit();
}
CameraZoomTest::CameraZoomTest()
{
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
Sprite* sprite;
// Camera *cam;
// LEFT
sprite = Sprite::create(s_pathGrossini);
2021-12-28 16:06:23 +08:00
addChild(sprite, 0);
sprite->setPosition(Vec2(s.width / 4 * 1, s.height / 2));
// cam = sprite->getCamera();
// cam->setEye(0, 0, 415/2);
// cam->setCenter(0, 0, 0);
2013-12-21 08:33:31 +08:00
// CENTER
sprite = Sprite::create(s_pathGrossini);
2021-12-28 16:06:23 +08:00
addChild(sprite, 0, 40);
sprite->setPosition(Vec2(s.width / 4 * 2, s.height / 2));
// RIGHT
sprite = Sprite::create(s_pathGrossini);
2021-12-28 16:06:23 +08:00
addChild(sprite, 0, 20);
sprite->setPosition(Vec2(s.width / 4 * 3, s.height / 2));
_z = 0;
scheduleUpdate();
}
2012-06-08 13:55:28 +08:00
void CameraZoomTest::update(float dt)
{
2021-12-28 16:06:23 +08:00
Node* sprite;
// Camera *cam;
2013-12-21 08:33:31 +08:00
_z += dt * 100;
2021-12-28 16:06:23 +08:00
sprite = getChildByTag(20);
2021-12-28 16:06:23 +08:00
// cam = sprite->getCamera();
// cam->setEye(0, 0, _z);
2013-12-21 08:33:31 +08:00
sprite = getChildByTag(40);
2021-12-28 16:06:23 +08:00
// cam = sprite->getCamera();
// cam->setEye(0, 0, -_z);
}
2014-02-28 23:02:22 +08:00
std::string CameraZoomTest::subtitle() const
{
return "Camera Zoom test";
}
2010-08-26 15:09:02 +08:00
//------------------------------------------------------------------
//
// CameraCenterTest
//
//------------------------------------------------------------------
void CameraCenterTest::onEnter()
{
TestCocosNodeDemo::onEnter();
_preProjection = Director::getInstance()->getProjection();
Director::getInstance()->setProjection(Director::Projection::_3D);
}
void CameraCenterTest::onExit()
{
TestCocosNodeDemo::onExit();
Director::getInstance()->setProjection(_preProjection);
}
CameraCenterTest::CameraCenterTest()
{
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
Sprite* sprite;
OrbitCamera* orbit;
// LEFT-TOP
sprite = Sprite::create("Images/white-512x512.png");
2021-12-28 16:06:23 +08:00
addChild(sprite, 0);
sprite->setPosition(Vec2(s.width / 5 * 1, s.height / 5 * 1));
sprite->setColor(Color3B::RED);
sprite->setTextureRect(Rect(0.0f, 0.0f, 120.0f, 50.0f));
orbit = OrbitCamera::create(10.0f, 1.0f, 0.0f, 0.0f, 360.0f, 0.0f, 0.0f);
2021-12-28 16:06:23 +08:00
sprite->runAction(RepeatForever::create(orbit));
// [sprite setAnchorPoint: Vec2(0,1));
// LEFT-BOTTOM
sprite = Sprite::create("Images/white-512x512.png");
2021-12-28 16:06:23 +08:00
addChild(sprite, 0, 40);
sprite->setPosition(Vec2(s.width / 5 * 1, s.height / 5 * 4));
sprite->setColor(Color3B::BLUE);
sprite->setTextureRect(Rect(0.0f, 0.0f, 120.0f, 50.0f));
orbit = OrbitCamera::create(10.0f, 1.0f, 0.0f, 0.0f, 360.0f, 0.0f, 0.0f);
2021-12-28 16:06:23 +08:00
sprite->runAction(RepeatForever::create(orbit));
// RIGHT-TOP
sprite = Sprite::create("Images/white-512x512.png");
2021-12-28 16:06:23 +08:00
addChild(sprite, 0);
sprite->setPosition(Vec2(s.width / 5 * 4, s.height / 5 * 1));
sprite->setColor(Color3B::YELLOW);
sprite->setTextureRect(Rect(0.0f, 0.0f, 120.0f, 50.0f));
orbit = OrbitCamera::create(10.0f, 1.0f, 0.0f, 0.0f, 360.0f, 0.0f, 0.0f);
2021-12-28 16:06:23 +08:00
sprite->runAction(RepeatForever::create(orbit));
// RIGHT-BOTTOM
sprite = Sprite::create("Images/white-512x512.png");
2021-12-28 16:06:23 +08:00
addChild(sprite, 0, 40);
sprite->setPosition(Vec2(s.width / 5 * 4, s.height / 5 * 4));
sprite->setColor(Color3B::GREEN);
sprite->setTextureRect(Rect(0.0f, 0.0f, 120.0f, 50.0f));
orbit = OrbitCamera::create(10.0f, 1.0f, 0.0f, 0.0f, 360.0f, 0.0f, 0.0f);
2021-12-28 16:06:23 +08:00
sprite->runAction(RepeatForever::create(orbit));
// CENTER
sprite = Sprite::create("Images/white-512x512.png");
2021-12-28 16:06:23 +08:00
addChild(sprite, 0, 40);
sprite->setPosition(Vec2(s.width / 2, s.height / 2));
sprite->setColor(Color3B::WHITE);
sprite->setTextureRect(Rect(0.0f, 0.0f, 120.0f, 50.0f));
orbit = OrbitCamera::create(10.0f, 1.0f, 0.0f, 0.0f, 360.0f, 0.0f, 0.0f);
2021-12-28 16:06:23 +08:00
sprite->runAction(RepeatForever::create(orbit));
}
std::string CameraCenterTest::title() const
{
return "Camera Center test";
}
std::string CameraCenterTest::subtitle() const
{
return "Sprites should rotate at the same speed";
}
2011-02-23 16:47:25 +08:00
//------------------------------------------------------------------
//
// ConvertToNode
//
//------------------------------------------------------------------
ConvertToNode::ConvertToNode()
{
2021-12-28 16:06:23 +08:00
auto listener = EventListenerTouchAllAtOnce::create();
2022-07-15 19:17:01 +08:00
listener->onTouchesEnded = AX_CALLBACK_2(ConvertToNode::onTouchesEnded, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
2021-12-28 16:06:23 +08:00
auto s = Director::getInstance()->getWinSize();
auto rotate = RotateBy::create(10, 360);
auto action = RepeatForever::create(rotate);
2021-12-28 16:06:23 +08:00
for (int i = 0; i < 3; i++)
{
auto sprite = Sprite::create("Images/grossini.png");
2021-12-28 16:06:23 +08:00
sprite->setPosition(Vec2(s.width / 4 * (i + 1), s.height / 2));
auto point = Sprite::create("Images/r1.png");
point->setScale(0.25f);
point->setPosition(sprite->getPosition());
addChild(point, 10, 100 + i);
2021-12-28 16:06:23 +08:00
switch (i)
{
case 0:
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
sprite->setAnchorPoint(Vec2::ZERO);
break;
case 1:
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
sprite->setAnchorPoint(Vec2(0.5f, 0.5f));
break;
case 2:
2021-12-28 16:06:23 +08:00
sprite->setAnchorPoint(Vec2(1, 1));
break;
}
point->setPosition(sprite->getPosition());
2021-12-28 16:06:23 +08:00
sprite->runAction(action->clone());
addChild(sprite, i);
}
}
2021-12-28 16:06:23 +08:00
void ConvertToNode::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
{
2021-12-28 16:06:23 +08:00
for (auto& touch : touches)
{
auto location = touch->getLocation();
2021-12-28 16:06:23 +08:00
for (int i = 0; i < 3; i++)
{
2021-12-28 16:06:23 +08:00
auto node = getChildByTag(100 + i);
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
Vec2 p1, p2;
p1 = node->convertToNodeSpaceAR(location);
p2 = node->convertToNodeSpace(location);
2022-07-16 10:43:05 +08:00
AXLOG("AR: x=%.2f, y=%.2f -- Not AR: x=%.2f, y=%.2f", p1.x, p1.y, p2.x, p2.y);
}
2021-12-28 16:06:23 +08:00
}
}
std::string ConvertToNode::title() const
{
return "Convert To Node Space";
}
std::string ConvertToNode::subtitle() const
{
return "testing convertToNodeSpace / AR. Touch and see console";
}
/// NodeOpaqueTest
NodeOpaqueTest::NodeOpaqueTest()
{
2021-12-28 16:06:23 +08:00
Sprite* background = nullptr;
for (int i = 0; i < 50; i++)
{
background = Sprite::create("Images/background1.png");
2021-12-28 16:06:23 +08:00
background->setBlendFunc(BlendFunc::ALPHA_PREMULTIPLIED);
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
background->setAnchorPoint(Vec2::ZERO);
addChild(background);
}
}
std::string NodeOpaqueTest::title() const
{
return "Node Opaque Test";
}
std::string NodeOpaqueTest::subtitle() const
{
return "Node rendered with GL_BLEND disabled";
}
/// NodeNonOpaqueTest
NodeNonOpaqueTest::NodeNonOpaqueTest()
{
2021-12-28 16:06:23 +08:00
Sprite* background = nullptr;
for (int i = 0; i < 50; i++)
{
background = Sprite::create("Images/background1.jpg");
background->setBlendFunc(BlendFunc::DISABLE);
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
background->setAnchorPoint(Vec2::ZERO);
addChild(background);
}
}
std::string NodeNonOpaqueTest::title() const
{
return "Node Non Opaque Test";
}
std::string NodeNonOpaqueTest::subtitle() const
{
return "Node rendered with GL_BLEND enabled";
}
/// NodeGlobalZValueTest
NodeGlobalZValueTest::NodeGlobalZValueTest()
{
Size s = Director::getInstance()->getWinSize();
for (int i = 0; i < 9; i++)
{
2021-12-28 16:06:23 +08:00
Sprite* sprite;
auto parent = Node::create();
2021-12-28 16:06:23 +08:00
if (i == 4)
{
sprite = Sprite::create("Images/grossinis_sister2.png");
_sprite = sprite;
_sprite->setGlobalZOrder(-1);
}
else
sprite = Sprite::create("Images/grossinis_sister1.png");
parent->addChild(sprite);
this->addChild(parent);
float w = sprite->getContentSize().width;
2021-12-28 16:06:23 +08:00
sprite->setPosition(s.width / 2 - w * 0.7 * (i - 5), s.height / 2);
}
this->scheduleUpdate();
}
void NodeGlobalZValueTest::update(float dt)
{
static float accum = 0;
accum += dt;
2021-12-28 16:06:23 +08:00
if (accum > 1)
{
float z = _sprite->getGlobalZOrder();
_sprite->setGlobalZOrder(-z);
accum = 0;
}
}
std::string NodeGlobalZValueTest::title() const
{
return "Global Z Value";
}
std::string NodeGlobalZValueTest::subtitle() const
{
return "Center Sprite should change go from foreground to background";
}
//
// MySprite: Used by CameraTest1 and CameraTest2
//
class MySprite : public Sprite
{
public:
2021-12-28 17:20:17 +08:00
static MySprite* create(std::string_view spritefilename)
{
2021-12-08 00:11:53 +08:00
auto sprite = new MySprite;
sprite->initWithFile(spritefilename);
sprite->autorelease();
2021-12-28 16:06:23 +08:00
auto program = backend::Program::getBuiltinProgram(backend::ProgramType::POSITION_TEXTURE_COLOR);
2021-12-08 00:11:53 +08:00
auto programState = new backend::ProgramState(program);
sprite->setProgramState(programState, false);
return sprite;
}
bool setProgramState(backend::ProgramState* programState, bool needsRetain = true) override;
2021-12-28 16:06:23 +08:00
virtual void draw(Renderer* renderer, const Mat4& transform, uint32_t flags) override;
protected:
CustomCommand _customCommand;
};
bool MySprite::setProgramState(backend::ProgramState* programState, bool needsRetain)
{
2021-12-28 16:06:23 +08:00
if (Sprite::setProgramState(programState, needsRetain))
{
auto& pipelineDescriptor = _customCommand.getPipelineDescriptor();
2020-09-09 13:03:31 +08:00
pipelineDescriptor.programState = programState;
2020-09-09 13:03:31 +08:00
_customCommand.setDrawType(CustomCommand::DrawType::ARRAY);
_customCommand.setPrimitiveType(CustomCommand::PrimitiveType::TRIANGLE_STRIP);
_customCommand.createVertexBuffer(sizeof(V3F_C4B_T2F), 4, CustomCommand::BufferUsage::STATIC);
_customCommand.updateVertexBuffer(&_quad, 4 * sizeof(V3F_C4B_T2F));
return true;
}
return false;
}
2021-12-28 16:06:23 +08:00
void MySprite::draw(Renderer* renderer, const Mat4& transform, uint32_t flags)
{
const auto& projectionMat = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
2021-12-28 16:06:23 +08:00
auto mvpMatrix = projectionMat * transform;
_customCommand.getPipelineDescriptor().programState->setUniform(_mvpMatrixLocation, mvpMatrix.m,
sizeof(mvpMatrix.m));
2015-01-16 06:00:49 +08:00
_customCommand.init(_globalZOrder, transform, flags);
renderer->addCommand(&_customCommand);
}
//------------------------------------------------------------------
//
// CameraTest1
//
//------------------------------------------------------------------
void CameraTest1::onEnter()
{
TestCocosNodeDemo::onEnter();
_preProjection = Director::getInstance()->getProjection();
Director::getInstance()->setProjection(Director::Projection::_3D);
2019-06-30 11:36:52 +08:00
Director::getInstance()->getRenderer()->setDepthTest(true);
2019-09-04 10:02:03 +08:00
Director::getInstance()->getRenderer()->setDepthWrite(true);
}
void CameraTest1::onExit()
{
Director::getInstance()->setProjection(_preProjection);
2019-06-30 11:36:52 +08:00
Director::getInstance()->getRenderer()->setDepthTest(false);
2019-09-04 10:02:03 +08:00
Director::getInstance()->getRenderer()->setDepthWrite(false);
TestCocosNodeDemo::onExit();
}
CameraTest1::CameraTest1()
{
auto s = Director::getInstance()->getWinSize();
_sprite1 = MySprite::create(s_back3);
2021-12-28 16:06:23 +08:00
addChild(_sprite1);
_sprite1->setPosition(Vec2(1 * s.width / 4, s.height / 2));
_sprite1->setScale(0.5);
_sprite2 = Sprite::create(s_back3);
2021-12-28 16:06:23 +08:00
addChild(_sprite2);
_sprite2->setPosition(Vec2(3 * s.width / 4, s.height / 2));
_sprite2->setScale(0.5);
auto camera = OrbitCamera::create(10, 0, 1, 0, 360, 0, 0);
2021-12-28 16:06:23 +08:00
_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();
_preProjection = Director::getInstance()->getProjection();
Director::getInstance()->setProjection(Director::Projection::_3D);
2019-06-30 11:36:52 +08:00
Director::getInstance()->getRenderer()->setDepthTest(true);
2019-09-04 10:02:03 +08:00
Director::getInstance()->getRenderer()->setDepthWrite(true);
}
void CameraTest2::onExit()
{
Director::getInstance()->setProjection(_preProjection);
2019-06-30 11:36:52 +08:00
Director::getInstance()->getRenderer()->setDepthTest(false);
2019-09-04 10:02:03 +08:00
Director::getInstance()->getRenderer()->setDepthWrite(false);
TestCocosNodeDemo::onExit();
}
CameraTest2::CameraTest2()
{
auto s = Director::getInstance()->getWinSize();
_sprite1 = MySprite::create(s_back3);
2021-12-28 16:06:23 +08:00
addChild(_sprite1);
_sprite1->setPosition(Vec2(1 * s.width / 4, s.height / 2));
_sprite1->setScale(0.5);
_sprite2 = Sprite::create(s_back3);
2021-12-28 16:06:23 +08:00
addChild(_sprite2);
_sprite2->setPosition(Vec2(3 * s.width / 4, s.height / 2));
_sprite2->setScale(0.5);
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
Vec3 eye(150, 0, 200), center(0, 0, 0), up(0, 1, 0);
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
Mat4 lookupMatrix;
Mat4::createLookAt(eye, center, up, &lookupMatrix);
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
Mat4 lookupMatrix2 = lookupMatrix;
2014-04-08 23:05:33 +08:00
_sprite1->setAdditionalTransform(&lookupMatrix2);
_sprite2->setAdditionalTransform(&lookupMatrix2);
}
std::string CameraTest2::title() const
{
return "Camera Test 2";
}
std::string CameraTest2::subtitle() const
{
return "Both images should look the same";
}
//------------------------------------------------------------------
//
// NodeNormalizedPositionTest1
//
//------------------------------------------------------------------
NodeNormalizedPositionTest1::NodeNormalizedPositionTest1()
{
2021-12-28 16:06:23 +08:00
Sprite* sprites[5];
2014-06-05 00:48:35 +08:00
Vec2 positions[5];
2021-12-28 16:06:23 +08:00
positions[0] = Vec2(0.0f, 0.0f);
positions[1] = Vec2(0.0f, 1.0f);
positions[2] = Vec2(0.5f, 0.5f);
positions[3] = Vec2(1.0f, 0.0f);
positions[4] = Vec2(1.0f, 1.0f);
2021-12-28 16:06:23 +08:00
for (int i = 0; i < 5; i++)
{
sprites[i] = Sprite::create("Images/grossini.png");
sprites[i]->setPositionNormalized(positions[i]);
addChild(sprites[i]);
}
}
std::string NodeNormalizedPositionTest1::title() const
{
return "setNormalizedPositon()";
}
std::string NodeNormalizedPositionTest1::subtitle() const
{
return "5 sprites: One in the center, the others on the corners";
}
//------------------------------------------------------------------
//
// NodeNormalizedPositionTest2
//
//------------------------------------------------------------------
2021-12-28 16:06:23 +08:00
NodeNormalizedPositionTest2::NodeNormalizedPositionTest2() : _accum(0)
{
2021-12-28 16:06:23 +08:00
Sprite* sprites[5];
2014-06-05 01:11:16 +08:00
Vec2 positions[5];
2021-12-28 16:06:23 +08:00
positions[0] = Vec2(0.0f, 0.0f);
positions[1] = Vec2(0.0f, 1.0f);
positions[2] = Vec2(0.5f, 0.5f);
positions[3] = Vec2(1.0f, 0.0f);
positions[4] = Vec2(1.0f, 1.0f);
2021-12-28 16:06:23 +08:00
for (int i = 0; i < 5; i++)
{
sprites[i] = Sprite::create("Images/grossini.png");
sprites[i]->setPositionNormalized(positions[i]);
addChild(sprites[i]);
}
scheduleUpdate();
2021-12-28 16:06:23 +08:00
setContentSize(Director::getInstance()->getWinSize());
_copyContentSize = getContentSize();
2021-12-28 16:06:23 +08:00
// setAnchorPoint(Vec2(0.5,0.5));
// setPositionNormalized(Vec2(0.5,0.5));
}
std::string NodeNormalizedPositionTest2::title() const
{
return "setNormalizedPositon() #2";
}
std::string NodeNormalizedPositionTest2::subtitle() const
{
return "5 sprites: One in the center, the others on the corners of its parents";
}
void NodeNormalizedPositionTest2::update(float dt)
{
_accum += dt;
// for 5 seconds
float norm = sinf(_accum);
2021-12-28 16:06:23 +08:00
Size s = Size(_copyContentSize.width * norm, _copyContentSize.height * norm);
setContentSize(s);
2022-07-16 10:43:05 +08:00
AXLOG("s: %f,%f", s.width, s.height);
}
2014-09-01 11:29:40 +08:00
//------------------------------------------------------------------
//
// NodeNormalizedPositionBugTest
//
//------------------------------------------------------------------
2021-12-28 16:06:23 +08:00
NodeNormalizedPositionBugTest::NodeNormalizedPositionBugTest() : _accum(0)
2014-09-01 11:29:40 +08:00
{
Vec2 position;
2021-12-28 16:06:23 +08:00
position = Vec2(0.5f, 0.5f);
2014-09-01 11:29:40 +08:00
sprite = Sprite::create("Images/grossini.png");
sprite->setPositionNormalized(position);
2014-09-01 11:29:40 +08:00
addChild(sprite);
2021-12-28 16:06:23 +08:00
2014-09-01 11:29:40 +08:00
scheduleUpdate();
}
std::string NodeNormalizedPositionBugTest::title() const
{
return "NodeNormalizedPositionBugTest";
}
std::string NodeNormalizedPositionBugTest::subtitle() const
{
return "When changing sprite normalizedPosition, the sprite doesn't move!";
}
void NodeNormalizedPositionBugTest::update(float dt)
{
_accum += dt;
2021-12-28 16:06:23 +08:00
2014-09-01 11:29:40 +08:00
// for 5 seconds
float norm = clampf(sinf(_accum), 0, 1.0);
2021-12-28 16:06:23 +08:00
sprite->setPositionNormalized(Vec2(norm, norm));
2014-09-01 11:29:40 +08:00
}
std::string NodeNameTest::title() const
{
return "getName()/setName()/getChildByName()/enumerateChildren()";
}
std::string NodeNameTest::subtitle() const
{
return "see console";
}
void NodeNameTest::onEnter()
{
TestCocosNodeDemo::onEnter();
2021-12-28 16:06:23 +08:00
2022-07-15 19:17:01 +08:00
this->scheduleOnce(AX_CALLBACK_1(NodeNameTest::test, this), 0.05f, "test_key");
}
2016-05-18 16:26:13 +08:00
void NodeNameTest::onExit()
{
TestCocosNodeDemo::onExit();
}
void NodeNameTest::test(float dt)
{
auto parent = Node::create();
2021-12-28 16:06:23 +08:00
// setName(), getName() and getChildByName()
char name[20];
for (int i = 0; i < 10; ++i)
{
sprintf(name, "node%d", i);
auto node = Node::create();
node->setName(name);
parent->addChild(node);
}
2021-12-28 16:06:23 +08:00
for (int i = 0; i < 10; ++i)
{
sprintf(name, "node%d", i);
auto node = parent->getChildByName(name);
2021-12-28 15:58:56 +08:00
log("find child: %s", node->getName().data());
}
2021-12-28 16:06:23 +08:00
// enumerateChildren()
// name = regular expression
2021-12-28 16:06:23 +08:00
int i = 0;
parent = Node::create();
for (int i = 0; i < 100; ++i)
{
auto node = Node::create();
sprintf(name, "node%d", i);
node->setName(name);
parent->addChild(node);
}
2021-12-28 16:06:23 +08:00
i = 0;
parent->enumerateChildren("node[[:digit:]]+", [&i](Node* node) -> bool {
++i;
return false;
});
CCAssert(i == 100, "");
2021-12-28 16:06:23 +08:00
i = 0;
parent->enumerateChildren("node[[:digit:]]+", [&i](Node* node) -> bool {
++i;
return true;
});
CCAssert(i == 1, "");
2021-12-28 16:06:23 +08:00
// enumerateChildren
// name = node[[digit]]+/node
2021-12-28 16:06:23 +08:00
parent = Node::create();
for (int i = 0; i < 10; ++i)
{
auto node = Node::create();
sprintf(name, "node%d", i);
node->setName(name);
parent->addChild(node);
2021-12-28 16:06:23 +08:00
for (int j = 0; j < 10; ++j)
{
auto child = Node::create();
child->setName("node");
node->addChild(child);
}
}
2021-12-28 16:06:23 +08:00
i = 0;
parent->enumerateChildren("node1/node", [&i](Node* node) -> bool {
++i;
return false;
});
CCAssert(i == 10, "");
2021-12-28 16:06:23 +08:00
i = 0;
parent->enumerateChildren("node1/node", [&i](Node* node) -> bool {
++i;
return true;
});
CCAssert(i == 1, "");
2021-12-28 16:06:23 +08:00
2014-07-01 16:09:25 +08:00
// search from root
parent = Node::create();
for (int i = 0; i < 10; ++i)
{
auto node = Node::create();
sprintf(name, "node%d", i);
node->setName(name);
parent->addChild(node);
2021-12-28 16:06:23 +08:00
for (int j = 0; j < 10; ++j)
{
auto child = Node::create();
child->setName("node");
node->addChild(child);
}
}
2021-12-28 16:06:23 +08:00
i = 0;
parent->enumerateChildren("node[[:digit:]]+/node", [&i](Node* node) -> bool {
++i;
return false;
});
CCAssert(i == 100, "");
2021-12-28 16:06:23 +08:00
i = 0;
parent->enumerateChildren("node[[:digit:]]+/node", [&i](Node* node) -> bool {
++i;
return true;
});
CCAssert(i == 1, "");
2021-12-28 16:06:23 +08:00
2014-07-01 16:09:25 +08:00
// search from parent
// name is xxx/..
i = 0;
parent->getChildByName("node1")->enumerateChildren("node[[:digit:]]+/node/..", [&i](Node* node) -> bool {
++i;
return true;
});
CCAssert(i == 1, "");
2021-12-28 16:06:23 +08:00
i = 0;
parent->getChildByName("node1")->enumerateChildren("node[[:digit:]]+/node/..", [&i](Node* node) -> bool {
++i;
return false;
});
CCAssert(i == 100, "");
2021-12-28 16:06:23 +08:00
// name = //xxx : search recursively
parent = Node::create();
for (int j = 0; j < 10; j++)
{
auto node = Node::create();
sprintf(name, "node%d", j);
node->setName(name);
parent->addChild(node);
2021-12-28 16:06:23 +08:00
for (int k = 0; k < 10; ++k)
{
auto child = Node::create();
sprintf(name, "node%d", k);
child->setName(name);
node->addChild(child);
}
}
2021-12-28 16:06:23 +08:00
i = 0;
parent->enumerateChildren("//node[[:digit:]]+", [&i](Node* node) -> bool {
++i;
return false;
});
2021-12-28 16:06:23 +08:00
CCAssert(i == 110, ""); // 100(children) + 10(parent)
i = 0;
parent->enumerateChildren("//node[[:digit:]]+", [&i](Node* node) -> bool {
++i;
return true;
});
CCAssert(i == 1, "");
2021-12-28 16:06:23 +08:00
i = 0;
parent->getChildByName("node1")->enumerateChildren("//node[[:digit:]]+/..", [&i](Node* node) -> bool {
++i;
return false;
});
CCAssert(i == 110, "");
2021-12-28 16:06:23 +08:00
2014-06-26 14:05:30 +08:00
// utils::findChildren()
2021-12-28 16:06:23 +08:00
2014-06-26 14:05:30 +08:00
parent = Node::create();
for (int i = 0; i < 50; ++i)
{
auto child = Node::create();
child->setName("node");
parent->addChild(child);
}
auto findChildren = utils::findChildren(*parent, "node");
CCAssert(findChildren.size() == 50, "");
}
//------------------------------------------------------------------
//
// Issue16100Test
//
//------------------------------------------------------------------
void Issue16100Test::onEnter()
{
TestCocosNodeDemo::onEnter();
// create user camera
auto s = Director::getInstance()->getWinSize();
auto delay = DelayTime::create(0.1f);
2021-12-28 16:06:23 +08:00
auto f = CallFunc::create([this, s]() {
auto camera = Camera::createOrthographic(s.width * 2, s.height * 2, -1024, 1024);
camera->setCameraFlag(CameraFlag::USER1);
addChild(camera);
2021-12-28 16:06:23 +08:00
});
this->runAction(Sequence::createWithTwoActions(delay, f));
// grossini using default camera
auto sprite = Sprite::create("Images/grossini.png");
this->addChild(sprite);
2021-12-28 16:06:23 +08:00
sprite->setPosition(-200, s.height / 3);
auto moveby = MoveBy::create(2, Vec2(400.0f, 0.0f));
auto movebyback = moveby->reverse();
2021-12-28 16:06:23 +08:00
auto seq = Sequence::create(moveby, movebyback, nullptr);
auto forever = RepeatForever::create(seq);
sprite->runAction(forever);
sprite->setCameraMask((int)CameraFlag::DEFAULT);
// grossini's sister using user camera
auto sister = Sprite::create("Images/grossinis_sister1.png");
this->addChild(sister);
2021-12-28 16:06:23 +08:00
sister->setPosition(-200, s.height * 2 / 3);
auto moveby1 = MoveBy::create(2, Vec2(400.0f, 0.0f));
auto movebyback1 = moveby1->reverse();
2021-12-28 16:06:23 +08:00
auto seq1 = Sequence::create(moveby1, movebyback1, nullptr);
auto forever1 = RepeatForever::create(seq1);
sister->runAction(forever1);
sister->setCameraMask((int)CameraFlag::USER1);
}
void Issue16100Test::onExit()
{
TestCocosNodeDemo::onExit();
}
std::string Issue16100Test::title() const
{
return "Issue 16100";
}
std::string Issue16100Test::subtitle() const
{
return "Sprite should appear on the screen";
}
//------------------------------------------------------------------
//
// Issue16735Test
//
//------------------------------------------------------------------
void Issue16735Test::onEnter()
{
TestCocosNodeDemo::onEnter();
auto visibleSize = Director::getInstance()->getVisibleSize();
2021-12-28 16:06:23 +08:00
auto origin = Director::getInstance()->getVisibleOrigin();
auto sprite1 = Sprite::create("Images/grossini.png");
sprite1->setPosition(Vec2(visibleSize / 2) + origin);
addChild(sprite1);
auto sprite2 = Sprite::create("Images/grossini.png");
sprite2->setPosition(Vec2(visibleSize / 2) + origin);
sprite2->setSkewX(30);
sprite2->setScale(2);
sprite2->setRotation(30);
addChild(sprite2);
auto d = DrawNode::create();
2021-12-28 16:06:23 +08:00
d->drawLine(Vec2(origin.x, origin.y + visibleSize.height / 2),
Vec2(origin.x + visibleSize.width, origin.y + visibleSize.height / 2), Color4F::RED);
d->drawLine(Vec2(origin.x + visibleSize.width / 2, origin.y),
Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height), Color4F::RED);
addChild(d);
}
void Issue16735Test::onExit()
{
TestCocosNodeDemo::onExit();
}
std::string Issue16735Test::title() const
{
return "Issue 16735";
}
std::string Issue16735Test::subtitle() const
{
return "Sprite should appear on the center of screen";
}