Files Class List
Vec4< T > Class Template Reference

Detailed Description

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

4D 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, T _w=1)
 
void Set (Vec2< T > const &p, T _z, T _w=1)
 
void Set (Vec3< T > const &p, T _w=1)
 
General methods
void Normalize ()
 
Vec4 GetNormalized () const
 
LengthSquared () const
 
Length () const
 
Sum () const
 
bool IsZero () const
 
Min () const
 
Max () const
 
int MinID () const
 
int MaxID () const
 
bool IsFinite () const
 
bool IsUnit () const
 
Vec4 Sqrt () const
 
Vec4 Abs () const
 
Vec4 SortDesc () const
 
Vec4 SortAsc () const
 
Limit methods
void Clamp (T minLimit, T maxLimit)
 
void ClampMin (T v)
 
void ClampMax (T v)
 
void SetAbs ()
 
Unary operators
Vec4 operator- () const
 
Binary operators
Vec4 operator+ (Vec4 const &p) const
 
Vec4 operator- (Vec4 const &p) const
 
Vec4 operator* (Vec4 const &p) const
 
Vec4 operator/ (Vec4 const &p) const
 
Vec4 operator+ (T const v) const
 
Vec4 operator- (T const v) const
 
Vec4 operator* (T const v) const
 
Vec4 operator/ (T const v) const
 
Assignment operators
Vec4 const & operator+= (Vec4 const &p)
 
Vec4 const & operator-= (Vec4 const &p)
 
Vec4 const & operator*= (Vec4 const &p)
 
Vec4 const & operator/= (Vec4 const &p)
 
Vec4 const & operator+= (T const v)
 
Vec4 const & operator-= (T const v)
 
Vec4 const & operator*= (T const v)
 
Vec4 const & operator/= (T const v)
 
Test operators
bool operator== (Vec4 const &p) const
 
bool operator!= (Vec4 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
 
Dot product
Dot (Vec4 const &p) const
 
operator% (Vec4 const &p) const
 
Conversion Methods
Vec2< T > XY () const
 
Vec3< T > XYZ () const
 
Vec3< T > GetNonHomogeneous () const
 

Public Attributes

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

Friends

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

Constructors

_y
 
T T _z
 
T T T _w: x( _x)
 
 Vec4 () CY_CLASS_FUNCTION_DEFAULT Vec4(T _x
 
T T T y (_y)
 
T T T z (_z)
 
T T T w (_w)
 
 Vec4 (T v)
 
 Vec4 (Vec2< T > const &p, T _z=0, T _w=1)
 
 Vec4 (Vec3< T > const &p, T _w=1)
 
template<typename S >
 Vec4 (Vec2< S > const &p, T _z=0, T _w=1)
 
template<typename S >
 Vec4 (Vec3< S > const &p, T _w=1)
 
template<typename S >
 Vec4 (Vec4< S > const &p)
 
template<int N>
 Vec4 (Vec< T, N > const &p)
 
template<int N, typename S >
 Vec4 (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/5]

void Set ( T const *  p)

Sets the coordinates using the values in the given array.

§ Set() [2/5]

void Set ( v)

Sets all coordinates using the given value.

§ Set() [3/5]

void Set ( _x,
_y,
_z,
_w = 1 
)

Sets the coordinates using the given values.

§ Set() [4/5]

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

Sets the coordinates using the given values.

§ Set() [5/5]

void Set ( Vec3< T > const &  p,
_w = 1 
)

Sets the coordinates using the given values.

§ Normalize()

void Normalize ( )

Normalizes the vector, such that its length becomes 1.

§ GetNormalized()

Vec4 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.

§ MinID()

int MinID ( ) const

Returns the index of the minimum component of the vector.

§ MaxID()

int MaxID ( ) 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()

Vec4 Sqrt ( ) const

Returns the square root of the vector.

§ Abs()

Vec4 Abs ( ) const

Returns a vector containing the absolute values of all components.

§ SortDesc()

Vec4 SortDesc ( ) const

Returns a vector with components sorted in descending order.

§ SortAsc()

Vec4 SortAsc ( ) const

Returns a vector with components sorted in descending order.

§ 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.

§ Dot()

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

Dot product.

§ operator%()

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

Dot product.

Friends And Related Function Documentation

§ operator+

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

Addition with a constant.

§ operator-

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

Subtraction from a constant.

§ operator*

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

Multiplication with a constant.

Member Data Documentation

§ elem

T elem[4]

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