X-Git-Url: https://git.ucc.asn.au/?p=atyndall%2Fcits2231.git;a=blobdiff_plain;f=scene.c;h=d4c09fdecb470b8e0a6e61148ad9b6a11c089616;hp=8a209b9bd5d8aefd9fca4d97be5244aa4c436058;hb=0fc3aef34b8228c1b1c7614588210f662d0420ab;hpb=5550746772c2276196fa79507b8f7983ec549706 diff --git a/scene.c b/scene.c index 8a209b9..d4c09fd 100644 --- a/scene.c +++ b/scene.c @@ -187,11 +187,11 @@ void windowReshape(int w, int h) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (w <= h) - glFrustum(-1.0, 1.0, -1.0*(GLfloat) h / (GLfloat) w, - 1.0*(GLfloat) h / (GLfloat) w, nearClip, farClip); + glFrustum(-near, far, -near*(GLfloat) h / (GLfloat) w, + far*(GLfloat) h / (GLfloat) w, nearClip, farClip); else - glFrustum(-1.0*(GLfloat) w / (GLfloat) h, - 1.0*(GLfloat) w / (GLfloat) h, -1.0, 1.0, nearClip, farClip); + glFrustum(-near*(GLfloat) w / (GLfloat) h, + far*(GLfloat) w / (GLfloat) h, near, far, nearClip, farClip); glMatrixMode(GL_MODELVIEW); } @@ -293,8 +293,15 @@ void motion(int x, int y) { */ void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glMatrixMode(GL_MODELVIEW); glLoadIdentity(); + //gluLookAt( + // -30.0, -30.0, -30.0, /* eye is at (x,y,z) */ + /// 0.0, 0.0, 0.0, /* center is at (x,y,z) */ + // 0.0, 1.0, 0.0 /* up is in postivie Y direction */ + // ); + /* Reposition the light source. */ lightPosition[0] = 12*cos(lightAngle); lightPosition[1] = lightHeight; @@ -340,9 +347,6 @@ void display() { * init function; sets initial OpenGL state */ void init() { - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glLightfv(GL_LIGHT0, GL_POSITION, light0_pos); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient0); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0); @@ -353,11 +357,11 @@ void init() { glLightModelfv(GL_LIGHT_MODEL_AMBIENT, glightmodel); - glMaterialfv(GL_FRONT, GL_AMBIENT, ambient); - glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse); - glMaterialfv(GL_FRONT, GL_SPECULAR, specular); - glMaterialfv(GL_FRONT, GL_EMISSION, emission0); - glMaterialf(GL_FRONT, GL_SHININESS, shine); + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular); + glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, emission0); + glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shine); glEnable(GL_LIGHT0); glEnable(GL_LIGHTING); @@ -398,22 +402,6 @@ int main(int argc, char **argv) { glEnable(GL_TEXTURE_2D); glLineWidth(1.0); - // **NOTE: Currently the perspective and look-at code is static, for testing purposes - //glMatrixMode(GL_PROJECTION); - //gluPerspective( - // 40.0, /* field of view in degree */ - // 1.0, /* aspect ratio */ - // 1.0, /* Z near */ // **NOTE: Seems to be issue with near < 0 causing invisible everything - // 100.0 /* Z far */ - // ); - - glMatrixMode(GL_MODELVIEW); - gluLookAt( - 0.0, 35.0, -20.0, /* eye is at (x,y,z) */ - 0.0, 10.0, 0.0, /* center is at (x,y,z) */ - 0.0, 1.0, 0.0 /* up is in postivie Y direction */ - ); - glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glutReshapeFunc(windowReshape);