The following lists the operator symbols that are used for actions such as add, subtract, multiply, and others. Note: it makes a difference if these operators are used with single floatpoint values or with vectors.
Arithmetic operators
+
-
*
/
%
Arithmetic operators and single values
For single floatpoint values these operators are used according to the basic rules of math.
1 + 1
1 - 1
2 * 2
4 / 2
Arithmetic operators and vectors
For operations between vector channels, vector variables and vector constants, the operators are treated like this:
Addition of components with +
vec( a, b, c ) + vec( d, e, f )
Example:
vec( 2, 5, 90 ) + vec( 9, 89, 5 )
Subtraction of components with -
vec( a, b, c ) - vec( d, e, f )
Example:
vec( 2, 5, 90 ) - vec( 9, 89, 5 ) /
Dot product of vectors with *
The dot product multiplies corresponding components of each vector, then adds the components to create a single floating point number result.
vec( a, b, c ) * vec( d, e, f )
Example
vec( 1, 3, 5 ) * vec( 2, 4, 6 )
For operations between a vector and a single floating point value, each component of the vector is operated by the single floating point value:
Addition
vec( a, b, c ) + x
Example:
vec( 1, 3, 5 ) + 5
Subtraction
vec( a, b, c ) - x
Example:
vec( 1, 3, 5 ) -2
Multiplication
vec( a, b, c ) * x
Example:
vec( 1, 3, 5 )* 2
division of vectors with /
Division of vectors with / is uncommon in programming syntax since a term like x / 4 could also be written as x * 0.25. But even though it may be uncommon, the / operator can also be used for multiplications within Xpressionist.
Relational operators
<
>
==
!=
<=
>=
Relational operators and single values
For operations in conditional statements you often use relational operators. For single floatpoint values the relational operators are used according to the rules of algebra.
Example
if ( time > 5 )
Light_1.Intensity = 1;
When the time is greater than 5 seconds the light's intensity will be set to 1.
Relational operators and vectors
If you use the == or != operators between two vector channels, vector variables or vector constants, Xpressionist compares the corresponding components of each vector.
Example:
if ( vec( a, b, c ) == vec( d, e, f ) )
attribute = x;
This expression sets "attribute" to x, if a is equal to d, b is equal to e and c is equal to f.
In contrast, the >, >=, <, and <= operators compare the length of two vectors and not its single components.
The length of a vector vec( a, b, c ) is the square root of a^2 + b^2 + c^2. This value can also be expressed with the vector function length( vector ).
Example:
if ( vec( a, b, c ) >= vec( d, e, f ) )
property = x;
This expression sets "property" to x, if the length of vec( a, b, c ) is greater or equal to the length of vec( d, e, f )
Logical operators
&&
||
These operators are often used in conditional statements together with the relational operators
Example for &&:
if ( ( time > 3 ) && ( time < 5 ) )
Light1.Intensity = 1;
This switches the light intensity to 1 when time is greater than three seconds and smaller than five seconds. Note that every condition in the statement is enclosed in brackets.
Example for ||:
if ( ( time < 3 ) || ( time > 5 ) )
Light1.Intensity = 1;
This switches the light intensity to 1 when time is smaller than three seconds or larger than 5 seconds.
String operators
$
+
Strings are mostly used to create flexible expressions. You can define for example strings that contain objectnames at the top of the expression, so you do not have to change the entire expression if you change the name of that object in the Animator.
Example for $:
$left_arm = "Marys_left_arm";
$left_arm.Position = vec( 0, 0, 0 );
Together with the + operator for strings we can address many objects in a loop:
Example for $ and +
for ( i = 0; i <= 1000; i = i + 1 )
{
$obj = "cube" + i;
$obj.Opacity = i / 1000;
}
This is the same as:
cube0.Opacity = 0 / 1000;
cube1.Opacity = 1 / 1000;
cube2.Opacity = 2 / 1000;
...
cube1000.Opacity = 1000 / 1000;
|