Shadowrun: Awakened 29 September 2011 - Build 871
Public Types | Public Member Functions | Protected Attributes
cat::Vector< DIM, Scalar, Double > Class Template Reference

#include <Vector.hpp>

Inheritance diagram for cat::Vector< DIM, Scalar, Double >:

List of all members.

Public Types

typedef Vector< DIM, Scalar,
Double > 
mytype

Public Member Functions

mytypeaddRotation2D (const mytype &r)
mytypeaddToEachElement (Scalar u)
mytypecomponentDivide (const mytype &u)
mytypecomponentMultiply (const mytype &u)
mytypecopy (const mytype &u)
f32 crossProduct2D (const mytype &u)
mytype crossProduct3D (const mytype &u)
Double dotProduct (const mytype &u) const
void generateRotation2D (f32 angle)
bool isZero ()
Double magnitude () const
mytypenegate ()
mytypenormalize ()
mytypenormalize_fast_f32 ()
const Scalar & operator() (int ii) const
Scalar & operator() (int ii)
mytype operator* (Scalar u) const
mytypeoperator*= (Scalar u)
mytype operator+ (const mytype &u) const
mytypeoperator+= (const mytype &u)
mytype operator- () const
mytype operator- (const mytype &u) const
mytypeoperator-= (const mytype &u)
mytype operator/ (Scalar u) const
mytypeoperator/= (Scalar u)
mytypeoperator= (const mytype &u)
mytypesubtractFromEachElement (Scalar u)
mytypesubtractRotation2D (const mytype &r)
 Vector (Scalar x, Scalar y)
 Vector (Scalar x, Scalar y, Scalar z)
 Vector ()
 Vector (Scalar x, Scalar y, Scalar z, Scalar w)
 Vector (const mytype &u)
const Scalar & w () const
Scalar & w ()
const Scalar & x () const
Scalar & x ()
const Scalar & y () const
Scalar & y ()
Scalar & z ()
const Scalar & z () const
void zero ()

Protected Attributes

Scalar _elements [DIM]

Detailed Description

template<int DIM, typename Scalar, typename Double>
class cat::Vector< DIM, Scalar, Double >

Definition at line 40 of file Vector.hpp.


Member Typedef Documentation

template<int DIM, typename Scalar, typename Double>
typedef Vector<DIM, Scalar, Double> cat::Vector< DIM, Scalar, Double >::mytype

Definition at line 48 of file Vector.hpp.


Constructor & Destructor Documentation

template<int DIM, typename Scalar, typename Double>
cat::Vector< DIM, Scalar, Double >::Vector ( ) [inline]

Definition at line 51 of file Vector.hpp.

{}
template<int DIM, typename Scalar, typename Double>
cat::Vector< DIM, Scalar, Double >::Vector ( Scalar  x,
Scalar  y 
) [inline]

Definition at line 54 of file Vector.hpp.

    {
        _elements[0] = x;
        _elements[1] = y;
    }
template<int DIM, typename Scalar, typename Double>
cat::Vector< DIM, Scalar, Double >::Vector ( Scalar  x,
Scalar  y,
Scalar  z 
) [inline]

Definition at line 59 of file Vector.hpp.

    {
        _elements[0] = x;
        _elements[1] = y;
        _elements[2] = z;
    }
template<int DIM, typename Scalar, typename Double>
cat::Vector< DIM, Scalar, Double >::Vector ( Scalar  x,
Scalar  y,
Scalar  z,
Scalar  w 
) [inline]

Definition at line 65 of file Vector.hpp.

    {
        _elements[0] = x;
        _elements[1] = y;
        _elements[2] = z;
        _elements[3] = w;
    }
template<int DIM, typename Scalar, typename Double>
cat::Vector< DIM, Scalar, Double >::Vector ( const mytype u) [inline]

Definition at line 82 of file Vector.hpp.

    {
        copy(u);
    }

Member Function Documentation

template<int DIM, typename Scalar, typename Double>
mytype& cat::Vector< DIM, Scalar, Double >::addRotation2D ( const mytype r) [inline]

Definition at line 320 of file Vector.hpp.

    {
        Double ax = x(), ay = y();
        Double rx = r.x(), ry = r.y();

        x() = static_cast<Scalar>( ax*rx - ay*ry ); // cos(a+r) = cos(a)*cos(r) - sin(a)*sin(r)
        y() = static_cast<Scalar>( ay*rx + ax*ry ); // sin(a+r) = sin(a)*cos(r) + cos(a)*sin(r)

        return *this;
    }
template<int DIM, typename Scalar, typename Double>
mytype& cat::Vector< DIM, Scalar, Double >::addToEachElement ( Scalar  u) [inline]

Definition at line 208 of file Vector.hpp.

    {
        FOR_EACH_DIMENSION(ii) _elements[ii] += u;

        return *this;
    }
template<int DIM, typename Scalar, typename Double>
mytype& cat::Vector< DIM, Scalar, Double >::componentDivide ( const mytype u) [inline]

Definition at line 290 of file Vector.hpp.

    {
        FOR_EACH_DIMENSION(ii) _elements[ii] /= u._elements[ii];

        return *this;
    }
template<int DIM, typename Scalar, typename Double>
mytype& cat::Vector< DIM, Scalar, Double >::componentMultiply ( const mytype u) [inline]

Definition at line 260 of file Vector.hpp.

    {
        FOR_EACH_DIMENSION(ii) _elements[ii] *= u._elements[ii];

        return *this;
    }
template<int DIM, typename Scalar, typename Double>
mytype& cat::Vector< DIM, Scalar, Double >::copy ( const mytype u) [inline]
template<int DIM, typename Scalar, typename Double>
f32 cat::Vector< DIM, Scalar, Double >::crossProduct2D ( const mytype u) [inline]

Definition at line 344 of file Vector.hpp.

    {
        return x() * u.y() - y() * u.x();
    }
template<int DIM, typename Scalar, typename Double>
mytype cat::Vector< DIM, Scalar, Double >::crossProduct3D ( const mytype u) [inline]

Definition at line 353 of file Vector.hpp.

    {
        mytype result;

        result.x() = y() * u.z() - z() * u.y();
        result.y() = z() * u.x() - x() * u.z();
        result.z() = x() * u.y() - y() * u.x();

        return result;
    }
template<int DIM, typename Scalar, typename Double>
Double cat::Vector< DIM, Scalar, Double >::dotProduct ( const mytype u) const [inline]

Definition at line 298 of file Vector.hpp.

    {
        Double sum = 0;

        FOR_EACH_DIMENSION(ii)
            sum += static_cast<Double>( _elements[ii] )
                * static_cast<Double>( u._elements[ii] );

        return sum;
    }
template<int DIM, typename Scalar, typename Double>
void cat::Vector< DIM, Scalar, Double >::generateRotation2D ( f32  angle) [inline]

Definition at line 313 of file Vector.hpp.

    {
        x() = cos(angle);
        y() = sin(angle);
    }
template<int DIM, typename Scalar, typename Double>
bool cat::Vector< DIM, Scalar, Double >::isZero ( ) [inline]

Definition at line 148 of file Vector.hpp.

    {
        FOR_EACH_DIMENSION(ii)
            if (_elements[ii] != static_cast<Scalar>( 0 ))
                return false;

        return true;
    }
template<int DIM, typename Scalar, typename Double>
Double cat::Vector< DIM, Scalar, Double >::magnitude ( ) const [inline]

Definition at line 94 of file Vector.hpp.

Referenced by cat::Vector< 4, Scalar, Double >::normalize().

    {
        Double element, sum = 0;

        FOR_EACH_DIMENSION(ii)
        {
            element = _elements[ii];
            sum += element * element;
        }

        return static_cast<Double>( sqrt(sum) );
    }
template<int DIM, typename Scalar, typename Double>
mytype& cat::Vector< DIM, Scalar, Double >::negate ( ) [inline]

Definition at line 182 of file Vector.hpp.

    {
        FOR_EACH_DIMENSION(ii) _elements[ii] = -_elements[ii];

        return *this;
    }
template<int DIM, typename Scalar, typename Double>
mytype& cat::Vector< DIM, Scalar, Double >::normalize ( ) [inline]

Definition at line 131 of file Vector.hpp.

Referenced by cat::Quaternion< Scalar, Double >::setFromEulerAngles().

    {
        Double m = magnitude();
        Double inv = static_cast<Double>( 1 ) / m;

        FOR_EACH_DIMENSION(ii) _elements[ii] *= inv;

        return *this;
    }
template<int DIM, typename Scalar, typename Double>
mytype& cat::Vector< DIM, Scalar, Double >::normalize_fast_f32 ( ) [inline]

Definition at line 108 of file Vector.hpp.

    {
        f32 element = _elements[0];
        f32 sum = element * element;

        for (int ii = 1; ii < DIM; ++ii)
        {
            element = _elements[ii];
            sum += element * element;
        }

        // If sum is not close to 1, then perform normalization:
        if (sum > 1.005f || sum < 0.995f)
        {
            f32 inv = InvSqrt(sum);

            FOR_EACH_DIMENSION(ii) _elements[ii] *= inv;
        }

        return *this;
    }
template<int DIM, typename Scalar, typename Double>
Scalar& cat::Vector< DIM, Scalar, Double >::operator() ( int  ii) [inline]

Definition at line 158 of file Vector.hpp.

{ return _elements[ii]; }
template<int DIM, typename Scalar, typename Double>
const Scalar& cat::Vector< DIM, Scalar, Double >::operator() ( int  ii) const [inline]

Definition at line 165 of file Vector.hpp.

{ return _elements[ii]; }
template<int DIM, typename Scalar, typename Double>
mytype cat::Vector< DIM, Scalar, Double >::operator* ( Scalar  u) const [inline]

Definition at line 242 of file Vector.hpp.

    {
        mytype x;

        FOR_EACH_DIMENSION(ii) x._elements[ii] = u * _elements[ii];

        return x;
    }
template<int DIM, typename Scalar, typename Double>
mytype& cat::Vector< DIM, Scalar, Double >::operator*= ( Scalar  u) [inline]

Definition at line 252 of file Vector.hpp.

    {
        FOR_EACH_DIMENSION(ii) _elements[ii] *= u;

        return *this;
    }
template<int DIM, typename Scalar, typename Double>
mytype cat::Vector< DIM, Scalar, Double >::operator+ ( const mytype u) const [inline]

Definition at line 190 of file Vector.hpp.

    {
        mytype x;

        FOR_EACH_DIMENSION(ii) x._elements[ii] = _elements[ii] + u._elements[ii];

        return x;
    }
template<int DIM, typename Scalar, typename Double>
mytype& cat::Vector< DIM, Scalar, Double >::operator+= ( const mytype u) [inline]

Definition at line 200 of file Vector.hpp.

    {
        FOR_EACH_DIMENSION(ii) _elements[ii] += u._elements[ii];

        return *this;
    }
template<int DIM, typename Scalar, typename Double>
mytype cat::Vector< DIM, Scalar, Double >::operator- ( ) const [inline]

Definition at line 172 of file Vector.hpp.

    {
        mytype x;

        FOR_EACH_DIMENSION(ii) x._elements[ii] = -_elements[ii];

        return x;
    }
template<int DIM, typename Scalar, typename Double>
mytype cat::Vector< DIM, Scalar, Double >::operator- ( const mytype u) const [inline]

Definition at line 216 of file Vector.hpp.

    {
        mytype x;

        FOR_EACH_DIMENSION(ii) x._elements[ii] = _elements[ii] - u._elements[ii];

        return x;
    }
template<int DIM, typename Scalar, typename Double>
mytype& cat::Vector< DIM, Scalar, Double >::operator-= ( const mytype u) [inline]

Definition at line 226 of file Vector.hpp.

    {
        FOR_EACH_DIMENSION(ii) _elements[ii] -= u._elements[ii];

        return *this;
    }
template<int DIM, typename Scalar, typename Double>
mytype cat::Vector< DIM, Scalar, Double >::operator/ ( Scalar  u) const [inline]

Definition at line 268 of file Vector.hpp.

    {
        mytype x;

        Scalar inv_u = static_cast<Scalar>( 1 ) / static_cast<Scalar>( u );

        FOR_EACH_DIMENSION(ii) x._elements[ii] = _elements[ii] * inv_u;

        return x;
    }
template<int DIM, typename Scalar, typename Double>
mytype& cat::Vector< DIM, Scalar, Double >::operator/= ( Scalar  u) [inline]

Definition at line 280 of file Vector.hpp.

    {
        Scalar inv_u = static_cast<Scalar>( 1 ) / static_cast<Scalar>( u );

        FOR_EACH_DIMENSION(ii) _elements[ii] *= inv_u;

        return *this;
    }
template<int DIM, typename Scalar, typename Double>
mytype& cat::Vector< DIM, Scalar, Double >::operator= ( const mytype u) [inline]

Definition at line 88 of file Vector.hpp.

    {
        return copy(u);
    }
template<int DIM, typename Scalar, typename Double>
mytype& cat::Vector< DIM, Scalar, Double >::subtractFromEachElement ( Scalar  u) [inline]

Definition at line 234 of file Vector.hpp.

    {
        FOR_EACH_DIMENSION(ii) _elements[ii] -= u;

        return *this;
    }
template<int DIM, typename Scalar, typename Double>
mytype& cat::Vector< DIM, Scalar, Double >::subtractRotation2D ( const mytype r) [inline]

Definition at line 332 of file Vector.hpp.

    {
        Double ax = x(), ay = y();
        Double rx = r.x(), ry = r.y();

        x() = static_cast<Scalar>( ax*rx + ay*ry ); // cos(a-r) = cos(a)*cos(r) + sin(a)*sin(r)
        y() = static_cast<Scalar>( ay*rx - ax*ry ); // sin(a-r) = sin(a)*cos(r) - cos(a)*sin(r)

        return *this;
    }
template<int DIM, typename Scalar, typename Double>
const Scalar& cat::Vector< DIM, Scalar, Double >::w ( ) const [inline]

Definition at line 169 of file Vector.hpp.

{ return _elements[3]; }
template<int DIM, typename Scalar, typename Double>
Scalar& cat::Vector< DIM, Scalar, Double >::w ( ) [inline]

Definition at line 162 of file Vector.hpp.

Referenced by cat::Vector< 4, Scalar, Double >::Vector().

{ return _elements[3]; }
template<int DIM, typename Scalar, typename Double>
Scalar& cat::Vector< DIM, Scalar, Double >::x ( ) [inline]
template<int DIM, typename Scalar, typename Double>
const Scalar& cat::Vector< DIM, Scalar, Double >::x ( ) const [inline]

Definition at line 166 of file Vector.hpp.

{ return _elements[0]; }
template<int DIM, typename Scalar, typename Double>
const Scalar& cat::Vector< DIM, Scalar, Double >::y ( ) const [inline]

Definition at line 167 of file Vector.hpp.

{ return _elements[1]; }
template<int DIM, typename Scalar, typename Double>
Scalar& cat::Vector< DIM, Scalar, Double >::y ( ) [inline]
template<int DIM, typename Scalar, typename Double>
const Scalar& cat::Vector< DIM, Scalar, Double >::z ( ) const [inline]

Definition at line 168 of file Vector.hpp.

{ return _elements[2]; }
template<int DIM, typename Scalar, typename Double>
Scalar& cat::Vector< DIM, Scalar, Double >::z ( ) [inline]
template<int DIM, typename Scalar, typename Double>
void cat::Vector< DIM, Scalar, Double >::zero ( ) [inline]

Definition at line 142 of file Vector.hpp.

    {
        OBJCLR(_elements);
    }

Member Data Documentation

template<int DIM, typename Scalar, typename Double>
Scalar cat::Vector< DIM, Scalar, Double >::_elements[DIM] [protected]

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

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net