WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 04-05-2015, 09:08 AM
sportykourty sportykourty is offline
Member
 
Join Date: Mar 2015
Posts: 4
Question Error Changing Scenes

I'm trying to have my program change scenes once I enter a proximity sensor. I keep receiving an error. Any ideas what i'm doing wrong?

Code:
import viz
import vizact
import vizproximity

viz.setMultiSample(4)
viz.go()

############# Movement Control Code###################
#Script to control viewpoint with keyboard arrow keys
MOVE_SPEED = 900
TURN_SPEED = 60

def updatecar():
	#move view forward and backward
	if viz.key.isDown(viz.KEY_UP):
			view.move([MOVE_SPEED*viz.elapsed(),0,0],viz.BODY_ORI)
	if viz.key.isDown(viz.KEY_DOWN):
			view.move([-MOVE_SPEED*viz.elapsed(),0,0],viz.BODY_ORI)
	if viz.key.isDown(viz.KEY_TAB):
			view.move([0,MOVE_SPEED*viz.elapsed(),0],viz.BODY_ORI)
	if viz.key.isDown(viz.KEY_SHIFT_L):
			view.move([0,-MOVE_SPEED*viz.elapsed(),0],viz.BODY_ORI) 

	#rotate body of view left and right
	if viz.key.isDown(viz.KEY_RIGHT):
			view.setEuler([TURN_SPEED*viz.elapsed(),0,0],viz.BODY_ORI,viz.REL_PARENT)
	elif viz.key.isDown(viz.KEY_LEFT):
			view.setEuler([-TURN_SPEED*viz.elapsed(),0,0],viz.BODY_ORI,viz.REL_PARENT)
vizact.ontimer(0,updatecar)

########### Viewpoint Code #################
#Start collision detection
viz.MainView.collision( viz.ON )
view = viz.MainView

#Get rid of gravity. 
viz.MainView.gravity(0)

#Set the viewpoint.
viz.MainView.setPosition(88,0,-443)

#Viewpoint
view = viz.MainView

#Actual Viewpoint
view.setPosition([-7034, 200, -10775])
view.setEuler([90, 0, 0])

mars = viz.add('gallery.osgb',scene = viz.Scene1)
viz.addChild('dojo.osgb',scene=viz.Scene2)

manager = vizproximity.Manager()
manager.setDebug(True)
manager.addTarget( vizproximity.Target(viz.MainView) )

# Create sensor using bounding box of node
node = viz.addChild('plant.osgb',pos=(-4034, 0, -10775),scale=(1000,1000,1000))
node.addAction(vizact.spin(0,1,0,45,viz.FOREVER))
sensor = vizproximity.addBoundingBoxSensor(node)
manager.addSensor(sensor)

def changeScene(scene):
	viz.MainWindow.setScene(scene)
	if scene == viz.Scene2:
		viz.MainView.setPosition([0,1.8,0])
		viz.MainView.setEuler([90,0,0])
	
manager.onEnter(None, changeScene)
Reply With Quote
  #2  
Old 04-08-2015, 06:03 AM
mape2k mape2k is offline
Member
 
Join Date: Mar 2013
Posts: 60
The problems you have originate from the last bits of your code:

Code:
def changeScene(scene):
	viz.MainWindow.setScene(scene)
	if scene == viz.Scene2:
		viz.MainView.setPosition([0,1.8,0])
		viz.MainView.setEuler([90,0,0])
	
manager.onEnter(None, changeScene)
In the last line, you tell Vizard to call the function changeScene() whenever the sensor is entered. The argument that gets passed to that function by default is the sensor that was activated. So your variable <scene> will be a proximity sensor => this will create an error when trying to change the scene to a sensor.

To fix this, you need to pass more arguments to the function changeScene, e.g.:

Code:
def changeScene(sensor,scene):

	viz.MainWindow.setScene(scene)
	if scene == viz.Scene2:
		viz.MainView.setPosition([0,1.8,0])
		viz.MainView.setEuler([90,0,0])
	
manager.onEnter(None, changeScene, desiredScene)
in which <desiredScene> is the variable to the scene you wish to change to.
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
Adding Objects to all Scenes jassel41 Vizard 1 11-29-2010 02:35 AM
displaying random scenes etc cl113 Vizard 1 05-10-2009 05:14 PM
Making buttons appear in scenes DBurks2818 Vizard 4 04-09-2009 02:25 PM
Arranging Scenes in Correct Order utepbereed Vizard 1 11-21-2008 09:19 AM
environment maps, scenes, and you! vadrian Vizard 1 01-12-2005 04:04 PM


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


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