ezEngine  Milestone 7
ezVec2Template< Type > Class Template Reference

A 2-component vector class. More...

#include <Vec2.h>

Public Types

typedef Type ComponentType
 

Public Member Functions

 EZ_DECLARE_POD_TYPE ()
 
 ezVec2Template ()
 default-constructed vector is uninitialized (for speed)
 
 ezVec2Template (Type X, Type Y)
 Initializes the vector with x,y.
 
 ezVec2Template (Type xy)
 Initializes all components with xy.
 
const ezVec3Template< Type > GetAsVec3 (Type z) const
 Returns an ezVec3Template with x,y from this vector and z set by the parameter.
 
const ezVec4Template< Type > GetAsVec4 (Type z, Type w) const
 Returns an ezVec4Template with x,y from this vector and z and w set by the parameters.
 
const Type * GetData () const
 Returns the data as an array.
 
Type * GetData ()
 Returns the data as an array.
 
void Set (Type xy)
 Sets all components to this value.
 
void Set (Type x, Type y)
 Sets the vector to these values.
 
void SetZero ()
 Sets the vector to all zero.
 
Type GetLength () const
 Returns the length of the vector.
 
Type GetLengthSquared () const
 Returns the squared length. Faster, since no square-root is taken. Useful, if one only wants to compare the lengths of two vectors.
 
Type GetLengthAndNormalize ()
 Normalizes this vector and returns its previous length in one operation. More efficient than calling GetLength and then Normalize.
 
const ezVec2Template GetNormalized () const
 Returns a normalized version of this vector, leaves the vector itself unchanged.
 
void Normalize ()
 Normalizes this vector.
 
ezResult NormalizeIfNotZero (const ezVec2Template< Type > &vFallback=ezVec2Template< Type >(1, 0), Type fEpsilon=ezMath::BasicType< Type >::DefaultEpsilon())
 Tries to normalize this vector. If the vector is too close to zero, EZ_FAILURE is returned and the vector is set to the given fallback value.
 
bool IsZero () const
 Returns, whether this vector is (0, 0).
 
bool IsZero (Type fEpsilon) const
 Returns, whether this vector is (0, 0) within a certain threshold.
 
bool IsNormalized (Type fEpsilon=ezMath::BasicType< Type >::HugeEpsilon()) const
 Returns, whether the squared length of this vector is between 0.999f and 1.001f. More...
 
bool IsNaN () const
 Returns true, if any of x or y is NaN.
 
bool IsValid () const
 Checks that all components are finite numbers.
 
const ezVec2Template operator- () const
 Returns the negation of this vector.
 
void operator+= (const ezVec2Template< Type > &cc)
 Adds cc component-wise to this vector.
 
void operator-= (const ezVec2Template< Type > &cc)
 Subtracts cc component-wise from this vector.
 
void operator*= (Type f)
 Multiplies all components of this vector with f.
 
void operator/= (Type f)
 Divides all components of this vector by f.
 
bool IsIdentical (const ezVec2Template< Type > &rhs) const
 Equality Check (bitwise)
 
bool IsEqual (const ezVec2Template< Type > &rhs, Type fEpsilon) const
 Equality Check with epsilon.
 
ezAngle GetAngleBetween (const ezVec2Template< Type > &rhs) const
 Returns the positive angle between *this and rhs (in degree).
 
Type Dot (const ezVec2Template< Type > &rhs) const
 Returns the Dot-product of the two vectors (commutative, order does not matter)
 
const ezVec2Template< Type > CompMin (const ezVec2Template< Type > &rhs) const
 Returns the component-wise minimum of *this and rhs.
 
const ezVec2Template< Type > CompMax (const ezVec2Template< Type > &rhs) const
 Returns the component-wise maximum of *this and rhs.
 
const ezVec2Template< Type > CompMult (const ezVec2Template< Type > &rhs) const
 Returns the component-wise multiplication of *this and rhs.
 
const ezVec2Template< Type > CompDiv (const ezVec2Template< Type > &rhs) const
 Returns the component-wise division of *this and rhs.
 
void MakeOrthogonalTo (const ezVec2Template< Type > &vNormal)
 Modifies this direction vector to be orthogonal to the given (normalized) direction vector. The result is NOT normalized. More...
 
const ezVec2Template< Type > GetOrthogonalVector () const
 Returns some arbitrary vector orthogonal to this one. The vector is NOT normalized.
 
const ezVec2Template< Type > GetReflectedVector (const ezVec2Template< Type > &vNormal) const
 Returns this vector reflected at vNormal.
 

Static Public Member Functions

static const ezVec2Template ZeroVector ()
 Static function that returns a zero-vector.
 

Public Attributes

Type x
 
Type y
 

Detailed Description

template<typename Type>
class ezVec2Template< Type >

A 2-component vector class.

Member Function Documentation

template<typename Type>
bool ezVec2Template< Type >::IsNormalized ( Type  fEpsilon = ezMath::BasicType<Type>::HugeEpsilon()) const
inline

Returns, whether the squared length of this vector is between 0.999f and 1.001f.

Note
Normalization, especially with SSE is not very precise. So this function checks whether the (squared) length is between a lower and upper limit.
template<typename Type>
void ezVec2Template< Type >::MakeOrthogonalTo ( const ezVec2Template< Type > &  vNormal)
inline

Modifies this direction vector to be orthogonal to the given (normalized) direction vector. The result is NOT normalized.

Note
This function may fail, e.g. create a vector that is zero, if the given normal is parallel to the vector itself. If you need to handle such cases, you should manually check afterwards, whether the result is zero, or cannot be normalized.

The documentation for this class was generated from the following files: