#include "../mapviewer.h" #include "glut.h" #include #define SENSITIVITY 500 int glut_width, glut_height; int isLDown, isRDown, isMDown; int ox, oy, mx, my; int isShiftDown, isCtrlDown; GLfloat movedist = 4.0f; void Resize(int w, int h) { glut_width = w; glut_height = h; glViewport(0, 0,w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f,(GLfloat)w/(GLfloat)h,0.1f,100.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void process_keys() { isShiftDown = 0; isCtrlDown = 0; if (glutGetModifiers() & GLUT_ACTIVE_SHIFT) isShiftDown = 1; else if (glutGetModifiers() & GLUT_ACTIVE_CTRL) isCtrlDown = 1; } void Keypress(unsigned char key, int x, int y) { int tmp; GLfloat dist; if (isupper(key)) key = tolower(key); process_keys(); if (isShiftDown) dist = movedist*2.0f; else if (isCtrlDown) dist = movedist/2.0f; else dist = movedist; switch(key) { case '[': Camera.ChangeFOV(1.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(Camera.GetFOV(), (GLfloat)(GLView.getWidth())/ (GLfloat)(GLView.getHeight()), 1.0f, Sky.GetFarClp()); glMatrixMode(GL_MODELVIEW); break; case ']': Camera.ChangeFOV(-1.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(Camera.GetFOV(), (GLfloat)(GLView.getWidth())/ (GLfloat)(GLView.getHeight()), 1.0f, Sky.GetFarClp()); glMatrixMode(GL_MODELVIEW); break; case 'n': if (isShiftDown) planescale -= 0.1; else planescale += 0.1; break; case 'm': cout << "Enter length of Minute in Milliseconds: " << flush; cin >> tmp; Game.SetMinuteLength(tmp); break; case 'o': GLView.MakeScreenshot(); break; case 'p': { GLfloat x, y, z; cout << "Enter new Position of Target: " << flush; cin >> x >> y >> z; Camera.SetTarget(x, y, z); } break; case 'w': Camera.MoveForwardBackward(dist); break; case 's': Camera.MoveForwardBackward(-dist); break; case 'a': Camera.PanLeftRight(dist); break; case 'd': Camera.PanLeftRight(-dist); break; case 'e': if (isShiftDown) Camera.IncreaseEyeDist(0.1); else Camera.DecreaseEyeDist(0.1); break; case 'i': if (isShiftDown) World.SetInterior(World.GetInterior()-1); else World.SetInterior(World.GetInterior()+1); cout << "Interior: " << World.GetInterior() << endl; break; case 'h': if (isShiftDown) Clock.TurnBackOneHour(); else Clock.AdvanceOneHour(); cout << "Time: " << Clock.GetHour() << ":" << Clock.GetMinute() << endl; break; case 'g': if (isShiftDown) Clock.TurnBackOneMinute(); else Clock.AdvanceOneMinute(); cout << "Time: " << Clock.GetHour() << ":" << Clock.GetMinute() << endl; break; case 'u': if (isShiftDown) Sky.PreviousWeather(); else Sky.NextWeather(); cout << "Weather: " << Sky.GetWeatherSelector() << endl; break; case 'l': if (isShiftDown) World.SetLODmultiplier(World.GetLODmultiplier()-0.05); else World.SetLODmultiplier(World.GetLODmultiplier()+0.05); break; case 't': GLView.ToggleTextures(); break; case 'v': GLView.ToggleVertexColors(); break; case 'y': GLView.ToggleTint(); break; case 'k': Game.ToggleTime(); break; case 'f': GLView.ToggleFog(); break; case 'c': GLView.ToggleStereo(); break; case 'r': GLView.ToggleRadar(); break; case 'j': GLView.ToggleCulling(); break; case 'q': GLView.ToggleWire(); break; case 'x': if (isShiftDown) movedist *= 2.0f; else movedist /= 2.0f; cout << movedist << endl; break; case 'b': // Camera.DumpPos(); printf("enter 2 new carcols (0-94): "); scanf("%d %d", &carcol1ind, &carcol2ind); if (carcol1ind >= 95) carcol1ind = 94; if (carcol2ind >= 95) carcol2ind = 94; break; case 'z': if (isShiftDown) Camera.Dolly(dist); else Camera.Dolly(-dist); break; case '.': Camera.SetDistanceToTarget(10.0f); break; case 27: exit(0); default: break; } } void MouseButton(int button, int state, int x, int y) { if (state == GLUT_DOWN) { if (button == GLUT_LEFT_BUTTON) { mx = x; my = y; isLDown = 1; } else if (button == GLUT_RIGHT_BUTTON) { mx = x; my = y; isRDown = 1; } else if (button == GLUT_MIDDLE_BUTTON) { mx = x; my = y; isMDown = 1; } } else { if (button == GLUT_LEFT_BUTTON) isLDown = 0; else if (button == GLUT_RIGHT_BUTTON) isRDown = 0; else if (button == GLUT_MIDDLE_BUTTON) isMDown = 0; } } void MouseMotion(int x, int y) { GLfloat dx, dy; GLfloat a, b; ox = mx; oy = my; mx = x; my = y; dx = ((float) (ox - mx) / GLView.getWidth()); dy = ((float) (oy - my) / GLView.getHeight()); a = tan(Camera.GetFOV()) * Camera.GetDistanceToTarget(); b = a*GLView.getHeight()/GLView.getWidth(); if (isLDown) { Camera.TurnLeftRight(dx*1.5f); Camera.TurnUpDown(dy*1.5f); } else if (isRDown) { Camera.ArcLeftRight(dx*1.5f); Camera.ArcUpDown(dy*1.5f); } else if (isMDown) { Camera.PanLeftRight(-dx*a); Camera.PanUpDown(dy*b); } } void Keypress_spec(int key, int x, int y) { GLfloat dist; process_keys(); if (isShiftDown) dist = movedist*2; else if (isCtrlDown) dist = movedist/2; else dist = movedist; switch(key) { case GLUT_KEY_UP: Camera.MoveTargetInOut(-dist); Camera.DumpPos(); break; case GLUT_KEY_DOWN: Camera.MoveTargetInOut(dist); Camera.DumpPos(); break; /* case GLUT_KEY_UP: Camera.TurnUpDown(phi); break; case GLUT_KEY_DOWN: Camera.TurnUpDown(-phi); break; case GLUT_KEY_LEFT: cout << "left\n"; Camera.TurnLeftRight(phi); break; case GLUT_KEY_RIGHT: Camera.TurnLeftRight(-phi); break; */ case GLUT_KEY_PAGE_UP: Camera.MoveUpDown(dist); break; case GLUT_KEY_PAGE_DOWN: Camera.MoveUpDown(-dist); break; case GLUT_KEY_F1: case GLUT_KEY_F2: case GLUT_KEY_F3: case GLUT_KEY_F4: case GLUT_KEY_F5: case GLUT_KEY_F6: case GLUT_KEY_F8: case GLUT_KEY_F9: case GLUT_KEY_F10: case GLUT_KEY_F11: case GLUT_KEY_F12: if (isShiftDown) { Camera.SavePosition(key-GLUT_KEY_F1); } else Camera.LoadPosition(key-GLUT_KEY_F1); break; default: break; } } void CGLView::SwapBuffers(void) { glutSwapBuffers(); } int CGLView::getWidth(void) { return glut_width; } int CGLView::getHeight(void) { return glut_height; } void glut_idle(void) { static int time, oldtime = clock(); time = clock(); GLView.UpdateScene((time - oldtime) * 1000/CLOCKS_PER_SEC); GLView.RenderScene(); oldtime = time; } void wrap_display(void) { GLView.RenderScene(); } void CGLView::StartOgl(int argc, char *argv[]) { glut_width = 850; glut_height = 480; isLDown = isRDown = isMDown = 0; glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH | GLUT_STENCIL); glutInitWindowSize(glut_width, glut_height); glutCreateWindow(progname); glutDisplayFunc(wrap_display); glutReshapeFunc(Resize); glutKeyboardFunc(Keypress); glutMouseFunc(MouseButton); glutMotionFunc(MouseMotion); glutSpecialFunc(Keypress_spec); glutIdleFunc(glut_idle); if (ViewMode == GAME) Game.Init(); else Viewer.Init(); glutMainLoop(); }