From 9db97251872a73e70cff9986aa5d8d3ef360766d Mon Sep 17 00:00:00 2001 From: josh Date: Wed, 30 Jan 2008 03:59:59 +0000 Subject: [PATCH] zoom support git-svn-id: svn://anubis/misc/wfobj-view@31 bd8a9e45-a331-0410-811e-c64571078777 --- wfobj-view.cc | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/wfobj-view.cc b/wfobj-view.cc index 42ba000..ce11b28 100644 --- a/wfobj-view.cc +++ b/wfobj-view.cc @@ -3,6 +3,8 @@ #include #include #include +#include +using namespace std; /* Some definitions */ #define WIDTH 800 @@ -13,6 +15,7 @@ float rotationMatrix[16]; int startx, starty; bool dragging = false; +float dist = 5.0; void initgl(void) { @@ -27,8 +30,8 @@ void initgl(void) glViewport(0, 0, WIDTH, HEIGHT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - gluPerspective(60.0, (GLfloat)WIDTH/(GLfloat)WIDTH, 1.0, 30.0); - gluLookAt(0, -4.0, 0, 0, 0, 0, 0, 0, 1); + gluPerspective(60.0, (GLfloat)WIDTH/(GLfloat)WIDTH, 0.01, 10000.0); + gluLookAt(0, -dist, 0, 0, 0, 0, 0, 0, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glGetFloatv(GL_MODELVIEW_MATRIX, rotationMatrix); @@ -92,6 +95,28 @@ int main(int argc, char * argv[]) starty = event.button.y; } } + else if (event.button.button == 4) + { + dist *= 0.85; + if (dist < 1.0f) + dist = 1.0f; + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(60.0, (GLfloat)WIDTH/(GLfloat)WIDTH, 0.01, 10000.0); + gluLookAt(0, -dist, 0, 0, 0, 0, 0, 0, 1); + glMatrixMode(GL_MODELVIEW); + display(); + } + else if (event.button.button == 5) + { + dist *= 1.2; + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(60.0, (GLfloat)WIDTH/(GLfloat)WIDTH, 0.01, 10000.0); + gluLookAt(0, -dist, 0, 0, 0, 0, 0, 0, 1); + glMatrixMode(GL_MODELVIEW); + display(); + } } else if (event.type == SDL_MOUSEBUTTONUP) {