X-Git-Url: https://git.ucc.asn.au/?p=atyndall%2Fcits2231.git;a=blobdiff_plain;f=scene.c;h=55b185623f5a2b8f6a46e9d6c735ed285a718bab;hp=57803e56aa52f479d83ef5b7066fece38a930337;hb=e167fee487eef79406a5baa2757a7262811b027b;hpb=cbe1aa264b15c345870500646003c777e4bdef03 diff --git a/scene.c b/scene.c index 57803e5..55b1856 100644 --- a/scene.c +++ b/scene.c @@ -87,7 +87,7 @@ void processMaterialEvents(int id) { void processLightEvents(int id) { switch (id) { case M_LIGHT_MOVE_LIGHT_1: - // Do stuff + manipulateState = STATE_LIGHT_1_MOVE; break; case M_LIGHT_RGBALL_LIGHT_1: @@ -95,7 +95,7 @@ void processLightEvents(int id) { break; case M_LIGHT_MOVE_LIGHT_2: - // Do stuff + manipulateState = STATE_LIGHT_2_MOVE; break; case M_LIGHT_RGBALL_LIGHT_2: @@ -153,9 +153,9 @@ void makeMenu() { // Construct light menu int lightMenu = glutCreateMenu(processLightEvents); glutAddMenuEntry("Move Light 1", M_LIGHT_MOVE_LIGHT_1); - glutAddMenuEntry("R/G/B/All Light 1", M_LIGHT_RGBALL_LIGHT_1); + //glutAddMenuEntry("R/G/B/All Light 1", M_LIGHT_RGBALL_LIGHT_1); glutAddMenuEntry("Move Light 2", M_LIGHT_MOVE_LIGHT_2); - glutAddMenuEntry("R/G/B/All Light 2", M_LIGHT_RGBALL_LIGHT_2); + //glutAddMenuEntry("R/G/B/All Light 2", M_LIGHT_RGBALL_LIGHT_2); // Construct object menu int objectMenu = makeSubmenuFromArray( objectMenuEntries, NMESH, processObjectEvents ); @@ -173,7 +173,7 @@ void makeMenu() { //glutAddSubMenu("Material", materialMenu); glutAddSubMenu("Texture", textureMenu); glutAddSubMenu("Ground texture", gTextureMenu); - //glutAddSubMenu("Lights", lightMenu); + glutAddSubMenu("Lights", lightMenu); glutAddMenuEntry("Exit", M_EXIT); // Bind to right mouse button @@ -216,66 +216,6 @@ void mouse(int button, int state, int x, int y) { } } -/** - * Keybord event handler - * w/s increase/decrease the z - * a/d increase/decrease the x - * q/e increase/decrease the y - * z/x increase/decrease the angle - * @param key Key pressed - * @param x x co-ordinate of mouse - * @param y y co-ordinate of mouse - */ -void keyboard(unsigned char key, int x, int y) { - switch(key) { - case 'w': - case 'W': - camz -= factor; - break; - case 'a': - case 'A': - camx -= factor; - break; - case 's': - case 'S': - camz += factor; - break; - case 'd': - case 'D': - camx += factor; - break; - case 'q': - case 'Q': - camy += factor; - break; - case 'e': - case 'E': - camy -= factor; - break; - case 'z': - case 'Z': - keyrot += factor; - break; - case 'x': - case 'X': - keyrot -= factor; - break; - case '=': - case '+': - factor += 0.1; - printf("Factor of change is now %f\n", factor); - break; - case '-': - case '_': - factor -= 0.1; - printf("Factor of change is now %f\n", factor); - break; - - } - printf("Camera is now at (%f, %f, %f), angle %f\n", camx, camy, camz, keyrot); - glutPostRedisplay(); -} - /** * Called when motion event occurs * @param x Mouse x position @@ -346,6 +286,29 @@ void motion(int x, int y) { break; + case STATE_LIGHT_1_MOVE: + case STATE_LIGHT_2_MOVE: + ; // Semi-colon required to allow variable declaration below + + int i = 0; + if ( manipulateState == STATE_LIGHT_2_MOVE ) i = 1; + + if ( buttonSelected == GLUT_LEFT_BUTTON ) { + // w: left/right, h: near/far + float angler = 2 * M_PI * ( (rotate*camRotateFactor)/360.0 ); + lightObjs[i].position[0] += diffx * cos(angler) * lleftrightFactor + diffy * cos(M_PI/2 + angler) * lnearfarFactor; + lightObjs[i].position[2] += diffx * sin(angler) * lleftrightFactor + diffy * sin(M_PI/2 + angler) * lnearfarFactor; + + } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) { + // w: increase/decrease some light param + // **NOTE: Currently not implemented + + // h: up/down + lightObjs[i].position[1] -= diffy * updownFactor; + } + + break; + } starty = y; @@ -389,24 +352,6 @@ void display() { glRotatef(camAngle*camAngleFactor, 1.0, 0.0, 0.0); // Set camera angle upward - /* Reposition the light source 0. */ - lightPosition0[0] = 12*cos(lightAngle0); - lightPosition0[1] = lightHeight0; - lightPosition0[2] = 12*sin(lightAngle0); - lightPosition0[3] = 0.0; - - direction0[0] = lightPosition0[0]; - direction0[2] = lightPosition0[2]; - - /* Reposition the light source 1. */ - lightPosition1[0] = 12*cos(lightAngle1); - lightPosition1[1] = lightHeight1; - lightPosition1[2] = 12*sin(lightAngle1); - lightPosition1[3] = 0.0; - - direction1[0] = lightPosition1[0]; - direction1[2] = lightPosition1[2]; - glPushMatrix(); /* Perform scene rotations based on user mouse/keyboard input. */ @@ -414,9 +359,6 @@ void display() { glTranslatef(camx, camy, camz); glRotatef(keyrot, 1.0, 0.0, 0.0); - glLightfv(GL_LIGHT0, GL_POSITION, lightPosition0); - glLightfv(GL_LIGHT1, GL_POSITION, lightPosition1); - drawFloor(); // Draw sceneObjs array @@ -460,21 +402,7 @@ void display() { glPopMatrix(); } - // Draw a white ball over the light sources - glDisable(GL_LIGHTING); - glColor3f(1.0, 1.0, 1.0); - - glPushMatrix(); - glTranslatef(lightPosition0[0], lightPosition0[1], lightPosition0[2]); - glutSolidSphere(0.5, 50, 50); - glPopMatrix(); - - glPushMatrix(); - glTranslatef(lightPosition1[0], lightPosition1[1], lightPosition1[2]); - glutSolidSphere(0.5, 50, 50); - glPopMatrix(); - - glEnable(GL_LIGHTING); + updateLights(); drawAxisLines(); @@ -483,28 +411,6 @@ void display() { glutSwapBuffers(); } -/** - * init function; sets initial OpenGL state - */ -void init() { - glLightfv(GL_LIGHT0, GL_AMBIENT, ambient0); - glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0); - glLightfv(GL_LIGHT0, GL_SPECULAR, specular0); - glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, direction0); - - glLightfv(GL_LIGHT1, GL_AMBIENT, ambient1); - glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse1); - glLightfv(GL_LIGHT1, GL_SPECULAR, specular1); - glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, direction1); - - glLightModelfv(GL_LIGHT_MODEL_AMBIENT, glightmodel); - glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR); - - glEnable(GL_LIGHT0); - glEnable(GL_LIGHT1); - glEnable(GL_LIGHTING); -} - /** * Main function * @param argc Number of arguments @@ -536,20 +442,19 @@ int main(int argc, char **argv) { glDepthRange(0,1); glEnable(GL_DEPTH_TEST); // Enables Depth Testing glDepthFunc(GL_LEQUAL); // the type - glEnable(GL_NORMALIZE); - glLineWidth(2.0); + //glEnable(GL_CULL_FACE); + glLineWidth(1.0); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glutReshapeFunc(windowReshape); glutDisplayFunc(display); glutMouseFunc(mouse); - glutKeyboardFunc(keyboard); glutMotionFunc(motion); makeMenu(); - - init(); + initializeLights(); + initializeState(); glutMainLoop(); } \ No newline at end of file