You can use a vector component operator (.) to read a component of a vector variable or vector array variable.
Format | Meaning |
---|---|
$variable.x |
left component |
$variable.y |
middle component |
$variable.z |
right component |
float $temp; vector $myvector = <<1,2,3>>; float $temp = $myvector.z;
This assigns the right component of $myvector, 3, to the floating point variable $temp.
Suppose you have a vector initialized as follows:
vector $myvector = <<1,2,3>>;
To replace the right component of $myvector, 3, with a new value such as 7, use this technique to preserve the other two components:
$myvector = <<$myvector.x,$myvector.y,7>>;
This statement is incorrect:
$myvector.z = 3;
An error occurs. A statement can read, but not directly assign, a component of a vector variable.