2016-06-17 6 views
1

vispyでシーンを基準にしてビュー方向を取得する最もクリーンな方法は何ですか?私はvarous種類の変換のリストを解析し、それらを構成するために何かを書き、変換構成からの視線方向を抽出し、私は、私は「疑うことができvispyのシーンに対するビュー方向を取得しますか?

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> 

view.scene.transformは、変換の全体チェーンが含まれています上流に泳ぐ。

答えて

0

Vispy変換には、シーンとスクリーン座標の間の座標をどちらの方向にもマップするために使用できる関数mapimapがあります。私はポイントでそれらを使用し、安全であるために多くの主張を投げた。おそらくより簡単な実装があります。私は正射投影についてこれをテストしました。私は、投影の中心が画面の真ん中にある限り、それは透視投影のためにも機能すると思います。

def get_view_direction_in_scene_coordinates(view): 
    import numpy 
    tform=view.scene.transform 
    w,h = view.canvas.size 
    screen_center = numpy.array([w/2,h/2,0,1]) # in homogeneous screen coordinates 
    d1 = numpy.array([0,0,1,0]) # in homogeneous screen coordinates 
    point_in_front_of_screen_center = screen_center + d1 # in homogeneous screen coordinates 
    p1 = tform.imap(point_in_front_of_screen_center) # in homogeneous scene coordinates 
    p0 = tform.imap(screen_center) # in homogeneous screen coordinates 
    assert(abs(p1[3]-1.0) < 1e-5) # normalization necessary before subtraction 
    assert(abs(p0[3]-1.0) < 1e-5) 
    d2 = p1 - p0 # in homogeneous screen coordinates 
    assert(abs(d2[3])< 1e-5) 
    d3 = d2[0:3] # in 3D screen coordinates 
    d4 = d3/numpy.linalg.norm(d3) 
    return d4 
関連する問題