Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / 3D Theory & Graphics / OpenGL projection matrix problem Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
insom

April 23, 2005, 07:47 PM

I'm quite new to OpenGL and I'm starting out by coding a bomberman clone. For those not familiar, it's a simple overhead tile-based game. Right now I am using glOrtho() to create an overhead view of the tile board (which is 15x15 tiles, 32 pixels per tile). I'm simply using textured quads to draw the tiles which covers all of the screen except for an empty strip on the right (for score etc). This method works fine and is incredibly easy to setup because the OpenGL coordinates I'm drawing to match the screen coordinates. So I'm drawing tiles starting from 0,0. This makes it easy on me but obviously makes the z-axis and depth buffer useless, and not a very 3D game.. I want to setup my view so that I can draw 15x15 tiles starting from the top left corner of the screen and use 3d objects for the tiles, not just textured quads. I know i could use gluPerspective() but I'm not very familiar with it. I still want an overhead view, and I want to be able to use the depth buffer and draw full 3-d objects... and eventually once I can get this coded and running implement a full 3-d camera class. Could anyone please help me with this simple problem.

I just want to setup an overhead view for a simple tilebased map (15x15) that matches perfectly with the screen edges (except for the right side of course). Please help...

 
Victor Widell

April 23, 2005, 08:29 PM

Just go ahead! There is nothing stoping you from using 3D objects and the depth buffer.

The scene you have right now is in fact fully 3D. It's just the projection that is done without perspective. If you put your objects behind eachother, they will occlude eachother.

To make the 3D a bit more interesting, you can use a "tennis court view", like "Chu-chu rocket" and "bomberman online" for Dreamcast. It's still mostly 2D, but with a slight perspective, so you can see the depth in the 3D objects.

 
Reedbeta

April 23, 2005, 09:06 PM

If I'm not mistaken, the glFrustum function will let you set up the perspective projection you want. It works almost the same way as the glOrtho function. The only difference is that the left/right/bottom/top parameters are specified at the near plane, which will be closer than the game world. So you must calculate the left parameter as old_left * near_distance / world_distance, where old_left is the left parameter you passed to glOrtho, and near_distance and world_distance are the distances from the camera to the near plane and the plane of the game world.

Note however that the center of projection is at (0, 0, 0) - so calling (for example) glFrustum(0, 15, 0, 15) will make things in the lower-left corner look like a pure top-down view with perspective becoming visible as you move up and right. You might want to use glFrustum(-7.5, 7.5, -7.5, 7.5) to balance this, and you can then apply a translation to remap the coordinates back to (0, 15)x(0, 15) if you desire.

 
This thread contains 3 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.