1

我遇到了滚动角在 vispy 转盘相机中不起作用的问题。

def surface_3D(x, y, z, name):

    canvas = scene.SceneCanvas(keys='interactive')
    view = canvas.central_widget.add_view()
    view.camera = 'turntable'
    view.camera.center = (0,0,0)
    view.camera.fov = 50
    view.camera.distance = 3
    view.camera.azimuth = -90  
    view.camera.elevation = 30
    view.camera.roll = 30  # This angle is not working

    Y, X = np.meshgrid(y, x)   

    tray1  = np.zeros_like(X)
    tray2  = np.zeros_like(X)

    tray1[0,:] = 0.5 ; tray1[:,0] = 1 ; tray1[-1,:] = 1 ; tray1[:,-1] = 1
    tray2[0,:] = z[0,:] ; tray2[:,0] = z[:,0] ;  tray2[-1,:] = z[-1,:] ; tray2[:,-1] = z[:,-1]

    surface  = scene.visuals.SurfacePlot(x, y, z, shading='smooth', color='#289fd2')
    surface1 = scene.visuals.SurfacePlot(x, y, tray1, shading='smooth', color=(0.5,0.5,0.5,0.2))
    surface2 = scene.visuals.SurfacePlot(x, y, tray2, shading='smooth', color='#289fd2')

    view.add(surface)
    view.add(surface2)
    view.add(surface1)

    canvas.show(run=True)

    im = _screenshot((0, 0, canvas.size[0], canvas.size[1]))
    io.imsave('vispy_screenshot.png', im)

    return 

即使我给出 30 度的滚动角度,视图也不会旋转。但是方位角、仰角和中心完美地工作。

我在这里的主要目的是为了动画目的滚动相机而不是滚动坦克。(晃动研究)。

在此处输入图像描述

4

1 回答 1

1

嗨@djhoese 谢谢你的建议。

我能够通过在 vispy 库中的 _rotate_tr 函数中添加额外的一行来解决滚动问题。

原始代码:

def _rotate_tr(self):
        """Rotate the transformation matrix based on camera parameters"""
        up, forward, right = self._get_dim_vectors()
        self.transform.rotate(self.elevation, -right)
        self.transform.rotate(self.azimuth, up)

修改后的代码

def _rotate_tr(self):
        """Rotate the transformation matrix based on camera parameters"""
        up, forward, right = self._get_dim_vectors()
        self.transform.rotate(self.elevation, -right)
        self.transform.rotate(self.azimuth, up)
        self.transform.rotate(self.roll, -right)  # New line added here

滚动角 0 度和 180 度的结果如下所示。

滚动设置为 0(默认) 滚动设置为 180 度

于 2020-06-10T06:48:24.063 回答