Vizard 7 » Reference » Proximity Sensors » vizproximity sensor
7.7

vizproximity sensor

A vizproximity sensor detects when a target is within range. A sensor has both an area and a transformation matrix. The area is determined by a sensor shape while the transformation matrix is based on a source object or fixed location. There are two categories of shapes; 3D shapes and area shapes.

3D Shapes

The following image shows sensors based on 3D shapes. The 3D shapes available are box, sphere, or any combination of these:

A. Sphere sensor and ball

B. Box sensor and plant

C. Sphere sensor and avatar head bone

D. Composite sensor and static matrix

Area Shapes

The following image shows examples of sensors based on area shapes. Area shapes are not represented with height because they continue indefinitely along the Y axis. The area shapes available are path, polygon, rectangle, and circle:

A. Path sensor

B. Polygon sensor

C. Rectangle sensor

D. Circle sensor

Commands

The following command creates a Sensor object:

Command

Description

vizproximity.Sensor(shape,

                          source)

The area of the sensor is determined by the specified shape.

The sensors position is determined by the specified source object (e.g. node, view, tracker, bone, matrix)

Use the following commands to create 3D sensor shapes:

Command

Description

vizproximity.Box(size,

                      center=(0.0,0.0,0.0))

Box shape.

vizproximity.Sphere(radius,

                           center=(0.0,0.0,0.0))

Spherical shape.

vizproximity.CompositeShape(shapes)

Shape composted of multiple shapes. shapes is a list that can contain any number of Box, Sphere, or  CompositeShape objects.

Use the following commands to create area shapes. Area shapes extend indefinitely along the Y axis and are defined using only X,Z coordinates:

Command

Description

vizproximity.CircleArea(radius,

                               center=(0.0,0.0)

Circular area shape.

vizproximity.RectangleArea(size,

                                     center=(0.0,0.0)

Rectangular area shape.

 

vizproximity.PolygonArea(points,

                                  offset=(0.0,0.0)

Polygonal area shape.

points: A list that contains the polygon vertices.

offset: Applies a position offset to the polygon.

vizproximity.PathArea(points,

                              radius,

                              offset=(0.0,0.0)

Path area shape.

points: A list of points that defines the centerline of the path.

radius: Distance from the path centerline to path edge.

offset: Applies a position offset to the path.

In addition to the Sensor command, the following utility functions can be used to create sensors using bounding shapes:

Command

Description

vizproximity.addBoundingBoxSensor(node,

                                                name='',

                                                scale=(1.0,1.0,1.0))

Create a proximity sensor using the bounding box of a node.

name: Name of sub-node to use for the bounding box.

scale: Scale factor to apply to computed bounding box size.

vizproximity.addBoundingSphereSensor(node,

                                                    name='',

                                                    scale=1.0)

Create a proximity sensor using the bounding sphere of a node.

name: Name of sub-node to use for the bounding sphere.

scale: Scale factor to apply to computed bounding sphere radius.

The following methods can be called on a Sensor object:

Method

Description

<Sensor>.containsPoint(point)

Return whether the sensor contains the specified point.

<Sensor>.getShape()

Return the shape object of the sensor.

<Sensor>.getSource()

Return the source object of the sensor.

<Sensor>.getSourceObject()

Return the underlying object of the sensor source  (e.g. node, view, bone, etc..).

Example

The examples below shows how to create sensors using a variety of source objects:

 

Bounding sphere of node

node = viz.addChild('beachball.osgb')
sensor = vizproximity.addBoundingSphereSensor(node)

Bounding Box of sub-node

node = viz.addChild('logo.ive')
sensor = vizproximity.addBoundingBoxSensor(node,name='Sphere01-FACES')

Sphere with avatar bone

avatar = viz.addAvatar('vcc_male2.cfg')
head = avatar.getBone('Bip01 Head')
sensor = vizproximity.Sensor(vizproximity.Sphere(0.3,center=[0,0.1,0]),head)

Box with tracker link

trackerLink = viz.link(tracker,viz.NullLinkable)
sensor = vizproximity.Sensor(vizproximity.Box([0.5,0.5,0.5]),trackerLink)

Composite with group node

group = viz.addGroup()
shapes = []
shapes.append(vizproximity.Box([1,1,1]))
shapes.append(vizproximity.Sphere(0.5,center=[0,1,0]))
sensor = vizproximity.Sensor(vizproximity.CompositeShape(shapes),group)

Sphere with static matrix

sensor = vizproximity.Sensor(vizproximity.Sphere(1.0),source=viz.Matrix.translate(2,1.5,1))

Circle area with avatar

male = viz.addAvatar('vcc_male2.cfg')
sensor = vizproximity.Sensor( vizproximity.CircleArea(1),source=male)

Rectangle area at fixed location

sensor = vizproximity.Sensor( vizproximity.RectangleArea([2,1],center=[3,2]), None )

Polygon area at fixed location

verts = [ [0,0], [1,1], [0,1.5], [-2,2], [-1,1], [-2,0.5] ]
sensor = vizproximity.Sensor( vizproximity.PolygonArea(verts,offset=[-3,1]), None )

Path area at fixed location

path = [(4,-0.2),(4,7),(1.7,8.7),(-1.7,8.7),(-4,7),(-4,-0.2)]
sensor = vizproximity.Sensor( vizproximity.PathArea(path,radius=0.4), None )

vizproximity introduction

vizproximity sensor

vizproximity target

vizproximity manager

vizproximity events