WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
Old 04-29-2014, 08:15 AM
rmcconnell11 rmcconnell11 is offline
Join Date: Mar 2013
Posts: 28
Hand Grab and Object Action

Hi guys,

I am trying to add an action to an object once it is grabbed by a hand. Unfortunately I am having a bit of trouble in getting the objects to move at all!
This is what I have so far....

import viz
import vizact

#function for changing numbers to three decimal places
def decimal(Pos):
	for i, number in enumerate(Pos):
		Pos[i] = round(number,3)
ground = viz.addChild('ground.osgb')

Tool = viz.add('Tool_V12.osgb', pos=[0,0,4], euler=[180,0,0])

#Get the clamp parts
ClampA_Transform = Tool.getChild('G05515000_SAJG01A-5068.2')
ClampA = ClampA_Transform.getChild('All Nodes')
ClampA_Pos = ClampA.getPosition(mode=viz.REL_GLOBAL)

#Clamp B
ClampB_Transform = Tool.getChild('G05515000_SAJG01A-5068.1')
ClampB = ClampB_Transform.getChild('All Nodes')
ClampB_Pos = ClampB.getPosition(mode=viz.REL_GLOBAL)

import viztracker
viztracker.DEFAULT_HANDS = True
rightHand = viztracker.get('lefthand')

#enable physics

closest = None #Used to identify closest object to hand
MoveableParts = [ClampA, ClampB]

def updateClosest():
	global closest
	list = viz.phys.intersectNode(rightHand)
	if list != []:
		closestDistance = 999999
		closest = None
		handPos = rightHand.getPosition()
		for object in list:
			if (object in MoveableParts):
				distance = vizmat.Distance(handPos, object.getPosition(viz.ABS_GLOBAL))
				if distance < closestDistance:
					closest = object
					closestDistance = distance
		closest = None
vizact.onupdate(viz.PRIORITY_DEFAULT, updateClosest)

link = None
def onGesture(e):
	global link
	if closest is not None:
		node = closest
		link = viz.grab(rightHand, node)
		if node is ClampA:
			#link= viz.grab(hand, closest)
			global ClampA_Pos
			Pos = ClampA.getPosition(mode=viz.REL_GLOBAL)
			if Pos == ClampA_Pos:
				node.addAction(vizact.spinTo(euler=[-90,0,0], speed=90))
			elif Pos != ClampA_Pos:
				node.addAction(vizact.spinTo(euler=[90,0,0], speed=90))
		if node is ClampB:
			global ClampB_Pos
			Pos = ClampB.getPosition(mode=viz.REL_GLOBAL)
			if Pos == ClampB_Pos:
				node.addAction(vizact.spinTo(euler=[90,0,0], speed=90))
			else:# CurrentPos != ClampB_Pos:
				node.addAction(vizact.spinTo(euler=[-90,0,0], speed=90))

import hand
viz.callback( hand.HAND_GESTURE_EVENT, onGesture )
Reply With Quote

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
Rotate object around mainView? performlabrit Vizard 3 12-19-2013 06:31 AM
How to render a texture of the transparent object and then blur it whj Vizard 1 09-25-2012 03:15 PM
retrieve Object names Geoffrey Vizard 11 12-11-2009 04:26 AM
How to make avatar's eyes to blink when speaking michelcm3 Vizard 12 01-15-2008 08:48 AM
rotate to object jargon Vizard 1 08-08-2005 12:20 PM

All times are GMT -7. The time now is 08:25 PM.

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