How to Reverse FOV Slider?

  • Hi,

    I have this slider that works pretty fine, but from left to right is the shallower field of view to the wider field of view.

    I'd like to have the opposite.

    The wider field of view on the left and the zoomed in fov on the right.

    Could anyone help me please?


    <!-- HORIZONTAL SLIDER -->
    <plugin name="slider_bg" url="slider-background.png" align="bottom" x="0" y="30" handcursor="false" zorder="1" parent="stage"/>

    <plugin name="slider_grip" url="slider-grip.png" align="left" edge="center" parent="slider_bg" x="0" zorder="2"
    dragging="if(pressed,
    sub(dx, mouse.stagex, drag_stagex);
    add(newx, drag_currentx, dx);
    if(newx LT 0, set(newx,0));
    if(newx GT plugin[slider_bg].pixelwidth, copy(newx,plugin[slider_bg].pixelwidth));
    copy(x,newx);
    div(val, newx, plugin[slider_bg].pixelwidth);

    sub(fovrange, view.fovmax, view.fovmin);
    mul(newfov, val, fovrange);
    add(newfov, view.fovmin);
    set(view.fov, get(newfov));

    delayedcall(0,dragging());
    );"
    ondown="copy(drag_currentx,x); copy(drag_stagex,mouse.stagex); dragging();"
    />


    <events name="sliderevents" keep="true" onviewchanged="updateslider();" />

    <action name="updateslider">
    sub(val, view.fov, view.fovmin);
    sub(fovrange, view.fovmax, view.fovmin);
    div(val, fovrange);
    mul(plugin[slider_grip].x, val, plugin[slider_bg].pixelwidth);
    </action>

    THANKS!

  • It's working greatly!!!
    Thank you so much!!

    I put a text on the side of the slider to show the FOV value, but what I really want to show is the Focal Length.

    I found this formula:

    FOV = 2*arctan(43.26/(2F))

    Where F is the Focal Length I need to know.

    43.26 is the diagonal of a full frame sensor.

    Do you have any idea how to get there?

    I have no idea how to make math inside krpano.

    I tried this: calc(view.fov, (2) * (Math.atan2(43.36) / (2) * (100))));


    But of course, it doesn't work. haha
    I have no clue how to program from scratch.



    I got the following code for the krpano fovtype example and simply removed the fov.type message:


    <events onresize="ifnot(in_area_tween, resizearea() );"
    onviewchange="showfovtext();"
    />


    <action name="showfovtext">
    copy(fov,view.fov);
    roundval(fov,2);
    txtadd(msg,' FOV =',get(fov),'°');
    showtext(get(msg),FOVTEXT);
    </action>

    So now I have the text showing FOV = 100º for example.

    But I'd love to show: Focal Length = 18mm


    I appreciate any help!!!

  • Haha.. yes

    I have no idea how to reverse this.

    But what if the slider is based on the Focal Length value.

    We feed the value with the focal length (that would be even better for me), and use this formula to translate it to view.fov?


    I have this in C#. Don't know if it can be useful:



    private void SetCameraFOV()

    {

    float fov = Mathf.Rad2Deg * 2.0f * Mathf.Atan(SENSOR_HEIGHT_FF / (2.0f * m_cameraFL));


    Camera.main.fieldOfView = fov;

    // Debug.Log(fov + " lens" + m_cameraFL);

    m_cameraFLTxt.text = string.Format(m_copyFL + ": {0:0} mm", m_actualFL);

    }


    private void SetFocalLength()

    {

    m_cameraFL = m_focalLengthValues[m_currentSensorSize] * m_actualFL;

    //m_cameraFLSl.value = (m_cameraFL - CAMERA_MIN_FL) / (CAMERA_MAX_FL - CAMERA_MIN_FL);


    SetCameraFOV();

    }


    Thanks for your patience! :)

  • I tried to create an example for a 24mm focal length:


    <action name="setcamerafov" >

    set(ff, 43.36);
    set(fl, 24);
    calc(fov, 180 / Math.PI * (2 * Math.atan(ff / (2 * fl)));

    set(view.fov, fov);

    </action>

    But it does absolutely nothing in the scene.


    I found this angle of view formula that could be translated to fov. It's almost the same.. or the same. I don't know.

    https://static1.pointsinfocus.com/2010/09/depth-of-field-and-equivalent-lens-calculator/aov-equation-method1.png[/size]

    I tried with and without the " 180 / Math.PI * " part, but both didn't work. It doesn't give me an error. Just don't do anything.

    [size=10]

    Quote

    But in fact it is necessary to calculate fl ?


    I need the slider to provide user friendly information.
    So if the slider could change focal length (mm) and not fov (º), this would be perfect.

    When this formula works, I would feed the data with focal lengths.
    So if the slider could work based on focal lengths, than there's no need to convert.

    If the slider still works based on fov, than it should be "translated" to focal length.

    Thanks for your help!!!!!!!!!!

  • the " 180 / Math.PI * " part
    translates radian to degrees

    and with
    set(view.fov, fov);
    you set view.fov to "fov" which is a string and not a valid input

    you need to use
    copy(view.fov, fov);

    https://krpano.com/docu/actions/#set
    https://krpano.com/docu/actions/#copy

    i dont know what units you must use for ff and fl
    mm? meters?

    maybe use
    trace("fl=", fl, " fov=", fov);
    before the copy command,
    to see what value comes out of the calculation
    press O to show the console

  • I'm totally lost here.

    I have this action:

    <action name="setcamerafov" >
    set(ff, 43.36);

    set(fl, %1);
    calc(fov, 180 / Math.PI * (2 * Math.atan(ff / (2 * fl)));
    copy(view.fov, fov);

    </action>


    The trace shows the actual fov of the screen. As it isn't changing anything, I can't be sure if it's working.



    I need to put the fov value into view.fov after the onclick.


    I know it's wrong, but for you to understand, it could be something like:
    onclick="tween(view.fov, get(fov));"

    Actually I have this code working for the onclick (using FOV, not focal length):


    <action name="change_fov">
    set(view.fovmin, 6.15);
    set(view.fovmax, 140);


    tween(view.fov, %2, 0.5);
    WAIT(0.5);
    set(view.fovmin, %1);
    set(view.fovmax, %2);

    updateslider();
    </action>



    And on the onclick I'm inserting:


    onclick="change_fov(12.3,34.3);"



    This is equivalent to a 70-200mm lens.

    The perfect solution for me would be the possibility to have an onclick in focal length like this;

    onclick="change_fov(70,200);"

    ---------

    I got the formula to do the reverse (FOV to Focal Length):

    Focal Length (fl) = (arctan * ff) / FOV
    ff = sensor diagonal size. Full Frame = 43.36mm


    Focal Length is in mm
    Sensor Size is in mm
    FOV is in º

    I'm sorry for these newbies questions.
    I try to do my best here.
    I have absolutely no coding experience and try to do things by trials and errors.
    But this is too advanced. I usually stay in the basic xml stuff.
    I'm trying to get out of the comfortable zone and break the blockage I have with coding, but it's hard to understand it fast.

    Sometimes I spend a day or two working in something that probably you'd do in a couple of minutes, but that's how I'm learning.
    And I couldn't find anything related to this specific need so I could learn from.

    I really appreciate your time and help!!!

  • I output the parameters FOV and F on the screen
    I used this formula calc(fov, 180 / Math.PI * (2 * Math.atan(ff / (2 * fl))));, but it seems to me the extreme positions do not match?


  • WOW!!

    Great! Almost there!!

    What works perfectly:

    Use the slider and see the Focal Length and FOV values


    What isn't correct:
    1) When I zoom in or out from any other way except moving the slider, the Focal Length data doesn't update, only the FOV. It may be lacking an updateslider action?.

    2) Yes. The extreme positions are crazy. The value respect the fovmin and fovmax settings, but the focal length slider value continues till till 0 or max.

    3) The dragging(%1) value sets the maximum focal length of the slider. But there's no minimum focal length option to enter.
    It would be interesting to have something like dragging(24,70); 24mm would be the minimum and 70mm the maximum.

    I've done this manually using fovmin and fovmax for each button.
    It works great with fov.



    And when I use this fov action, the scene is changed, but the slider keeps always showing values till 200mm Although it's only possible to se the changes in the range specified by fovmin and fovmax.


    There could be a onclick="make_slider(24,70);" based on focal length.
    And this, of course, would change the view.fovmin and view.fovmax settings.


    Well, let me be honest.
    Of course it would be AMAZING to have this working in this more intelligent way, but I see I will never (or so soon) be able to implement anything based on these math based options.


    So I was wondering if it's just possible to get the FOV value and output as focal length.

    No need to restrict the slider values like it's now.
    I'll do it with view.fov values and it should just be visually translated to focal length for the user.


    Now, the FOV to Focal Length "translation" only works when moving the slider.
    If it can work for every onviewchanged happenings, without interfering on the values of the slider (max value), so It would be solved for now!!

    I'll deal with all other manual stuff I need to do.
    It's faster to do this way.
    As far as you already got the math to work, I'm wondering if you could help me with this final touch.

    I'm sorry for so many requests. I've been learning a lot here, although it's still difficult for me to understand several things.

    Thank you so much for your patience and for being so helpful!!

  • To limit the focal length, put, for example, 70 mm - dragging (70); in a layer "slider_grip_S"

    Lower bounded by 8 mm:

    To update the zoom with the mouse wheel, you need the formula for calculating F (focal) through changing the FOV

  • Now it's completely weird.

    But anyway, I wish I could have the focal length working only.

    The formula is:
    Focal Length = (arctan * 43.27) / FOV
    Does the following makes sense?


    <action name="make_focallength" >
    set(ff, 43.27);
    set(fov, get(view.fov));
    calc(focallength, (Math.atan * ff) / fov);

    copy(focal, focallength);
    </action>


    If so, how to put the result to appear as text?

    Everything I try I get a NaN result! :P

  • Set the maximum focal length limit layer name="slider_grip_S" ondown="copy(drag_currentx,x); copy(drag_stagex,mouse.stagex);dragging(70);"


  • I'm almost there!

    I gave up the idea to enter the focal Length.
    I did it manually with view.fovmin and view.fovmax data. It's working beautifully.

    Now I'm almost there!!!

    I did the conversion from FOV to Focal Length based on actual view.fov.
    BUT... it's not accurate.

    Could you help me correcting this error?

    Thank you SO MUCH!!!

  • I made the working version. "crop_f" - Crop factor. For a full frame,set(crop_f,1); better put in the "onstart"

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!