def slerp_rotations(self,index_start,index_current,index_end): """ http://en.wikipedia.org/wiki/Slerp http://cgkit.sourceforge.net/doc2/cgtypes.html?highlight=slerp#cgkit.cgtypes.slerp """ from cgkit.cgtypes import quat, mat3, slerp def get_quaternion_from_matrix(matrix): q = quat() mat = mat3([num for row in matrix for num in row]) mat = mat.decompose()[0] q.fromMat(mat) return q if index_start == index_end: t = 0 else: t = float(index_current-index_start)/float(index_end-index_start) q_start = get_quaternion_from_matrix(self.rotations[index_start]) q_end = get_quaternion_from_matrix(self.rotations[index_end]) if t==0: q_current = q_start else: q_current = slerp(t,q_start,q_end) mat_current = q_current.toMat3() list_current = [] for i in range(3): list_current.append([]) for j in range(3): list_current[i].append(mat_current[i,j]) return list_current
def num_q_lerp(qA, qB, weight): assert (True not in [(math.isnan(x) or math.isinf(x)) for x in qA + qB]) eulerA, eulerB = qA[3:dof], qB[3:dof] quatA, quatB = num_euler_to_quat(eulerA), num_euler_to_quat(eulerB) posA, posB = qA[:3], qB[:3] newQuat = cgtypes.slerp(weight, quatA, quatB) newEuler = num_quat_to_euler(newQuat) newPos = vec3_lerp(posA, posB, weight) ret = newPos + newEuler return ret
def num_q_lerp(qA, qB, weight): assert(True not in [(math.isnan(x) or math.isinf(x)) for x in qA+qB]) eulerA, eulerB = qA[3:dof], qB[3:dof] quatA, quatB = num_euler_to_quat(eulerA), num_euler_to_quat(eulerB) posA, posB = qA[:3], qB[:3] newQuat = cgtypes.slerp(weight, quatA, quatB) newEuler = num_quat_to_euler(newQuat) newPos = vec3_lerp(posA, posB, weight) ret = newPos + newEuler return ret