You can create a custom
vizproximity.Shape class that applies an arbitrary transformation on the underlying shape. Here is an example:
Code:
import viz
import vizcam
import vizshape
import vizproximity
viz.go()
viz.fov(60)
# Create manager tracked axes
manager = vizproximity.Manager()
manager.setDebug(True)
manager.addTarget(vizproximity.Target(viz.MainView))
class TransformedShape(vizproximity.Shape):
def __init__(self, shape, transform):
self._shape = shape
self._transform = viz.Matrix(transform)
self._inverseTransform = self._transform.inverse()
def containsPoint(self,point):
"""Returns whether the point is inside the shape"""
# Transform point into local reference frame
point_local = self._inverseTransform.preMultVec(point)
# Return whether point is inside shape
return self._shape.containsPoint(point_local)
def createDebugNode(self,data):
"""Create and return node object for visualizing proximity shape"""
group = viz.addGroup()
group.setMatrix(self._transform)
s = self._shape.createDebugNode(data)
s.setParent(group)
return group
# Sensor callbacks
def onEnter(e):
print 'Entered'
def onExit(e):
print 'Exited'
shapes = []
shapes.append( vizproximity.Sphere(0.3,(0,1,0)) )
shapes.append( vizproximity.Box([0.4,1.0,0.2]) )
xform = viz.Matrix()
xform.setPosition((0.5,0.6,0))
xform.setEuler((0,0,-45))
shapes.append( TransformedShape(vizproximity.Box([0.2,0.5,0.2]),xform))
xform = viz.Matrix()
xform.setPosition((-0.5,0.6,0))
xform.setEuler((0,0,45))
shapes.append( TransformedShape(vizproximity.Box([0.2,0.5,0.2]),xform))
xform = viz.Matrix()
xform.setPosition((-0.3,-1,0))
xform.setEuler((0,0,-20))
shapes.append( TransformedShape(vizproximity.Box([0.2,0.8,0.2]),xform))
xform = viz.Matrix()
xform.setPosition((0.3,-1,0))
xform.setEuler((0,0,20))
shapes.append( TransformedShape(vizproximity.Box([0.2,0.8,0.2]),xform))
sensor = vizproximity.Sensor(vizproximity.CompositeShape(shapes),None)
manager.addSensor(sensor)
manager.onEnter(sensor,onEnter)
manager.onExit(sensor,onExit)
# Setup environment
vizshape.addGrid(color=[0.2]*3,pos=(0,-0.01,0))
viz.clearcolor(viz.GRAY)
# Setup pivot navigation
import vizcam
cam = vizcam.PivotNavigate(distance=10)
cam.rotateUp(60)
viz.cam.setHandler(cam)