ARUP.IssueTracker.Navisworks.NavisWindow.generateViewpoint C# (CSharp) Method

generateViewpoint() private method

private generateViewpoint ( Viewpoint oVP, int elemCheck ) : VisualizationInfo
oVP Viewpoint
elemCheck int
return VisualizationInfo
        private VisualizationInfo generateViewpoint(Viewpoint oVP, int elemCheck)
        {
            double units = GetGunits();
            VisualizationInfo v = new VisualizationInfo();
            try
            {

                Vector3D vi = getViewDir(oVP);
                Vector3D up = getViewUp(oVP);
                Point3D center = new Point3D(oVP.Position.X / units, oVP.Position.Y / units, oVP.Position.Z / units);
                double zoomValue = 1;


                oVP = oVP.CreateCopy();
                if (!oVP.HasFocalDistance)
                    oVP.FocalDistance = 1;

                if (oVP.Projection == ViewpointProjection.Orthographic) //IS ORTHO
                {
                    // **** CUSTOM VALUE FOR TEKLA **** //
                    // otherwise = 1
                    // **** CUSTOM VALUE FOR TEKLA **** //


                    double dist = oVP.VerticalExtentAtFocalDistance / 2 / units;
                    zoomValue = 3.125 * dist / (up.Length * 1.25);
                    //zoomValue = Math.Tan(oVP.HeightField / 2) * oVP.FarPlaneDistance / _feet *1.25;
                    //  MessageBox.Show(oVP.HeightField.ToString() + "  " + oVP.FarPlaneDistance.ToString() + "   " + zoomValue + "   " + oVP.HasFocalDistance.ToString() + "   " + oVP.VerticalExtentAtFocalDistance.ToString());
                    v.OrthogonalCamera = new OrthogonalCamera();
                    v.OrthogonalCamera.CameraViewPoint.X = center.X;
                    v.OrthogonalCamera.CameraViewPoint.Y = center.Y;
                    v.OrthogonalCamera.CameraViewPoint.Z = center.Z;
                    v.OrthogonalCamera.CameraUpVector.X = up.X;
                    v.OrthogonalCamera.CameraUpVector.Y = up.Y;
                    v.OrthogonalCamera.CameraUpVector.Z = up.Z;
                    v.OrthogonalCamera.CameraDirection.X = vi.X;
                    v.OrthogonalCamera.CameraDirection.Y = vi.Y;
                    v.OrthogonalCamera.CameraDirection.Z = vi.Z;
                    v.OrthogonalCamera.ViewToWorldScale = zoomValue;
                }
                else // it is a perspective view
                {
                    double f = oVP.FocalDistance;
                    //there is an issue when using vewpoint generated from clashes
                    //their VerticalExtentAtFocalDistance is correct but the HorizontalExtentAtFocalDistance is too small!
                    //so results that the aspect ratio in that case is <1. In which I try to get an approximate valut of the HorizontalExtentAtFocalDistance
                    // by multiplying the vercial by 1.35
                    //double hfov = (oVP.AspectRatio < 1) ? oVP.VerticalExtentAtFocalDistance * 1.23245 / 2 : oVP.HorizontalExtentAtFocalDistance / 2;
                    //double angle = Math.Atan(hfov * (1 / f)) * 2;
                    //double angled = (180 * angle / Math.PI);


                    //NAVIS USES HFOV
                    //double vfov = oVP.VerticalExtentAtFocalDistance / 2;
                    //double fov = Math.Sqrt(hfov * hfov + vfov * vfov);
                    //double angle = Math.Atan(fov*(1/f)) *2;
                    //double angled = (180 * angle / Math.PI);
                    //MessageBox.Show(angled.ToString() + "   " + oVP.FarDistance + "   " +f + "   " + oVP.NearDistance );// + "\n zoom" + zoom);

                    zoomValue = f;

                    v.PerspectiveCamera = new PerspectiveCamera();
                    v.PerspectiveCamera.CameraViewPoint.X = center.X;
                    v.PerspectiveCamera.CameraViewPoint.Y = center.Y;
                    v.PerspectiveCamera.CameraViewPoint.Z = center.Z;
                    v.PerspectiveCamera.CameraUpVector.X = up.X;
                    v.PerspectiveCamera.CameraUpVector.Y = up.Y;
                    v.PerspectiveCamera.CameraUpVector.Z = up.Z;
                    v.PerspectiveCamera.CameraDirection.X = vi.X;
                    v.PerspectiveCamera.CameraDirection.Y = vi.Y;
                    v.PerspectiveCamera.CameraDirection.Z = vi.Z;
                    v.PerspectiveCamera.FieldOfView = zoomValue;
                }



                if (elemCheck == 0)//visible (0)
                    _elementList = _oDoc.Models.First.RootItem.DescendantsAndSelf.Where(o => o.InstanceGuid != Guid.Empty && ChechHidden(o.AncestorsAndSelf) && o.FindFirstGeometry() != null && !o.FindFirstGeometry().Item.IsHidden).ToList<ModelItem>();

                if (null != _elementList && _elementList.Any() && elemCheck != 2)//not if none (2)
                {
                    v.Components = new Classes.Component[_elementList.Count];
                    string appname = Autodesk.Navisworks.Api.Application.Title;
                    for (var i = 0; i < _elementList.Count; i++)
                    {
                        string ifcguid = IfcGuid.ToIfcGuid(_elementList.ElementAt(i).InstanceGuid).ToString();
                        v.Components[i] = new ARUP.IssueTracker.Classes.Component(appname, "", ifcguid);

                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return v;
        }