From 3ff1c7a8a7bc7dabd4f85f5727d68be1b16d9b5f Mon Sep 17 00:00:00 2001 From: Josh Wilson Date: Thu, 10 Jan 2008 19:54:20 +0000 Subject: [PATCH] adding getShortestRotation(): useful for preventing spins in camera lerps --- direct/src/showbase/PythonUtil.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/direct/src/showbase/PythonUtil.py b/direct/src/showbase/PythonUtil.py index 327ebb8c6f..3b09d9546b 100644 --- a/direct/src/showbase/PythonUtil.py +++ b/direct/src/showbase/PythonUtil.py @@ -1653,6 +1653,21 @@ def lerp(v0, v1, t): """ return v0 + ((v1 - v0) * t) +def getShortestRotation(start, end): + """ + Given two heading values, return a tuple describing + the shortest interval from 'start' to 'end'. This tuple + can be used to lerp a camera between two rotations + while avoiding the 'spin' problem. + """ + start, end = start % 360, end % 360 + if abs(end - start) > 180: + if end < start: + end += 360 + else: + start += 360 + return (start, end) + def average(*args): """ returns simple average of list of values """ val = 0.