On Fri, May 20, 2011 at 12:12 PM, David Lonie <[email protected]> wrote:
> the short patch below
> will render an orthographic projection properly.

I think GMail mangled that diff up pretty badly -- I've attached a
plain text version.

Dave
commit e6c650f0417876f35f3e911cafe18a792cec961f
Author: David C. Lonie <[email protected]>
Date:   Fri Apr 29 10:49:00 2011 -0400

    Add option to render using an orthographic projection.
    
    Change-Id: I1c29ed99fddecb5048f069723b30e985c039233d

diff --git a/libavogadro/src/camera.cpp b/libavogadro/src/camera.cpp
index 6940b98..8e24ef8 100644
--- a/libavogadro/src/camera.cpp
+++ b/libavogadro/src/camera.cpp
@@ -189,13 +189,29 @@ namespace Avogadro
     if( d->parent == 0 ) return;
     if( d->parent->molecule() == 0 ) return;
 
+    /// @todo This needs to be a member variable + access functions/signals/slots
+    bool m_useOrthographicProjection = true;
+
     double molRadius = d->parent->radius() + CAMERA_MOL_RADIUS_MARGIN;
     double distanceToMolCenter = distance( d->parent->center() );
     double zNear = std::max( CAMERA_NEAR_DISTANCE, distanceToMolCenter - molRadius );
     double zFar = distanceToMolCenter + molRadius;
     double aspectRatio = static_cast<double>(d->parent->width()) / d->parent->height();
-    gluPerspective( d->angleOfViewY, aspectRatio, zNear, zFar );
-    glGetDoublev(GL_PROJECTION_MATRIX, d->projection.data());
+
+    if (m_useOrthographicProjection) {
+      double halfHeight = molRadius / aspectRatio;
+      GLdouble left  = -molRadius;
+      GLdouble right = molRadius;
+      GLdouble bottom = -halfHeight;
+      GLdouble top = halfHeight;
+      qDebug() << left << right << bottom << top << zNear << zFar;
+      glOrtho(left, right, bottom, top, zNear, zFar);
+      glGetDoublev(GL_PROJECTION_MATRIX, d->projection.data());
+    }
+    else {
+      gluPerspective( d->angleOfViewY, aspectRatio, zNear, zFar );
+      glGetDoublev(GL_PROJECTION_MATRIX, d->projection.data());
+    }
   }
 
   void Camera::applyModelview() const
------------------------------------------------------------------------------
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its 
next-generation tools to help Windows* and Linux* C/C++ and Fortran 
developers boost performance applications - including clusters. 
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
Avogadro-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/avogadro-devel

Reply via email to