WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 05-11-2009, 03: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
 


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 10:56 PM
Trying to integrate Source Code with Vizard djones1010 Vizard 1 03-10-2009 03:58 PM
Vizard Tip of the Month: Use Tasks to Simplify your Code Gladsomebeast Vizard 5 05-02-2008 05:30 PM
3D Music Interface Psirus Vizard 3 02-26-2008 12:48 PM
Vizard Crashes: causes are hard to determine, possible problem with the viz code vr_boyko Vizard 1 01-07-2005 11:52 AM


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


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