Isometric 2:1 projection in OpenGL

Started by
0 comments, last by shurcool 17 years, 7 months ago
Hi there, I am having problems getting my projection just right. I want a orthographic projection of my world such that it looks just like SimCity 2000, Transport tycoon etc. E.g. I want tiles with a 2:1 ratio on screen.

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-400, +400, -300, +300, -1000, +1000);
glRotated(-orthoAngle, 1, 0, 0);
glRotated(45, 0, 0, 1);

With the angle I calculated having to be arctangens of 2.

double PI = std::acos(-1);
double orthoAngle = (std::atan(2) * 180) / PI;

Now this is nearly correct, it the orthoAngle variable is set to about 63.43 degrees. Now this gives some artifacts in my world, such as the tiles that are being drawn are not exactly in the 2:1 ratio. An orthoAngle of about ~62.09 seems to do a better job. Obviously I don't want to have to fill in a random constant like that and I would like to get the theory right. Could anyone help me out?? The result of the original projection is as follows: CLICK! Kind regards, Mark
Advertisement
Your orthoAngle should be exactly 60 degrees, calculcated by acos(0.5).

That should fix your first problem of the lines not being drawn at exactly 1/2 slope.

After that, you will probably have to scale the projection in such a way, that the vertices in 3D coordinates end up being projected into the very center of every pixel, as opposed to a varying location.

This topic is closed to new replies.

Advertisement