From: Bruce S. <Bru...@nc...> - 2005-09-29 03:28:19
|
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 > |