WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 05-11-2009, 04:04 AM
nasr nasr is offline
Member
 
Join Date: Apr 2009
Posts: 27
how to write the interface code

hello all,

my university got a virtual reality suite which consists of a projector, a transluscent screen, amx controller, intersense 900 inertial ultra sonic motion tracking system, wand and head trackers. i will import a catia based 3d model in vizard. could some body please tell me how can i navigate with the wand and head tracker in my application. how to write the interface code? are there any ebooks available on the vizard site?

thankyou...

with regards
Nasr
Reply With Quote
  #2  
Old 05-11-2009, 02:03 PM
Gladsomebeast Gladsomebeast is offline
Member
 
Join Date: Mar 2005
Location: Isla Vizta, CA
Posts: 397
To support multiple hardware interfaces, like a keyboard+mouse test mode and production VR tracker mode, you want to separate the "application logic" from the hardware interface code. Their are a few ways you can organize the code to do this. I would use object oriented classes.

Say the user interacts with your Catia model with some 3D cursor thing. That is application logic. I'ed create a Cursor class that holds all the application level information and behavior for this 3D cursor: 3D position, appearance, methods for selecting and moving the Catia model.

I'd create another class called CursorControllerKeyboard that has a pointer to the Cursor class. This guy will respond to keyboard events and manipulate the Cursor appropratly. Another class called CursorControllerWand could manipulate the Cursor in response to input from the Intersense Wand device.

Let the Cursor classes constructor choose which controler to create based on some configuration varable. Here's some code:

Code:
import viz
import vizact

IS_VR_HARDWARE_CONNECTED = False

class Cursor:
	def __init__(self):
		#Application level stuff
		self.root = viz.addGroup() #3d position
		self.model = viz.add('arrow.wrl', parent=self.root)
		
		if IS_VR_HARDWARE_CONNECTED:
			self.CursorControllerWand(self) #pass pointer to self
		else:
			self.CursorControllerKeyboard(self) #pass pointer to self
		
	def grabModel(self):
		#application level stuff
		self.model.color(viz.GREEN)
		
	class CursorControllerKeyboard: #sub-class of Cursor, only Cursor can use me
		def __init__(self, appCursor):
			self.appCursor = appCursor
			vizact.onkeydown(viz.KEY_UP, self.appCursor.root.setPosition, [0,0,1], viz.REL_LOCAL)
			vizact.onkeydown(' ', self.appCursor.grabModel)
			
			
	class CursorControllerWand: #sub-class of Cursor, only Cursor can use me
		def __init__(self, appCursor):
			self.appCursor = appCursor
			#do Vr hardware callbacks
			
if __name__ == '__main__':
	viz.go()
	Cursor()
__________________
Paul Elliott
WorldViz LLC
Reply With Quote
  #3  
Old 05-12-2009, 02:26 AM
nasr nasr is offline
Member
 
Join Date: Apr 2009
Posts: 27
how to move the other part

Code:
def toggleLink():
	global link
	if link:
		#If link exits, stop grabbing
		link.remove()
		link = None

	elif vizmat.Distance(hand.getPosition(), ball.getPosition()) < .5:
		link = viz.grab( hand, ball )

vizact.onpick(ball,toggleLink)
with this code i am able to one component using the marker. i have included one more component.. when i am trying to pick the other component the first component is also moving how to disable the link between the market and first component?
Reply With Quote
  #4  
Old 05-12-2009, 11:15 AM
Gladsomebeast Gladsomebeast is offline
Member
 
Join Date: Mar 2005
Location: Isla Vizta, CA
Posts: 397
For your elif block:

if link is not none: remove link
__________________
Paul Elliott
WorldViz LLC
Reply With Quote
  #5  
Old 05-12-2009, 11:22 AM
Gladsomebeast Gladsomebeast is offline
Member
 
Join Date: Mar 2005
Location: Isla Vizta, CA
Posts: 397
Better. Replace elif with if.
Code:
def toggleLink():
	global link
	if link:
		#If link exits, stop grabbing
		link.remove()
		link = None

	if vizmat.Distance(hand.getPosition(), ball.getPosition()) < .5:
		link = viz.grab( hand, ball )

vizact.onpick(ball,toggleLink)
__________________
Paul Elliott
WorldViz LLC
Reply With Quote
  #6  
Old 05-13-2009, 12:09 AM
nasr nasr is offline
Member
 
Join Date: Apr 2009
Posts: 27
paul thank you very much for your reply.this is my full program
Code:
import viz

viz.go()

viz.MainView.setPosition(0,1.5,-4)
import viztracker
tracker = viztracker.MousePos()
myroom=viz.add('room.wrl')
#Add the object that will do the grabbing and link it to the tracker
hand = viz.add('marker.wrl')
viz.link(tracker, hand)

#turn off mouse navigation
viz.mouse(viz.OFF)

#Add the object that the marker will grab
ball = viz.add( 'ball.wrl' )

ball.translate( 0.5, 1.5, 3 )
table=viz.add('table.wrl')
link = None
#Grab or let go of the ball

def toggleLink():
	global link
	if link:
		#If link exits, stop grabbing
		link.remove()
		link = None
         elif vizmat.Distance(hand.getPosition(), ball.getPosition()) < .5:
		vizact.onpick(ball,toggleLink)

now i want to move the ball and the table seperately. now could you please tell me how to make the changes.
Reply With Quote
  #7  
Old 05-13-2009, 05:46 AM
nasr nasr is offline
Member
 
Join Date: Apr 2009
Posts: 27
vizmat.Distance(hand.getPosition(), ball.getPosition()) < .5: link = viz.grab( hand, ball )

vizact.onpick(ball,toggleLink)
paul

in the above code im able to grab the ball only. if im trying this loop with an if condition, after selecting the ball im not able to stop the ball how to change the code?
Reply With Quote
  #8  
Old 05-13-2009, 12:05 PM
Gladsomebeast Gladsomebeast is offline
Member
 
Join Date: Mar 2005
Location: Isla Vizta, CA
Posts: 397
My last post from yesterday will fix your problem. Notice how I changed the elif to if in the toggleLink function.

Also, you will want to call toggleLink whenever the mouse button is pressed, so replace vizact.onpick with vizact.onmousebutton.
__________________
Paul Elliott
WorldViz LLC
Reply With Quote
  #9  
Old 05-13-2009, 12:45 PM
nasr nasr is offline
Member
 
Join Date: Apr 2009
Posts: 27
paul thanks for your quick reply... if i want to rotate the object how can i do it?
Reply With Quote
  #10  
Old 05-13-2009, 01:37 PM
Gladsomebeast Gladsomebeast is offline
Member
 
Join Date: Mar 2005
Location: Isla Vizta, CA
Posts: 397
Because of the grab link, rotating the hand will rotate the object. Use whatever keyboard/mouse keys you want.
__________________
Paul Elliott
WorldViz LLC
Reply With Quote
  #11  
Old 05-14-2009, 12:49 PM
nasr nasr is offline
Member
 
Join Date: Apr 2009
Posts: 27
paul thankyou very much for your suggestions...could you tell the code for rotating the ball using the mouse...i dont have any idea how to do it...just give me the clue...

thankyou..
Reply With Quote
  #12  
Old 05-15-2009, 11:16 AM
nasr nasr is offline
Member
 
Join Date: Apr 2009
Posts: 27
hello paul...i tried rotating the object using the keyboard..by assigning keys for each axis....but i want to do this using mouse in order to reduce the number of lines of code...could u please tell me the function for that. how it could be done? i wil be waiting for ur reply..thankyou...
Reply With Quote
  #13  
Old 05-15-2009, 11:37 AM
Gladsomebeast Gladsomebeast is offline
Member
 
Join Date: Mar 2005
Location: Isla Vizta, CA
Posts: 397
How about rotating an object when you hold down the right mouse button. You could use Jerry's code from this post to rotate the object after it is selected: http://forum.worldviz.com/showthread.php?t=2022
__________________
Paul Elliott
WorldViz LLC
Reply With Quote
  #14  
Old 05-15-2009, 11:46 AM
nasr nasr is offline
Member
 
Join Date: Apr 2009
Posts: 27
Code:
def toggleLink():
	global link
	if link:
		#If link exits, stop grabbing
		link.remove()
		link = None

	if vizmat.Distance(hand.getPosition(), ball.getPosition()) < .5:
		link = viz.grab( hand, ball )
	if vizmat.Distance(hand.getPosition(),crank.getPosition()) < .5:
		link=viz.grab ( hand, crank)

vizact.onmousedown(' ' ,toggleLink())
i wrote this code for grabbing the first object and then releasing it and then trying to hold the second object..but its not working...paul can u tell me where is the problem?
Reply With Quote
  #15  
Old 05-15-2009, 12:08 PM
Gladsomebeast Gladsomebeast is offline
Member
 
Join Date: Mar 2005
Location: Isla Vizta, CA
Posts: 397
The vizact.onmousedown(' ' ,toggleLink()) needs a mouse button argument. Check docs on this.

Otherwise I don't see whats wrong. Throw some print statements around to see where the code is going or not going.

You also have the possibility of creating two links and loosing your handle to the first link. To fix create a list of grabable objects and use a "for in" loop to check if the hand should grab. If you grab, end the loop with a "break" statement.
__________________
Paul Elliott
WorldViz LLC
Reply With Quote
  #16  
Old 05-15-2009, 12:28 PM
nasr nasr is offline
Member
 
Join Date: Apr 2009
Posts: 27
Code:
def toggleLink():
	global link
	if link:
		#If link exits, stop grabbing
		link.remove()
		link = None

	if vizmat.Distance(hand.getPosition(), ball.getPosition()) < .5:
		link = viz.grab( hand, ball )
	if vizmat.Distance(hand.getPosition(),crank.getPosition()) < .5:
		link=viz.grab ( hand, crank)

vizact.onpick(viz.MOUSEBUTTON_RIGHT ,toggleLink)
paul im trying with this mouse event..but still not able to select any one object at this time...
Reply With Quote
  #17  
Old 05-15-2009, 12:32 PM
nasr nasr is offline
Member
 
Join Date: Apr 2009
Posts: 27
sorry i tried with this code also...but not working

Code:
def toggleLink():
	global link
	if link:
		#If link exits, stop grabbing
		link.remove()
		link = None

	if vizmat.Distance(hand.getPosition(), ball.getPosition()) < .5:
		link = viz.grab( hand, ball )
	if vizmat.Distance(hand.getPosition(),crank.getPosition()) < .5:
		link=viz.grab ( hand, crank)

vizact.onmousedown(viz.MOUSEBUTTON_RIGHT ,toggleLink)
Reply With Quote
  #18  
Old 05-19-2009, 04:21 AM
nasr nasr is offline
Member
 
Join Date: Apr 2009
Posts: 27
how to achieve the stereoscopic vision

how to enable the stereoscopic vision in a simple vizard application....
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
Any ideas on linking chess 3ds file with source code? djones1010 Vizard 1 04-24-2009 09:56 PM
Trying to integrate Source Code with Vizard djones1010 Vizard 1 03-10-2009 02:58 PM
Vizard Tip of the Month: Use Tasks to Simplify your Code Gladsomebeast Vizard 5 05-02-2008 04:30 PM
3D Music Interface Psirus Vizard 3 02-26-2008 11:48 AM
Vizard Crashes: causes are hard to determine, possible problem with the viz code vr_boyko Vizard 1 01-07-2005 10:52 AM


All times are GMT -7. The time now is 03:10 AM.


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