Bugfix: Zoom was broken for orthographic cameras. Fixes #853

master
Marius Kintel 2014-06-26 15:34:15 -04:00
parent 7e5ad73c66
commit 4bed4902e9
6 changed files with 42 additions and 13 deletions

Binary file not shown.

View File

@ -78,3 +78,28 @@ void Camera::viewAll(const BoundingBox &bbox, float scalefactor)
break;
}
}
void Camera::zoom(int delta)
{
if (this->projection == PERSPECTIVE) {
this->viewer_distance *= pow(0.9, delta / 120.0);
}
else {
this->height *= pow(0.9, delta / 120.0);
}
}
void Camera::setProjection(ProjectionType type)
{
if (this->projection != type) {
switch (type) {
case PERSPECTIVE:
this->viewer_distance = this->height;
break;
case ORTHOGONAL:
this->height = this->viewer_distance;
break;
}
this->projection = type;
}
}

View File

@ -28,6 +28,8 @@ public:
Camera(enum CameraType camtype = NONE);
void setup(std::vector<double> params);
void gimbalDefaultTranslate();
void setProjection(ProjectionType type);
void zoom(int delta);
void viewAll(const BoundingBox &bbox, float scalefactor = 1.0f);
// Vectorcam

View File

@ -424,7 +424,7 @@ void GLView::showAxes()
glLineWidth(this->getDPI());
glColor3d(0.5, 0.5, 0.5);
glBegin(GL_LINES);
double l = cam.viewer_distance;
double l = cam.projection == Camera::PERSPECTIVE ? cam.viewer_distance : cam.height;
glVertex3d(-l, 0, 0);
glVertex3d(+l, 0, 0);
glVertex3d(0, -l, 0);

View File

@ -178,12 +178,6 @@ void QGLView::paintGL()
if (running_under_wine) swapBuffers();
}
void QGLView::wheelEvent(QWheelEvent *event)
{
cam.viewer_distance *= pow(0.9, event->delta() / 120.0);
updateGL();
}
void QGLView::mousePressEvent(QMouseEvent *event)
{
mouse_drag_active = true;
@ -286,14 +280,25 @@ bool QGLView::save(const char *filename)
return img.save(filename, "PNG");
}
void QGLView::wheelEvent(QWheelEvent *event)
{
this->cam.zoom(event->delta());
updateGL();
}
void QGLView::ZoomIn(void)
{
cam.viewer_distance *= 0.9;
this->cam.zoom(120);
updateGL();
}
void QGLView::ZoomOut(void)
{
cam.viewer_distance /= 0.9;
this->cam.zoom(-120);
updateGL();
}
void QGLView::setOrthoMode(bool enabled) {
if (enabled) this->cam.setProjection(Camera::ORTHOGONAL);
else this->cam.setProjection(Camera::PERSPECTIVE);
}

View File

@ -34,10 +34,7 @@ public:
bool showCrosshairs() const { return this->showcrosshairs; }
void setShowCrosshairs(bool enabled) { this->showcrosshairs = enabled; }
bool orthoMode() const { return (this->cam.projection == Camera::ORTHOGONAL); }
void setOrthoMode(bool enabled) {
if (enabled) this->cam.projection = Camera::ORTHOGONAL;
else this->cam.projection = Camera::PERSPECTIVE;
}
void setOrthoMode(bool enabled);
std::string getRendererInfo() const;
#if QT_VERSION >= 0x050100
float getDPI() { return this->devicePixelRatio(); }