Advanced Usage - Functions, aliases and operator-overloads
<Label TranslationX="{z:Bind Sin(Count / 25.0) * 100.0}" ...float Lerp(float a, float b, float t)
{
return a + t * (b - a);
}<Label Rotation={z:Bind Lerp(0, 360, rotationPercent / 100.0)} ...var ep = ExpressionParserFactory.GetExpressionParser();ep.RegisterFunction("Lerp", DoLerp, 3);private static void DoLerp(Stack<IOperand> stack, IBackingStore backingStore, long paramCount)
{
// Pop the correct number of parameters from the operands stack, ** in reverse order **
// If an operand is a variable, it is resolved from the backing store provided
IOperand third = OperatorActions.PopAndResolve(operands, backingStore);
IOperand second = OperatorActions.PopAndResolve(operands, backingStore);
IOperand first = OperatorActions.PopAndResolve(operands, backingStore);
float a = Convert.ToSingle(first.GetValue());
float b = Convert.ToSingle(second.GetValue());
float t = Convert.ToSingle(third.GetValue());
// The result is of type float
float result = a + t * (b - a);
// Push the result back onto the operand stack
stack.Push(new Operand(-1, OperandType.Float, result));
}Last updated