/// <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); } }
/// <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); }