Constrain Mayavi mouse drag to rotating Earth around its axis

邮差的信 提交于 2019-12-05 16:16:21
Brandon Rhodes

Nine months later, I have finally run across a clue that lead me to a solution! Another Stack Overflow question and answer, Is it possible to prohibit axes rotation with the mouse in Mayavi?, exposed me to the idea of setting up a non-default “interactor” to control what mouse clicks and drags mean.

And there is indeed an interactor that keeps the Z-axis “up” no matter what the user does:

http://www.vtk.org/doc/nightly/html/classvtkInteractorStyleTerrain.html

To activate this interactor in the Mayavi main window, simply add the following three lines to your code (for example, you can add them to my globe-building code in the question), and the globe will always remain upright!

from tvtk.api import tvtk
fig = mlab.gcf()
fig.scene.interactor.interactor_style = tvtk.InteractorStyleTerrain()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!