WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-13-2009, 10:37 AM
mberkes mberkes is offline
Member
 
Join Date: Mar 2009
Posts: 8
Still can't figure out how to just move one object from the initial randomised scene to the returned scene. Actually, can't figure out a lot of things haha. I have a mouseclick selecting an object and should (hopefully) record the data of which object was clicked (which should also match with the object that moved, though can't figure that out, obviously), but I can't disable the mouseclicking before I need it. Any help?
Reply With Quote
  #2  
Old 03-13-2009, 11:43 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
To move one of the objects to a new place, you need to randomly select one of your objects and then randomly select one of the available positions to move it to.

Code:
import viz
viz.go()

viz.MainView.move(0,0,-10)

#keep nine positions in an array
pos = [[-4,0,0],[-3,0,0],[-2,0,0],[-1,0,0],[0,0,0],[1,0,0],[2,0,0],[3,0,0],[4,0,0]]

#add objects to an array
box = viz.add('box.wrl')
ball = viz.add('ball.wrl')
whiteball = viz.add('white_ball.wrl')

objects = [box,ball,whiteball]


import random

rand_positions = []
def sceneOn(num):

	global rand_positions
	
	positions = [0,1,2,3,4,5,6,7,8]
	
	if num == 1:
		
		#set objects to 3 different random positions
		rand_positions = random.sample(positions,3)
		
		objects[0].setPosition(pos[rand_positions[0]])
		objects[1].setPosition(pos[rand_positions[1]])
		objects[2].setPosition(pos[rand_positions[2]])

		vizact.ontimer2(2,0,sceneOff)

	elif num == 2:
		
		#choose one object to move randomly and leave others in there places
		
		#first get available positions
		diff_list = [item for item in positions if not item in rand_positions]
		rand_position = random.sample(diff_list,1)[0]
		
		#choose one of the objects
		rand_obj = random.randint(0,2)
		
		#set the randomly chosen object to the new random position
		objects[rand_obj].setPosition(pos[rand_position])
		print 'object ' + str(rand_obj) + ' moved to position ' + str(rand_position)  
		
	viz.MainScene.visible(viz.ON)
	

def sceneOff():
	
	viz.MainScene.visible(viz.OFF)
	vizact.ontimer2(2,0,sceneOn,2)

sceneOn(1)
Reply With Quote
  #3  
Old 03-17-2009, 12:48 PM
mberkes mberkes is offline
Member
 
Join Date: Mar 2009
Posts: 8
Thanks, that works great. I have an issue though where it runs through once perfectly, but then on any time after that, more than one object moves. I'll post the code, and would you be able to see where the issue lies? I added in a function ('prep') that keeps the screen blank and waits for a space press before going to 'sceneOn', and a mouseclick goes to 'prep'. Thanks

Code:
import random

objects = [bottle, candle, clamp, lock, wood]

def prep():
	viz.MainScene.visible(viz.OFF)
	vizact.onkeydown(' ', sceneOn,1)

rand_positions = []
def sceneOn(num):

	global rand_positions
	
	positions = [0,1,2,3,4,5,6,7,8]
	
	if num == 1:
		
		#set objects to 5 different random positions
		rand_positions = random.sample(positions,5)
		
		objects[0].setPosition(pos[rand_positions[0]])
		objects[1].setPosition(pos[rand_positions[1]])
		objects[2].setPosition(pos[rand_positions[2]])
		objects[3].setPosition(pos[rand_positions[3]])
		objects[4].setPosition(pos[rand_positions[4]])

		vizact.ontimer2(3,0,sceneOff)

	elif num == 2:
		
		#choose one object to move randomly and leave others in their places
		
		#first get available positions
		diff_list = [item for item in positions if not item in rand_positions]
		rand_position = random.sample(diff_list,1)[0]
		
		#choose one of the objects
		rand_obj = random.randint(0,4)
		
		#set the randomly chosen object to the new random position
		objects[rand_obj].setPosition(pos[rand_position])
		print 'object ' + str(rand_obj) + ' moved to position ' + str(rand_position)  
		
	viz.MainScene.visible(viz.ON)
	

def sceneOff():
	
	viz.MainScene.visible(viz.OFF)
	vizact.ontimer2(10,0,sceneOn,2)

prep()
Again, this isn't the complete code, but where I would think the issue lies.
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
Sharing Files on SourceForge farshizzo Vizard 1 09-03-2012 11:18 AM
Project .avi or .mpeg file pattie Vizard 2 02-06-2007 08:09 AM


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


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