原文链接:
http://adndevblog.typepad.com/manufacturing/2014/11/rotate-camera-around-any-axis-any-angle.html
大家知道,工程图里,先是生成基础视图(也就是主视图),然后产生投影视图。例如:
DrawingView.Rotation 或 DrawingView.RotateByAngle 只能让视图绕垂直纸面的轴 (也就是视点方向)旋转。如果我们要让视图绕着相机上方向旋转怎么办?
其实,Inventor API提供了丰富的相机功能,可以轻松实现这个流程。我直接贴代码了。注意其中的解释:
Sub RotateBaseView()
' 预先选择好基础视图
Dim baseView As DrawingView
Set baseView = ThisApplication.ActiveDocument.SelectSet(1)
' 通过设置相机的UpVector = 相机视点方向来实现旋转
' 视点方向 = 眼睛到观察点的向量
' 然后计算新眼睛位置
Dim c As Camera
Set c = baseView.Camera
Dim oldEye As Point
Set oldEye = c.Eye.Copy
Dim oldTarget As Point
Set oldTarget = c.Target.Copy
Dim oldViewDir As Vector
Set oldViewDir = oldEye.VectorTo(oldTarget)
Dim viewDist As Double
viewDist = oldViewDir.Length
Dim newTargetToEye As Vector
Set newTargetToEye = c.UpVector.AsVector().Copy
Call newTargetToEye.ScaleBy(viewDist)
Call oldTarget.TranslateBy(newTargetToEye)
c.Eye = oldTarget
c.UpVector = oldViewDir.AsUnitVector()
Call c.ApplyWithoutTransition
End Sub
运行结果:
推荐论坛阅读:
如何在iLogoic里使用相机