HPL3/SOMA/Scripting/cVector2f

From Frictional Wiki
< HPL3‎ | SOMA‎ | Scripting
Revision as of 01:29, 4 August 2020 by Abion47 (talk | contribs) (Created page with "A two dimensional vector unit. ==Fields== {| class="wikitable" ! Field Name !! Type !! Description |- | x || <syntaxhighlight lang="c++" inline>float</syntaxhighlight> || Th...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

A two dimensional vector unit.

Fields

Field Name Type Description
x float The x value of the vector.
y float The y value of the vector.

Functions

Return Type Function Name Parameters Description
float GetElement uint64 alIdx,
Gets the value at the given index. (Indices 0 and 1 are equal to x and y, respectively.)
float Length Returns the length of this vector.
float Normalize Returns the normalization factor for this vector. (See Remarks.)
void SetElement uint64 alIdx,
float,
Sets the value at the given index to the given value. (Indices 0 and 1 are equal to x and y, respectively.)
float SqrLength Returns the length-squared of this vector.

Remarks

A normalized vector is a vector whose length is equal to one, otherwise known as a unit vector. To convert a vector into a unit vector, get the normalization factor by calling the Normalize function, then divide each of the vector's x and y coordinates by that factor.

cVector2f vBaseVector(2.0, 5.0);
float fNormFactor = vBaseVector.Normalize();
cVector2f vNormalizedVector(vBaseVector.x / fNormFactor, 
                            vBaseVector.y / fNormFactor);