Classes/Camera/CameraLesson6.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 CameraLesson6::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(CameraLesson6::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);
    auto sizeInpixels = Director::getInstance()->getWinSizeInPixels();
    auto size = Director::getInstance()->getWinSize();
    auto fboSize = Size(sizeInpixels.width * 1, sizeInpixels.height * 1.5);
    auto fbo = experimental::FrameBuffer::create(1, fboSize.width, fboSize.height);
    auto rt = experimental::RenderTarget::create(fboSize.width, fboSize.height);
    auto rtDS = experimental::RenderTargetDepthStencil::create(fboSize.width, fboSize.height);
    fbo->attachRenderTarget(rt);
    fbo->attachDepthStencilTarget(rtDS);
    auto sprite = Sprite::createWithTexture(fbo->getRenderTarget()->getTexture());
    sprite->setScale(0.3);
    sprite->runAction(RepeatForever::create(RotateBy::create(1, 90)));
    sprite->setPosition(size.width/2, size.height/2);
    addChild(sprite);
    auto camera = Camera::createPerspective(60, visibleSize.width / visibleSize.height, 1.f, 1000.f);
    camera->setCameraFlag(CameraFlag::USER1);
    camera->setPosition3D(Vec3(0, 0, 10));
    camera->setFrameBufferObject(fbo);
    fbo->setClearColor(Color4F(1,1,1,1));
    addChild(camera);
    std::string filename = "res/Sprite3D/orc.c3b";
    auto sprite2 = Sprite3D::create(filename);
    sprite2->setPosition3D(Vec3(0, 0, -10.f));
    addChild(sprite2);
    auto animation = Animation3D::create(filename);
    auto animate = Animate3D::create(animation);
    sprite2->runAction(RepeatForever::create(animate));
    sprite2->setCameraMask((unsigned short)CameraFlag::USER1);
    return true;
}
bool CameraLesson6 :: init ( ) { if ( ! Layer :: init ( ) ) { return false ; } Size visibleSize = Director :: getInstance ( ) -> getVisibleSize ( ) ; Vec2 origin = Director :: getInstance ( ) -> getVisibleOrigin ( ) ; auto closeItem = MenuItemImage :: create ( " " , " " , CC_CALLBACK_1 ( CameraLesson6 :: 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 ) ; auto sizeInpixels = Director :: getInstance ( ) -> getWinSizeInPixels ( ) ; auto size = Director :: getInstance ( ) -> getWinSize ( ) ; auto fboSize = Size ( sizeInpixels . width * 1 , sizeInpixels . height * 1.5 ) ; auto fbo = experimental :: FrameBuffer :: create ( 1 , fboSize . width , fboSize . height ) ; auto rt = experimental :: RenderTarget :: create ( fboSize . width , fboSize . height ) ; auto rtDS = experimental :: RenderTargetDepthStencil :: create ( fboSize . width , fboSize . height ) ; fbo -> attachRenderTarget ( rt ) ; fbo -> attachDepthStencilTarget ( rtDS ) ; auto sprite = Sprite :: createWithTexture ( fbo -> getRenderTarget ( ) -> getTexture ( ) ) ; sprite -> setScale ( 0.3 ) ; sprite -> runAction ( RepeatForever :: create ( RotateBy :: create ( 1 , 90 ) ) ) ; sprite -> setPosition ( size . width / 2 , size . height / 2 ) ; addChild ( sprite ) ; auto camera = Camera :: createPerspective ( 60 , visibleSize . width / visibleSize . height , 1.f , 1000.f ) ; camera -> setCameraFlag ( CameraFlag :: USER1 ) ; camera -> setPosition3D ( Vec3 ( 0 , 0 , 10 ) ) ; camera -> setFrameBufferObject ( fbo ) ; fbo -> setClearColor ( Color4F ( 1 , 1 , 1 , 1 ) ) ; addChild ( camera ) ; std :: string filename = " " ; auto sprite2 = Sprite3D :: create ( filename ) ; sprite2 -> setPosition3D ( Vec3 ( 0 , 0 , -10.f ) ) ; addChild ( sprite2 ) ; auto animation = Animation3D :: create ( filename ) ; auto animate = Animate3D :: create ( animation ) ; sprite2 -> runAction ( RepeatForever :: create ( animate ) ) ; sprite2 -> setCameraMask ( ( unsigned short ) CameraFlag :: USER1 ) ; 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 "CameraLesson6" splash screen" //create Sprite3D