X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=scene.c;h=34824a49e97dabe570ae9645c13aada3e0125387;hb=768f7e83816fbfe455586b2e8d787369cdb9afd5;hp=683eb1b82b8b13c7b65fdf996d016122a6f7ce92;hpb=6a04459fa0081b99da7ec882a9a5c6426035dd95;p=atyndall%2Fcits2231.git diff --git a/scene.c b/scene.c index 683eb1b..34824a4 100644 --- a/scene.c +++ b/scene.c @@ -460,16 +460,24 @@ void makeMenu() { /** * Called when window is resized - * @param width New width - * @param height New height + * @param w New width + * @param h New height */ -void windowReshape(int width, int height) { - glViewport(0, 0, (GLsizei)width, (GLsizei)height); - printf("Width: %d, height: %d\n", width, height); +void windowReshape(int w, int h) { + GLdouble near = -10.0; + GLdouble far = 10.0; + + glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - gluPerspective(60, (GLfloat)width / (GLfloat)height, 0.1, 1000.0); - glMatrixMode(GL_MODELVIEW); + if (w <= h) + glOrtho(near, far, near*(GLfloat)h/(GLfloat)w, + far*(GLfloat)h/(GLfloat)w, near, far); + else + glOrtho(near*(GLfloat)w/(GLfloat)h, + far*(GLfloat)w/(GLfloat)h, near, far, near, far); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); } /** @@ -483,6 +491,42 @@ void mouse(int btn, int state, int x, int y) { } +static GLfloat floorVertices[4][3] = { + { -20.0, 0.0, 20.0 }, + { 20.0, 0.0, 20.0 }, + { 20.0, 0.0, -20.0 }, + { -20.0, 0.0, -20.0 }, +}; + +/* Draw a floor (possibly textured). */ +static void +drawFloor(void) +{ + glDisable(GL_LIGHTING); + + //if (useTexture) { + // glEnable(GL_TEXTURE_2D); + //} + + glBegin(GL_QUADS); + glTexCoord2f(0.0, 0.0); + glVertex3fv(floorVertices[0]); + glTexCoord2f(0.0, 16.0); + glVertex3fv(floorVertices[1]); + glTexCoord2f(16.0, 16.0); + glVertex3fv(floorVertices[2]); + glTexCoord2f(16.0, 0.0); + glVertex3fv(floorVertices[3]); + glEnd(); + + /*if (useTexture) { + glDisable(GL_TEXTURE_2D); + }*/ + + glEnable(GL_LIGHTING); +} + + /** * Display function */ @@ -490,19 +534,39 @@ void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); - glTranslatef(0.0f,0.0f,-4.0f); // Move Left 1.5 Units And Into The Screen 6.0 - + /*glTranslatef( 0.0f, 0.0f, 0.0f); glBegin(GL_QUADS); - glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red - glVertex3f(-1.0f, 1.0f, 0.0f); // Top left - glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right - glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right - glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left - glEnd(); + glVertex3f( 0.0f, 1.0f, -1.0f); + glVertex3f( 0.0f, 1.0f, 1.0f); + glVertex3f( 0.0f, -1.0f, 1.0f); + glVertex3f( 0.0f, -1.0f, -1.0f); + glEnd();*/ + + + //glTranslatef( 0.0f, 0.0f, -5.0f); // Move into the Screen 10.0 + //glutSolidTeapot(1); + + /* glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + gluLookAt(0.7f, 0.4f, 0.9f, -2.0f, -1.0f, -7.0f, 1.0f, 10.0f, 1.0f); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity();*/ + drawFloor(); glutSwapBuffers(); } +/** + * init function, sets OpenGL's starting state + */ +void init() { + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective( 60, 1, 0.1, 1000.0); + glMatrixMode(GL_MODELVIEW); +} + /** * Main function * @param argc Number of arguments @@ -528,18 +592,30 @@ int main(int argc, char **argv) { glutInitWindowSize(500, 500); glutCreateWindow("Scene Editor"); - glShadeModel(GL_SMOOTH); // Enables Smooth Shading - glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background - glClearDepth(1.0f); // Depth Buffer Setup - glEnable(GL_DEPTH_TEST); // Enables Depth Testing - glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do + glShadeModel(GL_SMOOTH); // Enables Smooth Shading + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background + glClearDepth(1.0f); // Depth Buffer Setup + glEnable(GL_DEPTH_TEST); // Enables Depth Testing + glDepthFunc(GL_LEQUAL); // the type - glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations + // glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations glutReshapeFunc(windowReshape); glutDisplayFunc(display); glutMouseFunc(mouse); makeMenu(); + + init(); + + glMatrixMode(GL_PROJECTION); + gluPerspective( /* field of view in degree */ 40.0, + /* aspect ratio */ 1.0, + /* Z near */ 20.0, /* Z far */ 100.0); + glMatrixMode(GL_MODELVIEW); + gluLookAt(0.0, 8.0, 60.0, /* eye is at (0,8,60) */ + 0.0, 8.0, 0.0, /* center is at (0,8,0) */ + 0.0, 1.0, 0.); /* up is in postivie Y direction */ + glutMainLoop(); }