0
import numpy as np
from vispy import app, scene
from vispy.visuals import transforms

canvas = scene.SceneCanvas(keys='interactive', show=True)
vb = canvas.central_widget.add_view()
vb.camera = 'turntable'
vb.camera.rect = (-10, -10, 20, 20)

box = scene.visuals.Box(width=1, height=2, depth=3, color=(0, 0, 1, 0.3),
                        edge_color='green')
vb.add(box)

# Define a scale and translate transformation :
box.transform = transforms.STTransform(translate=(0., 0., 0.),
                                       scale=(1., 1., 1.))


@canvas.events.key_press.connect
def on_key_press(ev):
    tr = np.array(box.transform.translate)
    sc = np.array(box.transform.scale)
    if ev.text in '+':
        tr[0] += .1
    elif ev.text == '-':
        tr[0] -= .1
    elif ev.text == '(':
        sc[0] += .1
    elif ev.text == ')':
        sc[0] -= .1
    box.transform.translate = tr
    box.transform.scale = sc
    print('Translate (x, y, z): ', list(tr),
          '\nScale (x, y, z): ', list(sc), '\n')

if __name__ == '__main__':
    import sys
    if sys.flags.interactive != 1:
        app.run()

In the above code if I add a MatrixTransform, and rotate the cube and then apply scaling, the cube becomes a Rhombus

What I would like to achieve is to rotate the cube in a canvas and scale it only in X direction, without other dimensions getting affected

1 Answers1

0

I think we covered this in a vispy repository bug report. The solution was to swap the order of the matrix transform and st transform in your multiplication. If this is still an issue, could you provide your code when you are using the matrix and we'll continue debugging this. Thanks.

djhoese
  • 3,567
  • 1
  • 27
  • 45