예제 #1
0
    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
예제 #2
0
    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
예제 #3
0
파일: utils.py 프로젝트: yazici/OptAnim
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
예제 #4
0
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