Nice piece of code, thanks for sharing. Writing my own slerp would be
my fallback, though, in the end I'm going to call my function per
frame, and therefore would look into having this C++ wrapped and
compiled. But for now, the API 2 access David suggested looks to be
exactly what I have been searching for.

Cheers!

  -André



On Oct 4, 11:50 pm, Chad Vernon <[email protected]> wrote:
> You could implement slerp function:
>
> import math
> def quaternionSlerp(a, b, t):
>     cos = quaternionDot(a, b)
>     if cos < 0.0:
>         cos = quaternionDot(a, b.negateIt())
>     theta = math.acos(cos)
>     sin = math.sin(theta)
>
>     if sin > 0.001:
>         w1 = math.sin((1.0 - t) * theta) / sin
>         w2 = math.sin(t * theta) / sin
>     else:
>         w1 = 1.0 - t
>         w2 = t
>     aa = OpenMaya.MQuaternion(a)
>     bb = OpenMaya.MQuaternion(b)
>     aa.scaleIt(w1)
>     bb.scaleIt(w2)
>
>     return aa + bb
>
> def quaternionDot(q1, q2):
>     return (q1.x * q2.x) + (q1.y * q2.y) + (q1.z * q2.z) + (q1.w * q2.w)
>
> On Tue, Oct 4, 2011 at 2:47 PM, David Moulder <[email protected]>wrote:
>
>
>
>
>
>
>
> > I don't know if slerp is correctly exposed but I can tell you that there is
> > a new api binding available in 2012.  Maya API 2.  Its a faster and more
> > friendly python api and the docs suggest that slerp is exposed correctly.
>
> > On Tue, Oct 4, 2011 at 5:26 PM, a_adam <[email protected]> wrote:
>
> >> Hi there,
>
> >> just joined in here, and I'm looking forward to some good discussions!
> >> And of course I stumbled into a problem today which brought me here in
> >> the first place: I can't for the life of me trigger the slerp function
> >> from the MQuaternion class.
>
> >> The API docs tell me that there are two slerps (odd enough), one
> >> considering spin and being marked as not exposed to scripting, and a
> >> simple one without a spin argument which should be accessable to
> >> scripting. It is this simpler version which I'm trying to get to work.
>
> >> I've seen in this group's archive that slerp indeed does not seem to
> >> be not implemented in the Python wrapper. However, that post is over a
> >> year old, and I asked myself if Autodesk did anything for Maya 2012 to
> >> make this work? Or anyone found a workaround in the meantime?
>
> >> Many thanks in advance for a quick hint, cheers!
>
> >> -Andre
>
> >> --
> >> view archives:http://groups.google.com/group/python_inside_maya
> >> change your subscription settings:
> >>http://groups.google.com/group/python_inside_maya/subscribe
>
> > --
> > David Moulder
> >http://www.google.com/profiles/squish3d
>
> >  --
> > view archives:http://groups.google.com/group/python_inside_maya
> > change your subscription settings:
> >http://groups.google.com/group/python_inside_maya/subscribe

-- 
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings: 
http://groups.google.com/group/python_inside_maya/subscribe

Reply via email to