void CCOrbitCamera::sphericalRadius(float *newRadius, float *zenith, float *azimuth)
{
    float ex, ey, ez, cx, cy, cz, x, y, z;
    float r; // radius
    float s;

    CCCamera* pCamera = m_pTarget->getCamera();
    pCamera->getEyeXYZ(&ex, &ey, &ez);
    pCamera->getCenterXYZ(&cx, &cy, &cz);

    x = ex-cx;
    y = ey-cy;
    z = ez-cz;

    r = sqrtf( powf(x,2) + powf(y,2) + powf(z,2));
    s = sqrtf( powf(x,2) + powf(y,2));
    if( s == 0.0f )
        s = FLT_EPSILON;
    if(r==0.0f)
        r = FLT_EPSILON;

    *zenith = acosf( z/r);
    if( x < 0 )
        *azimuth= (float)M_PI - asinf(y/s);
    else
        *azimuth = asinf(y/s);

    *newRadius = r / CCCamera::getZEye();                
}
Example #2
0
CameraZoomTest::CameraZoomTest()
{
	CCSize s = CCDirector::sharedDirector()->getWinSize();
	
	CCSprite *sprite;
	CCCamera *cam;
	
	// LEFT
	sprite = CCSprite::spriteWithFile(s_pPathGrossini);
	addChild( sprite, 0);		
	sprite->setPosition( CCPointMake(s.width/4*1, s.height/2) );
	cam = sprite->getCamera();
	cam->setEyeXYZ(0, 0, 415);
	
	// CENTER
	sprite = CCSprite::spriteWithFile(s_pPathGrossini);
	addChild( sprite, 0, 40);
	sprite->setPosition(CCPointMake(s.width/4*2, s.height/2));
//		cam = [sprite camera);
//		[cam setEyeX:0 eyeY:0 eyeZ:415/2);
	
	// RIGHT
	sprite = CCSprite::spriteWithFile(s_pPathGrossini);
	addChild( sprite, 0, 20);
	sprite->setPosition(CCPointMake(s.width/4*3, s.height/2));
//		cam = [sprite camera);
//		[cam setEyeX:0 eyeY:0 eyeZ:-485);
//		[cam setCenterX:0 centerY:0 centerZ:0);

	m_z = 0;
	scheduleUpdate();
}
Example #3
0
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();
}
Example #4
0
	//
	// CameraAction
	//
	void CCActionCamera::startWithTarget(CCNode *pTarget)
	{
		CCActionInterval::startWithTarget(pTarget);
		
		CCCamera *camera = pTarget->getCamera();
		camera->getCenterXYZ(&m_fCenterXOrig, &m_fCenterYOrig, &m_fCenterZOrig);
		camera->getEyeXYZ(&m_fEyeXOrig, &m_fEyeYOrig, &m_fEyeZOrig);
		camera->getUpXYZ(&m_fUpXOrig, &m_fUpYOrig, &m_fUpZOrig);
	}
Example #5
0
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;
}
Example #6
0
void CameraZoomTest::update(ccTime dt)
{
	CCNode *sprite;
	CCCamera *cam;
	
	m_z += dt * 100;
	
	sprite = getChildByTag(20);
	cam = sprite->getCamera();
	cam->setEyeXYZ(0, 0, m_z);
	
	sprite = getChildByTag(40);
	cam = sprite->getCamera();
	cam->setEyeXYZ(0, 0, m_z);	
}
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);
}