Colobot
Public Member Functions | Public Attributes | Friends | List of all members
Math::Vector Struct Reference

3D (3x1) vector More...

#include <vector.h>

Public Member Functions

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

Public Attributes

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

Friends

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

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

Math::Vector::Vector ( )
inline

Creates a zero vector (0, 0, 0)

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

Creates a vector from given values.

Member Function Documentation

void Math::Vector::LoadZero ( )
inline

Loads the zero vector (0, 0, 0)

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

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

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

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

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

Returns the vector length.

void Math::Vector::Normalize ( )
inline

Normalizes the vector.

Vector Math::Vector::CrossMultiply ( const Vector right) const
inline

Calculates the cross product with another vector.

Parameters
rightright-hand side vector
Returns
the cross product
float Math::Vector::DotMultiply ( const Vector right) const
inline

Calculates the dot product with another vector.

Parameters
rightright-hand side vector
Returns
the dot product
float Math::Vector::CosAngle ( const Vector right) const
inline

Returns the cosine of angle between this and another vector.

float Math::Vector::Angle ( const Vector right) const
inline

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

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

Returns the inverted vector.

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

Adds the given vector.

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

Subtracts the given vector.

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

Multiplies by given scalar.

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

Divides by given scalar.

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

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

Friends And Related Function Documentation

const Vector operator+ ( const Vector left,
const Vector right 
)
friend

Adds two vectors.

const Vector operator- ( const Vector left,
const Vector right 
)
friend

Subtracts two vectors.

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

Multiplies vector by scalar.

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

Multiplies vector by scalar.

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

Divides vector by scalar.

Member Data Documentation

float Math::Vector::x

X - 1st coord.

float Math::Vector::y

Y - 2nd coord.

float Math::Vector::z

Z - 3rd coord.


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