X-Git-Url: https://git.ucc.asn.au/?p=atyndall%2Fcits2231.git;a=blobdiff_plain;f=scene.c;h=69c5a820ed26fa4c983adfd966d7284f76c66f5c;hp=42b717c80db85090045f8569f37827090888ced8;hb=8ce9e04b2f947ad161075ba0a8cf822b5594d199;hpb=df4a1058cbb4a92922dd61c514c827392ba1330e diff --git a/scene.c b/scene.c index 42b717c..69c5a82 100644 --- a/scene.c +++ b/scene.c @@ -122,6 +122,7 @@ void processObjectEvents(int id) { void processTextureEvents(int id) { if ( curObject >= 0 ) { sceneObjs[curObject].texture.id = id; + sceneObjs[curObject].texture.scale = 1; glutPostRedisplay(); } } @@ -216,66 +217,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 @@ -338,8 +279,9 @@ void motion(int x, int y) { sceneObjs[curObject].rotation.x += diffx * rotateFactor; // h: texture scale + // **NOTE: Seems to be problem with scaling, delayed action float max = (float)height/texscaleFactor; - float scaling = (diffy + max) / max; + float scaling = (-diffy + max) / max; sceneObjs[curObject].texture.scale *= scaling; } @@ -347,19 +289,24 @@ void motion(int x, int y) { break; case STATE_LIGHT_1_MOVE: - case STATE_LIGHT_2_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) * leftrightFactor + diffy * cos(M_PI/2 + angler) * nearfarFactor; - lightObjs[i].position[2] += diffx * sin(angler) * leftrightFactor + diffy * sin(M_PI/2 + angler) * nearfarFactor; - + 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; @@ -409,10 +356,8 @@ void display() { glPushMatrix(); - /* Perform scene rotations based on user mouse/keyboard input. */ + /* Perform scene rotations based on user mouse input. */ glRotatef(rotate*camRotateFactor, 0.0, 1.0, 0.0); - glTranslatef(camx, camy, camz); - glRotatef(keyrot, 1.0, 0.0, 0.0); drawFloor(); @@ -497,32 +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(); - initializeLights(); - - /* Initial light 0 position. */ - lightObjs[0].position[0] = 4; - lightObjs[0].position[1] = 5; - lightObjs[0].position[2] = 6; - lightObjs[0].position[3] = 0.0; - - /* Initial light 1 position. */ - lightObjs[1].position[0] = -4; - lightObjs[1].position[1] = 5; - lightObjs[1].position[2] = -6; - lightObjs[1].position[3] = 0.0; + initializeState(); glutMainLoop(); } \ No newline at end of file