views:

312

answers:

2

Hello, I'm planning to create a tiled world with OpenGL, with slightly rotated tiles and houses and building in the world will be made of models. Can anybody suggest me what projection(Orthogonal, Perspective) should I use, and how to setup the View matrix(using OpenGL)?

If you can't figure what style of world I'm planning to create, look at this game: http://www.youtube.com/watch?v=i6eYtLjFu-Y&feature=PlayList&p=00E63EDCF757EADF&index=2

+2  A: 
Jon Watte
Wait, so, what do you mean by tile position and camera position?
Tamir
Good answer, but if you want to be direct, take a look here:http://irrlicht.sourceforge.net/docu/example006.html
eMgz
You obviously didn't get me.I know the tiles are 2D, but it involves the usage of models.If you take a better look in the video, you'll figure that the houses are models.
Tamir
My answer is specifically intended for 3D models on a 2D plane (although you could use it for quads, too, I suppose).And, by "camera" and "tile" position, I mean just that -- the camera's position in (imagined) world space, and the tile's (model's) position in (imagined) world space.
Jon Watte
+1  A: 

The projection used by that video game looks Oblique to me. There are many different projections, not just perspective and orthographic. See here for a list of the most common ones: http://en.wikipedia.org/wiki/File:Graphical_projection_comparison.png

You definitely want perspective, with a fixed rotation around the X-axis only. Around 45-60 degrees or thereof. If you don't care about setting up the projection code yourself, the gluPerspective function from the GLU library is handy. Assuming OpenGL 2.1:

glMatrixMode(GL_PROJECTION); //clip matrix
glLoadIdentity();
gluPerspective(90.0, width/height, 1.0, 20.0);
glMatrixMode(GL_MODELVIEW); //world/object matrix
glLoadIdentity();
glRotatef(45.0f, 1.0f, 0.0f, 0.0f);
/* render   */

The last two parameters to gluPerspective is the distance to the near and far clipping planes. Their values depend on the scale you use for the environment.

Mads Elvheim
Alright, thank you.So basically, this is the setup for the camera, and how do I scroll, and draw 2D tiles for example?I would be happy to get some information about the scale of the locations, like one unit as in twenty pixels, or what?
Tamir
With a perspective projection, units don't map to pixels. And definitely not in a linear manner. And you're asking too many questions for me to answer here in the comment field.
Mads Elvheim
I know unit don't map to pixels, I'm asking about the scale.What should be the interval of positioning between after each tile for example?
Tamir
That would depend on the size of the tile. With a perspective projection, x and y is scaled by z. That is, z is plugged into w, and then x, y and z is divided by w.
Mads Elvheim
Okay, so my solution was using a simple unit of 1 as the size of a tile in both factors (x, y).But now I get a little space between each tile, maybe it's because of a defect when loading the texture, here is my code: http://kono.pastebin.com/6sxqasph sorry for the shitty code.Thank you for your relevant answer.
Tamir
Tamir: Everything you're asking now is like 4-5 new questions. I'll gladly help you more on a more direct manner. If you have IRC, please come to ##OpenGL on FreeNode. I don't promise I have an answer for everything though.
Mads Elvheim