What is the cleanest way to get the view direction relative to your scene in vispy?
view.scene.transform
contains a whole chain of transforms:
In [88]: view.scene.transform
Out[88]:
<ChainTransform [<STTransform scale=[ 960. -540. 1. 1.] translate=[ 960. 540. 0. 0.] at 0x139757309901840>,
MatrixTransform(matrix=[[26.44507, 0.0, 0.0, 0.0],
[0.0, 47.013458, 0.0, 0.0],
[0.0, 0.0, -1e-06, 0.0],
[-0.0, -0.0, -0.0, 1.0]] at 0x7f1bc8d526d0),
<Inverse of '<ChainTransform [MatrixTransform(matrix=[[0.64390097845776273, -0.18562251042644023, -0.74225050593726238, 0.0],\n [0.74851597030808681, 0.35377196489238, 0.56086472437650059, 0.0],\n [0.15847830177938896, -0.91672770247177038, 0.36673552784799862, 0.0],\n [0.002241050448888897, 0.013296952664039196, 0.015024409939918581, 1.0]] at 0x7f1bc8c81710)] at 0x7f1bc8cb7e90>'>] at 0x7f1bc8e75490>
I could write something to parse lists of transforms of varous types and compose them, and extract the view direction from the composed transform, but I suspect I'm swimming upstream.
Vispy transformations have a
map
andimap
function you can use to map coordinates between scene and screen coordinates in either direction. I used them on points and threw in a lot of assertions to be safe; there are probably simpler implementations. I tested this for orthographic projection. I ~think it will work for perspective projections too as long as the center of projection is in the middle of the screen.