WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 06-16-2005, 10:48 AM
steve steve is offline
Member
 
Join Date: Jun 2005
Location: USA
Posts: 4
Mouse problem

Hi,
trying to develop a different navigation for vizard, I’m having three problems with the mouse commands:

1. When I bring the mouse up, at a certain position close to the top the program throws it down (MOUSEMOVE_EVENT), the same happens at the bottom, the mouse gets pushed up at a certain positon.
2. Also, when I click the ‘tabb’ and the left mouse-button (in the program below) and release the mouse and tabb again, the view still changes and moves in, also I did not program that.
3. How could I implement a keyboard-command that get’s only triggered if the user presses shift+ctrl (this question is not very important, so if it is complicated I just take another key).

Steve




Code:
view = viz.get(viz.MAIN_VIEWPOINT)
view.translate(2.50, 1.01, -0.25)#1.3269580602645874, 1.013837456703186, -0.55598777532577515)
view.rotate(-90,0,0)


mouseIsMovingUp=1
pointIsMovingRight=1
pointIsMovingUp=1

oldMousePos=0
currentMousePosX =0


def mykeyboard(whichKey):
	print 'This key was pressed: ', whichKey
	if whichKey == viz.KEY_CONTROL_L:
		viz.mouse(viz.ON)
	if whichKey == '65289':
		print'tabb',pointIsMovingUp
		if viz.buttonstate()==1:
			if pointIsMovingUp==1:
				viz.mouse(viz.OFF)
				print 'pointIsMovingUP==1'
				#print 'viz.get(viz.MAIN_VIEWPOINT):', view.get(viz.HEAD_POS)
				view.translate(view.get(viz.HEAD_POS)[0],view.get(viz.HEAD_POS)[1]+.05,view.get(viz.HEAD_POS)[2])
				return
			if pointIsMovingUp==0:
				viz.mouse(viz.OFF)
				print 'pointIsMovingUP==1'
				#print 'viz.get(viz.MAIN_VIEWPOINT):', view.get(viz.HEAD_POS)
				view.translate(view.get(viz.HEAD_POS)[0],view.get(viz.HEAD_POS)[1]-.05,view.get(viz.HEAD_POS)[2])
				return

viz.callback(viz.KEYBOARD_EVENT, mykeyboard)


def mymousemove(horz, vert):
	global mouseIsMovingUp,pointIsMovingRight,pointIsMovingUp, oldMousePos,currentMousePosX
	
	if vert>0:
		mouseIsMovingUp=1
		pointIsMovingUp=1
		print 'up'
		return
	if vert<0:
		mouseIsMovingUp=0
		pointIsMovingUp=0
		print 'down',pointIsMovingUp
		return


	#print 'horz, pos',horz, pos
	if horz>currentMousePosX:
		pointIsMovingRight=1
		#print 'in right1'
	if horz<currentMousePosX:
		pointIsMovingRight=0
		#print 'in right0'
	
	oldMousePos=currentMousePosX
	currentMousePosX = viz.mousepos()[0]
	print 'oldMousePos',oldMousePos,currentMousePosX


	#print 'My mouse moved to: ', horz, vert
viz.callback(viz.MOUSEMOVE_EVENT, mymousemove)



#def mymouse(whichButton):
#	if whichButton == viz.MOUSEBUTTON_LEFT:
#		#viz.mouse(viz.ON)

#viz.callback(viz.MOUSEUP_EVENT, mymouse)
Reply With Quote
  #2  
Old 06-16-2005, 11:36 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi Steve,

1) When the MOUSEMOVE callback returns relative data then it will automatically recenter the mouse when it reaches the edge of the window. If you don't want the mouse to be recentered, then you can change the callback so that it returns absolute data. By default, the horizontal data is absolute and the vertical data is relative. To change both to absolute do the following:
Code:
viz.mousedata(viz.ABSOLUTE,viz.ABSOLUTE)
2)I believe this is happening because you are turning off mouse movement while the viewpoint is moving. After you turn off mouse movement issue the following command to stop any current movement:
Code:
viz.velocity(0,0,0)
3) To check if "Shift + Ctrl" is pressed you can use the viz.iskeydown function. Example:
Code:
if whichKey == viz.KEY_CONTROL_L and viz.iskeydown(viz.KEY_SHIFT_L):
    print 'Shift + Ctrl pressed'
This will get triggered when the user presses CTRL while the SHIFT key is down. It won't work if the user presses SHIFT while the CTRL key is down. To do that you would have to swap the key values in the above sample code.

Let me know if you need any more help on this.
Reply With Quote
  #3  
Old 06-16-2005, 12:58 PM
steve steve is offline
Member
 
Join Date: Jun 2005
Location: USA
Posts: 4
rotation

Hey, thank you for your earlier help, and a have another question. How do you rotate a scene in all directions without changing your point of view.
This is what I tried:
view.rotate(view.get(viz.HEAD_ORI)[0]+2,view.get(viz.HEAD_ORI)[1],view.get(viz.HEAD_ORI)[2])


viz.scene(1).rotate(1,1,1,Orientation)
steve
Reply With Quote
  #4  
Old 06-16-2005, 01:03 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi Steve,

There is no way to rotate an entire scene. You will have to rotate the viewpoint. You can try rotating the BODY_ORI of the viewpoint instead. If you describe what you are trying to do I could provide you with some better help.
Reply With Quote
  #5  
Old 06-23-2005, 03:23 PM
steve steve is offline
Member
 
Join Date: Jun 2005
Location: USA
Posts: 4
Hi,thank you for all of your previous help.
The thing that I am trying to do is make a navigation system (as in Kaydara from Alias). So far I can zoom in and out, move up and down, and left and right. All that is left is the rotation part. I want to be able to rotate around the center of the visible scene.
I know how to get the radius of this imaginary circle (e.g. over view.get(viz.HEAD_POS)... Phytagoras...) but with view.get(viz.HEAD_POS) I only get the position towards the 0,0,0 point, but not to the center of the visible scene as seen by the user. How can I get that?

Thanks again for your help
--Steve
Reply With Quote
  #6  
Old 06-23-2005, 04:52 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

I've never used Kaydara, but I have a sample script that I believe does something similar to what you want. It creates a custom mouse navigation mode. To rotate about the center of the scene click and drag the left mouse button. To pan left/right and up/down click and drag the right mouse button. Use the mouse wheel to zoom in/out. You can also recenter the viewpoint by holding down the left shift button and clicking on an object in the scene. This will center the viewpoint rotations around the exact 3d location that was clicked. Let me know if this doesn't help you.
Code:
import viz
viz.go()

viz.add('mini.osgx')
viz.clearcolor(viz.GRAY)

class VizMouseNavigator(viz.EventClass):

	PAN_SCALE = 20.0
	MOVE_SCALE = 1.0
	
	def __init__(self):
		viz.EventClass.__init__(self)

		viz.mouse(0)

		self.__view = viz.get(viz.MAIN_VIEWPOINT)
		self.__view.translate(0,0,-10)
		
		self.__center = [0,0,0]
		self.__lastmousepos = [0,0]
		
		self.callback(viz.TIMER_EVENT,self.__ontimer)
		self.callback(viz.MOUSEWHEEL_EVENT,self.__onmousewheel)
		self.callback(viz.MOUSEDOWN_EVENT,self.__onmousedown)
		self.starttimer(0,0,viz.FOREVER)
		
	def __ontimer(self,num):
		button = viz.buttonstate()
		mouse = viz.mousepos()
		if button & viz.MOUSEBUTTON_RIGHT:
			self.panRight(-(mouse[0] - self.__lastmousepos[0])*self.PAN_SCALE)
			self.panUp(-(mouse[1] - self.__lastmousepos[1])*self.PAN_SCALE)
		if button & viz.MOUSEBUTTON_LEFT:
			self.rotateRight((mouse[0] - self.__lastmousepos[0])*self.MOVE_SCALE)
			self.rotateUp((mouse[1] - self.__lastmousepos[1])*self.MOVE_SCALE)
		self.__lastmousepos = mouse
		
	def __onmousewheel(self,dir):
		distance = vizmat.Distance(self.__view.get(viz.HEAD_POS),self.__center) / 8.0
		self.__view.move(0,0,dir*distance)

	def __onmousedown(self,button):
		if button == viz.MOUSEBUTTON_LEFT and viz.iskeydown(viz.KEY_SHIFT_L):
			info = viz.pick(1)
			if info.intersected:
				self.setCenter(info.intersectPoint)

	def rotateRight(self,amount):
		distance = vizmat.Distance(self.__view.get(viz.HEAD_POS),self.__center)
		self.__view.move(-distance*amount,0,0)
		self.__view.lookat(self.__center)
		headPos = viz.Vector(self.__view.get(viz.HEAD_POS))
		headPos = headPos - self.__center
		headPos.normalize()
		headPos *= distance
		headPos = headPos + self.__center
		self.__view.translate(headPos.get())
		
	def rotateUp(self,amount):
		oldPos = self.__view.get(viz.HEAD_POS)
		oldRot = self.__view.get(viz.HEAD_QUAT)
		distance = vizmat.Distance(self.__view.get(viz.HEAD_POS),self.__center)
		self.__view.move(0,-distance*amount,0)
		self.__view.lookat(self.__center)
		if abs(self.__view.get(viz.HEAD_PITCH)) > 85.0:
			self.__view.translate(oldPos)
			self.__view.rotatequat(oldRot)
			return
		headPos = viz.Vector(self.__view.get(viz.HEAD_POS))
		headPos = headPos - self.__center
		headPos.normalize()
		headPos *= distance
		headPos = headPos + self.__center
		self.__view.translate(headPos.get())

	def panRight(self,amount):
		mat = viz.Transform(self.__view.get(viz.HEAD_MAT))
		mat.setTrans(self.__center)
		mat.preTrans(amount,0,0)
		self.__center = mat.getTrans()
		self.__view.move(amount,0,0)
		
	def panUp(self,amount):
		mat = viz.Transform(self.__view.get(viz.HEAD_MAT))
		mat.setTrans(self.__center)
		mat.preTrans(0,amount,0)
		self.__center = mat.getTrans()
		self.__view.move(0,amount,0)
		
	def setCenter(self,center):
		diff = viz.Vector(center)
		diff = diff - self.__center
		pos = self.__view.get(viz.HEAD_POS)
		self.__view.translate(pos[0]+diff[0],pos[1]+diff[1],pos[2]+diff[2])
		self.__center = center


VizMouseNavigator()
Reply With Quote
  #7  
Old 07-14-2005, 02:30 PM
steve steve is offline
Member
 
Join Date: Jun 2005
Location: USA
Posts: 4
Hi,
thank you, that worked fine!

Now I want to switch between both navigation systems (old vizard native and new one). I imported the class as a Module, and it works fine, but what can I do to switch back and forth?

To stop the timer I used killTimer.
In an old thread I found that it was not possible to remove a callback function

(You wrote in http://www.worldviz.com/forum/showth...=stop+callback
There is no way to stop a callback. You can set a flag within your script and just ignore incoming events. However, we might consider adding this to the next release since it would not be too difficult to implement. )

Any suggestions? Is it now possible to remove callback functions?
I could use certain key-Commands, and only if the user presses that key, the new navigation system will be present...

Thank you.
Reply With Quote
  #8  
Old 07-14-2005, 03:01 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

That post is very old. In the current version of Vizard you can remove a callback by passing the number zero instead of a function. Example:
Code:
self.callback(viz.TIMER_EVENT,0)
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


All times are GMT -7. The time now is 11:07 AM.


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