public static void TestChangeFrom() { const float floatEnd = 4.8f; const float floatStart = 1.2f; float floatVal = floatStart; Ref <float> floatRef = new Ref <float>( () => floatVal, t => floatVal = t ); const double doubleEnd = 3.2; const double doubleStart = 9.2; double doubleVal = doubleStart; Ref <double> doubleRef = new Ref <double>( () => doubleVal, t => doubleVal = t ); Vector2 vec2End = new Vector2(9.5f, 2.0f); Vector2 vec2Start = new Vector2(4.0f, 5.0f); Vector2 vec2Val = vec2Start; Ref <Vector2> vec2Ref = new Ref <Vector2>( () => vec2Val, t => vec2Val = t ); Vector3 vec3End = new Vector3(4.0f, 19.0f, 2.0f); Vector3 vec3Start = new Vector3(92.0f, 0.5f, 34.0f); Vector3 vec3Val = vec3Start; Ref <Vector3> vec3Ref = new Ref <Vector3>( () => vec3Val, t => vec3Val = t ); Vector4 vec4End = new Vector4(92.0f, 0.5f, 14.0f, 7.0f); Vector4 vec4Start = new Vector4(0.4f, 10.0f, 3.0f, 82.0f); Vector4 vec4Val = vec4Start; Ref <Vector4> vec4Ref = new Ref <Vector4>( () => vec4Val, t => vec4Val = t ); CommandQueue queue = new CommandQueue(); queue.Enqueue( Cmd.Repeat(2, Cmd.Sequence( Cmd.Parallel( Cmd.ChangeFrom(floatRef, floatEnd, 1.0), Cmd.ChangeFrom(doubleRef, doubleEnd, 1.0), Cmd.ChangeFrom(vec2Ref, vec2End, 1.0), Cmd.ChangeFrom(vec3Ref, vec3End, 1.0), Cmd.ChangeFrom(vec4Ref, vec4End, 1.0) ), Cmd.WaitForFrames(1) ) ) ); queue.Update(0.3); // Check basic lerping works. AreEqual(floatVal, floatEnd * 0.7f + floatStart * 0.3f, 0.01); AreEqual(doubleVal, doubleEnd * 0.7 + doubleStart * 0.3, 0.01); AreEqual(vec2Val, vec2End * 0.7f + vec2Start * 0.3f, 0.01f); AreEqual(vec3Val, vec3End * 0.7f + vec3Start * 0.3f, 0.01f); AreEqual(vec4Val, vec4End * 0.7f + vec4Start * 0.3f, 0.01f); // Reset the vals to zero. Checks that 'ChangeTo' will force itself back on // track. floatVal = 0.0f; doubleVal = 0.0; vec2Val = Vector2.zero; vec3Val = Vector3.zero; vec4Val = Vector4.zero; queue.Update(0.2); // Completes the offset AreEqual(floatVal, floatEnd * 0.5f + floatStart * 0.5f, 0.01); AreEqual(doubleVal, doubleEnd * 0.5 + doubleStart * 0.5, 0.01); AreEqual(vec2Val, vec2End * 0.5f + vec2Start * 0.5f, 0.01f); AreEqual(vec3Val, vec3End * 0.5f + vec3Start * 0.5f, 0.01f); AreEqual(vec4Val, vec4End * 0.5f + vec4Start * 0.5f, 0.01f); queue.Update(0.5); AreEqual(floatVal, floatStart, 0.01f); AreEqual(doubleVal, doubleStart, 0.01); AreEqual(vec2Val, vec2Start, 0.01f); AreEqual(vec3Val, vec3Start, 0.01f); AreEqual(vec4Val, vec4Start, 0.01f); queue.Update(0.0); queue.Update(0.5); // Check that it does jump on repeat AreEqual(floatVal, floatEnd * 0.5f + floatStart * 0.5f, 0.01); AreEqual(doubleVal, doubleEnd * 0.5 + doubleStart * 0.5, 0.01); AreEqual(vec2Val, vec2End * 0.5f + vec2Start * 0.5f, 0.01f); AreEqual(vec3Val, vec3End * 0.5f + vec3Start * 0.5f, 0.01f); AreEqual(vec4Val, vec4End * 0.5f + vec4Start * 0.5f, 0.01f); Rect rectEnd = new Rect(-1.0f, 1.0f, 5.0f, 5.0f); Rect rectStart = new Rect(0.0f, 2.0f, 6.0f, 6.0f); Rect rectVal = rectStart; Ref <Rect> rectRef = new Ref <Rect>( () => rectVal, t => rectVal = t ); Vector2 firstAnchor = new Vector2(0.0f, 0.0f); Vector2 secondAnchor = new Vector2(1.0f, 0.0f); Vector3 thirdAnchor = new Vector2(0.0f, 1.0f); Vector2 forthAnchor = new Vector2(1.0f, 1.0f); queue = new CommandQueue(); queue.Enqueue( Cmd.ChangeFrom(rectRef, rectEnd, 1.0, firstAnchor), Cmd.WaitForFrames(1), Cmd.ChangeFrom(rectRef, rectEnd, 1.0, secondAnchor), Cmd.WaitForFrames(1), Cmd.ChangeFrom(rectRef, rectEnd, 1.0, thirdAnchor), Cmd.WaitForFrames(1), Cmd.ChangeFrom(rectRef, rectEnd, 1.0, forthAnchor) ); // Test the top left corner. queue.Update(0.5); AreEqual(rectVal, new Rect( -0.5f, 1.5f, (rectStart.width + rectEnd.width) * 0.5f, (rectStart.height + rectEnd.height) * 0.5f), 0.001f ); queue.Update(0.5); AreEqual(rectVal, rectStart, 0.001f); queue.Update(0.0f); // Test the top right corner. queue.Update(0.7); AreEqual(rectVal, new Rect( 5.4f - 5.7f, 1.7f, rectStart.width * 0.7f + rectEnd.width * 0.3f, rectStart.height * 0.7f + rectEnd.height * 0.3f), 0.001f ); queue.Update(0.3); AreEqual(rectVal, rectStart, 0.001f); queue.Update(0.0f); // Test the bottom left corner. queue.Update(0.6); AreEqual(rectVal, new Rect( -0.4f, 7.2f - 5.6f, rectStart.width * 0.6f + rectEnd.width * 0.4f, rectStart.height * 0.6f + rectEnd.height * 0.4f), 0.001f ); queue.Update(0.4); AreEqual(rectVal, rectStart, 0.001f); queue.Update(0.0); // Test the bottom right corner. queue.Update(0.6); AreEqual(rectVal, new Rect( 5.2f - 5.6f, 7.2f - 5.6f, rectStart.width * 0.6f + rectEnd.width * 0.4f, rectStart.height * 0.6f + rectEnd.height * 0.4f), 0.001f ); queue.Update(0.4); AreEqual(rectVal, rectStart, 0.001f); queue.Update(0.0f); }