WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 09-14-2016, 06:01 AM
M@rcello M@rcello is offline
Member
 
Join Date: May 2016
Posts: 11
Question Write using phantom omni

Good evening to everyone,
i am trying to use the phantom omni to write a letter.
I would like to have a function active while the buttom of the omni is down; for all this time the function has to print the trajectory of the omni.
Any ideas? Thanks in advance
Reply With Quote
  #2  
Old 09-14-2016, 07:57 AM
M@rcello M@rcello is offline
Member
 
Join Date: May 2016
Posts: 11
Question

This is the code:
Code:
import viz
import hd
import vizact
import vizshape
import vizact
import vizmat

viz.go()

viz.MainView.setPosition(0,0,-40)
viz.clearcolor(viz.GRAY)

pen=viz.add('art/pencil.obj')
pen.setPosition([0,0,-2])
pen.setScale([0.05,0.05,0.05])

cube=viz.add('art/box.wrl')
cube.color(0,0,0)
cube.setScale([35,20,0.1])

cube1=viz.add('art/box.wrl')
cube1.setPosition([-17.5,0,0])
cube1.setScale([1,21,0.2])
cube1.color(0,255,0)

cube2=viz.add('art/box.wrl')
cube2.color(0,255,0)
cube2.setPosition([17.5,0,0])
cube2.setScale([1,21,0.2])

cube3=viz.add('art/box.wrl')
cube3.color(0,255,0)
cube3.setPosition([0,10,0])
cube3.setScale([35,1,0.2])

cube4=viz.add('art/box.wrl')
cube4.color(0,255,0)
cube4.setPosition([0,-10,0])
cube4.setScale([35,1,0.2])

pos0=[]
pos1=[]

def UpdateModel():
	line = viz.MainWindow.screenToWorld(hd.get(hd.POSITION))
	pen.setPosition(line.endFromDistance(40))	
vizact.ontimer(0,UpdateModel)

def write(button):
	if button == hd.BUTTON1:
		global pos0
		pos0 = hd.get(hd.POSITION)

def Stop(button):
	if button == hd.BUTTON1:
		global pos1
		pos1=hd.get(hd.POSITION)
		viz.startLayer(viz.LINE_STRIP)
		viz.vertexColor(viz.WHITE)
		viz.vertex(pos0[0],pos0[1],0)
		viz.vertex(pos1[0],pos1[1],0)
		line=viz.endLayer(parent=viz.SCREEN)
	
hd.callback(hd.BUTTONDOWN_EVENT,write)
hd.callback(hd.BUTTONUP_EVENT,Stop)
The problem is that this function take a start point when the button1 is pushed down and a final point when the button is again up. If i hold the button1 nothing changes. I need to take all the points and draw the lines when the button1 holded1.
The effect should be the on of a digital sign!
Reply With Quote
  #3  
Old 09-15-2016, 06:00 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
The 'write' function is probably called continuously as long as button1 is held down. If that's the case the final value of pos0 will be the same as pos1. You could add a flag so that the write function only saves to pos0 the first time it is called. Then reset the flag when the buttonup event occurs.
Reply With Quote
  #4  
Old 09-15-2016, 06:22 AM
M@rcello M@rcello is offline
Member
 
Join Date: May 2016
Posts: 11
Hy jeff and thanks to give always an answer to my doubts.
The function write is called every time that button 1 is pressed,it doesn't matter if it held down or not.
Anyway,I have found on this forum a similar post,in which you suggested to use the pencil from the tools module.
This is the code and it works:
Code:
import viz
import vizact
import vizshape
import vizact
import vizmat
import viztask

viz.go()

viz.MainView.setPosition(0,0,-40)
viz.clearcolor(viz.GRAY)

sensable=viz.add('sensable3.dle')
device=sensable.addHapticDevice()
device.workspace.setScale([10,10,10])

from tools import pencil
tool=pencil.Pencil()

pen=viz.add('art/pencil.obj')
pen.setPosition([0,0,-2])
pen.setScale([0.05,0.05,0.05])

cube=viz.add('art/box.wrl')
cube.color(0,0,0)
cube.setScale([35,20,0.1])

cube1=viz.add('art/box.wrl')
cube1.setPosition([-17.5,0,0])
cube1.setScale([1,21,0.2])
cube1.color(0,255,0)

cube2=viz.add('art/box.wrl')
cube2.color(0,255,0)
cube2.setPosition([17.5,0,0])
cube2.setScale([1,21,0.2])

cube3=viz.add('art/box.wrl')
cube3.color(0,255,0)
cube3.setPosition([0,10,0])
cube3.setScale([35,1,0.2])

cube4=viz.add('art/box.wrl')
cube4.color(0,255,0)
cube4.setPosition([0,-10,0])
cube4.setScale([35,1,0.2])

myButton = viz.addButtonLabel('Erase')
myButton.setPosition(0.5,0.1,0)
myButton.setScale(3,1,1)

count=0

def MyTask():
	while True:
		yield viztask.waitButtonDown(myButton)
		tool.clear()
viztask.schedule( MyTask())

def UpdateModel():
	line = viz.MainWindow.screenToWorld(device.getPosition())
	pen.setPosition(line.endFromDistance(40))	
vizact.ontimer(0,UpdateModel)

def write(e):
	if e.button==0:
		update(tool)
		viz.link(pen,tool)
viz.callback(viz.SENSOR_DOWN_EVENT,write)

def update(tool):
	tool.draw()
tool.setUpdateFunction(update)
The problem is that when i press the button of the stylus it starts drawing the trajectory but it never ends. I am looking to implement some control so that when the button is pressed again the trajectory is not drawn, and again if i press the button for the third time the system starts again drawing the trajecotry.I hope it is clear
Suggestions?
I need something like when you enter in this function,execute and repeat it until this event happens. The problem is that with the while loop everything freeze
Reply With Quote
  #5  
Old 09-16-2016, 04:51 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
It sounds like you could set this up within a task function and wait for the sensor event to both start and stop the drawing:

Code:
def DrawingTask():
	
	while True:

		yield viztask.waitEvent(viz.SENSOR_DOWN_EVENT)
		# start drawing
		
		yield viztask.waitEvent(viz.SENSOR_DOWN_EVENT)
		# stop drawing
		

viztask.schedule( DrawingTask() )
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
Need help with Phantom omni sebzim4500 Vizard 3 05-26-2016 08:05 AM
Phantom omni Vs Vizard blessonisaac Vizard 2 03-23-2011 02:25 PM
Phantom Omni Device Scripts vSuejung Vizard 1 09-17-2008 04:42 PM
Phantom Omni Demo betancourtb82 Vizard 1 10-17-2006 10:23 AM
Direct access to phantom omni data vsully Vizard 1 03-14-2006 09:44 AM


All times are GMT -7. The time now is 02:26 AM.


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