SIQuaternion.Slerp

説明

球面リニア補間を、q1 と q2(2 つのユニタリクォータニオン)の間で計算します。

注:3.5 以前のバージョンでは、このメソッドは SLerp という名前でした。不要な大文字の使用を排除して、名前を変更しています。プラグインはバイナリで互換性を保持しますが、再コンパイルするときには SLerp から Slerp に名前を変更する必要があります。

C#構文

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

スクリプト構文

SIQuaternion.Slerp( q1, q2, alpha );

パラメータ

パラメータ タイプ 説明
q1 SIQuaternion ユニタリクォータニオンオペランド
q2 SIQuaternion ユニタリクォータニオンオペランド
alpha Double 補間係数

指定可能な値:

説明:

[0.0, 1.0] Validity ドメイン

1. JScript の例

/*

	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 の例

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

関連項目

SIQuaternion.Normalize SIVector3 SIMatrix3 SIMatrix4 SIRotation SITransformation SIQuaternion