Jump to content
Sign in to follow this  
Guest

screen possition

Recommended Posts

Guest

Hi

To clarify the question, I want to return the screen (pixel) coordinates of a node/element in the current screen view?

Share this post


Link to post
Share on other sites
Guest

Called the support - got no answer - but a colleague at work found out ...

Here is the solution:

# getScreenPosOfNode --##       Delivers the screen position of a node $nodeID. A node at the lower left#       corner of the viewport gives (0/0) - at the upper right corner (1/1).## Arguments:#       nodeID   node number to retrieve screen position for## Results:#       Returns a list of 2 values: relative x- and relative y-screen-positionproc getScreenPosOfNode {nodeID} {    set P [join [hm_nodevalue $nodeID]] ;# real world coords in global coord sys    set view [join [hm_getcurrentview]]    # extract transformation matrix T    set T [list [lrange $view 0 2] [lrange $view 4 6] [lrange $view 8 10]]    set v [lrange $view 12 14] ;# translation vector v    foreach {minx miny maxx maxy} [join [hm_getviewport]] {}    # rotational transformation: real world coords to screen coords (P-->P_)    set P_ {}    for {set row 0} {$row < 3} {incr row} {        set coord_ 0        for {set col 0} {$col < 3} {incr col} {            set coord_ [expr {$coord_+[lindex $T $col $row]*[lindex $P $col]}]        }        lappend P_ $coord_    }    # add translation (P_-->P_canvas)    set Px_canvas [expr {[lindex $P_ 0]+[lindex $v 0]}]    set Py_canvas [expr {[lindex $P_ 1]+[lindex $v 1]}]    # compute relative screen position    set Canvas_DeltaX [expr {$maxx-$minx}]    set Canvas_DeltaY [expr {$maxy-$miny}]    set P_relX [expr {($Px_canvas-$minx)/double($Canvas_DeltaX)}]    set P_relY [expr {($Py_canvas-$miny)/double($Canvas_DeltaY)}]    return [list $P_relX $P_relY]}

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...