Aller au contenu

Expressions

Expression in VRmaze is a feature that allows you to use a mathematical function that may be complex for the purpose of using the calculated value.

The idea of the expression in VRmaze is to provide an intermediate solution between the relatively limited use of the mathematical functions offered by default and pure computer programming. Expression offers the best of both worlds with the power of computer code without programming and using a graphical interface.

The expression system is based on the NCalc library and all NCalc functions are available in VRmaze.

Using expressions

Expressions take different forms in VRmaze. Property control expressions are nodes that allow a property to be varied according to a mathematical formula. The property control provides two nodes using expressions: A time-based signal generator and a property control system based on other entity properties.

The Excel exporter also uses expressions. It is indeed possible to perform a specific calculation when adding an Excel entry point, this will result in calculating a specific value before writing the Excel table.

Creating an expression

Expressions in VRmaze are written in the protocol tree, in the expression cell. When the expression is modified, it is validated, thus avoiding any error.

The parameters of the functions are written between [] and the mathematical functions are written in a direct way. Here are some simple examples:

Need Expression
Calculation of sine versus time Sin([T])
Absolute value of sine versus time Abs(Sin([T]))
Square signal as a function of time if(Sin([T])>0,1,0)
Square signal (over 5 seconds) with a modulo on the time if([T]%5>2.5,1,0)
Square signal (over 5 seconds) with a modulo on the time and of amplitude 3 3*if([T]%5>2.5,1,0)

It is possible, in some cases of expression to use other variables.

Composition

The expression has no limit, it can be as complex as desired.

Mathematical functions

the available mathematical functions are those of NCalc. The list is available here

Generic terms

A number of keywords are built into VRmaze, allowing them to be referenced in expression formulas.

Keyword Definition Note
[T]5 Time variable Current time since the start of the protocol
[Te]1 Time variable Current time since the beginning of the current experiment
[Tt]1 Time variable Current time since the beginning of the current trial
[dT] Time variable Time spent between the current frame and the previous one
[Sp.x]2 Subject position Current position of the subject on the x axis
[Sp.y]2 Subject position Current subject position on the y axis
[Sp.z]2 Subject position Current z-axis subject position
[Sp.x]2 Subject rotation Current subject rotation on x axis
[Sp.y]2 Subject rotation Current subject rotation on y axis
[Sp.z]2 Subject rotation Current subject rotation on z axis
[V] Value Value of the previous frame (or current value of the Excel entry point)
[Pi] Constant Value of the number Pi.
[Deg2Rad] Constant Constant for converting degrees to radians (0.01745)
[Rad2Deg] Constant Constant for converting radians to degrees (57.295)
[Input]23 Interaction variable Keyboard or joystick input variable (e.g. [Input.P] for the P key on the keyboard (1 if pressed, 0 otherwise)
[Axis]24 Interaction variable Analog mouse or joystick variable (e.g. [Axis.Horizontal] to get the value of the Horizontal interaction axis.
[Mouse.]2 Interaction Variable Mouse Button Status Variable (For example [Mouse.0] for the left button, [Mouse.1] for the middle button and [Mouse.2] for the right button

  1. Not available for the Floating Expression Controller (time-based property animation) since it supports the time repository based on its position in the protocol tree. 

  2. Not available for the Floating Expression Controller (time-based property animation). 

  3. Can take any KeyCode from Unity in the form [Input.KeyCode] 

  4. Can get the values of these axes: LeftRight, UpDown, ForwardBackward, MouseScrollWheel, Mouse X, Mouse Y, Horizontal, Vertical, HorizontalRotation and VerticalRotation 

  5. In the case of an animation triggered by a trigger, T is -1 while the trigger is not triggered.