WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 09-20-2012, 05:36 PM
mhtong mhtong is offline
Member
 
Join Date: Sep 2012
Posts: 6
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?
Reply With Quote
  #2  
Old 09-24-2012, 11:18 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
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)
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a Vizard Sensor Plugin farshizzo Plug-in development 25 08-01-2019 12:24 AM
Unusual tracker sensor setup with Vizard Zhi Vizard 2 06-12-2012 09:52 AM
sensor or not sensor? nige777 Vizard 0 03-29-2011 04:03 AM
wiimote and sensor bar masaki Vizard 1 03-06-2008 03:07 PM
Multiple Copies of same sensor plugin RedSpikeyThing Plug-in development 2 02-12-2008 02:10 PM


All times are GMT -7. The time now is 07:05 AM.


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