From 0c99328347a4c4cdccea04e9cce988911eff068f Mon Sep 17 00:00:00 2001 From: Darren Ranalli Date: Sat, 7 Dec 2002 00:48:29 +0000 Subject: [PATCH] added lerp, lineupPos --- direct/src/showbase/PythonUtil.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/direct/src/showbase/PythonUtil.py b/direct/src/showbase/PythonUtil.py index d0ddac94ee..65fc62918b 100644 --- a/direct/src/showbase/PythonUtil.py +++ b/direct/src/showbase/PythonUtil.py @@ -508,3 +508,22 @@ def bound(value, bound1, bound2): return min(max(value, bound2), bound1) else: return min(max(value, bound1), bound2) + +def lerp(v0, v1, t): + """ + returns a value lerped between v0 and v1, according to t + t must be in [0,1] + t == 0 maps to v0, t == 1 maps to v1 + """ + return v0 + (t * (v1 - v0)) + +def lineupPos(i, num, spacing): + """ + use to line up a series of 'num' objects, centered around zero + 'i' is the index of the object in the lineup + 'spacing' is the amount of space between objects in the lineup + """ + assert num >= 1 + assert i >= 0 and i < num + pos = float(i) * spacing + return pos - ((float(spacing) * (num-1))/2.)