diff --git a/Code/OysterMath/OysterMath.h b/Code/OysterMath/OysterMath.h index 3770bf02..dd4655c4 100644 --- a/Code/OysterMath/OysterMath.h +++ b/Code/OysterMath/OysterMath.h @@ -67,7 +67,7 @@ inline ::Oyster::Math::Float2 & operator *= ( ::Oyster::Math::Float2 &left, cons } inline ::Oyster::Math::Float2 operator * ( const ::Oyster::Math::Float2 &left, const ::Oyster::Math::Float2 &right ) -{ return ::Oyster::Math::Float2(left) *= right; } +{ return left.PiecewiseMultiplication( right; } inline ::Oyster::Math::Float2 operator * ( const ::Oyster::Math::Float &left, const ::Oyster::Math::Float2 &right ) { return ::Oyster::Math::Float2(right) *= left; } @@ -81,7 +81,7 @@ inline ::Oyster::Math::Float3 & operator *= ( ::Oyster::Math::Float3 &left, cons } inline ::Oyster::Math::Float3 operator * ( const ::Oyster::Math::Float3 &left, const ::Oyster::Math::Float3 &right ) -{ return ::Oyster::Math::Float3(left) *= right; } +{ return left.PiecewiseMultiplication( right ); } inline ::Oyster::Math::Float3 operator * ( const ::Oyster::Math::Float &left, const ::Oyster::Math::Float3 &right ) { return ::Oyster::Math::Float3(right) *= left; } @@ -96,7 +96,7 @@ inline ::Oyster::Math::Float4 & operator *= ( ::Oyster::Math::Float4 &left, cons } inline ::Oyster::Math::Float4 operator * ( const ::Oyster::Math::Float4 &left, const ::Oyster::Math::Float4 &right ) -{ return ::Oyster::Math::Float4(left) *= right; } +{ return left.PiecewiseMultiplication( right ); } inline ::Oyster::Math::Float4 operator * ( const ::Oyster::Math::Float &left, const ::Oyster::Math::Float4 &right ) { return ::Oyster::Math::Float4(right) *= left; } diff --git a/Code/OysterMath/Vector.h b/Code/OysterMath/Vector.h index 901ea5e4..d6ab69d9 100644 --- a/Code/OysterMath/Vector.h +++ b/Code/OysterMath/Vector.h @@ -57,6 +57,9 @@ namespace LinearAlgebra ScalarType GetMagnitude( ) const; ScalarType Dot( const Vector2 &vector ) const; + //! @return (a.x * b.x, a.y * b.y) + Vector2 PiecewiseMultiplication( const Vector2 &vector ) const; + Vector2 & Normalize( ); Vector2 GetNormalized( ) const; }; @@ -112,6 +115,9 @@ namespace LinearAlgebra ScalarType Dot( const Vector3 &vector ) const; Vector3 Cross( const Vector3 &vector ) const; + //! @return (a.x * b.x, a.y * b.y, a.z * b.z) + Vector3 PiecewiseMultiplication( const Vector3 &vector ) const; + Vector3 & Normalize( ); Vector3 GetNormalized( ) const; }; @@ -169,6 +175,9 @@ namespace LinearAlgebra ScalarType GetMagnitude( ) const; ScalarType Dot( const Vector4 &vector ) const; + //! @return (a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w ) + Vector4 PiecewiseMultiplication( const Vector4 &vector ) const; + Vector4 & Normalize( ); Vector4 GetNormalized( ) const; }; @@ -184,22 +193,22 @@ namespace LinearAlgebra template const Vector2 Vector2::standard_unit_y = Vector2( 0, 1 ); template - Vector2::Vector2( ) : x(), y() {} + inline Vector2::Vector2( ) : x(), y() {} template - Vector2::Vector2( const Vector2 &vector ) + inline Vector2::Vector2( const Vector2 &vector ) { this->x = vector.x; this->y = vector.y; } template - Vector2::Vector2( const ScalarType &_element ) + inline Vector2::Vector2( const ScalarType &_element ) { this->x = this->y = _element; } template - Vector2::Vector2( const ScalarType _element[2] ) + inline Vector2::Vector2( const ScalarType _element[2] ) { this->x = _element[0]; this->y = _element[1]; } template - Vector2::Vector2( const ScalarType &_x, const ScalarType &_y ) + inline Vector2::Vector2( const ScalarType &_x, const ScalarType &_y ) { this->x = _x; this->y = _y; } template @@ -227,7 +236,7 @@ namespace LinearAlgebra { return this->element[i]; } template - Vector2 & Vector2::operator = ( const Vector2 &vector ) + inline Vector2 & Vector2::operator = ( const Vector2 &vector ) { this->element[0] = vector.element[0]; this->element[1] = vector.element[1]; @@ -235,7 +244,7 @@ namespace LinearAlgebra } template - Vector2 & Vector2::operator = ( const ScalarType _element[2] ) + inline Vector2 & Vector2::operator = ( const ScalarType _element[2] ) { this->element[0] = _element[0]; this->element[1] = _element[1]; @@ -243,7 +252,7 @@ namespace LinearAlgebra } template - Vector2 & Vector2::operator *= ( const ScalarType &scalar ) + inline Vector2 & Vector2::operator *= ( const ScalarType &scalar ) { this->element[0] *= scalar; this->element[1] *= scalar; @@ -251,7 +260,7 @@ namespace LinearAlgebra } template - Vector2 & Vector2::operator /= ( const ScalarType &scalar ) + inline Vector2 & Vector2::operator /= ( const ScalarType &scalar ) { this->element[0] /= scalar; this->element[1] /= scalar; @@ -259,7 +268,7 @@ namespace LinearAlgebra } template - Vector2 & Vector2::operator += ( const Vector2 &vector ) + inline Vector2 & Vector2::operator += ( const Vector2 &vector ) { this->element[0] += vector.element[0]; this->element[1] += vector.element[1]; @@ -267,7 +276,7 @@ namespace LinearAlgebra } template - Vector2 & Vector2::operator -= ( const Vector2 &vector ) + inline Vector2 & Vector2::operator -= ( const Vector2 &vector ) { this->element[0] -= vector.element[0]; this->element[1] -= vector.element[1]; @@ -295,7 +304,7 @@ namespace LinearAlgebra { return Vector2(-this->x, -this->y); } template - bool Vector2::operator == ( const Vector2 &vector ) const + inline bool Vector2::operator == ( const Vector2 &vector ) const { if( this->x != vector.x ) return false; if( this->y != vector.y ) return false; @@ -303,7 +312,7 @@ namespace LinearAlgebra } template - bool Vector2::operator != ( const Vector2 &vector ) const + inline bool Vector2::operator != ( const Vector2 &vector ) const { if( this->x != vector.x ) return true; if( this->y != vector.y ) return true; @@ -319,7 +328,7 @@ namespace LinearAlgebra { return (ScalarType) ::sqrt( this->Dot(*this) ); } template - ScalarType Vector2::Dot( const Vector2 &vector ) const + inline ScalarType Vector2::Dot( const Vector2 &vector ) const { ScalarType value = 0; value += this->element[0] * vector.element[0]; @@ -327,6 +336,12 @@ namespace LinearAlgebra return value; } + template + inline Vector2 Vector2::PiecewiseMultiplication( const Vector2 &vector ) const + { + return Vector2( this->x * vector.x, this->y * vector.y ); + } + template inline Vector2 & Vector2::Normalize( ) { return (*this) /= this->GetLength(); } @@ -343,26 +358,26 @@ namespace LinearAlgebra template const Vector3 Vector3::standard_unit_z = Vector3( 0, 0, 1 ); template - Vector3::Vector3( ) : x(), y(), z() {} + inline Vector3::Vector3( ) : x(), y(), z() {} template - Vector3::Vector3( const Vector3 &vector ) + inline Vector3::Vector3( const Vector3 &vector ) { this->x = vector.x; this->y = vector.y; this->z = vector.z; } template - Vector3::Vector3( const Vector2 &vector, const ScalarType &_z ) + inline Vector3::Vector3( const Vector2 &vector, const ScalarType &_z ) { this->x = vector.x; this->y = vector.y; this->z = _z; } template - Vector3::Vector3( const ScalarType &_element ) + inline Vector3::Vector3( const ScalarType &_element ) { this->x = this->y = this->z = _element; } template - Vector3::Vector3( const ScalarType _element[3] ) + inline Vector3::Vector3( const ScalarType _element[3] ) { this->x = _element[0]; this->y = _element[1]; this->z = _element[2]; } template - Vector3::Vector3( const ScalarType &_x, const ScalarType &_y, const ScalarType &_z ) + inline Vector3::Vector3( const ScalarType &_x, const ScalarType &_y, const ScalarType &_z ) { this->x = _x; this->y = _y; this->z = _z; } template @@ -382,7 +397,7 @@ namespace LinearAlgebra { return this->element[i]; } template - Vector3 & Vector3::operator = ( const Vector3 &vector ) + inline Vector3 & Vector3::operator = ( const Vector3 &vector ) { this->element[0] = vector.element[0]; this->element[1] = vector.element[1]; @@ -391,7 +406,7 @@ namespace LinearAlgebra } template - Vector3 & Vector3::operator = ( const ScalarType element[3] ) + inline Vector3 & Vector3::operator = ( const ScalarType element[3] ) { this->element[0] = element[0]; this->element[1] = element[1]; @@ -400,7 +415,7 @@ namespace LinearAlgebra } template - Vector3 & Vector3::operator *= ( const ScalarType &scalar ) + inline Vector3 & Vector3::operator *= ( const ScalarType &scalar ) { this->element[0] *= scalar; this->element[1] *= scalar; @@ -409,7 +424,7 @@ namespace LinearAlgebra } template - Vector3 & Vector3::operator /= ( const ScalarType &scalar ) + inline Vector3 & Vector3::operator /= ( const ScalarType &scalar ) { this->element[0] /= scalar; this->element[1] /= scalar; @@ -418,7 +433,7 @@ namespace LinearAlgebra } template - Vector3 & Vector3::operator += ( const Vector3 &vector ) + inline Vector3 & Vector3::operator += ( const Vector3 &vector ) { this->element[0] += vector.element[0]; this->element[1] += vector.element[1]; @@ -427,7 +442,7 @@ namespace LinearAlgebra } template - Vector3 & Vector3::operator -= ( const Vector3 &vector ) + inline Vector3 & Vector3::operator -= ( const Vector3 &vector ) { this->element[0] -= vector.element[0]; this->element[1] -= vector.element[1]; @@ -456,7 +471,7 @@ namespace LinearAlgebra { return Vector3(-this->x, -this->y, -this->z); } template - bool Vector3::operator == ( const Vector3 &vector ) const + inline bool Vector3::operator == ( const Vector3 &vector ) const { if( this->x != vector.x ) return false; if( this->y != vector.y ) return false; @@ -465,7 +480,7 @@ namespace LinearAlgebra } template - bool Vector3::operator != ( const Vector3 &vector ) const + inline bool Vector3::operator != ( const Vector3 &vector ) const { if( this->x != vector.x ) return true; if( this->y != vector.y ) return true; @@ -482,7 +497,7 @@ namespace LinearAlgebra { return (ScalarType) ::sqrt( this->Dot(*this) ); } template - ScalarType Vector3::Dot( const Vector3 &vector ) const + inline ScalarType Vector3::Dot( const Vector3 &vector ) const { ScalarType value = 0; value += this->element[0] * vector.element[0]; @@ -492,13 +507,19 @@ namespace LinearAlgebra } template - Vector3 Vector3::Cross( const Vector3 &vector ) const + inline Vector3 Vector3::Cross( const Vector3 &vector ) const { return Vector3( (this->y*vector.z) - (this->z*vector.y), (this->z*vector.x) - (this->x*vector.z), (this->x*vector.y) - (this->y*vector.x) ); } + template + inline Vector3 Vector3::PiecewiseMultiplication( const Vector3 &vector ) const + { + return Vector3( this->x * vector.x, this->y * vector.y, this->z * vector.z ); + } + template inline Vector3 & Vector3::Normalize( ) { return (*this) /= this->GetLength(); } @@ -516,30 +537,30 @@ namespace LinearAlgebra template const Vector4 Vector4::standard_unit_w = Vector4( 0, 0, 0, 1 ); template - Vector4::Vector4( ) : x(), y(), z(), w() {} + inline Vector4::Vector4( ) : x(), y(), z(), w() {} template - Vector4::Vector4( const Vector4 &vector ) + inline Vector4::Vector4( const Vector4 &vector ) { this->x = vector.x; this->y = vector.y; this->z = vector.z; this->w = vector.w; } template - Vector4::Vector4( const Vector3 &vector, const ScalarType &_w ) + inline Vector4::Vector4( const Vector3 &vector, const ScalarType &_w ) { this->x = vector.x; this->y = vector.y; this->z = vector.z; this->w = _w; } template - Vector4::Vector4( const Vector2 &vector, const ScalarType &_z, const ScalarType &_w ) + inline Vector4::Vector4( const Vector2 &vector, const ScalarType &_z, const ScalarType &_w ) { this->x = vector.x; this->y = vector.y; this->z = _z; this->w = _w; } template - Vector4::Vector4( const ScalarType &_element ) + inline Vector4::Vector4( const ScalarType &_element ) { this->x = this->y = this->z = this->w = _element; } template - Vector4::Vector4( const ScalarType _element[4] ) + inline Vector4::Vector4( const ScalarType _element[4] ) { this->x = _element[0]; this->y = _element[1]; this->z = _element[2]; this->w = _element[3]; } template - Vector4::Vector4( const ScalarType &_x, const ScalarType &_y, const ScalarType &_z, const ScalarType &_w ) + inline Vector4::Vector4( const ScalarType &_x, const ScalarType &_y, const ScalarType &_z, const ScalarType &_w ) { this->x = _x; this->y = _y; this->z = _z; this->w = _w; } template @@ -559,7 +580,7 @@ namespace LinearAlgebra { return this->element[i]; } template - Vector4 & Vector4::operator = ( const Vector4 &vector ) + inline Vector4 & Vector4::operator = ( const Vector4 &vector ) { this->element[0] = vector.element[0]; this->element[1] = vector.element[1]; @@ -569,7 +590,7 @@ namespace LinearAlgebra } template - Vector4 & Vector4::operator = ( const ScalarType element[4] ) + inline Vector4 & Vector4::operator = ( const ScalarType element[4] ) { this->element[0] = element[0]; this->element[1] = element[1]; @@ -579,7 +600,7 @@ namespace LinearAlgebra } template - Vector4 & Vector4::operator *= ( const ScalarType &scalar ) + inline Vector4 & Vector4::operator *= ( const ScalarType &scalar ) { this->element[0] *= scalar; this->element[1] *= scalar; @@ -589,7 +610,7 @@ namespace LinearAlgebra } template - Vector4 & Vector4::operator /= ( const ScalarType &scalar ) + inline Vector4 & Vector4::operator /= ( const ScalarType &scalar ) { this->element[0] /= scalar; this->element[1] /= scalar; @@ -599,7 +620,7 @@ namespace LinearAlgebra } template - Vector4 & Vector4::operator += ( const Vector4 &vector ) + inline Vector4 & Vector4::operator += ( const Vector4 &vector ) { this->element[0] += vector.element[0]; this->element[1] += vector.element[1]; @@ -609,7 +630,7 @@ namespace LinearAlgebra } template - Vector4 & Vector4::operator -= ( const Vector4 &vector ) + inline Vector4 & Vector4::operator -= ( const Vector4 &vector ) { this->element[0] -= vector.element[0]; this->element[1] -= vector.element[1]; @@ -639,7 +660,7 @@ namespace LinearAlgebra { return Vector4(-this->x, -this->y, -this->z, -this->w); } template - bool Vector4::operator == ( const Vector4 &vector ) const + inline bool Vector4::operator == ( const Vector4 &vector ) const { if( this->x != vector.x ) return false; if( this->y != vector.y ) return false; @@ -649,7 +670,7 @@ namespace LinearAlgebra } template - bool Vector4::operator != ( const Vector4 &vector ) const + inline bool Vector4::operator != ( const Vector4 &vector ) const { if( this->x != vector.x ) return true; if( this->y != vector.y ) return true; @@ -667,7 +688,7 @@ namespace LinearAlgebra { return (ScalarType) ::sqrt( this->Dot(*this) ); } template - ScalarType Vector4::Dot( const Vector4 &vector ) const + inline ScalarType Vector4::Dot( const Vector4 &vector ) const { ScalarType value = 0; value += this->element[0] * vector.element[0]; @@ -677,6 +698,12 @@ namespace LinearAlgebra return value; } + template + inline Vector4 Vector4::PiecewiseMultiplication( const Vector4 &vector ) const + { + return Vector4( this->x * vector.x, this->y * vector.y, this->z * vector.z, this->w * vector.w ); + } + template inline Vector4 & Vector4::Normalize( ) { return (*this) /= this->GetLength(); }