使用C#在AutoCAD 2015中围绕相机旋转

3

我正在编写一个静态类,其中包含简化使用AutoCAD相机的方法。我的所有方法似乎都可以工作,除了轨道操作。以下是我的轨道方法:

public static class CameraMethods
    {
        #region _variables and Properties
        private static Document _activeDocument = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
        private static Database _database = _activeDocument.Database;
        private static Editor _editor = _activeDocument.Editor;
        private static ViewTableRecord _initialView = _editor.GetCurrentView();
        private static ViewTableRecord _activeViewTableRecord = (ViewTableRecord)_initialView.Clone();
        #endregion

/// <summary>
        /// Orbit the angle around a passed axis
        /// </summary>
        public static void Orbit(Vector3d axis, Angle angle)
        {
            // Adjust the ViewTableRecord
            //var oldDirection = _activeViewTableRecord.ViewDirection;
            _activeViewTableRecord.ViewDirection = _activeViewTableRecord.ViewDirection.TransformBy(Matrix3d.Rotation(angle.Radians, axis, Point3d.Origin));

            // Set it as the current view
            _editor.SetCurrentView(_activeViewTableRecord);
        }
}

问题在于每次调用轨道时,它都是基于上一次轨道的视图进行操作。例如,第一次调用轨道使其绕x轴旋转45度,它会按照我期望的那样运行。然而,如果我从AutoCAD内部更改相机,然后再次调用该方法,它就会像我调用了两次那样绕X轴旋转90度。我需要关于如何解决这个问题的建议。
1个回答

1
由于AutoCAD是一种MDI应用程序,因此建议不要像您现在这样将那些对象存储为STATIC。相反,每次调用依赖MdiActiveDocument的命令时,都应该获取所有这些变量。这可能是您遇到此问题的原因。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接