|
#1
|
|||
|
|||
Proximity Sensor Problem
Hi there,
I'm trying to use a proximity sensor to change the color of a piece of text when the viewpoint collides with a specific node. I've been following the tutorial but I can't figure out why this isn't working. Please help! < import viz viz.setMultiSample(4) viz.MainWindow.fov(60) #viz.setLogFile('Task-CP1.log') viz.go() #for i in [5]: import sid import time import math import random import vizinfo import vizmat import viztask #import vizjoy import vizcam import vizact import vizshape import vizproximity #def parameters(): #global experiment_data global sky global ground global bigground global grass global skybox #blank_screen.visible( viz.OFF ) sky = viz.add(viz.ENVIRONMENT_MAP,'sky.jpg') skybox = viz.add('skydome.dlc') skybox.texture(sky) ground = viz.add('randground.wrl') # Add ground ground.collidePlane() # Make collideable plane ground.setScale([10,10,10]) ground.disable(viz.INTERSECTION) bigground = viz.Transform('whitenoise.tga') bigground.setScale(5,5,5) ground.texmat(bigground) grass = viz.addTexture('whitenoise.tga') viz.MainView.setPosition([50, 1.5, -20]) viz.MainView.setEuler([-9,0,0]) viz.MainView.collision( viz.ON ) viz.MainView.stepsize(.02) global reward1 reward1 = vizshape.addCube(size=2) reward1.color(viz.WHITE) reward1.setPosition([47,0,-10]) reward1.setEuler([0,0,0]) reward1.texture(viz.addTexture('money.jpg')) global value1 value1 = viz.addText3D('$3') value1.fontSize(1) value1.color(viz.RED) value1Link = viz.link(reward1, value1) value1Link.postTrans( [-.8, 1, 0] ) global reward2 reward2 = vizshape.addCube(size=1.5) reward2.color(viz.WHITE) reward2.setPosition([53,0,5]) reward2.setEuler([0,0,0]) reward2.texture(viz.addTexture('money.jpg')) global value2 value2 = viz.addText3D('$12') value2.resolution(2) value2.fontSize(1) value2.color(viz.RED) #value2.center(65,1,5) value2Link = viz.link(reward2, value2) value2Link.postTrans( [-.8, 1, 0] ) global reward1Sensor global reward2Sensor reward1Sensor = vizproximity.Sensor(vizproximity.Box([5,2,5],center=[0,0,0]),source=reward1) reward2Sensor = vizproximity.Sensor(vizproximity.Box([5,2,5],center=[0,0,0]),source=reward2) global target target = vizproximity.Target(viz.MainView) #Create proximity manager global manager manager = vizproximity.Manager() #Add destination sensors to manager manager.addSensor(reward1Sensor) manager.addSensor(reward2Sensor) manager.addTarget(target) vizact.onkeydown('d',manager.setDebug,viz.TOGGLE) global choseReward1 choseReward1 = False global choseReward2 choseReward2 = False def EnterProximity(e): if e.sensor == reward1Sensor: value1.color(viz.GREEN) choseReward1 = True print 'reward: 1' elif e.sensor == reward2Sensor: value2.color(viz.GREEN) choseReward2 = True print 'reward: 2' manager.onEnter(None,EnterProximity)> |
#2
|
|||
|
|||
Please post example code that reproduces the issue, is simplified as much as possible, and can be run directly without modification. That will make it much easier for others to help troubleshoot. Also, when posting code, use the code tags to preserve indentation.
|
#3
|
|||
|
|||
The solution: simplified and readable (thanks to the code tags). Next time, posting with code tags makes it much easier to debug/troubleshoot as Jeff mentioned.
Code:
import viz import vizshape import vizproximity viz.setMultiSample(4) viz.MainWindow.fov(60) viz.go() ground = viz.add('ground.osgb') viz.MainView.collision( viz.ON ) global reward1 reward1 = vizshape.addCube(size=.5) reward1.color(viz.WHITE) reward1.setPosition([1,2,1]) reward1.setEuler([0,0,0]) global value1 value1 = viz.addText3D('$3') value1.fontSize(1) value1.color(viz.RED) value1Link = viz.link(reward1, value1) value1Link.postTrans( [-.8, 1, 0] ) global reward2 reward2 = vizshape.addCube(size=.5) reward2.color(viz.WHITE) reward2.setPosition([-1,2,1]) reward2.setEuler([0,0,0]) global value2 value2 = viz.addText3D('$12') value2.resolution(2) value2.fontSize(1) value2.color(viz.RED) #value2.center(65,1,5) value2Link = viz.link(reward2, value2) value2Link.postTrans( [-.8, 1, 0] ) global reward1Sensor global reward2Sensor reward1Sensor = vizproximity.Sensor(vizproximity.Box(reward1.getScale(),center=[0,0,0]),reward1) reward2Sensor = vizproximity.Sensor(vizproximity.Box(reward2.getScale(),center=[0,0,0]),reward2) #Create proximity manager global manager manager = vizproximity.Manager() global target target = vizproximity.Target(viz.MainView) manager.addTarget(target) #Add destination sensors to manager manager.addSensor(reward1Sensor) manager.addSensor(reward2Sensor) vizact.onkeydown('d',manager.setDebug,viz.TOGGLE) global choseReward1 choseReward1 = False global choseReward2 choseReward2 = False def EnterProximity(e): if e.sensor == reward1Sensor: value1.color(viz.GREEN) value2.color(viz.RED) choseReward1 = True choseReward2 = False print 'reward: 1' elif e.sensor == reward2Sensor: value1.color(viz.RED) value2.color(viz.GREEN) choseReward1 = False choseReward2 = True print 'reward: 2' manager.onEnter(None,EnterProximity) |
#4
|
|||
|
|||
Thank you! Sorry about the code tags.
|
Tags |
proximity sensor |
Thread Tools | |
Display Modes | Rate This Thread |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
CompositeShape proximity sensor | mhtong | Vizard | 1 | 09-24-2012 12:18 PM |
Phase Space and Proximity Sensors | snovob93 | Vizard | 3 | 06-13-2012 01:32 PM |
Outputting modules | just alex | Vizard | 0 | 02-16-2010 12:03 PM |
triggering actions on proximity | exhale | Vizard | 3 | 03-14-2005 03:26 AM |