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

From Frictional Wiki
< HPL3‎ | SOMA‎ | Scripting
Jump to navigation Jump to search
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
A two dimensional vector unit whose elements are stored as floats.
 
A two dimensional vector unit whose elements are stored as floats.
 +
 +
==Constructors==
 +
 +
{| class="wikitable"
 +
! Constructor !! Description
 +
|-
 +
| <syntaxhighlight lang="c++" inline>cVector2f(float, float)</syntaxhighlight> || Creates a <code>cVector2f</code> with the given element data.
 +
|}
  
 
==Fields==
 
==Fields==
Line 16: Line 24:
 
! Return Type !! Function Name !! Parameters !! Description
 
! Return Type !! Function Name !! Parameters !! Description
 
|-
 
|-
| <syntaxhighlight lang="c++" inline>float</syntaxhighlight> || GetElement || <syntaxhighlight lang="c++" inline>uint64 alIdx</syntaxhighlight>,<br /> || Gets the value at the given index. (Indices 0 and 1 are equal to x and y, respectively.)  
+
| <syntaxhighlight lang="c++" inline>float</syntaxhighlight> || GetElement || <syntaxhighlight lang="c++" inline>uint64 alIdx</syntaxhighlight> || Gets the value at the given index. (Indices 0 and 1 are equal to x and y, respectively.)  
 
|-
 
|-
 
| <syntaxhighlight lang="c++" inline>float</syntaxhighlight> || Length ||  ||  Returns the length of this vector.  
 
| <syntaxhighlight lang="c++" inline>float</syntaxhighlight> || Length ||  ||  Returns the length of this vector.  
Line 22: Line 30:
 
| <syntaxhighlight lang="c++" inline>float</syntaxhighlight> || Normalize ||  || Returns the normalization factor for this vector. (See Remarks.)  
 
| <syntaxhighlight lang="c++" inline>float</syntaxhighlight> || Normalize ||  || Returns the normalization factor for this vector. (See Remarks.)  
 
|-
 
|-
| <syntaxhighlight lang="c++" inline>void</syntaxhighlight> || SetElement || <syntaxhighlight lang="c++" inline>uint64 alIdx</syntaxhighlight>,<br /><syntaxhighlight lang="c++" inline>float</syntaxhighlight>,<br /> || Sets the value at the given index to the given value. (Indices 0 and 1 are equal to x and y, respectively.)  
+
| <syntaxhighlight lang="c++" inline>void</syntaxhighlight> || SetElement || <syntaxhighlight lang="c++" inline>uint64 alIdx</syntaxhighlight>,<br /><syntaxhighlight lang="c++" inline>float</syntaxhighlight> || Sets the value at the given index to the given value. (Indices 0 and 1 are equal to x and y, respectively.)  
 
|-
 
|-
 
| <syntaxhighlight lang="c++" inline>float</syntaxhighlight> || SqrLength ||  || Returns the length-squared of this vector.  
 
| <syntaxhighlight lang="c++" inline>float</syntaxhighlight> || SqrLength ||  || Returns the length-squared of this vector.  
Line 36: Line 44:
 
                             vBaseVector.y / fNormFactor);</syntaxhighlight>
 
                             vBaseVector.y / fNormFactor);</syntaxhighlight>
  
[[Category:HPL3]]
+
{{ReferencesSection}}
[[Category:SOMA]]
+
 
[[Category:HPL3 Scripting]]
+
{{HPL3SOMAScriptingCategories}}
[[Category:HPL3 Classes]]
 
[[Category:HPL3 Classes]]
 
 
__FORCETOC__
 
__FORCETOC__

Latest revision as of 16:22, 6 August 2020

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

Constructors

Constructor Description
cVector2f(float, float) Creates a cVector2f with the given element data.

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);

References

See all references...