コード例 #1
0
ファイル: NodeTest.cpp プロジェクト: HongXiao/Client-source
CameraZoomTest::CameraZoomTest()
{
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    CCSprite *sprite;
    CCCamera *cam;
    
    // LEFT
    sprite = CCSprite::create(s_pPathGrossini);
    addChild( sprite, 0);        
    sprite->setPosition( ccp(s.width/4*1, s.height/2) );
    cam = sprite->getCamera();
    cam->setEyeXYZ(0, 0, 415/2);
    cam->setCenterXYZ(0, 0, 0);
    
    // CENTER
    sprite = CCSprite::create(s_pPathGrossini);
    addChild( sprite, 0, 40);
    sprite->setPosition(ccp(s.width/4*2, s.height/2));
    
    // RIGHT
    sprite = CCSprite::create(s_pPathGrossini);
    addChild( sprite, 0, 20);
    sprite->setPosition(ccp(s.width/4*3, s.height/2));

    m_z = 0;
    scheduleUpdate();
}
コード例 #2
0
ファイル: Recipe72.cpp プロジェクト: DPigpen/cocos2dx_recipe
bool Recipe72::init()
{
    if ( !RecipeBase::init() )
    {
        return false;
    }
        
    CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Thonburi", 34);
    pLabel->setColor(ccBLACK);
    
    // ask director the window size
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    
    // position the label on the center of the screen
    pLabel->setPosition( ccp(size.width / 2, size.height - 20) );
    
    // add the label as a child to this layer
    this->addChild(pLabel, 1);
    
    // add "HelloWorld" splash screen"
    CCSprite* pSprite = CCSprite::create("HelloWorld.png");
    
    // position the sprite on the center of the screen
    pSprite->setPosition( ccp(size.width/2, size.height/2) );
    
    // add the sprite as a child to this layer
    this->addChild(pSprite, 0);
    
    /*
     float x=0, y=0, z=0;
     this->getCamera()->getCenterXYZ(&x, &y, &z);
     this->getCamera()->setCenterXYZ(x, y+0.0000001, z);
     */
    /*
     float x=0, y=0, z=0;
     this->getCamera()->getEyeXYZ(&x, &y, &z);
     this->getCamera()->setEyeXYZ(x, y, 200);
     */
    //this->scheduleUpdate();
    
    //CCDirector::sharedDirector()->setDepthTest(false);
    
    CCCamera* pCamera = this->getCamera();
    pCamera->setEyeXYZ(10.0f, 20.0f, 20.0f);
    pCamera->setCenterXYZ(0, 0, 0);
    pCamera->setUpXYZ(0.0f, 1.0f, 0.0f);
    
    return true;
}
コード例 #3
0
void 
CPrimitiveScene::draw()
{    
    CCCamera* pCamera = CCDirector::sharedDirector()->getRunningScene()->getCamera();
    pCamera->setEyeXYZ(0,0,10);
    pCamera->setCenterXYZ(-50.0f, -50.0f, 0);

    // open yellow poly
    ccDrawColor4B(255, 255, 0, 255);
    glLineWidth(10);
    ccVertex3F vertices[] = { vertex3(0,0,0), vertex3(50,50,0), vertex3(100,50,0), vertex3(100,100,0), vertex3(50,100,0.1) };
        
    s_pShader->use();
    s_pShader->setUniformForModelViewProjectionMatrix();
    s_pShader->setUniformLocationWith4fv(s_nColorLocation, (GLfloat*) &s_tColor.r, 1);

    ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );


    int numberOfPoints = 5;
    // XXX: Mac OpenGL error. arrays can't go out of scope before draw is executed
    ccVertex3F* newPoli = new ccVertex3F[numberOfPoints];

    // iPhone and 32-bit machines optimization
    if( sizeof(CCPoint) == sizeof(ccVertex3F) )
    {
        glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, 0, vertices);
    }
    else
    {
        // Mac on 64-bit
        for( unsigned int i=0; i<numberOfPoints;i++)
        {
            newPoli[i] = vertex3( vertices[i].x, vertices[i].y, vertices[i].z );
        }
        glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, 0, newPoli);
    }    

    glDrawArrays(GL_TRIANGLE_FAN, 0, (GLsizei) numberOfPoints);

    CC_SAFE_DELETE_ARRAY(newPoli);
    CC_INCREMENT_GL_DRAWS(1);
}