Vizard 8 » Reference » Viewpoints & Windows » Windows » Window & world coordinates
8.0

Window and world coordinates

Vizard has a couple commands that allow you to go between 2D window coordinates and 3D world coordinates. The window coordinates used in these commands are normalized where the bottom left corner of a window is (0,0) and the top right is (1,1).

Getting the 2D window coordinates of 3D point in the world

If you want to know the 2D pixel coordinates of a given point in the 3D world, use the worldToScreen command. This command will identify the pixel coordinates on the window corresponding to the 3D coordinates in the rendered world (where the window's coordinates begin at 0,0 at the lower left corner of the window and go to 1 in either direction). The command gives you a 3rd value corresponding to the depth of the 3D point with respect to those window coordinates.

#Add a 3D model and a function that identifies
#the corresponding 2D window coordinates.
object = viz.add( 'logo.wrl' )
def report():
    print( viz.MainWindow.worldToScreen( object.getPosition() ))
vizact.onkeydown( ' ', report )

Drawing a line from a 2D point on the window into the 3D world

The screenToWorld command takes the normalized coordinates of a point on the window and draws a line from that point into the world (perpendicular to the angle of view) with a beginning, end and direction.

#Create a function that draws a line from
#window coordinates into the rendered world.
def report():
    line = viz.MainWindow.screenToWorld( [.25,.25] )
    print( line.begin)
    print( line.end)
    print( line.dir)
vizact.onkeydown( ' ', report )

See also

In this section:

Window basics

Picking objects off the screen

Window command table

Other sections:

Viewpoint and window basics

Viewpoint basics

Stereo basics

Application window basics

Tutorial: Windows & views