本文整理汇总了C#中Quaternion.Slerp方法的典型用法代码示例。如果您正苦于以下问题:C# Quaternion.Slerp方法的具体用法?C# Quaternion.Slerp怎么用?C# Quaternion.Slerp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Quaternion
的用法示例。
在下文中一共展示了Quaternion.Slerp方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EvalFCurve
void EvalFCurve( BasicFCurve fcurve, float frame, float[] result )
{
float[] data = fcurve.KeyFrames ;
int lower = 0 ;
int upper = fcurve.KeyCount - 1 ;
int elementStride = fcurveElementStrides[ (int)fcurve.InterpType ] ;
int stride = elementStride * fcurve.DimCount + 1 ;
while ( upper - lower > 1 ) {
int center = ( upper + lower ) / 2 ;
float frame2 = data[ stride * center ] ;
if ( frame < frame2 ) {
upper = center ;
} else {
lower = center ;
}
}
int k1 = stride * lower ;
int k2 = stride * upper ;
float f1 = data[ k1 ++ ] ;
float f2 = data[ k2 ++ ] ;
float t = f2 - f1 ;
if ( t != 0.0f ) t = ( frame - f1 ) / t ;
BasicFCurveInterpType interp = fcurve.InterpType ;
if ( t <= 0.0f ) interp = BasicFCurveInterpType.Constant ;
if ( t >= 1.0f ) {
interp = BasicFCurveInterpType.Constant ;
k1 = k2 ;
}
switch ( interp ) {
case BasicFCurveInterpType.Constant :
for ( int i = 0 ; i < fcurve.DimCount ; i ++ ) {
result[ i ] = data[ k1 ] ;
k1 += elementStride ;
}
break ;
case BasicFCurveInterpType.Linear :
for ( int i = 0 ; i < fcurve.DimCount ; i ++ ) {
float v1 = data[ k1 ++ ] ;
float v2 = data[ k2 ++ ] ;
result[ i ] = ( v2 - v1 ) * t + v1 ;
}
break ;
case BasicFCurveInterpType.Hermite :
float s = 1.0f - t ;
float b1 = s * s * t * 3.0f ;
float b2 = t * t * s * 3.0f ;
float b0 = s * s * s + b1 ;
float b3 = t * t * t + b2 ;
for ( int i = 0 ; i < fcurve.DimCount ; i ++ ) {
result[ i ] = data[ k1 ] * b0 + data[ k1 + 2 ] * b1 + data[ k2 + 1 ] * b2 + data[ k2 ] * b3 ;
k1 += 3 ;
k2 += 3 ;
}
break ;
case BasicFCurveInterpType.Cubic :
for ( int i = 0 ; i < fcurve.DimCount ; i ++ ) {
float fa = f1 + data[ k1 + 3 ] ;
float fb = f2 + data[ k2 + 1 ] ;
float u = FindCubicRoot( f1, fa, fb, f2, frame ) ;
float v = 1.0f - u ;
float c1 = v * v * u * 3.0f ;
float c2 = u * u * v * 3.0f ;
float c0 = v * v * v + c1 ;
float c3 = u * u * u + c2 ;
result[ i ] = data[ k1 ] * c0 + data[ k1 + 4 ] * c1 + data[ k2 + 2 ] * c2 + data[ k2 ] * c3 ;
k1 += 5 ;
k2 += 5 ;
}
break ;
case BasicFCurveInterpType.Spherical :
var q1 = new Quaternion( data[ k1 + 0 ], data[ k1 + 1 ], data[ k1 + 2 ], data[ k1 + 3 ] ) ;
var q2 = new Quaternion( data[ k2 + 0 ], data[ k2 + 1 ], data[ k2 + 2 ], data[ k2 + 3 ] ) ;
// [note] 旧API
// var q3 = Quaternion.Slerp( q1, q2, t, 0.0f ) ;
var q3 = q1.Slerp( q2, t ) ;
result[ 0 ] = q3.X ;
result[ 1 ] = q3.Y ;
result[ 2 ] = q3.Z ;
result[ 3 ] = q3.W ;
break ;
}
}
示例2: Slerp
/// <summary>
/// Performs spherical linear interpolation between a specified Quaternion and another specified Quaternion
/// </summary>
/// <param name="a">the quaternion to interpolate from</param>
/// <param name="b">the quaternion to interpolate to</param>
/// <param name="t">the interpolation parameter</param>
/// <returns>a quaternion interpolated between two specified quaternion</returns>
public static Quaternion Slerp(Quaternion a, Quaternion b, float t)
{
return a.Slerp(b, t);
}