X-Git-Url: https://git.ucc.asn.au/?p=atyndall%2Fcits2231.git;a=blobdiff_plain;f=scene.c;h=914f3a6526010fd36e9d5f9b33f0945646bbb8b6;hp=b4469b752e909f30fe1628bf0764e440a27f8b76;hb=6bc2cf448a219d515341068e044b9610e060c747;hpb=e1fc70add9281f69123aef6261d7ac016f3275d6 diff --git a/scene.c b/scene.c index b4469b7..914f3a6 100644 --- a/scene.c +++ b/scene.c @@ -123,8 +123,8 @@ GLfloat angle = -150; /* in degrees */ GLfloat angle2 = 30; /* in degrees */ /* Near and far parameters */ -GLfloat near = -10; -GLfloat far = 10; +GLfloat near = -100; +GLfloat far = 100; /* Zoom factor for mouse movements */ GLfloat zoomFactor = 1.0; @@ -135,6 +135,15 @@ int drawFloorRecurse = 5; /* Size of floor, from -n to n */ int floorSize = 100; +/* Light 0 parameters */ +GLfloat diffuse0[] = {1.0, 1.0, 1.0, 1.0}; +GLfloat ambient0[] = {0.0, 0.0, 0.0, 1.0}; +GLfloat specular0[] = {1.0, 1.0, 1.0, 1.0}; +GLfloat emission0[] = {0.0, 0.0, 0.0, 0.0}; +GLfloat light0_pos[] ={1.0, 1.0, 0,0, 1.0}; +GLfloat glightmodel[] = {0.2,0.2,0.2,1}; + + /** * Prints out error message when file cannot be read * @param fileName Name of file that could not be read @@ -491,7 +500,7 @@ void makeMenu() { */ void windowReshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); - glMatrixMode(GL_PROJECTION); + /*glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (w <= h) glOrtho(near, far, near*(GLfloat)h/(GLfloat)w, @@ -500,7 +509,7 @@ void windowReshape(int w, int h) { glOrtho(near*(GLfloat)w/(GLfloat)h, far*(GLfloat)w/(GLfloat)h, near, far, near, far); glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); + glLoadIdentity();*/ } /** @@ -600,6 +609,25 @@ void drawFloor() { drawSquare(0, -floorSize, -floorSize, floorSize, floorSize); } +/** + * Draw x, z axis on floor + */ +void drawLine() { + // **NOTE: fix function + glDisable(GL_TEXTURE_2D); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4ub( 0.0, 0.0, 0.0, 0.5 ); + + glBegin(GL_LINES); + glVertex3i( 10.0, 0.1, 10.0); + glVertex3i( -10.0, 0.1, -10.0); + glEnd(); + + glDisable(GL_BLEND); + glEnable(GL_TEXTURE_2D); +} + /** * Display function */ @@ -607,11 +635,12 @@ void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt( - 0.0, 0.0, 10.0, /* eye is at (x,y,z) */ + 0.0, 10.0, 10.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 */ ); + // **NOTE: Currently this rotation function is all that moves the camera off // the flat surface. Need to integrate function into gluLookAt glRotatef(30.0, 1.0, 0.0, 0.0); @@ -626,29 +655,27 @@ void display() { /* Perform scene rotations based on user mouse input. */ glRotatef(angle, 0.0, 1.0, 0.0); - glRotatef(angle2, 1.0, 0.0, 0.0); + //glRotatef(angle2, 1.0, 0.0, 0.0); **NOTE: Only one degree of freedom glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); drawFloor(); - glDisable(GL_BLEND); - glPushMatrix(); + drawLine(); - glTranslatef(0.0, 1.0, 0.0); - glutWireTeapot(1); // Draw teapot for test + // Draw teapot for a test object + glPushMatrix(); + glTranslatef(0.0, 0.5, 0.0); // **NOTE: Teapot does not rest on surface + glColor3f(0.5, 0.5, 0.5); + glutSolidTeapot(1); glPopMatrix(); + // Draw a white ball over the light source glPushMatrix(); glDisable(GL_LIGHTING); glColor3f(1.0, 1.0, 1.0); - - /* Draw a yellow ball at the light source. */ glTranslatef(lightPosition[0], lightPosition[1], lightPosition[2]); glutSolidSphere(1.0, 50, 50); - glEnable(GL_LIGHTING); glPopMatrix(); @@ -665,24 +692,26 @@ void init() { glLoadIdentity(); gluPerspective( - 60.0, /* field of view in degree */ - 1.0, /* aspect ratio */ - near, /* Z near */ + 60.0, /* field of view in degree */ + 1.0, /* aspect ratio */ + near, /* Z near */ far /* Z far */ - ); - - -GLfloat diffuse0[] = {1.0, 1.0, 1.0, 1.0}; -GLfloat ambient0[] = {1.0, 1.0, 1.0, 1.0}; -GLfloat specular0[] = {1.0, 1.0, 1.0, 1.0}; -GLfloat light0_pos[] ={ 1.0, 2.0, 3,0, 1.0}; + ); -glEnable(GL_LIGHT0); -glLightfv(GL_LIGHT0, GL_POSITION, light0_pos); -glLightfv(GL_LIGHT0, GL_AMBIENT, ambient0); -glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0); -glLightfv(GL_LIGHT0, GL_SPECULAR, specular0); + + glLightfv(GL_LIGHT0, GL_POSITION, light0_pos); + glLightfv(GL_LIGHT0, GL_AMBIENT, ambient0); + glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0); + glLightfv(GL_LIGHT0, GL_SPECULAR, specular0); + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, glightmodel); + glEnable(GL_LIGHT0); glEnable(GL_LIGHTING); + glEnable(GL_COLOR_MATERIAL); + glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ); + glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, specular0); + glMaterialfv( GL_FRONT_AND_BACK, GL_EMISSION, emission0); + + glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -728,7 +757,6 @@ int main(int argc, char **argv) { glutDisplayFunc(display); glutMouseFunc(mouse); glutMotionFunc(motion); - //glutIdleFunc(idle); makeMenu();