SIQuaternion.Slerp
 
 
 

SIQuaternion.Slerp

Description

Calculates a spherical linear interpolation between q1 and q2 (two unitary quaternions).

Note: In versions earlier than v3.5 the method name was called SLerp. The unnecessary capitialization has been removed. Plug-ins will remain binary compatible but those that need to be recompiled will need editing to rename SLerp to Slerp.

C# Syntax

SIQuaternion.Slerp( SIQuaternion in_pQuat1, SIQuaternion in_pQuat2, Double in_dU );

Scripting Syntax

SIQuaternion.Slerp( q1, q2, alpha );

Parameters

Parameter Type Description
q1 SIQuaternion unitary quaternion operand
q2 SIQuaternion unitary quaternion operand
alpha Double Interpolation factor

Possible Values:

Description:

[0.0, 1.0] Validity domain

Examples

1. JScript Example

/*
        Example showing how to use SIQuaternion.Slerp 
        to blend between two rotations
*/
//
// Code for the example scripted operator
//
strDeclOperatorGlobals = "var gQA, gQB, gQC;" ;
function Slerper_Init( ctx )
{
        // The SIQuaternion objects are global
        // to avoid recreating them at each update
        gQA = XSIMath.CreateQuaternion() ;
        gQB = XSIMath.CreateQuaternion() ;
        gQC = XSIMath.CreateQuaternion() ;
}
function Slerper_Update( ctx, outC, inA, inB )
{
        slerpFactor = ctx.Parameters( "Slerp" ).Value ;
        oATrans = inA.Value.Transform ;
        oATrans.GetRotationQuaternion( gQA ) ;
        oBTrans = inB.Value.Transform ;
        oBTrans.GetRotationQuaternion( gQB ) ;
        gQA.Normalize() ;
        gQB.Normalize() ;
        gQC.Slerp( gQA, gQB, slerpFactor ) ; 
        oCTrans = outC.Value.Transform ;
        oCTrans.SetRotationFromQuaternion( gQC ) ;
        // Very important: oCTrans is just a temporary
        // so we must set it back to change it
        outC.Value.Transform = oCTrans ;
}
//
// Demo the scripted operator
//
// Build 3 cones.  C will show the blended rotation of A and B
NewScene( null,false) ;
var oConeA = ActiveSceneRoot.AddPrimitive( "Cone", "A" ) ;
var oConeB = ActiveSceneRoot.AddPrimitive( "Cone", "B" ) ;
var oConeC = ActiveSceneRoot.AddPrimitive( "Cone", "C" ) ;
//
// Set some initial position/rotation
//
oTransA = XSIMath.CreateTransform() ;
oTransA.SetTranslationFromValues( 5, 0 , 0 ) ;
oTransA.SetRotationFromXYZAnglesValues( 0, 0 , XSIMath.DegreesToRadians(-90) ) ;
oConeA.Kinematics.Global.Transform = oTransA ;
oTransB = XSIMath.CreateTransform() ;
oTransB.SetTranslationFromValues( -5, 0 , 0 ) ;
oTransB.SetRotationFromXYZAnglesValues( 0, 0 , XSIMath.DegreesToRadians(90) ) ;
oConeB.Kinematics.Global.Transform = oTransB ;
//
// Connect the Kinematics
//
strOpCode = strDeclOperatorGlobals + 
                        Slerper_Init.toString() + 
                        Slerper_Update.toString() ;
oOp = XSIFactory.CreateScriptedOp( 
                        "Slerper", 
                        strOpCode,
                        "JScript"
                        ) ;
oOp.AddOutputPort( oConeC.Kinematics.Global ) ;
oOp.AddInputPort( oConeA.Kinematics.Global )
oOp.AddInputPort( oConeB.Kinematics.Global ) ;
oSlerp = oOp.AddParameter ( XSIFactory.CreateParamDef2("Slerp", siDouble, 0.5, 0, 1) );
oOp.Connect() ;
// Show the operator so that the Slerp amount can be changed with a slider
InspectObj( oOp ) ;

2. VBScript Example

dim q1, q2, q3
' Create Quaternions.
set q1 = XSIMath.CreateQuaternion(1.0, 1.0, 2.0, 3.0)
set q2 = XSIMath.CreateQuaternion(1.0, 4.0, 5.0, 6.0)
set q3 = XSIMath.CreateQuaternion
q1.Normalize
q2.Normalize
for alpha = 0 to 1 step .1
q3.Slerp q1, q2, alpha
'do something with q3
next

See Also

SIQuaternion.Normalize SIVector3 SIMatrix3 SIMatrix4 SIRotation SITransformation SIQuaternion