WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 02-17-2014, 02:32 PM
kmkm kmkm is offline
Member
 
Join Date: Jun 2013
Posts: 7
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)>
Reply With Quote
  #2  
Old 02-20-2014, 05:10 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,462
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.
Reply With Quote
  #3  
Old 02-21-2014, 06:00 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
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)
Reply With Quote
  #4  
Old 03-04-2014, 11:54 AM
kmkm kmkm is offline
Member
 
Join Date: Jun 2013
Posts: 7
Thank you! Sorry about the code tags.
Reply With Quote
Reply

Tags
proximity sensor

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
CompositeShape proximity sensor mhtong Vizard 1 09-24-2012 11:18 AM
Phase Space and Proximity Sensors snovob93 Vizard 3 06-13-2012 12:32 PM
Outputting modules just alex Vizard 0 02-16-2010 11:03 AM
triggering actions on proximity exhale Vizard 3 03-14-2005 02:26 AM


All times are GMT -7. The time now is 02:55 AM.


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