WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   CompositeShape proximity sensor (https://forum.worldviz.com/showthread.php?t=4367)

mhtong 09-20-2012 05:36 PM

CompositeShape proximity sensor
 
I'm designing an environment where it's important to track whether or not the subject is on or off a particular path. The path is fairly simple, composed of a QUAD_STRIP. However, the proximity sensors just provide Box and Sphere.

I'm generally ok with the amount of slop introduced by rounding up each quad in the quad strip to be rectangular and a Box. Ideally, it seems like a CompositeShape sensor composed of a Box for each quad in the strip should work well. But the Box shape assumes axis alignment. Sensors attach fine to their parent's coordinate system, and then rotate accordingly - but Boxes themselves don't have parents, and a CompositeShape seems to therefore only be able to be made of boxes aligned to the same coordinate system.

Suggestions? Am I missing something?

farshizzo 09-24-2012 11:18 AM

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)



All times are GMT -7. The time now is 10:33 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC