namespace lm
{
-template<typename T>
+template <typename T>
class vector2 : public tuple2<T>
{
public:
- vector2(void) : tuple2<T>( T(0) , T(0) ) {}
- vector2( const T& _x, const T& _y ) : tuple2<T>( _x , _y ) {}
- vector2( const vector2<T>& _v ) : tuple2<T>( _v.x , _v.y ) {}
- vector2( const T* _v ) : tuple2<T>( _v ) {}
+ vector2(void) : tuple2<T>(T(0), T(0)) {}
+ vector2(const T& _x, const T& _y) : tuple2<T>(_x, _y) {}
+ vector2(const vector2<T>& _v) : tuple2<T>(_v.x, _v.y) {}
+ vector2(const T* _v) : tuple2<T>(_v) {}
- template<typename U>
+ template <typename U>
operator vector2<U>(void) const
{
- return vector2<U>( static_cast<U>(x) , static_cast<U>(y) );
+ return vector2<U>(static_cast<U>(x), static_cast<U>(y));
}
void set_zero(void);
static vector2<T> get_zero(void);
- void add( const vector2<T>& _v );
- void add( const T* _v );
- void add( const T& _x, const T& _y );
- vector2<T>& operator+=( const vector2<T>& _v );
+ void add(const vector2<T>& _v);
+ void add(const T* _v);
+ void add(const T& _x, const T& _y);
+ vector2<T>& operator+=(const vector2<T>& _v);
- void sub( const vector2<T>& _v );
- void sub( const T* _v );
- void sub( const T& _x, const T& _y );
- vector2<T>& operator-=( const vector2<T>& _v );
+ void sub(const vector2<T>& _v);
+ void sub(const T* _v);
+ void sub(const T& _x, const T& _y);
+ vector2<T>& operator-=(const vector2<T>& _v);
- void mult( const T& val );
- vector2<T>& operator*=( const T& _v );
+ void mult(const T& val);
+ vector2<T>& operator*=(const T& _v);
- void div( const T& val );
- vector2<T>& operator/=( const T& _v );
+ void div(const T& val);
+ vector2<T>& operator/=(const T& _v);
vector2<T> operator-(void) const;
T square_length(void) const;
- void rotate( const T& angle );
+ void rotate(const T& angle);
T operator*(const vector2<T>& _v) const
typedef vector2<float> vec2f;
-// global method
+// global method
-template<typename T> inline
-T dot(const vector2<T>& _a, const vector2<T>& _b)
+template <typename T>
+inline T dot(const vector2<T>& _a, const vector2<T>& _b)
{
return
_a.x * _b.x +
// vector implements
-template<typename T> inline
-void vector2<T>::set_zero(void)
+template <typename T>
+inline void vector2<T>::set_zero(void)
{
- this->set( T(0) , T(0) );
+ this->set(T(0), T(0));
}
-template<typename T> inline
-vector2<T> vector2<T>::get_zero(void)
+template <typename T>
+inline vector2<T> vector2<T>::get_zero(void)
{
- return vector2<T>( T(0) , T(0) );
+ return vector2<T>(T(0), T(0));
}
-template<typename T> inline
-void vector2<T>::add(const vector2<T>& _v)
+template <typename T>
+inline void vector2<T>::add(const vector2<T>& _v)
{
- x += _v.x ; y += _v.y ;
+ x += _v.x;
+ y += _v.y;
}
-template<typename T> inline
-void vector2<T>::add(const T* _v)
+template <typename T>
+inline void vector2<T>::add(const T* _v)
{
- x += _v[0] ; y += _v[1] ;
+ x += _v[0];
+ y += _v[1];
}
-template<typename T> inline
-void vector2<T>::add(const T& _x, const T& _y)
+template <typename T>
+inline void vector2<T>::add(const T& _x, const T& _y)
{
- x += _x ; y += _y ;
+ x += _x;
+ y += _y;
}
-template<typename T> inline
-vector2<T>& vector2<T>::operator+=(const vector2<T>& _v)
+template <typename T>
+inline vector2<T>& vector2<T>::operator+=(const vector2<T>& _v)
{
- x += _v.x ; y += _v.y ;
+ x += _v.x;
+ y += _v.y;
return *this;
}
-template<typename T> inline
-void vector2<T>::sub(const vector2<T>& _v)
+template <typename T>
+inline void vector2<T>::sub(const vector2<T>& _v)
{
- x -= _v.x ; y -= _v.y ;
+ x -= _v.x;
+ y -= _v.y;
}
-template<typename T> inline
-void vector2<T>::sub(const T* _v)
+template <typename T>
+inline void vector2<T>::sub(const T* _v)
{
- x -= _v[0] ; y -= _v[1] ;
+ x -= _v[0];
+ y -= _v[1];
}
-template<typename T> inline
-void vector2<T>::sub(const T& _x, const T& _y)
+template <typename T>
+inline void vector2<T>::sub(const T& _x, const T& _y)
{
- x -= _x ; y -= _y ;
+ x -= _x;
+ y -= _y;
}
-template<typename T> inline
-vector2<T>& vector2<T>::operator-=(const vector2<T>& _v)
+template <typename T>
+inline vector2<T>& vector2<T>::operator-=(const vector2<T>& _v)
{
- x -= _v.x ; y -= _v.y ;
+ x -= _v.x;
+ y -= _v.y;
return *this;
}
-template<typename T> inline
-void vector2<T>::mult(const T& val)
+template <typename T>
+inline void vector2<T>::mult(const T& val)
{
- x *= val ; y *= val ;
+ x *= val;
+ y *= val;
}
-template<typename T> inline
-vector2<T>& vector2<T>::operator*=(const T& _v)
+template <typename T>
+inline vector2<T>& vector2<T>::operator*=(const T& _v)
{
- x *= _v ; y *= _v ;
+ x *= _v;
+ y *= _v;
return *this;
}
-template<typename T> inline
-void vector2<T>::div(const T& val)
+template <typename T>
+inline void vector2<T>::div(const T& val)
{
- x /= val ; y /= val ;
+ x /= val;
+ y /= val;
}
-template<typename T> inline
-vector2<T>& vector2<T>::operator/=(const T& _v)
+template <typename T>
+inline vector2<T>& vector2<T>::operator/=(const T& _v)
{
- x /= _v ; y /= _v ;
+ x /= _v;
+ y /= _v;
return *this;
}
-template<typename T> inline
-vector2<T> vector2<T>::operator-(void) const
+template <typename T>
+inline vector2<T> vector2<T>::operator-(void) const
{
- return vector2<T>( -x , -y );
+ return vector2<T>(-x, -y);
}
-template<typename T> inline
-bool vector2<T>::is_zero(void) const
+template <typename T>
+inline bool vector2<T>::is_zero(void) const
{
T zero = static_cast<T>(0);
- if( x == zero && y == zero ) return true;
- else return false;
+ if (x == zero && y == zero)
+ return true;
+ else
+ return false;
}
-template<typename T> inline
-void vector2<T>::normalize(void)
+template <typename T>
+inline void vector2<T>::normalize(void)
{
- if( is_zero() )return;
+ if (is_zero())
+ return;
(*this) /= length();
}
-template<typename T> inline
-vector2<T> vector2<T>::get_normalize(void) const
+template <typename T>
+inline vector2<T> vector2<T>::get_normalize(void) const
{
vector2<T> tmp = *this;
tmp.normalize();
return tmp;
}
-template<typename T> inline
-void vector2<T>::perpendicular(void)
+template <typename T>
+inline void vector2<T>::perpendicular(void)
{
T tx = x;
T ty = y;
- set( -ty , tx );
+ set(-ty, tx);
}
-template<typename T> inline
-vector2<T> vector2<T>::get_perpendicular(void) const
+template <typename T>
+inline vector2<T> vector2<T>::get_perpendicular(void) const
{
vector2<T> perp = (*this);
perp.perpendicular();
return perp;
}
-template<typename T> inline
-void vector2<T>::reverse_perpendicular(void)
+template <typename T>
+inline void vector2<T>::reverse_perpendicular(void)
{
T tx = x;
T ty = y;
- set( ty , -tx );
+ set(ty, -tx);
}
-template<typename T> inline
-vector2<T> vector2<T>::get_reverse_perpendicular(void) const
+template <typename T>
+inline vector2<T> vector2<T>::get_reverse_perpendicular(void) const
{
vector2<T> rev_perp = (*this);
rev_perp.reverse_perpendicular();
return rev_perp;
}
-template<typename T> inline
-T vector2<T>::length(void) const
+template <typename T>
+inline T vector2<T>::length(void) const
{
- return sqrt( square_length() );
+ return sqrt(square_length());
}
-template<typename T> inline
-T vector2<T>::square_length(void) const
+template <typename T>
+inline T vector2<T>::square_length(void) const
{
- return x * x + y * y ;
+ return x * x + y * y;
}
-template<typename T> inline
-void vector2<T>::rotate(const T& angle)
+template <typename T>
+inline void vector2<T>::rotate(const T& angle)
{
- T c = cos(angle) , s = sin(angle);
- T tx = x * c - y * s ;
- T ty = x * s + y * c ;
- x = tx ; y = ty ;
+ T c = cos(angle), s = sin(angle);
+ T tx = x * c - y * s;
+ T ty = x * s + y * c;
+ x = tx;
+ y = ty;
}
// friend operations
-template<typename T> inline
-vector2<T> operator+(const vector2<T>& _a, const vector2<T>& _b)
+template <typename T>
+inline vector2<T> operator+(const vector2<T>& _a, const vector2<T>& _b)
{
- vector2<T> t = _a ; t += _b ; return t ;
+ vector2<T> t = _a;
+ t += _b;
+ return t;
}
-template<typename T> inline
-vector2<T> operator-(const vector2<T>& _a, const vector2<T>& _b)
+template <typename T>
+inline vector2<T> operator-(const vector2<T>& _a, const vector2<T>& _b)
{
- vector2<T> t = _a ; t -= _b ; return t ;
+ vector2<T> t = _a;
+ t -= _b;
+ return t;
}
-template<typename T> inline
-vector2<T> operator*(const vector2<T>& _v, const T& _t)
+template <typename T>
+inline vector2<T> operator*(const vector2<T>& _v, const T& _t)
{
- vector2<T> t = _v ; t *= _t ; return t ;
+ vector2<T> t = _v;
+ t *= _t;
+ return t;
}
-template<typename T> inline
-vector2<T> operator*(const T& _t, const vector2<T>& _v)
+template <typename T>
+inline vector2<T> operator*(const T& _t, const vector2<T>& _v)
{
- vector2<T> t = _v ; t *= _t ; return t ;
+ vector2<T> t = _v;
+ t *= _t;
+ return t;
}
-template<typename T> inline
-vector2<T> operator/(const vector2<T>& _v, const T& _t)
+template <typename T>
+inline vector2<T> operator/(const vector2<T>& _v, const T& _t)
{
- vector2<T> t = _v ; t /= _t ; return t ;
+ vector2<T> t = _v;
+ t /= _t;
+ return t;
}
namespace lm
{
-template<typename T>
+template <typename T>
class vector3 : public tuple3<T>
{
public:
- vector3(void) : tuple3<T>( T(0) , T(0) , T(0) ) {}
- vector3( const T& _x, const T& _y, const T& _z ) : tuple3<T>( _x , _y , _z ) {}
- vector3( const vector3<T>& _v ) : tuple3<T>( _v.x , _v.y , _v.z ) {}
- vector3( const T* _v ) : tuple3<T>( _v ) {}
+ vector3(void) : tuple3<T>(T(0), T(0), T(0)) {}
+ vector3(const T& _x, const T& _y, const T& _z) : tuple3<T>(_x, _y, _z) {}
+ vector3(const vector3<T>& _v) : tuple3<T>(_v.x, _v.y, _v.z) {}
+ vector3(const T* _v) : tuple3<T>(_v) {}
- template<typename U>
+ template <typename U>
operator vector3<U>(void) const
{
- return vector3<U>( static_cast<U>(x) , static_cast<U>(y) , static_cast<U>(z) );
+ return vector3<U>(static_cast<U>(x), static_cast<U>(y), static_cast<U>(z));
}
void set_zero(void);
static vector3<T> get_zero(void);
- void add( const vector3<T>& _v );
- void add( const T* _v );
- void add( const T& _x, const T& _y, const T& _z );
- vector3<T>& operator+=( const vector3<T>& _v );
+ void add(const vector3<T>& _v);
+ void add(const T* _v);
+ void add(const T& _x, const T& _y, const T& _z);
+ vector3<T>& operator+=(const vector3<T>& _v);
- void sub( const vector3<T>& _v );
- void sub( const T* _v );
- void sub( const T& _x, const T& _y, const T& _z );
- vector3<T>& operator-=( const vector3<T>& _v );
+ void sub(const vector3<T>& _v);
+ void sub(const T* _v);
+ void sub(const T& _x, const T& _y, const T& _z);
+ vector3<T>& operator-=(const vector3<T>& _v);
- vector3<T>& operator*=( const T& val );
- vector3<T>& operator/=( const T& val );
+ vector3<T>& operator*=(const T& val);
+ vector3<T>& operator/=(const T& val);
vector3<T> operator-(void) const;
T square_length(void) const;
- void rotate_x( const T& angle );
- void rotate_y( const T& angle );
- void rotate_z( const T& angle );
- void rotate( const T& angle, const vector3<T>& axis );
+ void rotate_x(const T& angle);
+ void rotate_y(const T& angle);
+ void rotate_z(const T& angle);
+ void rotate(const T& angle, const vector3<T>& axis);
- vector3<T> get_rotate_x( const T& angle ) const;
- vector3<T> get_rotate_y( const T& angle ) const;
- vector3<T> get_rotate_z( const T& angle ) const;
- vector3<T> get_rotate( const T& angle, const vector3<T>& axis ) const;
+ vector3<T> get_rotate_x(const T& angle) const;
+ vector3<T> get_rotate_y(const T& angle) const;
+ vector3<T> get_rotate_z(const T& angle) const;
+ vector3<T> get_rotate(const T& angle, const vector3<T>& axis) const;
T operator*(const vector3<T>& _v) const
typedef vector3<float> vec3f;
-// global method
+// global method
-template<typename T> inline
-T dot(const vector3<T>& _a, const vector3<T>& _b)
+template <typename T>
+inline T dot(const vector3<T>& _a, const vector3<T>& _b)
{
return
_a.x * _b.x +
_a.z * _b.z;
}
-template<typename T> inline
-vector3<T> cross(const vector3<T>& _a, const vector3<T>& _b)
+template <typename T>
+inline vector3<T> cross(const vector3<T>& _a, const vector3<T>& _b)
{
vector3<T> ret;
ret.x = _a.y * _b.z - _a.z * _b.y;
}
//! \83X\83J\83\893\8fd\90Ï ( = { ( a x b )\81Ec } = { a\81E( b x c ) } )
-template<typename T> inline
-float scholar_triple(const vector3<T>& _a, const vector3<T>& _b, const vector3<T>& _c)
+template <typename T>
+inline float scholar_triple(const vector3<T>& _a, const vector3<T>& _b, const vector3<T>& _c)
{
return dot(cross(_a, _b), c);
}
// implements
-template<typename T> inline
-void vector3<T>::set_zero(void)
+template <typename T>
+inline void vector3<T>::set_zero(void)
{
- this->set( T(0) , T(0) , T(0) );
+ this->set(T(0), T(0), T(0));
}
-template<typename T> inline
-vector3<T> vector3<T>::get_zero(void)
+template <typename T>
+inline vector3<T> vector3<T>::get_zero(void)
{
- return vector3<T>( T(0) , T(0) , T(0) );
+ return vector3<T>(T(0), T(0), T(0));
}
-template<typename T> inline
-void vector3<T>::add(const vector3<T>& _v)
+template <typename T>
+inline void vector3<T>::add(const vector3<T>& _v)
{
x += _v.x;
y += _v.y;
z += _v.z;
}
-template<typename T> inline
-void vector3<T>::add(const T* _v)
+template <typename T>
+inline void vector3<T>::add(const T* _v)
{
x += _v[0];
y += _v[1];
z += _v[2];
}
-template<typename T> inline
-void vector3<T>::add(const T& _x, const T& _y, const T& _z)
+template <typename T>
+inline void vector3<T>::add(const T& _x, const T& _y, const T& _z)
{
x += _x;
y += _y;
z += _z;
}
-template<typename T> inline
-vector3<T>& vector3<T>::operator+=(const vector3<T>& _v)
+template <typename T>
+inline vector3<T>& vector3<T>::operator+=(const vector3<T>& _v)
{
x += _v.x;
y += _v.y;
}
-template<typename T> inline
-void vector3<T>::sub(const vector3<T>& _v)
+template <typename T>
+inline void vector3<T>::sub(const vector3<T>& _v)
{
x -= _v.x;
y -= _v.y;
z -= _v.z;
}
-template<typename T> inline
-void vector3<T>::sub(const T* _v)
+template <typename T>
+inline void vector3<T>::sub(const T* _v)
{
x -= _v[0];
y -= _v[1];
z -= _v[2];
}
-template<typename T> inline
-void vector3<T>::sub(const T& _x, const T& _y, const T& _z)
+template <typename T>
+inline void vector3<T>::sub(const T& _x, const T& _y, const T& _z)
{
x -= _x;
y -= _y;
z -= _z;
}
-template<typename T> inline
-vector3<T>& vector3<T>::operator-=(const vector3<T>& _v)
+template <typename T>
+inline vector3<T>& vector3<T>::operator-=(const vector3<T>& _v)
{
x -= _v.x;
y -= _v.y;
}
-template<typename T> inline
-vector3<T>& vector3<T>::operator*=(const T& val)
+template <typename T>
+inline vector3<T>& vector3<T>::operator*=(const T& val)
{
x *= val;
y *= val;
}
-template<typename T> inline
-vector3<T>& vector3<T>::operator/=(const T& val)
+template <typename T>
+inline vector3<T>& vector3<T>::operator/=(const T& val)
{
x /= val;
y /= val;
}
-template<typename T> inline
-vector3<T> vector3<T>::operator-(void) const
+template <typename T>
+inline vector3<T> vector3<T>::operator-(void) const
{
- return vector3<T>( -x , -y , -z );
+ return vector3<T>(-x, -y, -z);
}
-
-template<typename T> inline
-bool vector3<T>::is_zero(void) const
+template <typename T>
+inline bool vector3<T>::is_zero(void) const
{
T zero = static_cast<T>(0);
- if( x == zero && y == zero && z == zero ) return true;
- else return false;
+ if (x == zero && y == zero && z == zero)
+ return true;
+ else
+ return false;
}
-template<typename T> inline
-void vector3<T>::normalize(void)
+template <typename T>
+inline void vector3<T>::normalize(void)
{
- if( is_zero() )return;
+ if (is_zero())
+ return;
(*this) /= length();
}
-template<typename T> inline
-vector3<T> vector3<T>::get_normalize(void) const
+template <typename T>
+inline vector3<T> vector3<T>::get_normalize(void) const
{
vector3<T> tmp = *this;
tmp.normalize();
return tmp;
}
-template<typename T> inline
-T vector3<T>::length(void) const
+template <typename T>
+inline T vector3<T>::length(void) const
{
- return sqrt( square_length() );
+ return sqrt(square_length());
}
-template<typename T> inline
-T vector3<T>::square_length(void) const
+template <typename T>
+inline T vector3<T>::square_length(void) const
{
- return x * x + y * y + z * z ;
+ return x * x + y * y + z * z;
}
-template<typename T> inline
-void vector3<T>::rotate_x(const T& angle)
+template <typename T>
+inline void vector3<T>::rotate_x(const T& angle)
{
T c = cos(angle);
T s = sin(angle);
z = tz;
}
-template<typename T> inline
-void vector3<T>::rotate_y(const T& angle)
+template <typename T>
+inline void vector3<T>::rotate_y(const T& angle)
{
T c = cos(angle);
T s = sin(angle);
x = tx;
}
-template<typename T> inline
-void vector3<T>::rotate_z(const T& angle)
+template <typename T>
+inline void vector3<T>::rotate_z(const T& angle)
{
T c = cos(angle);
T s = sin(angle);
y = ty;
}
-template<typename T> inline
-void vector3<T>::rotate(const T& angle, const vector3<T>& axis)
+template <typename T>
+inline void vector3<T>::rotate(const T& angle, const vector3<T>& axis)
{
- T c = cos(angle); T s = sin(angle);
- T mc = T(1) - c ;
+ T c = cos(angle);
+ T s = sin(angle);
+ T mc = T(1) - c;
const T& ax = axis.x;
const T& ay = axis.y;
T ty = y;
T tz = z;
- x = ( ax * ax * mc + c ) * tx + ( ax * ay * mc - az * s ) * ty + ( ax * az * mc + ay * s ) * tz ;
- y = ( ay * ax * mc + az * s ) * tx + ( ay * ay * mc + c ) * ty + ( ay * az * mc - ax * s ) * tz ;
- z = ( az * ax * mc - ay * s ) * tx + ( az * ay * mc + ax * s ) * ty + ( az * az * mc + c ) * tz ;
+ x = (ax * ax * mc + c) * tx + (ax * ay * mc - az * s) * ty + (ax * az * mc + ay * s) * tz;
+ y = (ay * ax * mc + az * s) * tx + (ay * ay * mc + c) * ty + (ay * az * mc - ax * s) * tz;
+ z = (az * ax * mc - ay * s) * tx + (az * ay * mc + ax * s) * ty + (az * az * mc + c) * tz;
}
-template<typename T> inline
-vector3<T> vector3<T>::get_rotate_x( const T& angle ) const
+template <typename T>
+inline vector3<T> vector3<T>::get_rotate_x(const T& angle) const
{
vector3<T> t = *this;
- t.rotate_x( angle );
+ t.rotate_x(angle);
return t;
}
-template<typename T> inline
-vector3<T> vector3<T>::get_rotate_y( const T& angle ) const
+template <typename T>
+inline vector3<T> vector3<T>::get_rotate_y(const T& angle) const
{
vector3<T> t = *this;
- t.rotate_y( angle );
+ t.rotate_y(angle);
return t;
}
-template<typename T> inline
-vector3<T> vector3<T>::get_rotate_z( const T& angle ) const
+template <typename T>
+inline vector3<T> vector3<T>::get_rotate_z(const T& angle) const
{
vector3<T> t = *this;
- t.rotate_z( angle );
+ t.rotate_z(angle);
return t;
}
-template<typename T> inline
-vector3<T> vector3<T>::get_rotate( const T& angle, const vector3<T>& axis ) const
+template <typename T>
+inline vector3<T> vector3<T>::get_rotate(const T& angle, const vector3<T>& axis) const
{
vector3<T> t = *this;
- t.rotate( angle , axis );
+ t.rotate(angle, axis);
return t;
}
// friend operations
-template<typename T> inline
-vector3<T> operator+(const vector3<T>& _a, const vector3<T>& _b)
+template <typename T>
+inline vector3<T> operator+(const vector3<T>& _a, const vector3<T>& _b)
{
vector3<T> t = _a;
t += _b;
return t;
}
-template<typename T> inline
-vector3<T> operator-(const vector3<T>& _a, const vector3<T>& _b)
+template <typename T>
+inline vector3<T> operator-(const vector3<T>& _a, const vector3<T>& _b)
{
vector3<T> t = _a;
t -= _b;
return t;
}
-template<typename T> inline
-vector3<T> operator*(const vector3<T>& _v, const T& _t)
+template <typename T>
+inline vector3<T> operator*(const vector3<T>& _v, const T& _t)
{
vector3<T> t = _v;
t *= _t;
return t;
}
-template<typename T> inline
-vector3<T> operator*(const T& _t, const vector3<T>& _v)
+template <typename T>
+inline vector3<T> operator*(const T& _t, const vector3<T>& _v)
{
vector3<T> t = _v;
t *= _t;
return t;
}
-template<typename T> inline
-vector3<T> operator/(const vector3<T>& _v, const T& _t)
+template <typename T>
+inline vector3<T> operator/(const vector3<T>& _v, const T& _t)
{
vector3<T> t = _v;
t /= _t;