OGRE  13.4
Object-Oriented Graphics Rendering Engine
Ogre::Vector< dims, T > Class Template Reference

Standard N-dimensional vector. More...

#include <OgreVector.h>

+ Inheritance diagram for Ogre::Vector< dims, T >:

Public Member Functions

 Vector ()
 Default constructor. More...
 
template<int N = dims>
 Vector (const typename std::enable_if< N==4, Vector3 >::type &rhs, T fW=1.0f)
 
template<typename U >
 Vector (const U *_ptr)
 
template<typename U >
 Vector (const Vector< dims, U > &o)
 
 Vector (T _x, T _y)
 
 Vector (T _x, T _y, T _z)
 
 Vector (T _x, T _y, T _z, T _w)
 
 Vector (T s)
 
Radian angleBetween (const Vector &dest) const
 Gets the angle between 2 vectors. More...
 
Real distance (const Vector &rhs) const
 Returns the distance to another vector. More...
 
dotProduct (const VectorBase< dims, T > &vec) const
 Calculates the dot (scalar) product of this vector with another. More...
 
bool isNaN () const
 Check whether this vector contains valid values. More...
 
bool isZeroLength () const
 Returns true if this vector is zero length. More...
 
Real length () const
 Returns the length (magnitude) of the vector. More...
 
void makeCeil (const Vector &cmp)
 Sets this vector's components to the maximum of its own and the ones of the passed in vector. More...
 
void makeFloor (const Vector &cmp)
 Sets this vector's components to the minimum of its own and the ones of the passed in vector. More...
 
Real normalise ()
 Normalises the vector. More...
 
Vector normalisedCopy () const
 As normalise, except that this vector is unaffected and the normalised vector is returned as a copy. More...
 
bool operator!= (const Vector &v) const
 
Vector operator* (const Vector &b) const
 
Vector operator* (Real s) const
 
Vectoroperator*= (const Vector &b)
 
Vectoroperator*= (Real s)
 
const Vectoroperator+ () const
 
Vector operator+ (const Vector &b) const
 
Vector operator+ (Real s) const
 
Vectoroperator+= (const Vector &b)
 
Vectoroperator+= (Real s)
 
Vector operator- () const
 
Vector operator- (const Vector &b) const
 
Vector operator- (Real s) const
 
Vectoroperator-= (const Vector &b)
 
Vectoroperator-= (Real s)
 
Vector operator/ (const Vector &b) const
 
Vector operator/ (Real s) const
 
Vectoroperator/= (const Vector &b)
 
Vectoroperator/= (Real s)
 
bool operator< (const Vector &rhs) const
 Returns true if the vector's scalar components are all greater that the ones of the vector it is compared against. More...
 
bool operator== (const Vector &v) const
 
bool operator> (const Vector &rhs) const
 Returns true if the vector's scalar components are all smaller that the ones of the vector it is compared against. More...
 
T & operator[] (size_t i)
 
operator[] (size_t i) const
 
bool positionEquals (const Vector &rhs, Real tolerance=1e-03f) const
 Returns whether this vector is within a positional tolerance of another vector. More...
 
Vector reflect (const Vector &normal) const
 Calculates a reflection vector to the plane with the given normal . More...
 
squaredDistance (const Vector &rhs) const
 Returns the square of the distance to another vector. More...
 
squaredLength () const
 Returns the square of the length(magnitude) of the vector. More...
 
Vector< 2, T > xy () const
 
Vector< 3, T > xyz () const
 Swizzle-like narrowing operations. More...
 
- Public Member Functions inherited from Ogre::VectorBase< dims, T >
 VectorBase ()
 
 VectorBase (T _x, T _y)
 
 VectorBase (T _x, T _y, T _z)
 
 VectorBase (T _x, T _y, T _z, T _w)
 
T * ptr ()
 
const T * ptr () const
 

Additional Inherited Members

- Public Attributes inherited from Ogre::VectorBase< dims, T >
data [dims]
 

Detailed Description

template<int dims, typename T>
class Ogre::Vector< dims, T >

Standard N-dimensional vector.

A direction in N-D space represented as distances along the orthogonal axes. Note that positions, directions and scaling factors can be represented by a vector, depending on how you interpret the values.

Constructor & Destructor Documentation

◆ Vector() [1/8]

template<int dims, typename T >
Ogre::Vector< dims, T >::Vector ( )
inline

Default constructor.

Note
It does NOT initialize the vector for efficiency.

◆ Vector() [2/8]

template<int dims, typename T >
Ogre::Vector< dims, T >::Vector ( _x,
_y 
)
inline

◆ Vector() [3/8]

template<int dims, typename T >
Ogre::Vector< dims, T >::Vector ( _x,
_y,
_z 
)
inline

◆ Vector() [4/8]

template<int dims, typename T >
Ogre::Vector< dims, T >::Vector ( _x,
_y,
_z,
_w 
)
inline

◆ Vector() [5/8]

template<int dims, typename T >
template<int N = dims>
Ogre::Vector< dims, T >::Vector ( const typename std::enable_if< N==4, Vector3 >::type &  rhs,
fW = 1.0f 
)
inlineexplicit

◆ Vector() [6/8]

template<int dims, typename T >
template<typename U >
Ogre::Vector< dims, T >::Vector ( const U *  _ptr)
inlineexplicit

◆ Vector() [7/8]

template<int dims, typename T >
template<typename U >
Ogre::Vector< dims, T >::Vector ( const Vector< dims, U > &  o)
inlineexplicit

◆ Vector() [8/8]

template<int dims, typename T >
Ogre::Vector< dims, T >::Vector ( s)
inlineexplicit

Member Function Documentation

◆ xyz()

template<int dims, typename T >
Vector<3, T> Ogre::Vector< dims, T >::xyz ( ) const
inline

Swizzle-like narrowing operations.

References Ogre::VectorBase< dims, T >::ptr().

◆ xy()

template<int dims, typename T >
Vector<2, T> Ogre::Vector< dims, T >::xy ( ) const
inline

◆ operator[]() [1/2]

template<int dims, typename T >
T Ogre::Vector< dims, T >::operator[] ( size_t  i) const
inline

◆ operator[]() [2/2]

template<int dims, typename T >
T& Ogre::Vector< dims, T >::operator[] ( size_t  i)
inline

◆ operator==()

template<int dims, typename T >
bool Ogre::Vector< dims, T >::operator== ( const Vector< dims, T > &  v) const
inline

◆ positionEquals()

template<int dims, typename T >
bool Ogre::Vector< dims, T >::positionEquals ( const Vector< dims, T > &  rhs,
Real  tolerance = 1e-03f 
) const
inline

Returns whether this vector is within a positional tolerance of another vector.

Parameters
rhsThe vector to compare with
toleranceThe amount that each element of the vector may vary by and still be considered equal

References Ogre::VectorBase< dims, T >::ptr(), and Ogre::Math::RealEqual().

◆ operator!=()

template<int dims, typename T >
bool Ogre::Vector< dims, T >::operator!= ( const Vector< dims, T > &  v) const
inline

◆ operator<()

template<int dims, typename T >
bool Ogre::Vector< dims, T >::operator< ( const Vector< dims, T > &  rhs) const
inline

Returns true if the vector's scalar components are all greater that the ones of the vector it is compared against.

References Ogre::VectorBase< dims, T >::ptr().

◆ operator>()

template<int dims, typename T >
bool Ogre::Vector< dims, T >::operator> ( const Vector< dims, T > &  rhs) const
inline

Returns true if the vector's scalar components are all smaller that the ones of the vector it is compared against.

References Ogre::VectorBase< dims, T >::ptr().

◆ makeFloor()

template<int dims, typename T >
void Ogre::Vector< dims, T >::makeFloor ( const Vector< dims, T > &  cmp)
inline

Sets this vector's components to the minimum of its own and the ones of the passed in vector.

'Minimum' in this case means the combination of the lowest
value of x, y and z from both vectors. Lowest is taken just
numerically, not magnitude, so -1 < 0.

References Ogre::VectorBase< dims, T >::ptr().

Referenced by Ogre::AxisAlignedBox::intersection(), and Ogre::AxisAlignedBox::merge().

◆ makeCeil()

template<int dims, typename T >
void Ogre::Vector< dims, T >::makeCeil ( const Vector< dims, T > &  cmp)
inline

Sets this vector's components to the maximum of its own and the ones of the passed in vector.

'Maximum' in this case means the combination of the highest
value of x, y and z from both vectors. Highest is taken just
numerically, not magnitude, so 1 > -3.

References Ogre::VectorBase< dims, T >::ptr().

Referenced by Ogre::AxisAlignedBox::intersection(), and Ogre::AxisAlignedBox::merge().

◆ dotProduct()

template<int dims, typename T >
T Ogre::Vector< dims, T >::dotProduct ( const VectorBase< dims, T > &  vec) const
inline

Calculates the dot (scalar) product of this vector with another.

The dot product can be used to calculate the angle between 2
vectors. If both are unit vectors, the dot product is the
cosine of the angle; otherwise the dot product must be
divided by the product of the lengths of both vectors to get
the cosine of the angle. This result can further be used to
calculate the distance of a point from a plane.
Parameters
vecVector with which to calculate the dot product (together with this one).
Returns
A float representing the dot product value.

References Ogre::VectorBase< dims, T >::ptr().

Referenced by Ogre::Vector< dims, T >::angleBetween(), Ogre::Math::calculateFaceNormal(), Ogre::Math::calculateFaceNormalWithoutNormalize(), Ogre::VectorBase< 3, Real >::directionEquals(), Ogre::Plane::getDistance(), Ogre::VectorBase< 3, Real >::getRotationTo(), Ogre::Ray::intersects(), Ogre::Matrix3::orthonormalised(), Ogre::Plane::redefine(), Ogre::Vector< dims, T >::reflect(), and Ogre::Vector< dims, T >::squaredLength().

◆ squaredLength()

template<int dims, typename T >
T Ogre::Vector< dims, T >::squaredLength ( ) const
inline

Returns the square of the length(magnitude) of the vector.

This  method is for efficiency - calculating the actual
length of a vector requires a square root, which is expensive
in terms of the operations required. This method returns the
square of the length of the vector, i.e. the same as the
length but before the square root is taken. Use this if you
want to find the longest / shortest vector without incurring
the square root.

References Ogre::Vector< dims, T >::dotProduct().

Referenced by Ogre::VectorBase< 3, Real >::getRotationTo(), Ogre::Ray::intersects(), Ogre::Vector< dims, T >::isZeroLength(), Ogre::Vector< dims, T >::length(), Ogre::Sphere::merge(), Ogre::VectorBase< 3, Real >::positionCloses(), and Ogre::AxisAlignedBox::squaredDistance().

◆ isZeroLength()

template<int dims, typename T >
bool Ogre::Vector< dims, T >::isZeroLength ( ) const
inline

Returns true if this vector is zero length.

References Ogre::Vector< dims, T >::squaredLength().

◆ length()

template<int dims, typename T >
Real Ogre::Vector< dims, T >::length ( ) const
inline

Returns the length (magnitude) of the vector.

Warning
This operation requires a square root and is expensive in terms of CPU operations. If you don't need to know the exact length (e.g. for just comparing lengths) use squaredLength() instead.

References Ogre::Math::Sqrt(), and Ogre::Vector< dims, T >::squaredLength().

Referenced by Ogre::Vector< dims, T >::angleBetween(), Ogre::Vector< dims, T >::normalise(), and Ogre::Plane::normalise().

◆ distance()

template<int dims, typename T >
Real Ogre::Vector< dims, T >::distance ( const Vector< dims, T > &  rhs) const
inline

Returns the distance to another vector.

Warning
This operation requires a square root and is expensive in terms of CPU operations. If you don't need to know the exact distance (e.g. for just comparing distances) use squaredDistance() instead.

◆ squaredDistance()

template<int dims, typename T >
T Ogre::Vector< dims, T >::squaredDistance ( const Vector< dims, T > &  rhs) const
inline

Returns the square of the distance to another vector.

This method is for efficiency - calculating the actual
distance to another vector requires a square root, which is
expensive in terms of the operations required. This method
returns the square of the distance to another vector, i.e.
the same as the distance but before the square root is taken.
Use this if you want to find the longest / shortest distance
without incurring the square root.

◆ normalise()

template<int dims, typename T >
Real Ogre::Vector< dims, T >::normalise ( )
inline

Normalises the vector.

This method normalises the vector such that it's
length / magnitude is 1. The result is called a unit vector.
Note
This function will not crash for zero-sized vectors, but there will be no changes made to their components.
Returns
The previous length of the vector.

References Ogre::Vector< dims, T >::length(), and Ogre::VectorBase< dims, T >::ptr().

Referenced by Ogre::Math::calculateBasicFaceNormal(), Ogre::Vector< dims, T >::normalisedCopy(), and Ogre::operator*().

◆ normalisedCopy()

template<int dims, typename T >
Vector Ogre::Vector< dims, T >::normalisedCopy ( ) const
inline

As normalise, except that this vector is unaffected and the normalised vector is returned as a copy.

References Ogre::Vector< dims, T >::normalise().

Referenced by Ogre::Math::lookRotation(), and Ogre::VectorBase< 3, Real >::perpendicular().

◆ isNaN()

template<int dims, typename T >
bool Ogre::Vector< dims, T >::isNaN ( ) const
inline

Check whether this vector contains valid values.

References Ogre::Math::isNaN(), and Ogre::VectorBase< dims, T >::ptr().

◆ angleBetween()

template<int dims, typename T >
Radian Ogre::Vector< dims, T >::angleBetween ( const Vector< dims, T > &  dest) const
inline

Gets the angle between 2 vectors.

Vectors do not have to be unit-length but must represent directions.

References Ogre::Math::ACos(), Ogre::Math::Clamp(), Ogre::Vector< dims, T >::dotProduct(), and Ogre::Vector< dims, T >::length().

◆ reflect()

template<int dims, typename T >
Vector Ogre::Vector< dims, T >::reflect ( const Vector< dims, T > &  normal) const
inline

Calculates a reflection vector to the plane with the given normal .

Remarks
NB assumes 'this' is pointing AWAY FROM the plane, invert if it is not.

References Ogre::Vector< dims, T >::dotProduct().

◆ operator*=() [1/2]

template<int dims, typename T >
Vector& Ogre::Vector< dims, T >::operator*= ( Real  s)
inline

◆ operator/=() [1/2]

template<int dims, typename T >
Vector& Ogre::Vector< dims, T >::operator/= ( Real  s)
inline

◆ operator+=() [1/2]

template<int dims, typename T >
Vector& Ogre::Vector< dims, T >::operator+= ( Real  s)
inline

◆ operator-=() [1/2]

template<int dims, typename T >
Vector& Ogre::Vector< dims, T >::operator-= ( Real  s)
inline

◆ operator+=() [2/2]

template<int dims, typename T >
Vector& Ogre::Vector< dims, T >::operator+= ( const Vector< dims, T > &  b)
inline

◆ operator-=() [2/2]

template<int dims, typename T >
Vector& Ogre::Vector< dims, T >::operator-= ( const Vector< dims, T > &  b)
inline

◆ operator*=() [2/2]

template<int dims, typename T >
Vector& Ogre::Vector< dims, T >::operator*= ( const Vector< dims, T > &  b)
inline

◆ operator/=() [2/2]

template<int dims, typename T >
Vector& Ogre::Vector< dims, T >::operator/= ( const Vector< dims, T > &  b)
inline

◆ operator-() [1/3]

template<int dims, typename T >
Vector Ogre::Vector< dims, T >::operator- ( ) const
inline

◆ operator+() [1/3]

template<int dims, typename T >
const Vector& Ogre::Vector< dims, T >::operator+ ( ) const
inline

◆ operator*() [1/2]

template<int dims, typename T >
Vector Ogre::Vector< dims, T >::operator* ( Real  s) const
inline

◆ operator/() [1/2]

template<int dims, typename T >
Vector Ogre::Vector< dims, T >::operator/ ( Real  s) const
inline

◆ operator-() [2/3]

template<int dims, typename T >
Vector Ogre::Vector< dims, T >::operator- ( Real  s) const
inline

◆ operator+() [2/3]

template<int dims, typename T >
Vector Ogre::Vector< dims, T >::operator+ ( Real  s) const
inline

◆ operator+() [3/3]

template<int dims, typename T >
Vector Ogre::Vector< dims, T >::operator+ ( const Vector< dims, T > &  b) const
inline

◆ operator-() [3/3]

template<int dims, typename T >
Vector Ogre::Vector< dims, T >::operator- ( const Vector< dims, T > &  b) const
inline

◆ operator*() [2/2]

template<int dims, typename T >
Vector Ogre::Vector< dims, T >::operator* ( const Vector< dims, T > &  b) const
inline

◆ operator/() [2/2]

template<int dims, typename T >
Vector Ogre::Vector< dims, T >::operator/ ( const Vector< dims, T > &  b) const
inline

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