Getting Field of View of a ViewPort inside of RhinoCommon

I’m currently programming a Conduit and I would like to get the Field Of View of the current RhinoViewport I am rendering into.

A RhinoViewport does supply the “Camera35mmLensLength” property, which seemed to be a constant value of 49.9999, which was too big to be the field of view. The field of view seemed to be closer to about 28.0.

Searching through the forum I found this post:

The post is quite old and the links in it are broken, so I was unable to determine what they were suggesting.

I also found this:
https://wiki.mcneel.com/rhino/rhinolensing
But that article is aimed towards setting up a new lens, and I was unable to use it to get the information I needed.

My question is: how can I get, or calculate, the field of view of a given viewport while inside a Conduit? Is it possible?

Hi @samuel1,

Does ViewportInfo.GetCameraAngles provide what you need?

var view = doc.Views.ActiveView;
if (null != view)
{
  var vpinfo = new ViewportInfo(view.ActiveViewport);
  if (vpinfo.GetCameraAngles(
    out double halfDiagonalAngleRadians, 
    out double halfVerticalAngleRadians, 
    out double halfHorizontalAngleRadians)
    )
  {
    // TODO...
  }
}

– Dale

1 Like

Nice work, @dale that worked well for me!
I had to do a little more math:

var view = doc.Views.ActiveView;
if (null != view)
{
  var vpinfo = new ViewportInfo(view.ActiveViewport);
  if (vpinfo.GetCameraAngles(
    out double halfDiagonalAngleRadians, 
    out double halfVerticalAngleRadians, 
    out double halfHorizontalAngleRadians)
    )
  {
      var verticalAngle = 2.0d * halfVerticalAngle;
      fieldOfView = (verticalAngle * 180.0d) / Math.PI;
  }
}

Which works perfectly - as I size up or down the Lens Length in the Viewport’s settings, my fieldOfView now changes appropriately! :slight_smile:
Thanks for the help, Dale!

1 Like