# How to get a dimetric projection ?

Hello.

I would like to render a cube with a dimetric view :

• the edge of the cube should render as a 2:1 line of pixels (see )
• two of the three angles between the axes are equal (116.565°, 116.565°, 126.87°) (see )

My question are :

• what are the corresponding camera rotations to form a dimetric perspective ?
• why does my code not work when i make a rotation of (90 - 26.565)° and 45° (i must do 55 then 45, see ) ?

Regards.

 a link on sometric perspectives http://en.wikipedia.org/wiki/Isometric_projection#Blurring_of_the_definition

 my code

`````` // g++ -Wall -o foo foo.cc -lGL -lglut

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>

float angle = 55;

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);

glPushMatrix();

// Begin of the section where i don't know what to do
glRotatef(angle, 1.0, 0.0, 0.0);
glRotatef(45, 0.0, 0.0, 1.0);
// End

glScalef(1.0, 1.0, 0.5);
glutWireCube(1);

glPopMatrix();

glFlush ();
}

void reshape(int w, int h)
{
h = w;

glViewport (0, 0, w, h);

glMatrixMode (GL_PROJECTION);

glOrtho(-2, 2, -2, 2, -2, 2);
}

void keyboard (unsigned char key, int x, int y)
{
switch (key) {
case 'a':
angle += 0.1;
printf("%g
", angle);
break;
case 'z':
angle -= 0.1;
printf("%g
", angle);
break;
case 27:
exit(0);
break;
default:
break;
}
glutPostRedisplay();
}

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(250, 250);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv);

glClearColor (0.0, 0.0, 0.0, 0.0);
glColor3f(1.0, 1.0, 0.0);

glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}

``````

No one else seems to have responded so here is some code to do a cavalier view (google for the matrix values you need for any other dimetric view)

GLfloat cavalier_view = {1 ,0 ,0 ,0,
0 ,1 ,0 ,0,
0.555360367,0.555360367,1 ,0,
0 ,0 ,0 ,1};

glMatrixMode( GL_PROJECTION );
glOrtho(-ScreenData.draw_win_width ,ScreenData.draw_win_width,
-ScreenData.draw_win_height,ScreenData.draw_win_height,
ScreenData.draw_win_depth ,-ScreenData.draw_win_depth);
glMultMatrixf(cavalier_view);
glMatrixMode( GL_MODELVIEW);

Hi,

I’m not sure whether the problem you have is still unsolved, but since I had exactly the same problem last night, here is the way how I solved it:

The error in the posted code was just a small one:
You have to first multiply the cavalier matrix and then, after that, call the glOrtho command.

If you want to define the angle of this obligue projection, here is how it can be done:

``````
gl.glMatrixMode(GL_PROJECTION);

double[] cavalier = {
1, 0, Math.cos(Math.PI/4),0,
0, 1, Math.sin(Math.PI/4),0,
0, 0, 1,                  0,
0, 0, 0,                  1};

gl.glMultTransposeMatrixd(cavalier,0);
gl.glOrtho(-5, 5, -5, 5, -15, 15);

``````

Hope this helps you (or anyone having ever the same problem).

Best regards,
Oliver Demetz

I don’t know what you are doing, but the code I posted was taken straight from a working application where it works fine. (wrote the app back in 2000 as part of a graphics assignment at uni)