2011-11-02 78 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轴的旋转角度。