zoom support

git-svn-id: svn://anubis/misc/wfobj-view@31 bd8a9e45-a331-0410-811e-c64571078777
This commit is contained in:
josh 2008-01-30 03:59:59 +00:00
parent dd1f9a834d
commit 9db9725187

View File

@ -3,6 +3,8 @@
#include <SDL/SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <iostream>
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)
{