# Frictional Game Wiki

### Site Tools

hpl3:community:scripting:classes:cvector4f

# Differences

This shows you the differences between two versions of the page.

 hpl3:community:scripting:classes:cvector4f [2015/11/05 12:00]abion47 created hpl3:community:scripting:classes:cvector4f [2015/11/06 03:42] (current)abion47 2015/11/06 03:42 abion47 2015/11/05 12:00 abion47 created 2015/11/06 03:42 abion47 2015/11/05 12:00 abion47 created Line 4: Line 4: ^ Field Name ^ Type ^ Description ^ ^ Field Name ^ Type ^ Description ^ - | x | float |   ​| + | x | float | The x value of the vector. ​| - | y | float |   ​| + | y | float | The y value of the vector. ​| - | z | float |   ​| + | z | float | The z value of the vector. ​| - | w | float |   ​| + | w | float | The w value of the vector. ​| ====Functions==== ====Functions==== ^ Return Type ^ Function Name ^ Parameters ^ Description ^ ^ Return Type ^ Function Name ^ Parameters ^ Description ^ - | float | GetElement | uint64 alIdx, \\ const |   ​| + | float | GetElement | uint64 alIdx, \\ const | Gets the value at the given index. (Indices 0, 1, 2, and 3 are equal to x, y, z, and w respectively.) ​| - | void | SetElement | uint64 alIdx, \\ float, \\ const |   ​| + | void | SetElement | uint64 alIdx, \\ float, \\ const | Sets the value at the given index to the given value. (Indices 0, 1, 2, and 3 are equal to x, y, z, and w respectively.) ​| - | float | SqrLength | const |   ​| + | float | SqrLength | const | Returns the length-squared of this vector. ​| - | float | Length | const |   ​| + | float | Length | const | Returns the length of this vector. ​| - | float | Normalize |     ​| ​  ​| + | float | Normalize |     ​| ​Returns the normalization factor for this vector. (See Remarks.) ​| ====Remarks==== ====Remarks==== - Have some helpful descriptions to add to this class? Edit this page and add your insight ​to the Wiki! + 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, z, and w coordinates by that factor. + + <​code=c++>​cVector4f vBaseVector(2.0,​ 5.0, 3.0, 4.0); + float fNormFactor = vBaseVector.Normalize();​ + cVector3f vNormalizedVector(vBaseVector.x / fNormFactor,​ + vBaseVector.y / fNormFactor,​ + vBaseVector.z / fNormFactor,​ + vBaseVector.w / fNormFactor);