diff options
author | Marius Kintel <marius@kintel.net> | 2011-08-05 01:27:17 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2011-08-05 01:27:17 (GMT) |
commit | 0340d4e0a1e3e8a74fdc13d04079d384f7906247 (patch) | |
tree | 98e899b2eca4b390cfbd80aab651e27841968109 /tests/OffscreenView.cc | |
parent | 38f50db0e061353b8ef7055a39357fcf6442d199 (diff) |
Improved view distance
Diffstat (limited to 'tests/OffscreenView.cc')
-rw-r--r-- | tests/OffscreenView.cc | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/tests/OffscreenView.cc b/tests/OffscreenView.cc index 95063b6..f137041 100644 --- a/tests/OffscreenView.cc +++ b/tests/OffscreenView.cc @@ -7,8 +7,10 @@ #define FAR_FAR_AWAY 100000.0 OffscreenView::OffscreenView(size_t width, size_t height) - : orthomode(false), showaxes(true), showfaces(true), showedges(false), viewer_distance(500), - object_rot_x(35), object_rot_y(0), object_rot_z(25) + : orthomode(false), showaxes(true), showfaces(true), showedges(false), + object_rot_x(35), object_rot_y(0), object_rot_z(25), + camera_eye_x(0), camera_eye_y(0), camera_eye_z(0), + camera_center_x(0), camera_center_y(0), camera_center_z(0) { for (int i = 0; i < 10; i++) this->shaderinfo[i] = 0; this->ctx = create_offscreen_context(width, height); @@ -158,27 +160,27 @@ void OffscreenView::setupPerspective() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glFrustum(-w_h_ratio, +w_h_ratio, -(1/w_h_ratio), +(1/w_h_ratio), +10.0, +FAR_FAR_AWAY); + gluPerspective(90, w_h_ratio, 0.1*(this->camera_center_y - this->camera_eye_y), + 3*(this->camera_center_y - this->camera_eye_y)); } -void OffscreenView::setupOrtho(double distance, bool offset) +void OffscreenView::setupOrtho(bool offset) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); - if(offset) - glTranslated(-0.8, -0.8, 0); - double l = distance/10; + if (offset) glTranslated(-0.8, -0.8, 0); + double l = (this->camera_eye_y - this->camera_center_y)/10; glOrtho(-w_h_ratio*l, +w_h_ratio*l, - -(1/w_h_ratio)*l, +(1/w_h_ratio)*l, - -FAR_FAR_AWAY, +FAR_FAR_AWAY); + -(1/w_h_ratio)*l, +(1/w_h_ratio)*l, + -FAR_FAR_AWAY, +FAR_FAR_AWAY); } void OffscreenView::paintGL() { glEnable(GL_LIGHTING); - if (orthomode) - setupOrtho(viewer_distance); + if (orthomode) setupOrtho(); + else setupPerspective(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -187,9 +189,9 @@ void OffscreenView::paintGL() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - gluLookAt(0.0, -viewer_distance, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0); - -// glTranslated(object_trans_x, object_trans_y, object_trans_z); + gluLookAt(this->camera_eye_x, this->camera_eye_y, this->camera_eye_z, + this->camera_center_x, this->camera_center_y, this->camera_center_z, + 0.0, 0.0, 1.0); glRotated(object_rot_x, 1.0, 0.0, 0.0); glRotated(object_rot_y, 0.0, 1.0, 0.0); @@ -202,7 +204,7 @@ void OffscreenView::paintGL() glLineWidth(1); glColor3d(0.5, 0.5, 0.5); glBegin(GL_LINES); - double l = viewer_distance/10; + double l = 3*(this->camera_eye_y - this->camera_center_y); glVertex3d(-l, 0, 0); glVertex3d(+l, 0, 0); glVertex3d(0, -l, 0); @@ -231,3 +233,15 @@ bool OffscreenView::save(const char *filename) { return save_framebuffer(this->ctx, filename); } + +void OffscreenView::setCamera(double xpos, double ypos, double zpos, + double xcenter, double ycenter, double zcenter) +{ + this->camera_eye_x = xpos; + this->camera_eye_y = ypos; + this->camera_eye_z = zpos; + this->camera_center_x = xcenter; + this->camera_center_y = ycenter; + this->camera_center_z = zcenter; +} + |