Previous:Vector Identifiers   Main Index   Next:Operator Promotion

#### Vector Operators

Vector literals, identifiers and functions may also be combined in expressions the same as float values. Operations are performed on a component-by-component basis. For example `<1,2,3> + <4,5,6>` evaluates the same as `<1+4,2+5,3+6>` or `<5,7,9>`. Other operations are done on a similar component-by-component basis. For example `(<1,2,3> = <3,2,1>)` evaluates to `<0,1,0>` because the middle components are equal but the others are not. Admittedly this isn't very useful but its consistent with other vector operations.

Conditional expressions such as `(C ? A : B)` require that `C` is a float expression but `A` and `B` may be vector expressions. The result is that the entire conditional evaluates as a valid vector. For example if `Foo` and `Bar` are floats then `(Foo < Bar ? <1,2,3> : <5,6,7>)` evaluates as the vector `<1,2,3>` if `Foo` is less than `Bar` and evaluates as `<5,6,7>` otherwise.

You may use the dot operator to extract a single float component from a vector. Suppose the identifier `Spot` was previously defined as a vector. Then `Spot.x` is a float value that is the first component of this x, y, z vector. Similarly `Spot.y` and `Spot.z` reference the 2nd and 3rd components. If `Spot` was a two component UV vector you could use `Spot.u` and `Spot.v` to extract the first and second component. For a 4D vector use `.x`, `.y`, `.z`, and `.t` to extract each float component. The dot operator is also used in color expressions which are covered later.

Previous:Vector Identifiers   Main Index   Next:Operator Promotion