1

I am having a problem with the roll angle not working in vispy turntable camera.

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 

Even though I give 30 degree roll angle the view is not rotating. But azimuth, elevation and center works perfectly.

My main purpose here is to roll the camera instead of the rolling the tank for animation pupose. (Sloshing research).

enter image description here

  • 1
    One thing that is a little worrying is the comment on https://github.com/vispy/vispy/blob/b5f6228c7c4ec734206e9556033f5c3e7941616c/vispy/scene/cameras/turntable.py#L63 It seems that roll may not be fully used. Most likely these methods need to be updated https://github.com/vispy/vispy/blob/b5f6228c7c4ec734206e9556033f5c3e7941616c/vispy/scene/cameras/turntable.py#L128-L154 but I'm not super familiar with this camera. – djhoese Jun 09 '20 at 14:12

1 Answers1

1

Hi @djhoese thank you for your advice.

I was able to fix the roll problem by adding an additional line to the _rotate_tr function in the vispy library.

Original code:

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)

Modified Code

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

Results with roll angle 0 degrees and 180 degrees are shown below.

Roll set as 0 (default) Roll set as 180 degrees

  • 1
    Awesome! Do you think you could make a pull request for this fix? – djhoese Jun 10 '20 at 13:32
  • Hi @djhoese I just realised another problem. The workaround that I mentioned does not work in arbitrary orientation :( . But the advice that you gave helped me to solve my existing problem. If I find a general solution I will make the pull request. – sreenath subramaniam Jun 10 '20 at 15:46