mathUtil.py (2002B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\carbon\common\script\util\mathUtil.py 2 import math 3 try: 4 import geo2 5 except ImportError: 6 geo2 = None 7 8 MATH_PI_2 = math.pi / 2 9 MATH_PI_4 = math.pi / 4 10 MATH_PI_8 = math.pi / 8 11 MATH_2_PI = math.pi * 2 12 13 def LtoI(v): 14 if v < 2147483648L: 15 return int(v) 16 return ~int(~v & 4294967295L) 17 18 19 def LerpList(color1, color2, lerpValue): 20 invLerpValue = 1.0 - lerpValue 21 return [invLerpValue * color1[0] + lerpValue * color2[0], 22 invLerpValue * color1[1] + lerpValue * color2[1], 23 invLerpValue * color1[2] + lerpValue * color2[2], 24 invLerpValue * color1[3] + lerpValue * color2[3]] 25 26 27 def LerpVector(v1, v2, s): 28 v = v1.CopyTo() 29 v.Lerp(v2, s) 30 return v 31 32 33 def Lerp(start, end, s): 34 return start + min(max(s, 0.0), 1.0) * (end - start) 35 36 37 def LerpTupleThree(tuple1, tuple2, scaling): 38 return (Lerp(tuple1[0], tuple2[0], scaling), Lerp(tuple1[1], tuple2[1], scaling), Lerp(tuple1[2], tuple2[2], scaling)) 39 40 41 def LerpTupleFour(tuple1, tuple2, scaling): 42 return (Lerp(tuple1[0], tuple2[0], scaling), 43 Lerp(tuple1[1], tuple2[1], scaling), 44 Lerp(tuple1[2], tuple2[2], scaling), 45 Lerp(tuple1[3], tuple2[3], scaling)) 46 47 48 def LerpByTime(startVal, endVal, startTime, endTime, curTime): 49 lerpRatio = float(curTime - startTime) / float(endTime - startTime) 50 return Lerp(startVal, endVal, lerpRatio) 51 52 53 def RayToPlaneIntersection(P, d, Q, n, returnSign = False): 54 position = P 55 sign = 1 56 denom = geo2.Vec3Dot(n, d) 57 if abs(denom) >= 1e-05: 58 distance = -geo2.Vec3Dot(Q, n) 59 t = -(geo2.Vec3Dot(n, P) + distance) / denom 60 if t < 0: 61 sign = -1 62 S = geo2.Add(geo2.Scale(d, t), P) 63 position = S 64 if returnSign: 65 return (position, sign) 66 return position 67 68 69 def ClampRotation(rotation): 70 if rotation > math.pi * 2: 71 rotation -= math.pi * 2 72 elif rotation < 0: 73 rotation += math.pi * 2 74 return rotation