X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=scene.c;h=79c506e416821bcdccd30f3d0ad5cde31c8e235a;hb=79f4b6e1d83d5ec50cfac2f71487bd9d07d8fc8e;hp=963f78bec7032ce6f465cc73d5a5f5382a3e08ae;hpb=db2ce035b0f1f0c957ce8dbf998a45b799b8aa29;p=atyndall%2Fcits2231.git diff --git a/scene.c b/scene.c index 963f78b..79c506e 100644 --- a/scene.c +++ b/scene.c @@ -491,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 */ @@ -498,28 +534,39 @@ void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); - glTranslatef( 0.0f, 0.0f, 0.0f); + /*glTranslatef( 0.0f, 0.0f, 0.0f); glBegin(GL_QUADS); 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(); + glEnd();*/ glTranslatef( 0.0f, 0.0f, -5.0f); // Move into the Screen 10.0 glutSolidTeapot(1); - glMatrixMode(GL_MODELVIEW); + /* 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(); + 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 @@ -559,10 +606,16 @@ int main(int argc, char **argv) { makeMenu(); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective( 60, 1, 0.1, 1000.0); - glMatrixMode(GL_MODELVIEW); + 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(); }