Hi all,

2011/5/20 Geoffrey Hutchison <[email protected]>:
>> Now I want to have my structures in an orthographic view (for top/side 
>> view). I tried to edit glwidget.cpp from the stable release as below.
>> It now seems to display stuff orthographically but it looks like depth 
>> queuing doesn't work anymore. Bond sticks are above their atoms and atoms in 
>> the back are above atoms in the front. (see attached picture).

I have also needed this from time to time, and the short patch below
will render an orthographic projection properly. The navigation
functions need to be changed (e.g. right now trying to zoom in will
translate the camera...). If someone wants to finish this up to make
it less of hack feel free. Otherwise I might....someday :-)

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());
+    }
   }

Cheers,

Dave

------------------------------------------------------------------------------
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