I’d like to explain a few things about the kalzium 3d code that I have not
commented in the code. This is especially intended for Donald: I hope it
helps you take the stuff out of kalzium 3d into avogadro.
In KalziumGLWidget::prepareMoleculeData(), we compute the molecule’s best
fitting plane using Eigen’s computeFittingHyperplane() function. We then
rotate the molecule in such a way that this plane becomes the XY-plane, i.e.
the plane given by the equation z=0.
The purpose of this is twofold:
- it makes it easy to set up the camera in such a way that the user has a nice
top-down viewpoint on the molecule
- it makes it easier to draw the double (and multiple) bonds in such a way
that they don’t look like single bonds. This is done by Cylinder::draw(), the
bond order being passed as the “order” argument. The code for rendering
multiple bonds is at the bottom of Cylinder::draw().
See my blog entry here: http://bjacob.livejournal.com/1762.html
Another thing that I’d like to mention is display lists.
- performance: display lists are important, thanks to them we can put
complicated computations in e.g. Cylinder::draw() without affecting
performance. Also display lists are the fastest way of rendering on
software-only systems, which is what we want to focus on
(hardware-accelerated systems are more than fast enough anyway).
- nesting: you have probably noticed that we used nested display lists, i.e.
there is a display list for the whole molecule, and it calls display lists
for the sphere and the cylinder. The rationale for having a display list for
the whole molecule is what I said above, performance. The rationale for
having display lists for the sphere and cylinder is that if we hadn’t, i.e.
if we directly drew spheres and cylinders into the molecule display list,
that would make it huge because for n atoms there would be n spheres in this
display list. The cool thing with display list nesting is that the small list
doesn’t get unfolded into the big list: it just gets called. This way, thanks
to display list nesting, regardless of the number of atoms in the molecule,
the molecule displaylist remains quite small - it just consists of matrix
operations, material operations, and calling the sphere and cylinder lists.
Also a general remark on my code: I’m not very proud of its quality and
architecture. Really feel free to take completely different design decisions.
This code was the first I wrote after several years without coding, and now
that I’ve learnt a lot while doing Eigen, when I look back at my Kalzium
code, I find it clumsy and wrongly architected.