views:

42

answers:

0

Seem like I'm not clearing the image correctly or something. On the other hand the view takes to much to render using the cos function. I appreciate if you can guide me to optmize the code with best practices. Thanks

And I would like to share with you this link: http://iphonedevelopment.blogspot.com/2009/05/opengl-es-from-ground-up-table-of.html

alt text

Render function inside Thumbnail3D

-(void)render
{
    Triangle3D  triangle[2];
    triangle[0].v1 = Vertex3DMake( (-width * 0.5 ) + x, (-height * 0.5 ) + y, z);
    triangle[0].v2 = Vertex3DMake( ( width * 0.5 ) + x, ( height * 0.5 ) + y, z);
    triangle[0].v3 = Vertex3DMake( (-width * 0.5 ) + x, ( height * 0.5 ) + y, z);
    triangle[1].v1 = Vertex3DMake( (-width * 0.5 ) + x, (-height * 0.5 ) + y, z);
    triangle[1].v2 = Vertex3DMake( ( width * 0.5 ) + x, ( height * 0.5 ) + y, z);
    triangle[1].v3 = Vertex3DMake( ( width * 0.5 ) + x, (-height * 0.5 ) + y, z);
    glLoadIdentity();
    glColor4f(color.red, color.green, color.blue, color.alpha);
    glVertexPointer(3, GL_FLOAT, 0, &triangle);
    glDrawArrays(GL_TRIANGLES, 0, 18);

}

drawView function inside OpenGL View

- (void)drawView:(UIView *)theView
{

    NSInteger elements = 6;
    GLfloat angle = DEGREES_TO_RADIANS( 360 / elements );
    GLfloat elementWidth = 3.0;
    //GLfloat l = ( elements * ( elementWidth + 0.2 ) ) * (elements / 300000);
    GLfloat l = elements * ( elementWidth + 0.2 ) ;
    GLfloat radius = l / (2 * M_PI);



    glLoadIdentity();
    glClearColor(1.0, 1.0, 1.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnableClientState(GL_VERTEX_ARRAY);

    for (int columns = 0; columns < elements; columns++) 
    {
        for (int rows = 0; rows < 1; rows++) 
        {

            Thumbnail3D *thumbnail = [ [ Thumbnail3D alloc ] init ];
            thumbnail.color = Color3DMake(1.0, 0.0, 0.0, 1.0);

            thumbnail.width = 3.0;
            thumbnail.height = 2.0;

            thumbnail.x = ( ( thumbnail.width + 0.2 ) * columns ) - 3;
            //thumbnail.y = ( ( thumbnail.height + 0.2  ) * rows ) - 5;

            //thumbnail.x = sin( angle * columns ) / radius;
            thumbnail.y = ( cos( angle * columns ) / radius );
            thumbnail.z = -18;

            NSLog(@"Drawing  n%d: { radius: %f }, { angle: %f }, { x: %f }, { y: %f }", columns, radius, angle, sin( angle * columns ) / radius,cos( angle * columns ) / radius);
            NSLog(@"Drawing in: { x: %f }, { y: %f }, { z: %f }", thumbnail.x, thumbnail.y, thumbnail.z);

            [ thumbnail render ];
            [ thumbnail release ];

        }
    }

     glDisableClientState(GL_VERTEX_ARRAY);
}