*/\r
void processTextureEvents(int id) {\r
if ( curObject >= 0 ) {\r
- sceneObjs[curObject].texture = id;\r
+ sceneObjs[curObject].texture.id = id;\r
glutPostRedisplay();\r
}\r
}\r
// Construct light menu\r
int lightMenu = glutCreateMenu(processLightEvents);\r
glutAddMenuEntry("Move Light 1", M_LIGHT_MOVE_LIGHT_1);\r
- glutAddMenuEntry("R/G/B/All Light 1", M_LIGHT_RGBALL_LIGHT_1);\r
+ //glutAddMenuEntry("R/G/B/All Light 1", M_LIGHT_RGBALL_LIGHT_1);\r
glutAddMenuEntry("Move Light 2", M_LIGHT_MOVE_LIGHT_2);\r
- glutAddMenuEntry("R/G/B/All Light 2", M_LIGHT_RGBALL_LIGHT_2);\r
+ //glutAddMenuEntry("R/G/B/All Light 2", M_LIGHT_RGBALL_LIGHT_2);\r
\r
// Construct object menu\r
int objectMenu = makeSubmenuFromArray( objectMenuEntries, NMESH, processObjectEvents );\r
//glutAddSubMenu("Material", materialMenu);\r
glutAddSubMenu("Texture", textureMenu);\r
glutAddSubMenu("Ground texture", gTextureMenu);\r
- //glutAddSubMenu("Lights", lightMenu);\r
+ glutAddSubMenu("Lights", lightMenu);\r
glutAddMenuEntry("Exit", M_EXIT);\r
\r
// Bind to right mouse button\r
void motion(int x, int y) {\r
if ( buttonSelected == -1 ) return; // No button selected, no action\r
\r
+ float diffx = x - startx;\r
+ float diffy = y - starty;\r
+\r
switch ( manipulateState ) {\r
case STATE_CAMERA_ROTATE_MOVE:\r
// w: rotate\r
- rotate += (x - startx);\r
+ rotate += diffx;\r
\r
if ( buttonSelected == GLUT_LEFT_BUTTON ) {\r
// h: zoom\r
- zoom += (y - starty);\r
+ zoom += diffy;\r
} else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) {\r
// h: tilt\r
- camAngle += (y - starty);\r
+ camAngle += diffy;\r
}\r
-\r
- starty = y;\r
- startx = x;\r
-\r
break;\r
\r
case STATE_OBJECT_POSITION_SCALE:\r
- \r
+\r
if ( buttonSelected == GLUT_LEFT_BUTTON ) {\r
// w: left/right, h: near/far\r
- //so.x, so.y, so.z\r
- //sceneObjs[curObject].x += (x - startx)*leftrightFactor;\r
+ float angler = 2 * M_PI * ( (rotate*camRotateFactor)/360.0 );\r
+ sceneObjs[curObject].x += diffx * cos(angler) * leftrightFactor + diffy * cos(M_PI/2 + angler) * nearfarFactor;\r
+ sceneObjs[curObject].z += diffx * sin(angler) * leftrightFactor + diffy * sin(M_PI/2 + angler) * nearfarFactor;\r
+\r
} else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) {\r
// w: big/small\r
- float diff = (x - startx);\r
float max = (float)height/bigsmallFactor;\r
- float scaling = ( diff + max) / max;\r
+ float scaling = (diffx + max) / max;\r
\r
sceneObjs[curObject].scale[0] *= scaling;\r
sceneObjs[curObject].scale[1] *= scaling;\r
sceneObjs[curObject].scale[2] *= scaling;\r
\r
// h: up/down\r
- sceneObjs[curObject].y -= (y - starty) * updownFactor;\r
+ sceneObjs[curObject].y -= diffy * updownFactor;\r
}\r
\r
- starty = y;\r
- startx = x;\r
-\r
break;\r
\r
case STATE_OBJECT_ROTATION_TEXTURE_SCALE:\r
+\r
if ( buttonSelected == GLUT_LEFT_BUTTON ) {\r
- // w: rotate on width, h: rotate on h\r
+ // w: rotate on y\r
+ sceneObjs[curObject].rotation.y += diffx * rotateFactor;\r
+\r
+ // h: rotate on x\r
+ sceneObjs[curObject].rotation.x += diffy * rotateFactor;\r
\r
} else if ( buttonSelected == GLUT_MIDDLE_BUTTON ) {\r
- // w: rotate on height, h: texture scale\r
- \r
+ // w: rotate on x\r
+ sceneObjs[curObject].rotation.x += diffx * rotateFactor;\r
+\r
+ // h: texture scale\r
+ float max = (float)height/texscaleFactor;\r
+ float scaling = (diffy + max) / max;\r
+ sceneObjs[curObject].texture.scale *= scaling;\r
+\r
}\r
+ \r
break;\r
\r
}\r
\r
+ starty = y;\r
+ startx = x;\r
+\r
glutPostRedisplay();\r
}\r
\r
0.0, 10.0, 0.0 /* up is in postivie Y direction */\r
);\r
\r
- //glRotatef(camAngle*camAngleFactor, 1.0, 0.0, 0.0);\r
+ glRotatef(camAngle*camAngleFactor, 1.0, 0.0, 0.0); // Set camera angle upward\r
\r
/* Reposition the light source 0. */\r
- lightPosition0[0] = 12*cos(lightAngle0);\r
- lightPosition0[1] = lightHeight0;\r
- lightPosition0[2] = 12*sin(lightAngle0);\r
- lightPosition0[3] = 0.0;\r
-\r
- direction0[0] = lightPosition0[0];\r
- direction0[2] = lightPosition0[2];\r
+ lightObjs[0].position[0] = 4;\r
+ lightObjs[0].position[1] = 5;\r
+ lightObjs[0].position[2] = 6;//12*sin(0);\r
+ lightObjs[0].position[3] = 0.0;\r
\r
/* Reposition the light source 1. */\r
- lightPosition1[0] = 12*cos(lightAngle1);\r
- lightPosition1[1] = lightHeight1;\r
- lightPosition1[2] = 12*sin(lightAngle1);\r
- lightPosition1[3] = 0.0;\r
+ lightObjs[1].position[0] = -6;\r
+ lightObjs[1].position[1] = 5;\r
+ lightObjs[1].position[2] = -4;//12*sin(90);\r
+ lightObjs[1].position[3] = 0.0;\r
\r
- direction1[0] = lightPosition1[0];\r
- direction1[2] = lightPosition1[2];\r
+ //direction0[0] = lightPosition0[0];\r
+ //direction0[2] = lightPosition0[2];\r
\r
glPushMatrix();\r
\r
/* Perform scene rotations based on user mouse/keyboard input. */\r
- glRotatef(rotate*rotateFactor, 0.0, 1.0, 0.0);\r
+ glRotatef(rotate*camRotateFactor, 0.0, 1.0, 0.0);\r
glTranslatef(camx, camy, camz);\r
glRotatef(keyrot, 1.0, 0.0, 0.0);\r
\r
- glLightfv(GL_LIGHT0, GL_POSITION, lightPosition0);\r
- glLightfv(GL_LIGHT1, GL_POSITION, lightPosition1);\r
-\r
drawFloor();\r
\r
// Draw sceneObjs array\r
glPushMatrix();\r
SceneObject so = sceneObjs[i];\r
\r
- // Apply rotation vector\r
- glRotatef(so.rotation.amount, so.rotation.vector[0], so.rotation.vector[1], so.rotation.vector[2]);\r
+ // Apply translation vector\r
+ glTranslatef(so.x, so.y, so.z);\r
+\r
+ // Apply independant rotation vectors\r
+ glRotatef(so.rotation.x, 1.0, 0.0, 0.0);\r
+ glRotatef(so.rotation.y, 0.0, 1.0, 0.0);\r
+ glRotatef(so.rotation.z, 0.0, 0.0, 1.0);\r
\r
// Apply scaling vector\r
glScalef(so.scale[0], so.scale[1], so.scale[2]);\r
\r
- // Apply translation vector\r
- glTranslatef(so.x, so.y, so.z);\r
-\r
// Apply texture\r
- if ( so.texture > 0 ) {\r
- getTexture(so.texture);\r
- glBindTexture(GL_TEXTURE_2D, so.texture);\r
+ if ( so.texture.id > 0 ) {\r
+ getTexture(so.texture.id);\r
+ glBindTexture(GL_TEXTURE_2D, so.texture.id);\r
+ glMatrixMode(GL_TEXTURE);\r
+ glScalef(so.texture.scale, so.texture.scale, so.texture.scale);\r
+ glMatrixMode(GL_MODELVIEW);\r
} else {\r
glBindTexture(GL_TEXTURE_2D, 0);\r
}\r
glBindTexture(GL_TEXTURE_2D, 0);\r
glPopMatrix();\r
}\r
- \r
\r
- // Draw a white ball over the light source\r
- glPushMatrix();\r
- glDisable(GL_LIGHTING);\r
- glColor3f(1.0, 1.0, 1.0);\r
- glTranslatef(lightPosition0[0], lightPosition0[1], lightPosition0[2]);\r
- glutSolidSphere(0.5, 50, 50);\r
- glEnable(GL_LIGHTING);\r
- glPopMatrix();\r
-\r
- // Draw a white ball over the light source\r
- glPushMatrix();\r
- glDisable(GL_LIGHTING);\r
- glColor3f(1.0, 1.0, 1.0);\r
- glTranslatef(lightPosition1[0], lightPosition1[1], lightPosition1[2]);\r
- glutSolidSphere(0.5, 50, 50);\r
- glEnable(GL_LIGHTING);\r
- glPopMatrix();\r
+ updateLights();\r
\r
drawAxisLines();\r
\r
glutSwapBuffers();\r
}\r
\r
-/**\r
- * init function; sets initial OpenGL state\r
- */\r
-void init() {\r
- glLightfv(GL_LIGHT0, GL_AMBIENT, ambient0);\r
- glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0);\r
- glLightfv(GL_LIGHT0, GL_SPECULAR, specular0);\r
- glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, direction0);\r
-\r
- glLightfv(GL_LIGHT1, GL_AMBIENT, ambient1);\r
- glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse1);\r
- glLightfv(GL_LIGHT1, GL_SPECULAR, specular1);\r
- glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, direction1);\r
-\r
- glLightModelfv(GL_LIGHT_MODEL_AMBIENT, glightmodel);\r
- glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);\r
-\r
- glEnable(GL_LIGHT0);\r
- glEnable(GL_LIGHT1);\r
- glEnable(GL_LIGHTING);\r
-}\r
-\r
/**\r
* Main function\r
* @param argc Number of arguments\r
\r
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);\r
\r
- glutInitWindowSize(500, 500);\r
- glutCreateWindow("Scene Editor");\r
+ glutInitWindowSize(width, height);\r
+ glutCreateWindow("Scene Editor - Ashley Tyndall (20915779), Jenna de la Harpe (20367932)");\r
\r
glShadeModel(GL_SMOOTH); // Enables Smooth Shading\r
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background\r
\r
makeMenu();\r
\r
- init();\r
+ initializeLights();\r
\r
glutMainLoop();\r
}
\ No newline at end of file