Classes/Camera/CameraLesson5.cpp
// on "init" you need to initialize your instance
on "init" you need to initialize your instance
on " init " you need to initialize your instance
bool CameraLesson5::init()
{
    if ( !Layer::init() )
    {
        return false;
    }
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    auto closeItem = MenuItemImage::create(
                                           "CloseNormal.png",
                                           "CloseSelected.png",
                                           CC_CALLBACK_1(CameraLesson5::menuCloseCallback, this));
	closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
                                origin.y + closeItem->getContentSize().height/2));
    auto menu = Menu::create(closeItem, NULL);
    menu->setPosition(Vec2::ZERO);
    this->addChild(menu, 1);
    std::string filename = "res/Sprite3D/orc.c3b";
    auto sprite = Sprite3D::create(filename);
    sprite->setPosition3D(Vec3(0, 0, -10.f));
    addChild(sprite);
    auto animation = Animation3D::create(filename);
    auto animate = Animate3D::create(animation);
    sprite->runAction(RepeatForever::create(animate));
    auto camera = Camera::createPerspective(60, visibleSize.width / visibleSize.height, 1.f, 1000.f);
    camera->setCameraFlag(CameraFlag::USER1);
    camera->setPosition3D(Vec3(0, 0, 10.f));
    camera->lookAt(Vec3(0, 0, 0));
    addChild(camera);
    _camera = camera;
    auto screenpos = camera->projectGL(Vec3(0,5,0));
    CCLOG("%f, %f", screenpos.x, screenpos.y);
    sprite->setCameraMask((unsigned short)CameraFlag::USER1);
    auto listener = EventListenerTouchAllAtOnce::create();
    listener->onTouchesEnded = CC_CALLBACK_2(CameraLesson5::onTouchesEnded, this);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
    return true;
}
bool CameraLesson5 :: init ( ) { if ( ! Layer :: init ( ) ) { return false ; } Size visibleSize = Director :: getInstance ( ) -> getVisibleSize ( ) ; Vec2 origin = Director :: getInstance ( ) -> getVisibleOrigin ( ) ; auto closeItem = MenuItemImage :: create ( " " , " " , CC_CALLBACK_1 ( CameraLesson5 :: menuCloseCallback , this ) ) ; closeItem -> setPosition ( Vec2 ( origin . x + visibleSize . width - closeItem -> getContentSize ( ) . width / 2 , origin . y + closeItem -> getContentSize ( ) . height / 2 ) ) ; auto menu = Menu :: create ( closeItem , NULL ) ; menu -> setPosition ( Vec2 :: ZERO ) ; this -> addChild ( menu , 1 ) ; std :: string filename = " " ; auto sprite = Sprite3D :: create ( filename ) ; sprite -> setPosition3D ( Vec3 ( 0 , 0 , -10.f ) ) ; addChild ( sprite ) ; auto animation = Animation3D :: create ( filename ) ; auto animate = Animate3D :: create ( animation ) ; sprite -> runAction ( RepeatForever :: create ( animate ) ) ; auto camera = Camera :: createPerspective ( 60 , visibleSize . width / visibleSize . height , 1.f , 1000.f ) ; camera -> setCameraFlag ( CameraFlag :: USER1 ) ; camera -> setPosition3D ( Vec3 ( 0 , 0 , 10.f ) ) ; camera -> lookAt ( Vec3 ( 0 , 0 , 0 ) ) ; addChild ( camera ) ; _camera = camera ; auto screenpos = camera -> projectGL ( Vec3 ( 0 , 5 , 0 ) ) ; CCLOG ( " " , screenpos . x , screenpos . y ) ; sprite -> setCameraMask ( ( unsigned short ) CameraFlag :: USER1 ) ; auto listener = EventListenerTouchAllAtOnce :: create ( ) ; listener -> onTouchesEnded = CC_CALLBACK_2 ( CameraLesson5 :: onTouchesEnded , this ) ; _eventDispatcher -> addEventListenerWithSceneGraphPriority ( listener , this ) ; return true ; }
on "init" you need to initialize your instance
on " init " you need to initialize your instance
////////////////////////////// // 1. super init first ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program //    you may modify it. // add a "close" icon to exit the progress. it's an autorelease object // create menu, it's an autorelease object ///////////////////////////// // 3. add your codes below... // add a label shows "Hello World" // create and initialize a label // add "CameraLesson5" splash screen" //create Sprite3D