WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 01-23-2013, 04:01 PM
Gladsomebeast Gladsomebeast is offline
Member
 
Join Date: Mar 2005
Location: Isla Vizta, CA
Posts: 397
Tractor beam module to inspect objects

Hacked a little code that moves selected objects close to the view, then puts them back.

To try, run the module, press and hold the spacebar, move the ball to an object, release the spacebar. Enjoy

Code:
import viz
import vizmat
import viztask
import vizact

TRACTOR_TIME = 4

tractorNodes = []
def init(trackerNodeList):
	global startProjectSignal, tractorNodes
	tractorNodes = trackerNodeList
	startProjectSignal = viztask.Signal()
	viztask.schedule(think())

def startProject():
	global isProjectionDone
	startProjectSignal.send()
	
def stopProject():
	global isProjectionDone
	isProjectionDone = True

def think():
	global isProjectionDone
	cursor = viz.add('white_ball.wrl')
	cursor.color(viz.GREEN)
	cursor.alpha(.5)
	cursor.visible(viz.OFF)
	viz.startLayer(viz.LINES)
	viz.vertex([0,0,0])
	viz.vertex([0,0,0])
	lazer = viz.endLayer()
	lazer.color(viz.GREEN)
	lazer.visible(viz.OFF)
	while True:
#		print 'wait'
		yield startProjectSignal.wait()
		print 'start tractor'
		isProjectionDone = False
		cursor.visible(viz.ON)
		lazer.visible(viz.ON)
		hitObject = None
		while not isProjectionDone:
			line = viz.MainWindow.screenToWorld([.5, .5])
			line.length = 100
			lazerStart = line.begin
			lazerStart[1] -= .1 
			lazer.setVertex(0, lazerStart)
			lazer.setVertex(1, line.end)
			intersectObj = viz.phys.intersectLine(line.begin, line.end)
			if intersectObj.valid:
				cursor.setPosition(intersectObj.point)
				if intersectObj.object in tractorNodes:
					hitObject = intersectObj.object
				else:
					hitObject = None
			yield None
#		print 'done'
		cursor.visible(viz.OFF)
		lazer.visible(viz.OFF)
		if hitObject:
			#start Tractor
			isProjectionDone = False
			startTime = viz.tick()
			startPos = hitObject.getPosition(viz.ABS_GLOBAL)
			bb = hitObject.getBoundingBox(viz.ABS_GLOBAL)
			distanceFromView = max(bb.width, bb.height, bb.depth) * 2
			centerOffset = vizmat.Vector(startPos)- vizmat.Vector(bb.center)
			while not isProjectionDone:
				percentageToGo = (viz.tick()-startTime) / TRACTOR_TIME
				if percentageToGo > 1.0:
					isProjectionDone = True
					break
				line = viz.MainWindow.screenToWorld([.5, .5])
				line.length = distanceFromView
				targetPos = line.end + centerOffset
				pos = vizmat.Interpolate(hitObject.getPosition(viz.ABS_GLOBAL), targetPos, percentageToGo)
				hitObject.setPosition(pos, viz.ABS_GLOBAL)
				yield None
			hitObject.runAction( vizact.moveTo(startPos, time=TRACTOR_TIME*.2) )
		
		
if __name__ == "__main__":
	viz.go()
	viz.phys.enable()
	room = viz.add('gallery.osgb')
	room.collideMesh()
	list = []
	for i in range(5):
		b = viz.add('box.wrl', pos=[i*.5, 1.5, 2], scale=[.3]*3)
		b.collideMesh()
		list.append(b)
	h = viz.add('tut_hedra.wrl', pos=[-1, 1, 4])
	h.collideMesh()
	list.append( h )
	h = viz.add('vcc_female.cfg', pos=[-2, 1, 4])
	h.collideMesh()
	list.append( h )
	h = viz.add('ball.wrl', pos=[-2, 1, 4])
	h.collideMesh()
	list.append( h )
	
	init(list)
	
	vizact.onkeydown(' ', startProject)
	vizact.onkeyup(' ', stopProject)
Attached Files
File Type: zip tractor beam.zip (1.0 KB, 325 views)
__________________
Paul Elliott
WorldViz LLC
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
Exception in module vizjoy fordprefect Vizard 2 12-03-2012 01:41 AM
Trouble picking text3d objects Salvar Vizard 4 12-01-2010 03:07 PM
static or dynamic objects shahramy Vizard 2 11-10-2010 12:32 AM
Semi-circle array containing target and distractor objects ptjt255 Vizard 3 08-04-2009 03:09 AM
Could not find plugin to load objects... halley Vizard 1 05-30-2006 11:01 AM


All times are GMT -7. The time now is 10:51 PM.


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