vec2d
DescriptionRepresents a 2-dimensional vector object consisting of two floating-point values (x, y).
vec2d provides arithmetic operators, value assignment, printing and resetting, as well as several vector-specific script methods like normalization, length calculation and null-vector checking.
An vec2d is typically created and manipulated inside scripts when 2D positions, offsets or directions are required.
Methods
normalize()
Normalizes the vector so that its length becomes 1 (unit vector).
If the vector is a null vector, no change is applied.
length()
Returns the floating-point vector length calculated as sqrt(x*x + y*x).
isNull()
Checks whether the vector is a null vector (x = 0 and y = 0).
Returns true if the vector is zero-length.
set(x, y)
Assigns new floating-point values to the vector.
Example:
v.set(10.0, 5.0);Operators
ObjectVec2d supports the operators +, - and * with another vector, returning a new vec2d.
Return
Depends on the method:
void - normalize(), set()
float - length()
bool - isNull()
vec2d - operator results
Example
void main()
{
vec2d v(3.0, 4.0);
float len = v.length();
Print("Length: " + len);
v.normalize();
Print("Normalized vector length: " + v.length());
bool isZero = v.isNull();
Print("Is Null Vector: " + isZero);
v.set(10.0, 5.0);
Print("Vector set to ");
Print(v);
}