View Single Post
  #1  
Old 12-15-2014, 04:33 AM
fordprefect fordprefect is offline
Member
 
Join Date: Oct 2012
Location: Vienna, Austria, Europe
Posts: 39
Arrow vizproximity hint - debug 2D areas related to a source only after adding a target!

Hello @ll,

FYI I'll post a problem (with root cause and -if you want to say so- a workaround) that cost me quite some time to track down:

Conditions
  • create a proximity manager and set it to debug mode
  • sensor: use a 2D proximity area..
  • ..connected to a source
  • for the moment, do not add a target
Problem
The outcome is that world coordinates will be used to position the area, instead of the parent's coordinate system. And when the source is moved, the area is not affected.

Workaround/Solution
It will work ok only after a target was added to the manager.

Question to WorldViz
Is that intended behaviour, or an issue that could be fixed in the future?

Example
I have modified the example code for proximity areas to show the effect
Code:
"""
Demonstrates that area shapes from the vizproximity module are indicated
on their correct position only after a target is added to the manager.
The cone should be enclosed by the rectangle which should move together with the cone
but will do so only while a target is added to the manager.
Use x/X to move the cone
Use t to add and T to remove a target from the manager.
Use the WASD keys to move the axes and trigger the sensors (when target active).
"""
import viz
import vizact		# +
import vizcam
import vizshape
import vizproximity
viz.go()
viz.fov(60)

import vizinfo
vizinfo.InfoPanel()

# Add axes controlled by keyboard
axis = vizshape.addAxes(length=0.5)
tracker = vizcam.addKeyboardPos()
viz.link(tracker,axis)

# Create manager tracked axes
manager = vizproximity.Manager()
manager.setDebug(True)
target = vizproximity.Target(tracker)

# Sensor callbacks
def onEnterSensor(e):
	print 'Entered',e.sensor.name

def onExitSensor(e):
	print 'Exited',e.sensor.name

manager.onEnter(None, onEnterSensor)
manager.onExit(None, onExitSensor)

def AddSensor(shape,name, source=None):		# !
	sensor = vizproximity.Sensor(shape,source)	# !
	sensor.name = name
	manager.addSensor(sensor)

# Add circle area
shape = vizproximity.CircleArea(0.5,center=[0,2])
AddSensor(shape,'Circle')

# Add rectangle area
# connect it to a source object (BUT IT IS NOT!!)	  +
node = vizshape.addCone(pos=[3,0,2])		# +
shape = vizproximity.RectangleArea([1.8,1.2],center=[0,0])
AddSensor(shape,'Rectangle',node)			# !

# + shift the node
xDist = 1.0
xTime = 1.0
vizact.onkeychar('x', node.addAction, vizact.move(-xDist, 0, 0, xTime))
vizact.onkeychar('X', node.addAction, vizact.move(+xDist, 0, 0, xTime))

# Setup environment
vizshape.addGrid(color=viz.GRAY,pos=(0,-0.01,0))
viz.clearcolor(viz.SLATE)

# Setup pivot navigation
import vizcam
cam = vizcam.PivotNavigate(distance=10,center=(0,0,3))
cam.rotateUp(60)
viz.cam.setHandler(cam)

# + add/remove target on demand
vizact.onkeychar('t', manager.addTarget, target)
vizact.onkeychar('T', manager.removeTarget, target)
__________________
21 is only half the truth.
Reply With Quote