IOS OpenGL ES - 围绕场景旋转相机

时间:2012-03-01 14:04:03

标签: opengl-es ios5 camera perspective

这是我的代码:

- (void)drawView {

    // Define square for flowers head (vertecies)

    const GLfloat flowerHead[] = {

        -1.0, 1.0, 1.0,             // top left
        -1.0, -1.0, 1.0,            // bottom left
        1.0, -1.0, 1.0,             // bottom right
        1.0, 1.0, 1.0

    };

    // Define the texture coordinates --> as the flowerHead vertecies

    const GLshort flowerHeadTextureCoord[] = {

        0, 1,       // top left
        0, 0,       // bottom left
        1, 0,       // bottom right
        1, 1        // top right

    };

    rota = 1.0;

    [EAGLContext setCurrentContext:context];    
    glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
    glViewport(0, 0, backingWidth, backingHeight);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    glMatrixMode(GL_MODELVIEW);

    glTexCoordPointer(2, GL_SHORT, 0, flowerHeadTextureCoord);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    // flower #1
    glPushMatrix();

    {
        glEnable(GL_ALPHA_TEST); // enable alpha -> transparency state
        glTranslatef(0.0, 0.0, -6.0); // positioning the flower      
        glRotatef(55.0, 1.0, 0.0, 0.0); // rotate flower on (x) axis
        glVertexPointer(3, GL_FLOAT, 0, flowerHead); // pointer to the flowerHead vertecies array
        glEnableClientState(GL_VERTEX_ARRAY); // enable the vertex array state


        // Draw the front face
        // Bind texture
        glBindTexture(GL_TEXTURE_2D, textures[0]);        
        glDrawArrays(GL_TRIANGLE_FAN, 0, 4);       


    }

    glPopMatrix();

    glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
    [context presentRenderbuffer:GL_RENDERBUFFER_OES];

    [self checkGLError:NO];
}

现在这是我的绘图代码......我现在需要的是围绕对象旋转相机(而不是对象本身)......

我的setupView功能:

const GLfloat zNear = 0.1, zFar = 1000.0, fieldOfView = 60.0;
    GLfloat size;

    // Set the general polygon properties - for transparency!!!
    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
    glAlphaFunc(GL_GREATER,0.1f);

    glEnable(GL_DEPTH_TEST);
    glMatrixMode(GL_PROJECTION);
    size = zNear * tanf(DEGREES_TO_RADIANS(fieldOfView) / 2.0);

    // This give us the size of the iPhone display
    CGRect rect = self.bounds;
    glFrustumf(-size, size, -size / (rect.size.width / rect.size.height), size / (rect.size.width / rect.size.height), zNear, zFar);
    glViewport(0, 0, rect.size.width, rect.size.height);

    glClearColor(0.0f, 0.0f, 0.0f, 0.5f);

0 个答案:

没有答案