2011-11-02 1 views
-1

OpenGL ES를 사용하여 큐브를 그렸습니다. 위의 관점을 원합니다. 그러나 무엇을 수정해야할지 모르겠는데 ... 아마도 도움이 될 수 있습니다.OpenGL ES에서 3D 큐브의 원근감을 변경하는 방법은 무엇입니까?

- (void)render:(CADisplayLink*)displayLink { 
    //-(void) render{ 

    glClearColor(255.0, 255.0/255.0, 255.0/255.0, 1.0); 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    glEnable(GL_DEPTH_TEST);  

    //projection 
    CC3GLMatrix *projection = [CC3GLMatrix matrix]; 
    float h = 4.0f * self.frame.size.height/self.frame.size.width; 


    [projection populateFromFrustumLeft:-2 andRight:2 andBottom:-h/2 andTop:h/2 andNear:4 andFar:8]; 

     glUniformMatrix4fv(_projectionUniform, 1, 0, projection.glMatrix); 

    CC3GLMatrix *modelView = [CC3GLMatrix matrix]; 

    // _currentScaling += displayLink.duration * 1.0; 


    [modelView populateFromTranslation:CC3VectorMake(sin(30), _currentScaling , -7)]; 

    [modelView rotateBy:CC3VectorMake(0, -15, 0)]; 


    // [modelView scaleByY:_currentScaling]; 


    if(_currentScaling > 2){ 
     [displayLink invalidate]; 

     _running = 1; 
    // scale = 0; 
    } 

    glUniformMatrix4fv(_modelViewUniform, 1, 0, modelView.glMatrix); 

    // 1 
    glViewport(0, 0, self.frame.size.width, self.frame.size.height); 

    // 2 
    glVertexAttribPointer(_positionSlot, 3, GL_FLOAT, GL_FALSE, 
          sizeof(Vertex), 0); 
    glVertexAttribPointer(_colorSlot, 4, GL_FLOAT, GL_FALSE, 
          sizeof(Vertex), (GLvoid*) (sizeof(float) * 3)); 

    // 3 
    glDrawElements(GL_TRIANGLES, sizeof(Indices)/sizeof(Indices[0]), 
        GL_UNSIGNED_BYTE, 0); 

    [_context presentRenderbuffer:GL_RENDERBUFFER]; 
} 

답변

1

나는 최근에 OpenGL을 직접보고 시작하여 this same example을 발견했습니다.

[modelView rotateBy:CC3VectorMake(0, -15, 0)]; 

을하고 X, Y, Z 축에 원하는 회전 각도를 지정 : 난 당신이 관점을 변경하려면이 줄을 변경하기위한 것입니다 찾고있는 것을 믿습니다.

관련 문제