Vizard 7 » Reference » Tools » Laser Pointer
7.7

Laser Pointer

A tool for pointing in the scene. The distance from the pointer to the intersecting object is displayed. The following command creates a LaserPointer object:

Command

Description

laser_pointer.LaserPointer(displayDistance=True)

displayDistance: When True, displays text with distance information.

The following methods are available on the LaserPointer object:

Method

Description

<LaserPointer>.shoot()

Draws a ray from the laser pointer to the closest intersecting object.

<LaserPointer>.remove()

Removes the laser pointer.

<LaserPointer>.setUpdateFunction(updateFunction)

Sets the update function that gets called every frame. The update function calls methods on the tool based on the state of input devices.

Example

"""  
Left mouse button activates the laser.  
Mouse movements control viewpoint orientation.  
Arrow Keys control viewpoint position.  
""" 

import viz
import vizact
import vizshape
import vizinfo
vizinfo.InfoPanel(align=viz.ALIGN_LEFT_BOTTOM)

viz.setMultiSample(4)
viz.fov(60)
viz.go()

# add a background environment
maze = viz.add('maze.osgb')

# add an arrow to represent the tool
arrow = vizshape.addArrow(length=0.2, color = viz.ORANGE)

# initialization code for laserpointer which is a LaserPointer
from tools import laser_pointer
tool = laser_pointer.LaserPointer()

# update code for laserpointer
def update(tool):
    state = viz.mouse.getState()
    if state & viz. MOUSEBUTTON_LEFT:
        tool.shoot()

tool.setUpdateFunction(update)

#Link the laser tool to an arrow  
#Then move the arrow in the reference frame of the viewpoint
from vizconnect.util import virtual_trackers
mouseTracker = virtual_trackers.ScrollWheel(followMouse = True)
mouseTracker.distance = 1
arrowLink = viz.link(mouseTracker,arrow)
arrowLink.postMultLinkable(viz.MainView)
viz.link(arrowLink,tool)

import vizcam
vizcam.FlyNavigate()

#Hide the mouse cursor
viz.mouse.setVisible(viz.OFF)