Reference: Viewpoints & windows

Hotspots

Hotspots are areas in your world that automatically trigger events. An analogy in the real-world is motion detectors - the devices used to open doors, turn on lights, or signal alarms when you enter certain areas.

 

When you define a hotspot, you specify its location, shape, and size. A hotspot can be floating out in space, or it can be associated with a 3D object. You can also specify whether you want the hotspot to be triggered when the viewpoint leaves the specified area or when the viewpoint enters the specified area. Once a hotspot has been set off, it's de-activated. So, if you want to continue using a hotspot at that place, you'll need to create a new one.

Defining a hotspot

To set up a hotspot, you need to both a) register the callback function that will handle hotspot events and b) start the hotspot.

 

Vizard has a hotspot callback in the Callback Wizard on the main toolbar or you can type it in yourself, using viz.callback(viz.HOTSPOT_EVENT, <hotspot function>) where <hotspot function> is the function that'll be called when a hotspot is triggered.

 

This function should be able to handle four parameters: the hotspot's id and the x,y, and z of the viewpoint's current position. Once you've registered this callback function, you can add as many hotspots as you want using viz.starthotspot(<hotspot id, shape and kind, and dimensions> ).

 

def onHotspot(id,x,y,z):
    print 'you hit it'
viz.callback(viz.HOTSPOT_EVENT,onHotspot)
viz.starthotspot(1, viz.RECTANGLE_HOTSPOT_IN, 0,3,.5,.5)

Hotspot parameters

Hotspots can be either circular or rectangular.  A hotspot can be triggered when you enter its area (an "IN" hotspot) or when you leave its area (an "OUT" hotspot). These two parameters make up the hotspot type in the viz.starthotspot command.

 

When you specify the position of a hotspot, you specify the x and z of the hotspot's center. The y dimension doesn't matter because hotspots continue indefinitely along the y axis.  If you use <node3d>.starthotspot, you can attach a hotspot to a 3d node. This hotspot will be centered at the 3D node such that its x and z parameters will be applied relative to this center..

 

To set the dimensions of a circular hotspot, you need only set the radius. If you're using a rectangular hotspot, specify both its width (x) and its depth (z).

 

viz.add('court.ive')
#Add a moving duck.
duck = viz.add('duck.cfg')
duck.setPosition(0,1,10)
duck.addAction( vizact.moveTo([0,0,-10],speed=10) )
#Define the hotspot ids.
DUCK, FIRST_SPOT, SECOND_SPOT = 1, 2, 3
#Define the hotspot function.
def onHotspot(id,x,y,z):
    if id == DUCK:
        print 'you hit the duck spot'
    elif id == FIRST_SPOT:
        print 'you hit the first spot'
    elif id == SECOND_SPOT:
        print 'you hit the second spot'
#Callback the hotspot event.
viz.callback(viz.HOTSPOT_EVENT,onHotspot)
#Set up hotspot to go off when the viewer moves away from the origin.
viz.starthotspot( FIRST_SPOT, viz.RECTANGLE_HOTSPOT_OUT, 0,0,.5,.5)
#Set a hotspot to go off when the viewpoint moves to the right a couple meters.
viz.starthotspot( SECOND_SPOT, viz.RECTANGLE_HOTSPOT_IN, 3,0,.5,.5)
#Attach a hotspot to the duck.
duck.starthotspot(DUCK, viz.CIRCLE_HOTSPOT_IN, 0,0,.5)

Deleting hotspots

Use viz.deletehotspot(<hotspot id>) or <node3d>.deletehotspot(<hotspot id>) to get rid of a hotspot.

See also

In this section:

Viewpoint basics

Camera handlers

Moving and rotating a viewpoint

Viewpoint collision and gravity

Viewpoint command table

Other sections:

Viewpoint and Window basics