Making an isometric view

Hi. I am experimenting with different projections, and I am trying to make an isometric view of a house.

I want to do this again by supplying my own matrices, but I am having a little trouble figurring out how I should rotate my objects.
I was thinking about rotating the objects 45 degrees around the z-axis, but this seems to be a bit off.
And then I need something more.

I was hoping to get a little advise in here.

The following are the 2 abjects (the house and profile) that i need to make an isometric view of.

Hope not this is too much.
Many regards

void ctrlpolygon (void) {
int i;

GLfloat ctrlpoints [5][3] = {{0.,0.,0.},{0.,0.,5.},{5.,0.,10.},{10.,0.,5.},{10.,0.,0.} };

glPointSize(5.0);
glColor3f(0.0, 1.0, 1.0);
glBegin(GL_POINTS);
	for (i = 0; i < 5; i++) 
		glVertex3fv(&ctrlpoints[i][0]);
glEnd();

glColor3f(0.0, 0.0, 0.0);
glBegin(GL_LINE_STRIP);
    for (i = 0; i < 5; i++) 
      glVertex3fv(&ctrlpoints[i][0]);
glEnd();
}

void house (void) {
int i;
/* This code draws the house.
The house consists of 6 polygon as defined below: 
Two Ends: Ep and Ep2, Two Walls: Wp and Wp2, and Two Roofs: Rp and Rp2
The code also sets up the normals of the polygons. 
*/
GLfloat Ep [5][3] = {{0.,0.,0.},{0.,0.,5.},{5.,0.,10.},{10.,0.,5.},{10.,0.,0.} };
GLfloat Wp[4][3] = {{0.,0.,0.},{0.,-10.0,0.},{0.,-10.,5.},{0.,0.,5.} };
GLfloat Rp [4][3] = {{0.,0.,5.},{0.,-10.,5.},{5.,-10.,10.},{5.,0.,10.} };	
GLfloat Ep2 [5][3] = {{10.,-10.,0.},{10.,-10.,5.},{5.,-10.,10.},{0.,-10.,5.},{0.,-10.,0.}};
GLfloat Wp2 [4][3] = {{10.,0.,0.},{10.,0.,5.},{10.,-10.,5.},{10.,-10.,0.}};
GLfloat Rp2 [4][3] = {{10.,0.,5.},{5.,0.,10.},{5.,-10.,10.},{10.,-10.,5.} };

glPushMatrix ();
glColor3f (0.8, 0.0, 0.0);

glBegin(GL_POLYGON);
glNormal3f (0.0,1.0,0.0);
for (i = 0; i < 5; i++) 
	glVertex3fv(&Ep[i][0]);
glEnd();

glBegin(GL_POLYGON);
glNormal3f (-1.0,0.0,0.0);
for (i = 0; i < 4; i++) 
	glVertex3fv(&Wp[i][0]);
glEnd();

glBegin(GL_POLYGON);
glNormal3f (-1.0,0.0,1.0);
for (i = 0; i < 4; i++) 
	glVertex3fv(&Rp[i][0]);
glEnd();

glBegin(GL_POLYGON);
glNormal3f (0.0,-1.0,0.0);
for (i = 0; i < 5; i++) 
	glVertex3fv(&Ep2[i][0]);
glEnd();

glBegin(GL_POLYGON);
glNormal3f (1.0,0.0,0.0);
for (i = 0; i < 4; i++) 
	glVertex3fv(&Wp2[i][0]);
glEnd();

glBegin(GL_POLYGON);
glNormal3f (1.0,0.0,1.0);
for (i = 0; i < 4; i++) 
	glVertex3fv(&Rp2[i][0]);
glEnd();

glPopMatrix();
}

Hello,

you need orthogonal projection and more likely rotate the scene by 45 degrees about the Y axis and the X axis.

cheers
John

Hello John.
Thank you for your answer :slight_smile:

I tried to rotate with 45 degrees around x and z axis, but it didnt really give me the isometric view. I must be doing something wrong.

I know its a lot to ask, but I have posted my program code and was hoping that you could maybe take a small look and see if you can find out what I am doing wrong. The code is most likely very basic to you.

What I really wanted to do was to set up the projection matrix myself, but hmm its a bit difficult.

Thank you very much in advance.

Many regards…

#include <GL/glut.h>
#include <stdlib.h>

GLfloat ctrlpoints [5][3] = {{0.,0.,0.},{0.,0.,5.},{5.,0.,10.},{10.,0.,5.},{10.,0.,0.} };



void ctrlpolygon (void);
void axis (void);
void house (void);

void init (void);
void display (void);
void reshape (int w, int h);
void keyboard(unsigned char key, int x, int y);
int main(int argc, char** argv);


void init(void) {
glClearColor(1.0, 1.0, 1.0, 1.0);
glShadeModel(GL_SMOOTH);
glEnable (GL_DEPTH_TEST);
glEnable (GL_NORMALIZE);
}


void display(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(0.0, 0.0, 0.0);
glLoadIdentity ();
gluLookAt (12., 10., 10.,  5., 0., 5.,  0., 0., 1.);

glPushMatrix ();

glRotatef(45.0,1.0,0.0,0.0);
glRotatef(45.0,0.0,0.0,1.0);

/* Draws the control points and the connecting control polygon */
ctrlpolygon ();

/* draw axis */
axis();

/* Draws the House */ 
house ();

glPopMatrix ();
glFlush();
}


void reshape(int w, int h)  {
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h)
	glOrtho (-30.0, 30.0, -30.0*(GLfloat)h/(GLfloat)w, 
               30.0*(GLfloat)h/(GLfloat)w , -30., 30.);
else
	glOrtho(-30.0*(GLfloat)w/(GLfloat)h, 
               30.0*(GLfloat)w/(GLfloat)h, -30.0, 30.0, -30., 30.);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}


void keyboard(unsigned char key, int x, int y) {
switch (key) {
	case 27:
		exit(0);
	break;
	}
}


int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc (keyboard);
glutMainLoop();
return 0;
}


void ctrlpolygon (void) {
int i;

/* The following code displays the control points as dots ...*/
glPointSize(5.0);
glColor3f(0.0, 1.0, 1.0);
glBegin(GL_POINTS);
	for (i = 0; i < 5; i++) 
		glVertex3fv(&ctrlpoints[i][0]);
glEnd();

/* ... and draws the Control Polygon as a line strip*/
glColor3f(0.0, 0.0, 0.0);
glBegin(GL_LINE_STRIP);
    for (i = 0; i < 5; i++) 
      glVertex3fv(&ctrlpoints[i][0]);
glEnd();
}


void axis (void){
/* Red Xw-axis */
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_LINES);
	glVertex3f(0.,0.,0.);
	glVertex3f(15.,0.,0.);
glEnd();

/* Green Yw-axis*/
glColor3f(0.0, 1.0, 0.0);
glBegin(GL_LINES);
	glVertex3f(0.,0.,0.);
	glVertex3f(0.,15.,0.);
glEnd();

/* Blue Zw-axis */
glColor3f(0.0, 0.0, 1.0);
glBegin(GL_LINES);
	glVertex3f(0.,0.,0.);
	glVertex3f(0.,0.,15.);
glEnd();
}



void house (void) {
int i;
/* This code draws the house.
The house consists of 6 polygon as defined below: 
Two Ends: Ep and Ep2, Two Walls: Wp and Wp2, and Two Roofs: Rp and Rp2
The code also sets up the normals of the polygons. 
*/
GLfloat Ep [5][3] = {{0.,0.,0.},{0.,0.,5.},{5.,0.,10.},{10.,0.,5.},{10.,0.,0.} };
GLfloat Wp[4][3] = {{0.,0.,0.},{0.,-10.0,0.},{0.,-10.,5.},{0.,0.,5.} };
GLfloat Rp [4][3] = {{0.,0.,5.},{0.,-10.,5.},{5.,-10.,10.},{5.,0.,10.} };	
GLfloat Ep2 [5][3] = {{10.,-10.,0.},{10.,-10.,5.},{5.,-10.,10.},{0.,-10.,5.},{0.,-10.,0.}};
GLfloat Wp2 [4][3] = {{10.,0.,0.},{10.,0.,5.},{10.,-10.,5.},{10.,-10.,0.}};
GLfloat Rp2 [4][3] = {{10.,0.,5.},{5.,0.,10.},{5.,-10.,10.},{10.,-10.,5.} };

glPushMatrix ();
glColor3f (0.8, 0.0, 0.0);

glBegin(GL_POLYGON);
glNormal3f (0.0,1.0,0.0);
for (i = 0; i < 5; i++) 
	glVertex3fv(&Ep[i][0]);
glEnd();

glBegin(GL_POLYGON);
glNormal3f (-1.0,0.0,0.0);
for (i = 0; i < 4; i++) 
	glVertex3fv(&Wp[i][0]);
glEnd();

glBegin(GL_POLYGON);
glNormal3f (-1.0,0.0,1.0);
for (i = 0; i < 4; i++) 
	glVertex3fv(&Rp[i][0]);
glEnd();

glBegin(GL_POLYGON);
glNormal3f (0.0,-1.0,0.0);
for (i = 0; i < 5; i++) 
	glVertex3fv(&Ep2[i][0]);
glEnd();

glBegin(GL_POLYGON);
glNormal3f (1.0,0.0,0.0);
for (i = 0; i < 4; i++) 
	glVertex3fv(&Wp2[i][0]);
glEnd();

glBegin(GL_POLYGON);
glNormal3f (1.0,0.0,1.0);
for (i = 0; i < 4; i++) 
	glVertex3fv(&Rp2[i][0]);
glEnd();

glPopMatrix();
}

Why do you want to setup the matrix yourself ? is there anything wrong with glOrtho ?

Mikael

Not at all.
Its just that I am new and beginning to learn the mathematics and how openGl coupes with it.

So it was just to get a better understanding :slight_smile:

But if it is way to much work then maybe its better to just use the ortho.

Can you see a problem in my code?

yes

you’re using glLookat. That’s throwing away any isometric transformation you set up.

cheers
John

glLoadIdentity ();
// gluLookAt (12., 10., 10.,  5., 0., 5.,  0., 0., 1.);
glPushMatrix ();
glRotatef(-45.0,1.0,0.0,0.0);
glRotatef(-45.0,0.0,1.0,0.0);

hi,

ok, so I compiled it and tweaked it. the above code fragment is from your draw method. Make the changes and see that now the X and Z axis form a ‘V’ and the Y points vertically up in the common or garden-variety isometric mode. Incidentially, your house model uses the Y axis as its length, which… is… probably counter intuitive :wink: (it looks strange in THIS configuration since it’s on its end, right?).

incidentially, your original code used lookat (bad!) and rotated about the X and Z axis—not the X and Y axis.

cheers
John

Ahhh yes okay i see…

I made the changes to my code, and now i have
:

btw. I also changed all
glBegin(GL_LINES); to glBegin(GL_POLYGON);
down in the house(); function, thus filling it up.

It looks rather strange i find. Is this really an isometric view?

why yes… yes, it is.,

but since you know what you want, the question really is: is this what you want?

as i said in my post, your house is aligned with the y axis==depth, which is probably not what you want