X-Git-Url: https://git.ucc.asn.au/?p=atyndall%2Fcits2231.git;a=blobdiff_plain;f=scene.c;h=27fc5474f8b9d08e2769ff05526103c236d8aece;hp=31eff0e3ffdd3fdbf6f39e1606596f0928202ac0;hb=2090fa97207b7008eaddbab184478b1720e5fad1;hpb=36aa202c760cb524f105a465007983f224cb97e3 diff --git a/scene.c b/scene.c index 31eff0e..27fc547 100644 --- a/scene.c +++ b/scene.c @@ -1,6 +1,6 @@ /** * CITS2231 Graphics Scene Editor - * @author Ashley Tyndall (20915779) + * @author Ashley Tyndall (20915779), Jenna de la Harpe (20367932) */ #include @@ -25,17 +25,14 @@ void processMainEvents(int id) { switch (id) { case M_ROTATE_MOVE_CAMERA: - // Do stuff + manipulateState = STATE_CAMERA_ROTATE_MOVE; break; - case M_POSITION_SCALE: - // Do stuff + manipulateState = STATE_OBJECT_POSITION_SCALE; break; - case M_ROTATION_TEXTURE_SCALE: - // Do stuff + manipulateState = STATE_OBJECT_ROTATION_TEXTURE_SCALE; break; - case M_EXIT: exit(EXIT_SUCCESS); @@ -113,8 +110,9 @@ void processLightEvents(int id) { * @param id ID of object selected */ void processObjectEvents(int id) { - // **NOTE: For the testing phase, only have the teapot addSceneObject(id); + manipulateState = STATE_OBJECT_POSITION_SCALE; + glutPostRedisplay(); } /** @@ -122,7 +120,10 @@ void processObjectEvents(int id) { * @param id ID of texutre selected */ void processTextureEvents(int id) { - + if ( curObject >= 0 ) { + sceneObjs[curObject].texture = id; + glutPostRedisplay(); + } } /** @@ -165,12 +166,12 @@ void makeMenu() { // Construct main menu glutCreateMenu(processMainEvents); - //glutAddMenuEntry("Rotate/Move Camera", M_ROTATE_MOVE_CAMERA); - //glutAddSubMenu("Add object", objectMenu); - //glutAddMenuEntry("Position/Scale", M_POSITION_SCALE); - //glutAddMenuEntry("Rotation/Texture Scale", M_ROTATION_TEXTURE_SCALE); + glutAddMenuEntry("Rotate/Move Camera", M_ROTATE_MOVE_CAMERA); + glutAddSubMenu("Add object", objectMenu); + glutAddMenuEntry("Position/Scale", M_POSITION_SCALE); + glutAddMenuEntry("Rotation/Texture Scale", M_ROTATION_TEXTURE_SCALE); //glutAddSubMenu("Material", materialMenu); - //glutAddSubMenu("Texture", textureMenu); + glutAddSubMenu("Texture", textureMenu); glutAddSubMenu("Ground texture", gTextureMenu); //glutAddSubMenu("Lights", lightMenu); glutAddMenuEntry("Exit", M_EXIT); @@ -293,27 +294,51 @@ void motion(int x, int y) { } starty = y; - printf("zoom is %f, y is %d starty is %d\n", zoom, y, starty); startx = x; break; case STATE_OBJECT_POSITION_SCALE: - //SceneObject co = sceneObjs[curObject]; - + //so.x, so.y, so.z if ( buttonSelected == GLUT_LEFT_BUTTON ) { // w: left/right, h: near/far - + //sceneObjs[curObject].x += (x - startx)*leftrightFactor; } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) { // w: big/small, h: up/down + + // For big/small scaling, we map negative numbers to 0->1 and positive numbers to 1->inf + float diff = (y - starty); + float scaling; + + if ( diff < 0 ) { + scaling = (diff - -((float)height/2))/(0 - -((float)height/2)); + } else { + scaling = pow(1.1, diff); + } + + if ( scaling != 0 ) { + + + sceneObjs[curObject].scale[0] *= scaling; + sceneObjs[curObject].scale[1] *= scaling; + sceneObjs[curObject].scale[2] *= scaling; + printf("Diff is %f, Scaling by %f on all axii\n", diff, sceneObjs[curObject].scale[0]); + + } + + starty = y; } + + startx = x; break; case STATE_OBJECT_ROTATION_TEXTURE_SCALE: if ( buttonSelected == GLUT_LEFT_BUTTON ) { // w: rotate on width, h: rotate on h + } else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) { - // w & h, rotate on h + // w: rotate on height, h: texture scale + } break; @@ -388,17 +413,15 @@ void display() { drawFloor(); // Draw sceneObjs array - glPushMatrix(); - for ( int i = 0; i < nObjects; i++ ) { + for ( int i = 0; i < nObjects; i++ ) { + glPushMatrix(); SceneObject so = sceneObjs[i]; // Apply rotation vector - vector* rv = so.rotation.vect; - glRotatef(so.rotation.parameter, *rv[0], *rv[1], *rv[2]); + glRotatef(so.rotation.amount, so.rotation.vector[0], so.rotation.vector[1], so.rotation.vector[2]); // Apply scaling vector - vector* sv = so.scale; - glScalef(*sv[0], *sv[1], *sv[2]); + glScalef(so.scale[0], so.scale[1], so.scale[2]); // Apply translation vector glTranslatef(so.x, so.y, so.z); @@ -408,7 +431,6 @@ void display() { getTexture(so.texture); glBindTexture(GL_TEXTURE_2D, so.texture); } else { - getTexture(0); glBindTexture(GL_TEXTURE_2D, 0); } @@ -423,8 +445,9 @@ void display() { } glBindTexture(GL_TEXTURE_2D, 0); - } - glPopMatrix(); + glPopMatrix(); + } + // Draw a white ball over the light source glPushMatrix();