From: Bill W. <ww...@la...> - 2005-09-29 21:52:23
|
Cheers Bruce, very cool! I think the joke alone is worth the price of admission. Speaking of obvious, studying the stonehenge example was my first instinct, but that one still baffles me. How to get anything that looks like zoom from adjusting only the center is beyond me, at least, for positions that are there. There is more to this problem than meets the eye (or the camera), and it's taken me a good part of the day to figure out what might be going on with the obvious" script you sent. I started with the one from the "Contributed" page figuring it was a little newer. Here are a couple of buried gotchas: * Rotating by mouse enough changes scene.forward but can also change scene.up! Without saving and restoring that you sometimes get mirror images on recalling the view. * Saving/restoring more than one view is trickier, and here is what I think is happening. Mouse zoom only changes the camera, not range/scale. Any programmatic changes to range, however, do produce a new camera distance, which breaks any previous relationship. So the program cannot zoom or even restore a saved view without throwing everything off for views already stored. I've attached a version of your script with modifications to try to emphasize what's going on and suggest how to compensate. It doesn't feel pretty but unless there is some unknown parameter to work with, this is the only way I see to work it (short of grabbing full mouse control and rolling your own navigation). I tried to highlight places I hacked it with triple ###. Thanks again for the prompt and careful help. Bill -----Original Message----- From: Bruce Sherwood [mailto:Bru...@nc...] Sent: Wednesday, September 28, 2005 8:28 PM To: ww...@la... Cc: vis...@li... Subject: Re: [Visualpython-users] Can the camera be reset after user zoom? Or else... Here is a little routine that restores a previous view. To try it, zoom and spin, then click (left button) to save that view. Next zoom and spin some more, to make a completely different view. Click and you'll see your saved view restored. This routine makes me think of the joke about the physics professor who during a class says, "It's obvious that such and such," then pauses and muses, "Is that really obvious?" He stands there deep in thought for 20 minutes, then announces, "Yes, it is obvious," and proceeds with the rest of the lecture without further comment. It wasn't obvious how to write this program. I've put it in the contributed section of the vpython.org web site. I'll also draw attention to a somewhat related routine in the example program stonehenge.py distributed with VPython, where you fly through a scene by continual readjustment of scene.center. Bruce Sherwood from visual import * ##from time import clock # If you want to access scene.range before any user adjustments # have been made (zoom or spin), you need to wait for the scene # to be rendered and autoscaled. In that case you need to import # the clock() function to make it possible to wait for 0.1 s (say). # But if you wait on a mouse click for the user to complete zoom # or spin, you don't need to pause the 0.1 s. box(pos=(-1.5,0,0), color=color.red) box(pos=(1.5,0,0), color=color.blue) ##t = clock() ##while clock() < t+0.1: ## continue # Wait while user adjusts the view. scene.mouse.getclick() # Determine how wide the scene is. halfwidth = max(scene.range) # Determine how far we are from the center of the scene. distance = mag(scene.mouse.camera-scene.center) # Keep a copy of current scene.forward. # Without the adding of the zero vector, "direction" # would just be another name for the current scene.forward. direction = scene.forward+vector(0,0,0) # Wait while user changes the view, then restore the previous view. scene.mouse.getclick() # Determine the new distance from the center. newdistance = mag(scene.mouse.camera-scene.center) # Adjust the range based on the new distance. scene.range = halfwidth*distance/newdistance # Reset the viewing direction. scene.forward = direction Bill Ward wrote: > Hi everyone, > > I'm new to the list, so first my gratitude to everyone involved in the > creation and enhancement of this package...where has it been all my > life? An outstanding and accessible framework with clear > tutorials...except for the following! > > I've gathered from reading archives and the reference manual that > direct program control of the camera is not an option. I have > explored scale/range, center, forward, and the mouse.camera attributes > to where I have a couple of clues. But how can I do the following: > > I want to establish a set of fixed views of my scene that can be > called up from controls (button or menu). Ideally, I'd like to mouse > my way into the correct view, then save the camera position for > recall. I see the camera position is modified, but when I zoom in by > mousing there is no change to "scale" , or center, or forward, or > anything else I can set. Am I running up against a buried > "manual_scale" that I can't read or write? > > Even if I can only establish the right scale programmatically, that's > fine. But, if I allow the user to zoom and rotate around the scene, > how can I go back to a nominal camera distance to establish those > fixed viewpoints that will be designed to illustrate the underlying > physics? Hence the subject line, is there such thing as a camera > reset? Can I get the effect by toggling userzoom, or autoscale? Or do > I have to just shut of userzoom entirely? > > Thanks in advance for your suggestions. > > Bill Ward > |