vec2
Header file: include/vec2.h
vec2 is a vector with 2 scalars, x and y.
\(vec2 = \begin{bmatrix} x \\ y \end{bmatrix}\)
Class variables
Type |
Name |
Description |
|---|---|---|
float |
x |
The first element of the vec2. |
float |
y |
The second element of the vec2. |
Class functions
Constructors
Name |
Description |
|---|---|
Construct a (0.0, 0.0) vector. |
|
Construct a (_value, _value) vector. |
|
Construct a (_x, _y) vector. |
|
Construct a vector from a pointer. |
|
Construct a (_xyz.x, _xyz.y) vector. |
|
Construct a (_xyzw.x, _xyzw.y) vector. |
Operators
Name |
Description |
|---|---|
Add a vec2 to the current vec2. |
|
Substract a vec2 from the current vec2. |
|
Multiply the current vec2 by a scalar. |
|
Divide the current vec2 by a scalar. |
|
Return the negative of the current vec2. |
|
Return a reference to x if index is 0 or a reference to y if index is 1, else, throw an exception. |
|
Return the value of x if index is 0 or the value of y if index is 1, else, throw an exception. |
Functions
Name |
Description |
|---|---|
Return the length of the vector. |
|
Return a pointer to the vector’s elements. |
Namespace functions
Operators
Name |
Description |
|---|---|
Return a vec2 that is the sum between two vec2. |
|
Return a vec2 that is the difference between two vec2. |
|
Return a vec2 that is the product between a vec2 and a scalar. |
|
Return a vec2 that is the product between a scalar and a vec2. |
|
Return a vec2 that is the quotient between a vec2 and a scalar. |
|
Return true if the two vec2 are identical, else, return false. |
|
Return true if the two vec2 are different, else, return false. |
Functions
Name |
Description |
|---|---|
Return a vec2 with the same direction as vec but with length 1. |
|
Return the dot product between two vec2. |
|
nml::vec2 nml::reflect(const nml::vec2& i, const nml::vec2& n) |
Return the reflected direction between the incident vector i and the normal n. n should be normalized. |
nml::vec2 nml::refract(const nml::vec2& i, const nml::vec2& n, float ior) |
Return the refracted direction between the incident vector i, the normal n and the ratio of indices of refraction ior. n should be normalized. |
Return a vec2 as a string under the format “[x, y]”. |