View Single Post
  #3  
Old 05-12-2009, 11:21 AM
Penguin Penguin is offline
Member
 
Join Date: Mar 2009
Posts: 14
Except for the slight roll, your code works fine. But here it comes: when I attach the sphere to the main view the rotation doesn't work any longer.

Code:
import viz
import vizmat
import vizshape

viz.go()
viz.mouse.setOverride(viz.ON)

node = vizshape.addSphere(pos=[0, 1.8, 3])
node.texture(viz.add('image2.jpg'))

viewLink = viz.link(viz.MainView,node)
viewLink.preTrans([0,0,3])

rotation = None
def onGrab():
	global rotation
	intersectionItem = viz.pick(1)
	if intersectionItem.valid:
		src_ori = vizmat.Quat(node.getQuat(viz.ABS_GLOBAL))
		node.lookat(intersectionItem.point, viz.ABS_GLOBAL)
		dst_ori = vizmat.Quat(node.getQuat(viz.ABS_GLOBAL))
		#D = O * S so O = D * 1/S
		rotation =  src_ori * dst_ori.inverse()
		
vizact.onmousedown(viz.MOUSEBUTTON_LEFT, onGrab)

def moveSphere():
	if rotation:
		intersectionItem = viz.pick(1)
		if intersectionItem.valid:
			node.lookat(intersectionItem.point)
			node.setQuat(rotation, viz.ABS_LOCAL)
		
vizact.onupdate(viz.PRIORITY_DEFAULT, moveSphere)
		
def endGrab():
	global rotation
	rotation = None
vizact.onmouseup(viz.MOUSEBUTTON_LEFT, endGrab)
Reply With Quote