Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions MeshViewer/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Camera::Camera(int viewWidth, int viewHeight) {
ortho = 0;
viewportWidth = viewWidth;
viewportHeight = viewHeight;
zoom = 1;
horizaspectlock = 16.0 / 9.0
if ((viewportHeight / viewportWidth) < horizaspectlock) {
zoom = zoom / (viewportHeight / viewportWidth) / horizaspectlock;
}
perspectiveFOV = 45.0;
}

Expand All @@ -17,15 +22,15 @@ void Camera::render() {
if (ortho) {
Vector3d temp = eye - lookAt;
double d = temp.length();
double w2 = d * tan(perspectiveFOV / 360 * 3.141592);
double w2 = d * tan(perspectiveFOV / 360 * 3.141592) / zoom;
double h2 = (double)viewportHeight / viewportWidth * w2;
glOrtho(-w2, w2, -h2, h2, 1, 100000);
}
else
gluPerspective(perspectiveFOV, (double)viewportWidth / viewportHeight, 1, 100000);
gluPerspective(atan(tan(perspectiveFOV * 3.141592 / 360) / zoom) * 360 / 3.141592, (double)viewportWidth / viewportHeight, 1, 100000);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(eye.x, eye.y, eye.z, lookAt.x, lookAt.y, lookAt.z, up.x, up.y, up.z);

}
}