View Single Post
  #5  
Old 03-27-2009, 03:02 PM
durf durf is offline
Member
 
Join Date: Feb 2009
Posts: 61
Well I tried to upload a .wrl file and it wouldn't let me. So pretty much this file has moving animation to it that loops. It also has 5 skins of color on it as well. The program runs slow. Im trying to figure out how to make it run faster. Instead of adding and removing the image, I tried copy() and clone(). copy() just copies it and doesnt allow the animation to run. All clone() does is makes the animation appear wherever it is in its loop(meaning that there is a original animation that is running during this program, when it clones itself it picks up from whever that image is in its loop). Im trying to make it bloom seperately. Sorry if this is confusing. Your forum just doesn't like .wrl files.

Code:
import viz
import viztask
import vizact
viz.go()

viz.MainView.setPosition([0,10,-35]) #sets camera position
viz.MainView.setEuler([0,2,0]) #sets camera pitch

PORT_PPT = 6
PORT_INTERSENSE = 8

#creates a stage
viz.add('tut_ground.wrl')

#Create sensor
ppt1 = viz.add('vizppt.dls')
ppt2 = viz.add('vizppt.dls')

#Creates visual of dancer 1 location (make viz.OFF)
ball1 = viz.add('white_ball.wrl')
ball1.scale(1,1,1)
ballLink1 = viz.link(ppt1, ball1)

int1 = viz.add('intersense.dls')
interLink1 = viz.link(int1, ball1)

#Creates visual of dancer 2 location (make viz.OFF)
ball2 = viz.add('white_ball.wrl')
ball2.scale(1,1,1)
ballLink2 = viz.link(ppt2, ball2)

int2 = viz.add('intersense.dls')
interLink2 = viz.link(int2, ball2)

#controls distance in virtual world
ballLink1.postScale([8,1,13],target = viz.LINK_FULL_OP)
ballLink2.postScale([8,1,13],target = viz.LINK_FULL_OP)

def CalculateSpeed(obj):
	
	#Get current and last position
	current_pos = obj.getPosition()
	last_pos = getattr(obj, 'last_pos', None)

	if last_pos is None:
		#This is first call, so save position and set speed to 0
		obj.last_pos = current_pos
		obj.speed = 0.0
		
	else:
		#Compute speed using last position
		obj.speed = vizmat.Distance(current_pos,last_pos) / viz.elapsed()
		obj.last_pos = current_pos
		#Makes new animation and removes it (and sets euler position "eventually")
		if obj.speed > 1 and obj.speed < 2.5:
			def showFlower():
				flower1 = viz.add('flowers_grow_01.wrl')
				flower1.scale(.06,.06,.06)
				flower1.color(viz.RED)
				
				x,y,z = ball1.getPosition()
				
				if z < 0:
					flower1.setPosition([x,0,-10])
				if z >= 0:
					flower1.setPosition([x,0,10])
				
				a,b,c = int1.getEuler()
				flower1.setEuler(a,0,0)
				
				yield viztask.waitTime( 3.5 )
				flower1.remove()
				
			viztask.schedule( showFlower() )

		if obj.speed >= 2.5 and obj.speed < 3:
			def showFlower1():
				flower1 = viz.add('flowers_grow_01.wrl')
				flower1.scale(.2,.2,.2)
				flower1.color(viz.PURPLE)
				
				x,y,z = ball1.getPosition()
				
				if z < 0:
					flower1.setPosition([x,0,-10])
				if z >= 0:
					flower1.setPosition([x,0,10])
				
				a,b,c = int1.getEuler()
				flower1.setEuler(a,0,0)
				
				yield viztask.waitTime( 3.5 )
				flower1.remove()
				
			viztask.schedule( showFlower1() )
		if obj.speed >= 3 and obj.speed < 5:
			def showFlower1():
				x,y,z = ball1.getPosition()
				if z >= 0:
					flower1 = viz.add('flowers_grow_01.wrl')
					flower1.setPosition([x,0,10])
					flower1.scale(1,1,1)
					flower1.color(viz.BLUE)

				if z < 0:
					flower1 = viz.add('flowers_grow_01.wrl')
					flower1.setPosition([x,0,-10])
					flower1.scale(.2,.2,.2)
					flower1.color(viz.BLUE)
				
				a,b,c = int1.getEuler()
				flower1.setEuler(a,0,0)
				
				yield viztask.waitTime( 3.5 )
				flower1.remove()
				
			viztask.schedule( showFlower1() )
vizact.ontimer(0,CalculateSpeed,ppt1)

def CalculateSpeed(obj):
	
	#Get current and last position
	current_pos = obj.getPosition()
	last_pos = getattr(obj, 'last_pos', None)
	
	if last_pos is None:
		#This is first call, so save position and set speed to 0
		obj.last_pos = current_pos
		obj.speed = 0.0
		
	else:
		#Compute speed using last position
		obj.speed = vizmat.Distance(current_pos,last_pos) / viz.elapsed()
		obj.last_pos = current_pos
		#Checks speed between 3 and 5
		if obj.speed > 1 and obj.speed < 2.5:
			def showFlower2():
				flower2 = viz.add('flowers_grow_01.wrl')
				flower2.scale(.06,.06,.06)
				flower2.color(viz.PURPLE)
				x,y,z = ball2.getPosition()
				
				if z < 0:
					flower2.setPosition([x,0,-10])
				if z >= 0:
					flower2.setPosition([x,0,10])
				
				a,b,c = int2.getEuler()
				flower2.setEuler(a,0,0)
				
				yield viztask.waitTime( 3.5 )
				flower2.remove()
				
			viztask.schedule( showFlower2() )

		if obj.speed >= 2.5 and obj.speed < 3:
			def showFlower2():
				flower2 = viz.add('flowers_grow_01.wrl')
				flower2.scale(.2,.2,.2)
				flower2.color(viz.BLUE)
				x,y,z = ball1.getPosition()
				
				if z < 0:
					flower2.setPosition([x,0,-10])
				if z >= 0:
					flower2.setPosition([x,0,10])
				
				a,b,c = int2.getEuler()
				flower2.setEuler(a,0,0)
				
				yield viztask.waitTime( 3.5 )
				flower2.remove()
				
			viztask.schedule( showFlower2() )
			
		if obj.speed >= 3 and obj.speed < 5:
			def showFlower2():
				x,y,z = ball2.getPosition()
				if z >= 0:
					flower2 = viz.add('flowers_grow_01.wrl')
					flower2.setPosition([x,0,10])
					flower2.scale(1,1,1)
					flower2.color(viz.RED)

				if z < 0:
					flower2 = viz.add('flowers_grow_01.wrl')
					flower2.setPosition([x,0,-10])
					flower2.scale(.2,.2,.2)
					flower2.color(viz.RED)
				
				a,b,c = int2.getEuler()
				flower2.setEuler(a,0,0)
				
				yield viztask.waitTime( 3.5 )
				flower2.remove()
				
			viztask.schedule( showFlower2() )
vizact.ontimer(0,CalculateSpeed,ppt2)
Reply With Quote