|
From: Symion <kn...@ip...> - 2010-02-06 05:08:21
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=windows-1252"
http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Craig Berry wrote:
<blockquote
cite="mid:8de...@ma..."
type="cite">
<pre wrap="">On Wed, Feb 3, 2010 at 14:49, Craig Berry <a class="moz-txt-link-rfc2396E" href="mailto:cd...@gm..."><cd...@gm...></a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">On Wed, Feb 3, 2010 at 13:53, Bruce Sherwood <a class="moz-txt-link-rfc2396E" href="mailto:Bru...@nc..."><Bru...@nc...></a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Could you describe briefly what it is that you want to do?
</pre>
</blockquote>
<pre wrap="">I want to allow the user to control the camera with middle- and
right-drag mouse gestures, but also, if they click on an object, slew
the camera to point at that object from a particular distance. I can
slew the camera's aim point by changing scene.center, but I'm having
the difficulties described previously with putting it at a particular
(apparent) distance from the selected object.
</pre>
</blockquote>
<pre wrap=""><!---->
So...anybody have a clue on how to do that elegantly?
</pre>
</blockquote>
Hi there,<br>
I don't know if this program is elegant or not but it does give you
control over Range, Center and Forward.<br>
It also enables you to defines the Range upper and lower boundaries.<br>
This requires that Userzoom be turned off and scene.range driven
directly.<br>
<br>
A Feedback loop is setup between scene.range and scene.mouse.pos that
drives the zoom effect.<br>
Careful positioning of the mouse pointer gives you more control.<br>
<br>
<br>
''Simple zoom routine GNU \xa9 Symion MMX<br>
<br>
"r" will Reset the scene range, scene.center and scene.forward<br>
<br>
Middle Mouse key and drag will Zoom<br>
Hint:<br>
Find the spot (any corner) and draw mouse with middle key pressed<br>
toward the scene center and back to the corner!<br>
<br>
Right Mouse key will Spin<br>
Left Mouse key will change scene.center<br>
<br>
"x" will exit<br>
'''<br>
<br>
from visual import *<br>
<br>
userzoom = False<br>
nexit = False<br>
scene.userzoom = userzoom<br>
scene.autoscale = False<br>
srange = 10.0<br>
scene.range = srange<br>
rangemin = 1.0<br>
rangemax = 100.0<br>
scenter = vector(scene.center)<br>
forward = vector(scene.forward)<br>
<br>
col = (0,1,0)<br>
work = list()<br>
work.append(sphere(color=col))<br>
work.append(box(pos=(1,0,0),color=(1,0,0)))<br>
scene.visible = True<br>
print __doc__<br>
while not nexit:<br>
post = scene.mouse.pos<br>
if scene.kb.keys>0:<br>
km = scene.kb.getkey()<br>
if km == 'x':<br>
nexit = True<br>
elif km == 'r':<br>
srange = 10.0<br>
scene.range = srange<br>
scenter = vector(0,0,0)<br>
scene.center = scenter<br>
scene.forward = forward<br>
elif scene.mouse.events>0:<br>
mk = scene.mouse.getevent()<br>
if mk.drop == 'middle':<br>
userzoom = False<br>
print 'Zoom Off: %s' %(srange)<br>
elif mk.drag == 'middle':<br>
userzoom = True<br>
print 'Zoom On: %s' %(srange)<br>
elif mk.press == 'left':<br>
if mk.pick:<br>
post = vector(mk.pick.pos)<br>
scene.center = scenter = post<br>
print 'Center %s' %(scenter)<br>
if userzoom:<br>
# print 'range (%0.3f,%0.3f,%0.3f) = %s'
%(post.x,post.y,post.z,mag(post))<br>
# Limit zoom! This line controls the Entire process<br>
srange = min(rangemax,max(rangemin,mag(post)))<br>
scene.range = srange<br>
<br>
for thing in work:<br>
thing.visible = False<br>
del work<br>
scene.visible = False<br>
<br>
<br>
Symion<br>
</body>
</html>
|