Converting OpenGL coordinates to lower UIView (and UIImagePickerController)

Posted by John Qualis on Stack Overflow See other posts from Stack Overflow or by John Qualis
Published on 2010-03-15T09:55:52Z Indexed on 2010/03/15 14:49 UTC
Read the original article Hit count: 144

Filed under:
|
|
|

I am new to OpenGL on the iPhone.

I am developing an iPhone app similar to a barcode reader but with an extra OpenGL layer. The bottommost layer is UIImagePickerController, then I use UIView on top and draw a rectangle at certain coordinates on the iPhone screen. So far everything is OK. Then I am trying to draw an OpenGL 3-D model in that rectangle. I am able to load a 3-D model in the iPhone based on this code here - http://iphonedevelopment.blogspot.com/2008/12/start-of-wavefront-obj-file-loader.html

I am not able to transform the coordinates of the rectangle into OpenGL coordinates. Appreciate any help.

Do I need to use a matrix to translate the currentPosition of the 3-D model so it is drawn within myRect? The code is given below.

-(void)setupView:(GLView*)view
{
    const GLfloat zNear = 0.01, zFar = 1000.0, fieldOfView = 45.0; 
    GLfloat size; 
    glEnable(GL_DEPTH_TEST);
    glMatrixMode(GL_PROJECTION); 

    size = zNear * tanf(DEGREES_TO_RADIANS(fieldOfView) / 2.0); 
    CGRect rect = view.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);  
    glMatrixMode(GL_MODELVIEW);

    glLoadIdentity(); 

    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    NSString *path = [[NSBundle mainBundle] pathForResource:@"plane" ofType:@"obj"];
    OpenGLWaveFrontObject *theObject = [[OpenGLWaveFrontObject alloc] initWithPath:path];
    Vertex3D position;
    position.z = -8.0;
    position.y = 3.0;
    position.x = 2.0;
        theObject.currentPosition = position;
    self.plane = theObject;
    [theObject release];
}

- (void)drawView:(GLView*)view;
{
    static GLfloat rotation = 0.0;

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity(); 
    glColor4f(0.0, 0.5, 1.0, 1.0);
        // the coordinates of the rectangle are
        // myRect.x, myRect.y, myRect.width, myRect.height
        // Do I need to use a matrix to translate the currentPosition of the
        // 3-D model so it is drawn within myRect?
    //glOrthof(-160.0f, 160.0f, -240.0f, 240.0f, -1.0f, 1.0f);
    [plane drawSelf];
}

© Stack Overflow or respective owner

Related posts about iphone

Related posts about opengles