使用IPython的筆記本電腦,我已經能夠調出地球的地球儀有類似的代碼:約束Mayavi的鼠標拖拽到繞軸旋轉的地球
from mayavi import mlab
from mayavi.sources.builtin_surface import BuiltinSurface
ocean_blue = (0.4, 0.5, 1.0)
r = 6371 # km
sphere = mlab.points3d(0, 0, 0, name='Globe',
scale_mode='none', scale_factor=r * 2.0,
color=ocean_blue, resolution=50)
sphere.actor.property.specular = 0.20
sphere.actor.property.specular_power = 10
continents_src = BuiltinSurface(source='earth', name='Continents')
continents_src.data_source.on_ratio = 1 # detail level
continents_src.data_source.radius = r
continents = mlab.pipeline.surface(continents_src, color=(0, 0, 0))
但是,當我用得到的3D窗口交互使用鼠標很難保持它的正面朝上,因爲UI將解釋鼠標拖動到左邊或右邊作爲試圖旋轉場景(或相機?)圍繞當前的垂直軸窗口,而不是通過地球本身的軸。
是否有任何方法來限制用戶交互代碼,以便鼠標左鍵或右鍵拖動地球圍繞其軸旋轉,而不管軸是否指向直立或垂直,無論是通過設置一些Mayavi參數,或者通過獲取一些註冊爲用於鼠標拖動的UI事件處理程序的Python代碼?
它會做到這一點,如果你點擊「ctrl」並拖動。 – aestrivex
在我的筆記本電腦上安裝的Mayavi版本中,按住Ctrl僅僅是旋轉地球周圍表面上我正在查看的那一刻;它不會將運動限制在地球本身的極點附近。 –
好的,我沒有完全理解你想要的交互。 – aestrivex