Drawing a random x,y grid of objects within a prespective

Posted by T Reddy on Game Development See other posts from Game Development or by T Reddy
Published on 2013-10-29T21:41:04Z Indexed on 2013/10/29 22:22 UTC
Read the original article Hit count: 297

Filed under:

I'm wrapping my head around OpenGL ES 2.0 and I think I'm trying to do something very simple, but I think the math may be eluding me.

I created a simple, flat-ish cylinder in Blender that is 2 units in diameter. I want to create an arbitrary grid of these edge to edge (think of a checker board).

I'm using a 3D perspective with GLKit:

    CGSize size = [[self view] bounds].size;
    _projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(45.0f), size.width/size.height, 0.1f, 100.0f);

So, I managed to manually get all of these cylinders drawn on the screen just fine. However, I would like to understand how I can programmatically "fit" all of these cylinders on the screen at the same time given the camera location, screen size, cylinder diameter, and the number of rows/columns.

So the net effect is that for small grids (i.e., 5x5) the objects are closer to the camera, but for large grids (i.e., 30x30) the objects are farther away. In either case, all of the cylinders are visible.

© Game Development or respective owner

Related posts about opengl-es2