views:

125

answers:

1

Hi,

I am new to OpenGL over 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 co-ordinates 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 co-ordinates of the rectangle into OpenGL co-ordinates. 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.. Appreciate any help/pointers in this regards.

John

- (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 a transform matrix here?  
    //glOrthof(-160.0f, 160.0f, -240.0f, 240.0f, -1.0f, 1.0f);  
    [plane drawSelf];  
   ....
}

-(void)setupView:(GLView*)view  
{  
    const GLfloat zNear = 0.01, zFar = 1000.0, fieldOfView = 45.0;     
    GLfloat size;   
    glEnable(GL_DEPTH_TEST);  
    glMatrixMode(GL_PROJECTION);   
    //glMatrixMode(GL_MODELVIEW);   
    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);  
}  
A: 

hi everyone.....i have the same query...anyone help??

Rony