Difference between revisions of "HPL3/SOMA/Scripting/cVector3f"

From Frictional Wiki
< HPL3‎ | SOMA‎ | Scripting
Jump to navigation Jump to search
(Created page with "A three dimensional vector unit whose elements are stored as floats. ==Fields== {| class="wikitable" ! Field Name !! Type !! Description |- | x || <syntaxhighlight lang="c++...")
 
Line 38: Line 38:
 
                             vBaseVector.y / fNormFactor,  
 
                             vBaseVector.y / fNormFactor,  
 
                             vBaseVector.z / fNormFactor);</syntaxhighlight>
 
                             vBaseVector.z / fNormFactor);</syntaxhighlight>
                           
+
 
[[Category:HPL3]]
+
{{HPL3SOMAScriptingCategories}}
[[Category:SOMA]]
 
[[Category:HPL3 Scripting]]
 
[[Category:HPL3 Classes]]
 
[[Category:HPL3 Classes]]
 
 
__FORCETOC__
 
__FORCETOC__

Revision as of 01:36, 4 August 2020

A three dimensional vector unit whose elements are stored as floats.

Fields

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

Functions

Return Type Function Name Parameters Description
float GetElement uint64 alIdx Gets the value at the given index. (Indices 0, 1, and 2 are equal to x, y, and z, 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 afValue
Sets the value at the given index to the given value. (Indices 0, 1, and 2 are equal to x, y, and z, 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, y, and z coordinates by that factor.

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