Files Class List
Vec3< T > Class Template Reference

Detailed Description

template<typename T>
class cy::Vec3< T >

3D vector class

#include <cyVector.h>

Public Member Functions

Set & Get value methods
void Zero ()
 
void Get (T *p) const
 
void Set (T const *p)
 
void Set (T v)
 
void Set (T _x, T _y, T _z)
 
void Set (Vec2< T > const &p, T _z)
 
General methods
void Normalize ()
 
Vec3 GetNormalized () const
 
LengthSquared () const
 
Length () const
 
Sum () const
 
bool IsZero () const
 
Min () const
 
Max () const
 
int MinIndex () const
 
int MaxIndex () const
 
bool IsFinite () const
 
bool IsUnit () const
 
Vec3 Sqrt () const
 
Vec3 Abs () const
 
Vec3 SortDesc () const
 
Vec3 SortAsc () const
 
Vec3 GetPerpendicular () const
 
void GetOrthonormals (Vec3 &v0, Vec3 &v1) const
 
Limit methods
void Clamp (T minLimit, T maxLimit)
 
void ClampMin (T v)
 
void ClampMax (T v)
 
void SetAbs ()
 
Unary operators
Vec3 operator- () const
 
Binary operators
Vec3 operator+ (Vec3 const &p) const
 
Vec3 operator- (Vec3 const &p) const
 
Vec3 operator* (Vec3 const &p) const
 
Vec3 operator/ (Vec3 const &p) const
 
Vec3 operator+ (T const v) const
 
Vec3 operator- (T const v) const
 
Vec3 operator* (T const v) const
 
Vec3 operator/ (T const v) const
 
Assignment operators
Vec3 const & operator+= (Vec3 const &p)
 
Vec3 const & operator-= (Vec3 const &p)
 
Vec3 const & operator*= (Vec3 const &p)
 
Vec3 const & operator/= (Vec3 const &p)
 
Vec3 const & operator+= (T const v)
 
Vec3 const & operator-= (T const v)
 
Vec3 const & operator*= (T const v)
 
Vec3 const & operator/= (T const v)
 
Test operators
bool operator== (Vec3 const &p) const
 
bool operator!= (Vec3 const &p) const
 
Access operators
T & operator[] (int i)
 
T const & operator[] (int i) const
 
T & Element (int i)
 
T const & Element (int i) const
 
T * Elements ()
 
T const * Elements () const
 
Cross product and dot product
Vec3 Cross (Vec3 const &p) const
 
Vec3 operator^ (Vec3 const &p) const
 
Dot (Vec3 const &p) const
 
operator% (Vec3 const &p) const
 
Conversion Methods
Vec2< T > XY () const
 

Public Attributes

x
 
y
 
z
 
elem [3]
 
Components of the vector
union {
   struct {
      T   x
 
      T   y
 
      T   z
 
   } 
 
   T   elem [3]
 
}; 
 

Friends

Vec3 operator+ (T v, Vec3 const &p)
 
Vec3 operator- (T v, Vec3 const &p)
 
Vec3 operator* (T v, Vec3 const &p)
 

Constructors

_y
 
T T _z: x( _x)
 
 Vec3 () CY_CLASS_FUNCTION_DEFAULT Vec3(T _x
 
T T y (_y)
 
T T z (_z)
 
 Vec3 (T v)
 
 Vec3 (Vec2< T > const &p, T _z=0)
 
 Vec3 (Vec4< T > const &p)
 
template<typename S >
 Vec3 (Vec3< S > const &p)
 
template<typename S >
 Vec3 (Vec2< S > const &p, T _z=0)
 
template<typename S >
 Vec3 (Vec4< S > const &p)
 
template<int N>
 Vec3 (Vec< T, N > const &p)
 
template<int N, typename S >
 Vec3 (Vec< S, N > const &p)
 

Member Function Documentation

§ Zero()

void Zero ( )

Sets the coordinates as zero.

§ Get()

void Get ( T *  p) const

Puts the coordinate values into the array.

§ Set() [1/4]

void Set ( T const *  p)

Sets the coordinates using the values in the given array.

§ Set() [2/4]

void Set ( v)

Sets all coordinates using the given value.

§ Set() [3/4]

void Set ( _x,
_y,
_z 
)

Sets the coordinates using the given values.

§ Set() [4/4]

void Set ( Vec2< T > const &  p,
_z 
)

Sets the coordinates using the given values.

§ Normalize()

void Normalize ( )

Normalizes the vector, such that its length becomes 1.

§ GetNormalized()

Vec3 GetNormalized ( ) const

Returns a normalized copy of the vector.

§ LengthSquared()

T LengthSquared ( ) const

Returns the square of the length. Effectively, this is the dot product of the vector with itself.

§ Length()

T Length ( ) const

Returns the length of the vector.

§ Sum()

T Sum ( ) const

Returns the sum of its components.

§ IsZero()

bool IsZero ( ) const

Returns true if all components are exactly zero.

§ Min()

T Min ( ) const

Returns the minimum component of the vector.

§ Max()

T Max ( ) const

Returns the maximum component of the vector.

§ MinIndex()

int MinIndex ( ) const

Returns the index of the minimum component of the vector.

§ MaxIndex()

int MaxIndex ( ) const

Returns the index of the maximum component of the vector.

§ IsFinite()

bool IsFinite ( ) const

Returns true if all components are finite real numbers.

§ IsUnit()

bool IsUnit ( ) const

Returns true if the length of the vector is close to 1.

§ Sqrt()

Vec3 Sqrt ( ) const

Returns the square root of the vector.

§ Abs()

Vec3 Abs ( ) const

Returns a vector containing the absolute values of all components.

§ SortDesc()

Vec3 SortDesc ( ) const

Returns a vector with components sorted in descending order.

§ SortAsc()

Vec3 SortAsc ( ) const

Returns a vector with components sorted in ascending order.

§ GetPerpendicular()

Vec3 GetPerpendicular ( ) const

Returns a perpendicular vector.

§ GetOrthonormals()

void GetOrthonormals ( Vec3< T > &  v0,
Vec3< T > &  v1 
) const

< Returns two orthogonal vectors to this vector, forming an orthonormal basis

§ Clamp()

void Clamp ( minLimit,
maxLimit 
)

Ensures that all components of the vector are within the given limits.

§ ClampMin()

void ClampMin ( v)

Ensures that all components of the vector are greater than or equal to the given limit.

§ ClampMax()

void ClampMax ( v)

Ensures that all components of the vector are smaller than or equal to the given limit.

§ SetAbs()

void SetAbs ( )

Converts all negative components to positive values.

§ Cross()

Vec3 Cross ( Vec3< T > const &  p) const

Cross product.

§ operator^()

Vec3 operator^ ( Vec3< T > const &  p) const

Cross product.

§ Dot()

T Dot ( Vec3< T > const &  p) const

Dot product.

§ operator%()

T operator% ( Vec3< T > const &  p) const

Dot product.

Friends And Related Function Documentation

§ operator+

Vec3 operator+ ( v,
Vec3< T > const &  p 
)
friend

Addition with a constant.

§ operator-

Vec3 operator- ( v,
Vec3< T > const &  p 
)
friend

Subtraction from a constant.

§ operator*

Vec3 operator* ( v,
Vec3< T > const &  p 
)
friend

Multiplication with a constant.

Member Data Documentation

§ elem

T elem[3]

Array-type access to the vector elements x, y, and z.