Loading...
Searching...
No Matches
Math::Vector Struct Reference

3D (3x1) vector More...

`#include <src/math/vector.h>`

## Public Member Functions

| Vector ()
| Creates a zero vector (0, 0, 0).
| Vector (float _x, float _y, float _z)
| Creates a vector from given values.
void | LoadZero ()
| Loads the zero vector (0, 0, 0).
float * | Array ()
| Returns the struct cast to `float*` array; use with care!
const float * | Array () const
| Returns the struct cast to const float* array; use with care!
float | Length () const
| Returns the vector length.
void | Normalize ()
| Normalizes the vector.
Vector | CrossMultiply (const Vector &right) const
| Calculates the cross product with another vector.
float | DotMultiply (const Vector &right) const
| Calculates the dot product with another vector.
float | CosAngle (const Vector &right) const
| Returns the cosine of angle between this and another vector.
float | Angle (const Vector &right) const
| Returns angle (in radians) between this and another vector.
Vector | operator- () const
| Returns the inverted vector.
const Vector & | operator+= (const Vector &right)
| Adds the given vector.
const Vector & | operator-= (const Vector &right)
| Subtracts the given vector.
const Vector & | operator*= (const float &right)
| Multiplies by given scalar.
const Vector & | operator/= (const float &right)
| Divides by given scalar.
std::string | ToString () const
| Returns a string "[x, y, z]".

## Public Attributes

float | x
| X - 1st coord.
float | y
| Y - 2nd coord.
float | z
| Z - 3rd coord.

## Friends

const Vector | operator+ (const Vector &left, const Vector &right)
| Adds two vectors.
const Vector | operator- (const Vector &left, const Vector &right)
| Subtracts two vectors.
const Vector | operator* (const float &left, const Vector &right)
| Multiplies vector by scalar.
const Vector | operator* (const Vector &left, const float &right)
| Multiplies vector by scalar.
const Vector | operator/ (const Vector &left, const float &right)
| Divides vector by scalar.

## Detailed Description

3D (3x1) vector

Represents a universal 3x1 vector that can be used in OpenGL and DirectX engines. Contains the required methods for operating on vectors.

All methods are made inline to maximize optimization.

Unit tests for the structure and related functions are in module: math/test/vector_test.cpp.

## Constructor & Destructor Documentation

## Vector() [1/2]

Math::Vector::Vector | ( |  | ) |

inline

Creates a zero vector (0, 0, 0).

## Vector() [2/2]

Math::Vector::Vector | ( | float | _x,
|  | float | _y,
|  | float | _z )

inline explicit

Creates a vector from given values.

## Member Function Documentation

## LoadZero()

void Math::Vector::LoadZero | ( |  | ) |

inline

Loads the zero vector (0, 0, 0).

## Array() [1/2]

float * Math::Vector::Array | ( |  | ) |

inline

Returns the struct cast to `float*` array; use with care!

## Array() [2/2]

const float * Math::Vector::Array | ( |  | ) | const

inline

Returns the struct cast to const float* array; use with care!

## Length()

float Math::Vector::Length | ( |  | ) | const

inline

Returns the vector length.

## Normalize()

void Math::Vector::Normalize | ( |  | ) |

inline

Normalizes the vector.

## CrossMultiply()

Vector Math::Vector::CrossMultiply | ( | const Vector & | right | ) | const

inline

Calculates the cross product with another vector.

Parameters

  right | right-hand side vector

Returns
  the cross product

## DotMultiply()

float Math::Vector::DotMultiply | ( | const Vector & | right | ) | const

inline

Calculates the dot product with another vector.

Parameters

  right | right-hand side vector

Returns
  the dot product

## CosAngle()

float Math::Vector::CosAngle | ( | const Vector & | right | ) | const

inline

Returns the cosine of angle between this and another vector.

## Angle()

float Math::Vector::Angle | ( | const Vector & | right | ) | const

inline

Returns angle (in radians) between this and another vector.

## operator-()

Vector Math::Vector::operator- | ( |  | ) | const

inline

Returns the inverted vector.

## operator+=()

const Vector & Math::Vector::operator+= | ( | const Vector & | right | ) |

inline

Adds the given vector.

## operator-=()

const Vector & Math::Vector::operator-= | ( | const Vector & | right | ) |

inline

Subtracts the given vector.

## operator*=()

const Vector & Math::Vector::operator*= | ( | const float & | right | ) |

inline

Multiplies by given scalar.

## operator/=()

const Vector & Math::Vector::operator/= | ( | const float & | right | ) |

inline

Divides by given scalar.

## ToString()

std::string Math::Vector::ToString | ( |  | ) | const

inline

Returns a string "[x, y, z]".

## Friends And Related Symbol Documentation

## operator+

const Vector operator+ | ( | const Vector & | left,
|  | const Vector & | right )

friend

Adds two vectors.

## operator-

const Vector operator- | ( | const Vector & | left,
|  | const Vector & | right )

friend

Subtracts two vectors.

## operator* [1/2]

const Vector operator* | ( | const float & | left,
|  | const Vector & | right )

friend

Multiplies vector by scalar.

## operator* [2/2]

const Vector operator* | ( | const Vector & | left,
|  | const float & | right )

friend

Multiplies vector by scalar.

## operator/

const Vector operator/ | ( | const Vector & | left,
|  | const float & | right )

friend

Divides vector by scalar.

## Member Data Documentation

## x

float Math::Vector::x

X - 1st coord.

## y

float Math::Vector::y

Y - 2nd coord.

## z

float Math::Vector::z

Z - 3rd coord.

The documentation for this struct was generated from the following file:

- src/math/vector.h