This chapter presents the syntax used in VC for arithmetic expressions.
Arithmetic expressions in VC car occur in most elements. They are used to compute the values of float or integer attributes in such elements as points, colors or materials, schedules...
For instance,
( round( ({#n} - {$transl:z}) / 3.5 ) * 1.5 )
is a correct formula that substracts the value of the
attribute z of the
node transl to the value of the
attribute n, divides by 3.5, rounds to
nearest integer, and multiplies by 1.5.
Parameters are defined at compile-time through the <set> and <repeat> macro-commands (see Chapter 4). The value of the parameter param can be accessed in an expression through {#param}.
Variables are attribute values and can be accessed at runtime by providing the path to the node that contains the attribute. For instance, {$train path 3:x} refers to the x attribute of the node named train path.
Expressions can be used in the definition of integer and float value. They can also be used in strings by enclosing them between parentheses. Opening parentheses that do not signal the beginning of an expression must be backslashed. In the following string, the expression is not evaluated.
"#node \\(main node)"
on keystroke('A')
Arithmetic expressions are only evaluated at runtime.
For this reason, the instantaneous value of attributes
is used, not their value at compile time. The following
script command uses the x,
y, and z values
of the translation node named translation viewpoint
4 to modify the attribute values
of the target translation
named node transformed sphere 1.
<action>
<set_node_attribute_value operator="=">
<transformation x="{$translation viewpoint 4:x}"
y="{$translation viewpoint 4:y}"
z="{$translation viewpoint 4:z}" />
</set_node_attribute_value>
<target type="single_node" value="#node transformed sphere 1" />
</action>