コード例 #1
0
ファイル: CameraControl.cs プロジェクト: Co-de-iT/froGH
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Point3d location = new Point3d();

            if (!DA.GetData(0, ref location))
            {
                return;
            }

            Point3d target = new Point3d();

            if (!DA.GetData(1, ref target))
            {
                return;
            }

            double lens = 35;

            DA.GetData(2, ref lens);

            if (lens == 0)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Lens cannot be zero");
            }

            Vector3d up = Vector3d.ZAxis;

            DA.GetData(3, ref up);

            bool activate = false;

            DA.GetData(4, ref activate);

            if (!activate)
            {
                Message = "";
            }
            else
            {
                Message = "active";
                //Get current viewport
                vp = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport;
                //Set new camera
                vp.SetCameraLocations(target, location);
                vp.CameraUp = up;
                vp.ChangeToPerspectiveProjection(true, lens);
            }
        }
コード例 #2
0
ファイル: Turntable.cs プロジェクト: Co-de-iT/froGH
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <GeometryBase> G = new List <GeometryBase>();

            if (!DA.GetDataList(0, G))
            {
                return;
            }

            //Plane P = new Plane();
            //DA.GetData(1, ref P);

            double distMult = 0.0;

            DA.GetData(1, ref distMult);

            Interval lensRange = new Interval();

            DA.GetData(2, ref lensRange);

            double lensPar = 0.0;

            DA.GetData(3, ref lensPar);

            double lens = lensRange.ParameterAt(lensPar);

            int direction = 0;

            DA.GetData(4, ref direction);
            direction = direction % 2;

            double adjustStart = 0.0;

            DA.GetData(5, ref adjustStart);

            double slideCamZ = 0.0, slideTarZ = 0.0;

            DA.GetData(6, ref slideCamZ);
            DA.GetData(7, ref slideTarZ);

            double animT = 0.0;

            DA.GetData(8, ref animT);

            bool activate = false;

            DA.GetData(9, ref activate);
            if (!activate)
            {
                Message = "";
                return;
            }

            BoundingBox bb = new BoundingBox();

            foreach (GeometryBase gg in G)
            {
                bb.Union(gg.GetBoundingBox(false));
            }

            double d = Math.Max(bb.Diagonal.X, bb.Diagonal.Y) * 2;

            // compensate lens/distance
            double  radius = d * distMult * (lens / ((lensRange[1] + lensRange[0]) * 0.5));
            Point3d center = bb.Center;
            Point3d target = center;

            center.Z += slideCamZ;
            target.Z += slideTarZ;

            double  sign   = direction * 2 - 1;
            double  angle  = Math.PI * 2 * (adjustStart + animT) * sign;
            Point3d camera = center + new Point3d(Math.Cos(angle) * radius, Math.Sin(angle) * radius, 0.0);

            Message = string.Format("{0:f1}", lens);
            //Get current viewport
            vp = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport;
            //Set new camera
            vp.SetCameraLocations(target, camera);
            vp.CameraUp = Vector3d.ZAxis;
            vp.ChangeToPerspectiveProjection(true, lens);
        }
コード例 #3
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //  Retrieve input data, exit if non-existent
            if (!DA.GetData(0, ref Activate))
            {
                return;
            }
            if (!DA.GetData(1, ref SrcViewportName))
            {
                return;
            }
            if (!DA.GetData(2, ref DestViewportName))
            {
                return;
            }


            bool srcToggled  = false;
            bool destToggled = false;

            Rhino.Display.RhinoViewport srcViewport = null, destViewport = null;

            if (Activate)
            {
                foreach (Rhino.Display.RhinoView thisview in RhinoDoc.ActiveDoc.Views)
                {
                    if (SrcViewportName == thisview.ActiveViewport.Name)
                    {
                        srcViewport = thisview.ActiveViewport;
                        srcToggled  = true;
                    }
                    if (DestViewportName == thisview.ActiveViewport.Name)
                    {
                        destViewport = thisview.ActiveViewport;
                        destToggled  = true;
                    }
                }

                if (srcToggled == false)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Viewport '" + SrcViewportName + "' does not exist!");
                }
                if (destToggled == false)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Viewport '" + DestViewportName + "' does not exist!");
                }


                if (srcToggled == true && destToggled == true)
                {
                    foreach (Rhino.Display.RhinoView thisview in RhinoDoc.ActiveDoc.Views)
                    {
                        if (DestViewportName == thisview.ActiveViewport.Name)
                        {
                            destViewport = thisview.ActiveViewport;
                            destViewport.SetCameraLocations(srcViewport.CameraTarget, srcViewport.CameraLocation);
                            destViewport.Camera35mmLensLength = srcViewport.Camera35mmLensLength;
                            destViewport.CameraUp             = srcViewport.CameraUp;
                        }
                    }
                }
            }
        }