ABRG-Models / morphologica

A library of supporting code for numerical modelling (JSON config, HDF5 data, Modern OpenGL visualization)
https://abrg-models.github.io/morphologica/
Apache License 2.0
255 stars 29 forks source link

Typo in `orthographic()` in `TransformMatrix.h` #190

Closed GeoSpark closed 4 months ago

GeoSpark commented 4 months ago

The code looks like this:

            orthoMat[0] = Flt{2}/(tr[0]-bl[1]);  // Subtracting bottom from right.
            orthoMat[5] = Flt{2}/(tr[1]-bl[1]);
            orthoMat[10] = Flt{-2}/(zFar-zNear);
            orthoMat[12] = -(tr[0]+bl[1])/(tr[0]-bl[0]);  // Adding right and bottom.

But it should look like this:

            orthoMat[0] = Flt{2}/(tr[0]-bl[0]);  // Subtracting left from right.
            orthoMat[5] = Flt{2}/(tr[1]-bl[1]);
            orthoMat[10] = Flt{-2}/(zFar-zNear);
            orthoMat[12] = -(tr[0]+bl[0])/(tr[0]-bl[0]); // Adding right and left.
sebjameswml commented 4 months ago

Well done for noticing this! The way I had the 'ortho_bl' and 'ortho_tr' set in morph::Visual (to (-4,-4) and (4,4)) meant that the projection looked ok, despite the error.

I think fix is slightly different from what you wrote down. I think because the 'tr' and 'bl' names for those coordinates was confusing - I've changed them to rt and bl so that rt[0] is 'r' and rt[1] is 't'. Do you agree with my PR? https://github.com/ABRG-Models/morphologica/pull/191/commits

GeoSpark commented 4 months ago

It certainly confused me for a good hour or so! I do prefer that naming convention, but then you should also rename ortho_bl and ortho_tr in Visual.h

sebjameswml commented 4 months ago

I'll do that and add to the PR

sebjameswml commented 4 months ago

Presumably you figured out how to view the orthographic projection? Run any morphologica example program and press "Ctrl-y" to cycle from perspective projection to orthographic (press it once more and you'll get a hacky, incomplete, but fun cylindrical projection. It's back to perspective with a third press of Ctrl-y.)

sebjameswml commented 4 months ago

Lastly - what motivated you to examine the orthographic projection code? I'd be interested to know. I don't use this projection much in my own work; I pretty much always have my programs produce the perspective projection. Do you have an interest in orthographic visualisation?

GeoSpark commented 4 months ago

I was looking for a visualisation library that worked with Qt for displaying 2D gridded archaeological geophysics data, and also one that can do some basic charting, and I stumbled across morphologica. I wanted the gridded data to appear 2D when viewed normally, but with the option of 3D after some processing. It all worked fine but because it generates a 3D mesh, perspective effects were visible in the viewport. I've ended up making a copy of viswidget.h so I can mess about with my own functionality, such as modifying the keybinds, and calculating ortho viewport size based on zoom and aspect ratio.

sebjameswml commented 4 months ago

Thanks for sharing that information. Glad it's potentially of use for your work. To avoid perspective effects you could maybe toggle the z values for your grid when viewing 2d, possibly doing this automatically based on the rotational state in morph::Visual. I was also thinking about the ortho projection and thought it would be good to map the mouse wheel to scale ortho_tr and ortho_lb to make it possible to zoom in ortho view