From: Bruce S. <Bru...@nc...> - 2009-05-10 04:07:34
|
from visual import * # This routine watches scene.forward and changes the directions of # the lights to stay fixed with respect to scene.forward. # The effect is to let the user rotate the scene while keeping # the lights fixed, as though one were rotating an object in the # hand to examine it, with fixed lighting, rather than rotating # the camera. # To compare, comment out the while loop, in which case you'll see # that when you rotate around to the back of the scene, it is dark. # This requires Visual 5. A similar routine in Visual 3 would be # somewhat more complicated because the lights were not objects # and so could not be put in a frame. Instead, one would have to # adjust the directions of the lights individually. # Bruce Sherwood, May 2009 lframe = frame() for obj in scene.lights: obj.frame = lframe # put lights in a frame box(pos=(-2,0,0), color=color.red) box(pos=(2,0,0), color=color.cyan) cylinder(pos=(0,-0.5,0), radius=1, axis=(0,1,0), color=color.orange) old = vector(scene.forward) # keep a copy of the old forward while 1: rate(50) if scene.forward != old: new = scene.forward axis = cross(old,new) angle = new.diff_angle(old) lframe.rotate(axis=axis, angle=angle) old = vector(new) |