Ho I'm sorry ... I just see that the code I sent was not the right one ... I
did some testing and suddenly the code had become anything ...
def slerp_quaternion(m_quaternion_1, m_quaternion_2, f_weight):
"""
!@Brief Apply Spherical interpolation between two quaternions.
@type m_quaternion_1: OpenMaya.MQuaternion
@param m_quaternion_1: First Quaternion.
@type m_quaternion_2: OpenMaya.MQuaternion
@param m_quaternion_2: Second Quaternion.
@type f_weight: float
@param f_weight: Value for blending.
"""
# Normalize quaternions
m_quaternion_1 = m_quaternion_1.normal()
m_quaternion_2 = m_quaternion_2.normal()
# If is equial return first quaternion
if m_quaternion_1.isEquivalent(m_quaternion_2):
return m_quaternion_1
# TODO: fixlater
# If the inputs are too close for comfort,
# linearly interpolate and normalize the result.
# if abs(dot) > 0.9995:
# pass
# If the dot product is negative, the quaternions
# have opposite handed-ness and slerp won't take
# the shorter path. Fix by reversing one quaternion.
# dot = dot_product(m_quaternion_1, m_quaternion_2)
dot = dot_product(m_quaternion_1, m_quaternion_2)
if dot < 0.0:
m_quaternion_2.negateIt()
dot *= -1.0
# Weight Blend
f_scale_1 = 1.0 - f_weight
f_scale_2 = f_weight
# Get Quaternion median
dot = max(min(dot, 1.0), -1.0)
f_theta = math.acos(dot)
f_sin_theta = math.sin(f_theta)
f_scale_1 = math.sin(f_scale_1 * f_theta) / f_sin_theta
f_scale_2 = math.sin(f_scale_2 * f_theta) / f_sin_theta
# New Quaternion
a_new_values = []
for i in xrange(4):
a_new_values.append(f_scale_1 * m_quaternion_1[i] + f_scale_2 *
m_quaternion_2[i])
return OpenMaya.MQuaternion(a_new_values[0], a_new_values[1],
a_new_values[2], a_new_values[3])
I do not get a better result. I wanted to use the function slerp of maya
but it is accessible only in c ++ not in python. So I make a slerp function
in python. The current problem is that as I can not know if my dot is
positive or negative. So I have a flip of 180 that is done on my rotation.
I understand better now with your explanation. I use the matrices to
retrieve quaternions. So I would have to retrieve the quaternions since the
euler rotations?
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/54eec6b1-e0f0-42e1-af3b-0ee6d4e69d94%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.