2011-11-02 119 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軸的旋轉角度。