Discussion:
[OpenSCAD] View All bug
nop head
2018-08-22 19:50:57 UTC
Permalink
The ViewAll button has always produced a view that nowhere nears fill the
window. There was a discussion recently that pointed out a cube at the
origin comes out a different size if it is centred or not. An extreme case
is this:

translate([0, 10000, 0])
cube([100,100,100], center = true);



A 100 cube far from the origin comes out tiny. The culprit seem to be this
line
https://github.com/openscad/openscad/blob/0904a3b3a5b56b16bb423b177972468eeca775a9/src/Camera.cc#L75

I don't understand what (bbox.center()-this->center).norm() is trying to
do. It is this that makes the view change size depending on where it is and
removing it solves the problem. A 100 cube is a constant size regardless of
where it is. Here is the same cube.



So I can submit a PR unless somebody can explain why that expression is
needed.

In general it doesn't give the optimum zoom but it does fit the scene in
the window unless you make the window thinner than it is tall. It basically
ensures the bounding sphere of the object doesn't exceed the height of the
screen regardless of how the object is oriented. It should really look at
the bounding rectangle of the projected 2D image compared with the window
dimensions.
nop head
2018-08-22 20:12:00 UTC
Permalink
The previous discussions was actually this issue:
https://github.com/openscad/openscad/issues/2386
Post by nop head
The ViewAll button has always produced a view that nowhere nears fill the
window. There was a discussion recently that pointed out a cube at the
origin comes out a different size if it is centred or not. An extreme case
translate([0, 10000, 0])
cube([100,100,100], center = true);
A 100 cube far from the origin comes out tiny. The culprit seem to be this
line https://github.com/openscad/openscad/blob/
0904a3b3a5b56b16bb423b177972468eeca775a9/src/Camera.cc#L75
I don't understand what (bbox.center()-this->center).norm() is trying to
do. It is this that makes the view change size depending on where it is and
removing it solves the problem. A 100 cube is a constant size regardless of
where it is. Here is the same cube.
So I can submit a PR unless somebody can explain why that expression is
needed.
In general it doesn't give the optimum zoom but it does fit the scene in
the window unless you make the window thinner than it is tall. It basically
ensures the bounding sphere of the object doesn't exceed the height of the
screen regardless of how the object is oriented. It should really look at
the bounding rectangle of the projected 2D image compared with the window
dimensions.
Marius Kintel
2018-08-22 21:44:09 UTC
Permalink
I don't understand what (bbox.center()-this->center).norm() is trying to do. It is this that makes the view change size depending on where it is and removing it solves the problem. A 100 cube is a constant size regardless of where it is. Here is the same cube.
I cannot remember the details, but there’s an ‘autocenter’ flag in that class, which could influence how the camera distance is calculated for View All.

-Marius
nop head
2018-08-23 10:20:02 UTC
Permalink
Yes it looks like (bbox.center()-this->center).norm() is needed when the
camera is not looking at the centre of the bounding box. I think that only
happens when using the command line because
QGLView::*viewAll*() forces the camera to look at the center without
setting autocenter by setting the transformation itself.
https://github.com/openscad/openscad/blob/a84da9a110b46543520f7e2e73e69b0f071c90db/src/QGLView.cc#L94
.

Camera::center is initialised to [0,0,0] in the constructor and
autocenter false,
so in view all in the GUI they remain at those values hence it looks at the
object's centre but calculates the distance as if it is looking at the
origin, so the origin is always in view as well. the size of the object
depends on its offset from the origin.

I think the correct fix is to set camera->autocenter in QGLView::*viewAll*()
instead of setting cam.object_trans. That will cause Camera::ViewAll() to
set the transformation but it should also set Camera::center to match. That
should fix the GUI and also the command line when using autocentre with the
gimble camera.

I am not sure why the command line has viewall and autocenter as separate
options when they are always together in the GUI. Also I don't think
viewall without autocenter will work currently with the gimble camera
because nothing sets Camera::centre in that case.
Post by nop head
I don't understand what (bbox.center()-this->center).norm() is trying
to do. It is this that makes the view change size depending on where it is
and removing it solves the problem. A 100 cube is a constant size
regardless of where it is. Here is the same cube.
I cannot remember the details, but there’s an ‘autocenter’ flag in that
class, which could influence how the camera distance is calculated for View
All.
-Marius
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Loading...