X-Git-Url: https://git.ucc.asn.au/?p=atyndall%2Fcits2231.git;a=blobdiff_plain;f=scene.c;h=618c1aeac78d29da927b7e7e0ff2febeb21f077b;hp=deb8c0e0a0524295f7709d216531fd2ec666c310;hb=f17147662a091d75d8ab9fb984722caf0e3067ae;hpb=f62aef4de83dd13677a8e436597abbc139d06ea3 diff --git a/scene.c b/scene.c index deb8c0e..618c1ae 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 @@ -305,13 +305,9 @@ void motion(int x, int y) { if ( buttonSelected == GLUT_LEFT_BUTTON ) { // w: left/right, h: near/far - - // **NOTE: Currently a work in progress, does not work correctly float angler = 2 * M_PI * ( (rotate*camRotateFactor)/360.0 ); - printf("cam angle: %f\n", rotate*camRotateFactor); - // float arc = arctan() - sceneObjs[curObject].x += diffx * sin(angler) * 0.3; - sceneObjs[curObject].z += diffx * cos(angler) * 0.3; + sceneObjs[curObject].x += diffx * cos(angler) * leftrightFactor + diffy * cos(M_PI/2 + angler) * nearfarFactor; + sceneObjs[curObject].z += diffx * sin(angler) * leftrightFactor + diffy * sin(M_PI/2 + angler) * nearfarFactor; } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) { // w: big/small @@ -350,6 +346,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; @@ -393,24 +412,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. */ @@ -418,9 +419,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 @@ -464,21 +462,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(); @@ -487,28 +471,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 @@ -553,7 +515,19 @@ int main(int argc, char **argv) { makeMenu(); - init(); + 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; glutMainLoop(); } \ No newline at end of file