1

How do you use Vispy to rotate a cube in three dimensions (roll, pitch, yaw)?

There's an example for rotating a cube in two dimensions here, but I'm not sure how to extend it to rotate in the third dimension.

I think I need to modify the on_timer() method. I tried changing it from:

def on_timer(self, event):
    self.theta += .5
    self.phi += .5
    self.model = np.dot(rotate(self.theta, (0, 1, 0)),
                        rotate(self.phi, (0, 0, 1)))
    self.program['u_model'] = self.model
    self.update()

to:

def on_timer(self, event):
    self.gamma += .5
    self.theta += .5
    self.phi += .5
    self.model = np.dot(
        rotate(self.gamma, (1, 0, 0)),
        np.dot(rotate(self.theta, (0, 1, 0)),
                        rotate(self.phi, (0, 0, 1))),
    )
    self.program['u_model'] = self.model
    self.update()

but that only seems to make the third dimension duplicate the second. What am I doing wrong?

Cerin
  • 60,957
  • 96
  • 316
  • 522

1 Answers1

0

Instead of increasing gamma, theta, and phi, run the same code but only increase one of the three variables. Repeat for each of the three variables. You will see that you are, in fact, rotating in three different dimensions at once with your new code; maybe it just doesn't look like you thought it would? Or maybe you were thinking it would change from the perspective of the cube, but it's actually doing the coordinate transformation from the camera's perspective?

Also, an easier starting place may be from the scene cube example: https://github.com/vispy/vispy/blob/master/examples/basics/scene/cube.py. Unless you're actually looking to understand the lower level OpenGL API layer.

Cody Piersall
  • 8,312
  • 2
  • 43
  • 57