From: Stef M. <s.m...@ru...> - 2008-12-30 01:08:28
|
hello, while trying to get the correct the user zoom changed by code (as Bruce suggested), I bounced into another problem, parallelism of up and forward. Normally this problem won't occur, but switching between application, made by different persons, within the same scene (as I do right now) can cause this problem. So I've made a convenience procedure to prevent the problem, maybe some of you might benefit from it ,... ... or even have better (simpler) solutions. cheers, Stef # *********************************************************************** def Forward_Up ( Forward, Up ) : """ Sets both FORWARD and UP, preventing temporary parallelism of FORWARD and UP """ # Be sure we've vectors Forward = vector ( Forward ) Up = vector ( Up ) # Temp_Forward should not allign with # 1. scene.up # 2. Up # 3. Forward # And we may assume that Up and Forward don't allign # The sum of Forward and Up, will fullfill conditions 2,3 Temp_Forward = Up + Forward # calculate alfa, critical a=0 and alfa=pi alfa = Temp_Forward.diff_angle ( scene.up ) # make alfa in range 0 .. pi/2, critical alfa = pi/2 alfa = abs ( alfa - pi/2 ) # make alfa in range pi/2 .. 0, critical alfa = 0 alfa = pi/2 - alfa # if Temp_Forward alligned with current scene.up if alfa < 0.1 : # Create the product vector, # which is perpendicular to Up and Forward (conditions 2,3) # and will not allign with scene.up Temp_Forward = dot ( Up, Forward ) scene.forward = Temp_Forward scene.up = Up scene.forward = Forward |