/// <summary> /// Gets the arbitrary scale of a sequence at a specified keyframe. /// </summary> /// <param name="seq">The sequence.</param> /// <param name="keyframeNum">The keyframe number</param> /// <param name="scaleNum">The node index.</param> /// <param name="scale">Receives the scale.</param> public void GetArbitraryScale(Sequence seq, int keyframeNum, int scaleNum, out ArbitraryScale scale) { NodeArbitraryScaleRotations[seq.BaseScale + scaleNum * seq.KeyframeCount + keyframeNum].Get(out scale.Rotate); scale.Scale = NodeArbitraryScaleFactors[seq.BaseScale + scaleNum * seq.KeyframeCount + keyframeNum]; }
/// <summary> /// Interpolate between one arbitrary scale and another. /// </summary> /// <param name="s1">The start scale</param> /// <param name="s2">The end scale</param> /// <param name="t">Value between 0.0 and 1.0 to interpolate at</param> /// <param name="s12">The interpolated scale</param> public static void Interpolate(ref ArbitraryScale s1, ref ArbitraryScale s2, float t, out ArbitraryScale s12) { Transform.Interpolate(s1.Rotate, s2.Rotate, t, out s12.Rotate); Transform.Interpolate(s1.Scale, s2.Scale, t, out s12.Scale); }
void _HandleAnimatedScale(Thread thread, int a, int b, ref BitVector scaleBeenSet) { int j = 0; int start = thread.Sequence.DoesScaleMatter.Start(); int end = b; // code the Scale conversion (might need to "upgrade" from uniform to arbitrary, e.g.) // code uniform, aligned, and arbitrary as 0,1, and 2, respectively, // with _sequence coding in first two bits, shape coding in Next two bits int code = 0; if (thread.Sequence.IsAlignedScaleAnimated()) code += 1; else if (thread.Sequence.IsArbitraryScaleAnimated()) code += 2; if (AnimatesAlignedScale()) code += 3; if (AnimatesArbitraryScale()) code += 6; float uniformScale = 1.0f; Vector3 alignedScale = new Vector3(1, 1, 1); ArbitraryScale arbitraryScale = new ArbitraryScale(); for (int nodeIndex = start; nodeIndex < end; thread.Sequence.DoesScaleMatter.Next(ref nodeIndex), j++) { if (nodeIndex < a) continue; if (!scaleBeenSet.Test(nodeIndex)) { // compute Scale in _sequence format switch (code) { case 0: // uniform -> uniform case 1: // uniform -> aligned case 2: // uniform -> arbitrary { float s1 = _shape.GetUniformScale(thread.Sequence, thread._keyNum1, j); float s2 = _shape.GetUniformScale(thread.Sequence, thread._keyNum2, j); uniformScale = Transform.Interpolate(s1, s2, thread._keyPos); alignedScale = new Vector3(uniformScale, uniformScale, uniformScale); break; } case 4: // aligned -> aligned case 5: // aligned -> arbitrary { Vector3 s1 = _shape.GetAlignedScale(thread.Sequence, thread._keyNum1, j); Vector3 s2 = _shape.GetAlignedScale(thread.Sequence, thread._keyNum2, j); Transform.Interpolate(s1, s2, thread._keyPos, out alignedScale); break; } case 8: // arbitrary -> arbitary { ArbitraryScale s1, s2; _shape.GetArbitraryScale(thread.Sequence, thread._keyNum1, j, out s1); _shape.GetArbitraryScale(thread.Sequence, thread._keyNum2, j, out s2); Transform.Interpolate(ref s1, ref s2, thread._keyPos, out arbitraryScale); break; } default: Assert.Fatal(false, "ShapeInstance.HandleAnimatedScale - Invalid sequence code."); break; } switch (code) { case 0: // uniform -> uniform { _nodeCurrentUniformScales[nodeIndex] = uniformScale; break; } case 1: // uniform -> aligned case 4: // aligned -> aligned { _nodeCurrentAlignedScales[nodeIndex] = alignedScale; break; } case 2: // uniform -> arbitrary case 5: // aligned -> arbitrary { _nodeCurrentArbitraryScales[nodeIndex].SetIdentity(); _nodeCurrentArbitraryScales[nodeIndex].Scale = alignedScale; break; } case 8: // arbitrary -> arbitary { _nodeCurrentArbitraryScales[nodeIndex] = arbitraryScale; break; } default: Assert.Fatal(false, "ShapeInstance.HandleAnimatedScale - Invalid sequence code."); break; } _workScaleThreads[nodeIndex] = thread; scaleBeenSet.Set(nodeIndex); } } }
/// <summary> /// Applies a scale to a matrix. /// </summary> /// <param name="scale">The scale value</param> /// <param name="mat">The matrix to scale</param> public static void ApplyScale(ArbitraryScale scale, ref Matrix mat) { Matrix mat2; Transform.SetMatrix(scale.Rotate, out mat2); Matrix mat3 = Matrix.Invert(mat2); Transform.ApplyScale(scale.Scale, ref mat3); mat2 = Matrix.Multiply(mat3, mat2); mat = Matrix.Multiply(mat2, mat); }