ViewPoint is how eyes look at the model. In the past, we need to use COM API to access viewpoint and camera. 2013 .NET API provides the relevant object Viewpoint.
Viewpoint represents the anonymous viewpoint, containing the properties such as near plane distance, far plane distance, linear speed, angular speed etc. It also includes the abilities to manipulate the camera directly. The current viewpoint is accessed by DocumentCurrentViewpoint.
One particular property of Viewpoint is Rotation, which is an object Roation3D. It defines a quaternion to configure the behaviors of the camera.
Note: in current release, API does not provide the property of view direction and the method to multiply two quaternion. While they can be achieved with the theory of quaternion, using Roation3D. The following code snippet dumps the properties of current view point. It also demos how to get view direction. A help method MultiplyRotation3D is to multiply quaternion.
using System.Diagnostics; using Autodesk.Navisworks.Api; using Autodesk.Navisworks.Api.Plugins;
private void dumpViewPoint() { Document oDoc = Autodesk.Navisworks.Api.Application.ActiveDocument; // get current viewpoint Viewpoint oCurVP = oDoc.CurrentViewpoint; // common properties Debug.Print("Far Plane Distance: " + oCurVP.FarPlaneDistance); Debug.Print("Near Plane Distance: " + oCurVP.NearPlaneDistance); Debug.Print("Projection: " + oCurVP.Projection); Debug.Print("Aspect Ratio: " + oCurVP.AspectRatio); if (oCurVP.HasLinearSpeed) Debug.Print("Linear Speed: " + oCurVP.LinearSpeed); else Debug.Print("Linear Speed: "); if (oCurVP.HasAngularSpeed) Debug.Print("Angular Speed: " + oCurVP.AngularSpeed); else Debug.Print("Angular Speed: "); if (oCurVP.HasLighting) Debug.Print("Lighting: " + oCurVP.Lighting); else Debug.Print("Lighting: "); if (oCurVP.HasRenderStyle) Debug.Print("RenderStyle: " + oCurVP.RenderStyle); else Debug.Print("RenderStyle: " + oCurVP.RenderStyle); if (oCurVP.HasTool) Debug.Print("Tool: " + oCurVP.Tool); else Debug.Print("Tool: " + oCurVP.Tool); // camera properties double oFocal = oCurVP.FocalDistance; Debug.Print("Focal Distance: " + oFocal); &
#160; // Rotation Rotation3D oRot = oCurVP.Rotation; Debug.Print( "Quaternion: = ", oRot.A, oRot.B, oRot.C, oRot.D); // calculate view direction Rotation3D oNegtiveZ = new Rotation3D(0, 0, -1, 0); Rotation3D otempRot = MultiplyRotation3D(oNegtiveZ, oRot.Invert()); Rotation3D oViewDirRot = MultiplyRotation3D(oRot, otempRot); // get view direction Vector3D oViewDir = new Vector3D(oViewDirRot.A, oViewDirRot.B, oViewDirRot.C); oViewDir.Normalize(); Debug.Print("View Direction: ", oViewDir.X, oViewDir.Y, oViewDir.Z); // position Point3D oPos = oCurVP.Position; Debug.Print("Position: ", oPos.X, oPos.Y, oPos.Z); // target Point3D oTarget = new Point3D(oPos.X + oViewDir.X * oFocal, oPos.Y + oViewDir.Y * oFocal, oPos.Z + oViewDir.Z * oFocal); Debug.Print("Target: ", oTarget.X, oTarget.Y, oTarget.Z); // rotation information AxisAndAngleResult oAR = oRot.ToAxisAndAngle(); Debug.Print("Rotation Axis: ", oAR.Axis.X, oAR.Axis.Y, oAR.Axis.Z); Debug.Print("Rotation Angle: " + oAR.Angle); }
private Rotation3D MultiplyRotation3D( Rotation3D r2, Rotation3D r1) { Rotation3D oRot = new Rotation3D(r2.D * r1.A + r2.A * r1.D + r2.B * r1.C - r2.C * r1.B,
r2.D * r1.B + r2.B * r1.D + r2.C * r1.A - r2.A * r1.C, r2.D * r1.C + r2.C * r1.D + r2.A * r1.B - r2.B * r1.A, r2.D * r1.D - r2.A * r1.A - r2.B * r1.B - r2.C * r1.C); oRot.Normalize(); return oRot; }
In the next article, we will introduce how to manipulate viewpoint.
(To be continued)

Leave a Reply