![]() |
|
|
|
#1
|
|||
|
|||
|
Interesting goal. I whipped up a bit of code that orbits the sphere by telling the sphere to "lookat" the intersection point, then rotating the sphere the initial offset amount.
The code is not quite right yet because sustained clicking on the same point rolls the sphere around that point. Maybe somebody knows whats wrong? 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'))
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)
__________________
Paul Elliott WorldViz LLC |
|
#2
|
|||
|
|||
|
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)
|
|
#3
|
|||
|
|||
|
Righto. The link is overriding the rotation we are giving the sphere. To fix we tell the link to only operate on position
Code:
viewLink = viz.link(viz.MainView,node, mask=viz.LINK_POS)
__________________
Paul Elliott WorldViz LLC |
|
#4
|
|||
|
|||
|
Step by step I'm able to locate the source of the problem: I use the sphere in a hierarchical group order. The following code reproduces the strange behaviour of rotating.
Code:
import viz
import vizmat
import vizshape
viz.go()
viz.mouse.setOverride(viz.ON)
root = viz.add(viz.GROUP, parent=viz.WORLD)
root.setPosition([0,1.8,3],viz.REL_GLOBAL)
node = vizshape.addSphere(pos=[0,0,0], parent=root)
node.texture(viz.add('image2.jpg'))
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)
|
|
#5
|
|||
|
|||
|
Here's another way to do it.
Code:
from viz import *
go()
clearcolor(.8,.8,.8)
vert = add('ball.wrl')
vert.translate(0,1.8,2)
xang = 0
yang = 0
INCREMENT = .5
mouse(OFF)
restrictmouse(OFF)
def mousemove(x,y):
global xang,yang
state = buttonstate()
if state == MOUSEBUTTON_LEFT:
xang = xang + x*INCREMENT
yang = yang + y*INCREMENT
vert.rotate(0,1,0,-x*INCREMENT,RELATIVE_WORLD)
vert.rotate(1,0,0,y*INCREMENT,RELATIVE_WORLD)
mousedata(RELATIVE,RELATIVE)
callback(MOUSEMOVE_EVENT,mousemove)
|
|
#6
|
|||
|
|||
|
Interesting... I shall dub thee Spinner Metaphor Method and place you in a file of honor.
__________________
Paul Elliott WorldViz LLC |
|
#7
|
|||
|
|||
|
Hi Gladsomebeast, the effect of slight roll results in the lookat call. The second argument is a optional roll value. The internal value of viz.ABS_GLOBAL is 4:
Code:
node.lookat(intersectionItem.point, 0, viz.ABS_GLOBAL) Code:
node.lookat(intersectionItem.point,viz.ABS_GLOBAL) Code:
node.lookat(intersectionItem.point,4) |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| retrieve Object names | Geoffrey | Vizard | 11 | 12-11-2009 05:26 AM |
| reseting an object | durf | Vizard | 3 | 03-18-2009 12:48 AM |
| Object rotating around world axis, not own axis | tacbob | Vizard | 1 | 02-15-2007 10:12 AM |
| Child Object Rotation | paulgoldberg | Vizard | 5 | 09-05-2006 12:33 PM |
| rotate to object | jargon | Vizard | 1 | 08-08-2005 01:20 PM |