Hello,
I would like to re-modell one building in Openscad. Therefore I have some
photos and found windows app which makes windows transparent.
But if I set correct viewport distance the object is very small. Therefore I
need to set the angle of view - to zoom the object (I can not advance the
object as it looks differently).
How can I do that in Openscad ?
Thank you for help,
Vaclav
See this discussion
http://forum.openscad.org/How-to-translate-3-vector-axis-to-a-camera-viewpoint-td20289.html#a20303
.
And see if you are using OpenSCAD with parallel or perspective view.
There are special variables for the camera which you can set
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Other_Language_Features#.24vpr.2C_.24vpt_and_.24vpd
On Sun, Nov 12, 2017 at 11:01 AM, Vaclav Peroutka vaclavpe@seznam.cz wrote:
Hello,
I would like to re-modell one building in Openscad. Therefore I have some
photos and found windows app which makes windows transparent.
But if I set correct viewport distance the object is very small. Therefore I
need to set the angle of view - to zoom the object (I can not advance the
object as it looks differently).
How can I do that in Openscad ?
Thank you for help,
Vaclav
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
On 11/12/2017 9:01 AM, Vaclav Peroutka wrote:
I would like to re-modell one building in Openscad. Therefore I have
some photos and found windows app which makes windows transparent.
But if I set correct viewport distance the object is very small.
Therefore I need to set the angle of view - to zoom the object (I can
not advance the object as it looks differently).
How can I do that in Openscad ?
I'm not sure, but I don't think you can.
I'm not really good with the math, but after experimenting for a while
it seems like you can move the camera around, but you can't directly
zoom it.
There are three variables that control the camera:
$vpr controls rotation. (Note that it controls rotation of the model,
not the camera. Changing it turns the model rather than turning the
camera. You can also look at it as causing the camera to orbit around
the model.)
$vpt controls where the center of the viewport is. Normally this is
used for panning left and right, but it can also pan in and out.
$vpd controls the distance from the center of the viewport to the
camera. For "zoom" purposes, I believe this is the same as using $vpt
to move the center of the viewport in and out.
What you want is to zoom the image, not to move the camera closer to
it. The difference is in the angles; zoom magnifies the image but does
not change the angles. Visibility of an object does not change as you
zoom in and out, while moving the camera out may make more objects visible.
You can zoom, by changing the window size. However, that's severely
constrained; you can't just make the window ten times bigger than your
screen.
It might be possible to do what you need by applying the right matrix
multiply to your object, to sort of do your viewport translation in the
construction of the object. But I would I have to think for a long time
about exactly how to do that.
Here's an animation that lets you play with moving the viewport center
and/or the camera distance. Note that the two cubes on the side are
more visible when the camera is further away; when the camera is close
they are hidden behind the big cube. Pick one of the $vpt lines and one
of the $vpd lines to enable (remember Ctrl+D and Ctrl+Shift+D are your
friends). Note that if you enable both calculated values, they exactly
cancel each other out. If one of them controlled camera position and
the other controlled zoom, that wouldn't be true.
// t will vary from 0 to 1 and back to 0.
t = 1-abs($t-0.5)*2;
#cube(10,center=true);
translate([5.5,0,0]) cube(1,center=true);
translate([-5.5,0,0]) cube(1,center=true);
//$vpt=[0,60t-30,0]; // Varies from -30 to +30
$vpt=[0,0,0];
$vpr=[90,0,0];
$vpd=(60t)+30; // Varies from 30 to 60
//$vpd=60;
translate($vpt) sphere(0.1);
If you haven't used an animation before: View/Animate, then in the
fields at the bottom of the window enter values for FPS and Steps. 10
and 100 are working well for me.
@Vaclad
There is no way to get zoom effect with OpenSCAD in perspective mode. In
camera lenses, zoom results from changing the camera lens focus distance.
In OpenSCAD, the "camera lens focus distance" seems to be fixed to the
equivalent of a 60mm focus lens for 35mm films. However, you may simulate
zoom in parallel mode by changing the camera distance. To get zoom we would
need to control either the viewport size (equivalent to change the camera
film format) or the focus distance of the camera lens.
@Jordan
I disagree with your interpretation of $vpr. Changing $vpr will not rotate
the model; it rotates the coordinate system (relative to the viewer). The
sun doesn't rotate around the earth although that is the feeling of an
observer on the earth.
On 11/13/2017 3:14 AM, Ronaldo Persiano wrote:
There is no way to get zoom effect with OpenSCAD in perspective mode.
In camera lenses, zoom results from changing the camera lens focus
distance. In OpenSCAD, the "camera lens focus distance" seems to be
fixed to the equivalent of a 60mm focus lens for 35mm films. However,
you may simulate zoom in parallel mode by changing the camera
distance. To get zoom we would need to control either the viewport
size (equivalent to change the camera film format) or the focus
distance of the camera lens.
From a mathematical perspective, I think zoom is applying a
straightforward uniform scaling transformation after applying the
perspective transformation, either before or after discarding the depth
coordinate to project into 2D. But I'm not sure.
He's trying to match a photograph, so switching to orthogonal view won't
do the right thing either.
I disagree with your interpretation of $vpr. Changing $vpr will not
rotate the model; it rotates the coordinate system (relative to the
viewer). The sun doesn't rotate around the earth although that is the
feeling of an observer on the earth.
You're right - I was speaking informally. I wasn't drawing a
distinction between rotating the coordinate system (and thus rotating
the objects defined in that coordinate system) and rotating the objects
themselves. The objects don't move.
Having the camera orbit the center of the viewport is probably still
more correct - if I'm doing my right-hand-rule right, that's what the
numbers say - but I just can't convince my brain that that's what's
happening, at least for most models. (Maybe for architectural models.)
It's tempting to think that you could achieve something a lot like a
zoom effect by scaling the model, but my experiments suggest not - you
need the scaling to happen after the perspective, and matrix multiply
isn't commutative. (Or not commutative enough? Or I haven't figured
out how.) It seems like maybe you could switch to orthogonal mode and
transform the model to apply both perspective and zoom, but some
experiments suggest that you can't do perspective transforms. Or maybe
in perspective mode use a transform that's the equivalent of scaling
after perspective, but I suspect that such a matrix would resemble a
perspective matrix.
Od: Jordan Brown
"
On 11/13/2017 3:14 AM, Ronaldo Persiano wrote:
"
There is no way to get zoom effect with OpenSCAD in perspective mode. In
camera lenses, zoom results from changing the camera lens focus distance. In
OpenSCAD, the "camera lens focus distance" seems to be fixed to the
equivalent of a 60mm focus lens for 35mm films. However, you may simulate
zoom in parallel mode by changing the camera distance. To get zoom we would
need to control either the viewport size (equivalent to change the camera
film format) or the focus distance of the camera lens.
"
From a mathematical perspective, I think zoom is applying a straightforward
uniform scaling transformation after applying the perspective
transformation, either before or after discarding the depth coordinate to
project into 2D. But I'm not sure.
He's trying to match a photograph, so switching to orthogonal view won't do
the right thing either.
"
Exactly. I tried orthogonal view but it seemed to me that it was even worse.
I need to somehow change the "lens focus".
I guess I have a way to produce a zoomed image. The following code
illustrate the concept (I hope it is correct):
zoom=0.5cos(360$t) + 2*(1-cos(360*$t));
cam_dist = 100;
cam_dir = -[10,10,20];
cam_top = [0,0,1];
echo(zoom=zoom);
module model()
cube(10);
$vpd = zoom*cam_dist;
$vpr = RM2EAxyz(camRot(cam_dir,cam_top));
$vpt = [0,0,0];
rot = camRot(cam_dir,cam_top);
irot = transpose(rot);// rot inverse
multmatrix(irot*mscale([1,1,zoom])*rot) // the compress or stretch of the
model
model();
// converts a rotation matrix into the Euler angles
// with the order Rx.Ry.Rz
function RM2EAxyz(M) =
let( sy = norm([M[0][0],M[0][1]]) )
sy > 1e-6 ?
[ atan2(M[1][2],M[2][2]),
atan2(-M[0][2],sy),
atan2(M[0][1],M[0][0]) ] :
[ atan2(-M[2][1], M[1][1]),
atan2(-M[0][2],sy),
0 ];
// the rotation matrix of a camera local system
function camRot(dir,top) =
let( dx = cross(dir,top),
dy = -cross(dir,dx) )
[unit(dx), unit(dy), -unit(dir)];
// scale matrix
function mscale(s) =
[for(i=[0:2])[for(j=[0:2]) i==j? s[i]: 0]];
function unit(v) = v/norm(v);
function transpose(M) =
[for(j=[0:2])[for(i=[0:2]) M[i][j]]];
The first 4 lines set the camera parameters:
zoom is the zoom factor; 1 is the normal lens (60mm lens); <1 is a
telephoto lens (>60mm lens); >1 is a wide angle lens (<60mm lens)
cam_dist is the distance between the camera and the scene center
cam_dir is the direction the camera lens is pointing to
cam_top is the direction of the vertical axis of the viewport
The principle behind the code is: given the zoom factor (a scale of the
viewport), multiply the camera distance by zoom and scale (compress or
strecth) the scene (model) by the same factor just in the direction of the
camera.
In the code, we can set the camera position as for instance
cam_pos = [100,100,200];
and compute $vpt from it:
$vpt = cam_pos+unit(cam_dir)*cam_dist;