[FORMAT] rework some class coding style

This commit is contained in:
Edouard DUPIN 2014-01-08 21:25:30 +01:00
parent a61639ef29
commit b0e3b31664
6 changed files with 408 additions and 279 deletions

View File

@ -216,6 +216,24 @@ etk::CCout& etk::operator <<(etk::CCout &_os, const etk::Color<float>& _obj)
return _os; return _os;
} }
etk::CCout& etk::operator <<(etk::CCout& _os, const std::vector<etk::Color<uint8_t> >& _obj) {
for (size_t iii = 0; iii < _obj.size(); ++iii) {
if (iii != 0) {
_os << " ";
}
_os << _obj[iii];
}
return _os;
}
etk::CCout& etk::operator <<(etk::CCout& _os, const std::vector<etk::Color<float> >& _obj) {
for (size_t iii = 0; iii < _obj.size(); ++iii) {
if (iii != 0) {
_os << " ";
}
_os << _obj[iii];
}
return _os;
}

View File

@ -242,6 +242,8 @@ namespace etk {
etk::CCout& operator <<(etk::CCout &_os, const Color<uint8_t>& _obj); etk::CCout& operator <<(etk::CCout &_os, const Color<uint8_t>& _obj);
//! @not-in-doc //! @not-in-doc
etk::CCout& operator <<(etk::CCout &_os, const Color<float>& _obj); etk::CCout& operator <<(etk::CCout &_os, const Color<float>& _obj);
etk::CCout& operator <<(etk::CCout& _os, const std::vector<Color<uint8_t> >& _obj);
etk::CCout& operator <<(etk::CCout& _os, const std::vector<Color<float> >& _obj);
/** /**
* @brief List of all native define colors ... * @brief List of all native define colors ...
*/ */

View File

@ -8,8 +8,7 @@
#include <etk/math/Vector2D.h> #include <etk/math/Vector2D.h>
etk::CCout& etk::operator <<(etk::CCout& _os, const etk::Vector2D<int32_t>& _obj) etk::CCout& etk::operator <<(etk::CCout& _os, const etk::Vector2D<int32_t>& _obj) {
{
_os << "("; _os << "(";
_os << _obj.x(); _os << _obj.x();
_os << ","; _os << ",";
@ -18,8 +17,7 @@ etk::CCout& etk::operator <<(etk::CCout& _os, const etk::Vector2D<int32_t>& _obj
return _os; return _os;
} }
etk::CCout& etk::operator <<(etk::CCout& _os, const etk::Vector2D<float>& _obj) etk::CCout& etk::operator <<(etk::CCout& _os, const etk::Vector2D<float>& _obj) {
{
_os << "("; _os << "(";
_os << _obj.x(); _os << _obj.x();
_os << ","; _os << ",";
@ -28,8 +26,7 @@ etk::CCout& etk::operator <<(etk::CCout& _os, const etk::Vector2D<float>& _obj)
return _os; return _os;
} }
etk::CCout& etk::operator <<(etk::CCout& _os, const etk::Vector2D<uint32_t>& _obj) etk::CCout& etk::operator <<(etk::CCout& _os, const etk::Vector2D<uint32_t>& _obj) {
{
_os << "("; _os << "(";
_os << _obj.x(); _os << _obj.x();
_os << ","; _os << ",";
@ -38,8 +35,7 @@ etk::CCout& etk::operator <<(etk::CCout& _os, const etk::Vector2D<uint32_t>& _ob
return _os; return _os;
} }
etk::CCout& etk::operator <<(etk::CCout& _os, const etk::Vector2D<bool>& _obj) etk::CCout& etk::operator <<(etk::CCout& _os, const etk::Vector2D<bool>& _obj) {
{
_os << "("; _os << "(";
_os << _obj.x(); _os << _obj.x();
_os << ","; _os << ",";
@ -48,6 +44,45 @@ etk::CCout& etk::operator <<(etk::CCout& _os, const etk::Vector2D<bool>& _obj)
return _os; return _os;
} }
etk::CCout& etk::operator <<(etk::CCout& _os, const std::vector<vec2 >& _obj) {
for (size_t iii = 0; iii < _obj.size(); ++iii) {
if (iii != 0) {
_os << " ";
}
_os << _obj[iii];
}
return _os;
}
etk::CCout& etk::operator <<(etk::CCout& _os, const std::vector<ivec2 >& _obj) {
for (size_t iii = 0; iii < _obj.size(); ++iii) {
if (iii != 0) {
_os << " ";
}
_os << _obj[iii];
}
return _os;
}
etk::CCout& etk::operator <<(etk::CCout& _os, const std::vector<uivec2 >& _obj) {
for (size_t iii = 0; iii < _obj.size(); ++iii) {
if (iii != 0) {
_os << " ";
}
_os << _obj[iii];
}
return _os;
}
etk::CCout& etk::operator <<(etk::CCout& _os, const std::vector<bvec2 >& _obj) {
for (size_t iii = 0; iii < _obj.size(); ++iii) {
if (iii != 0) {
_os << " ";
}
_os << _obj[iii];
}
return _os;
}
namespace etk { namespace etk {
template<> Vector2D<bool>::operator std::string(void) const { template<> Vector2D<bool>::operator std::string(void) const {

View File

@ -35,136 +35,145 @@ namespace etk {
m_floats[0] = _x; m_floats[0] = _x;
m_floats[1] = _y; m_floats[1] = _y;
}; };
Vector2D(const Vector2D<double>& obj) { m_floats[0] = (T)obj.x(); m_floats[1] = (T)obj.y(); }; Vector2D(const Vector2D<double>& _obj) {
Vector2D(const Vector2D<float>& obj) { m_floats[0] = (T)obj.x(); m_floats[1] = (T)obj.y(); }; m_floats[0] = (T)_obj.x();
Vector2D(const Vector2D<int32_t>& obj) { m_floats[0] = (T)obj.x(); m_floats[1] = (T)obj.y(); }; m_floats[1] = (T)_obj.y();
Vector2D(const std::string& str); };
Vector2D(const std::u32string& str); Vector2D(const Vector2D<float>& _obj) {
m_floats[0] = (T)_obj.x();
m_floats[1] = (T)_obj.y();
};
Vector2D(const Vector2D<int32_t>& _obj) {
m_floats[0] = (T)_obj.x();
m_floats[1] = (T)_obj.y();
};
Vector2D(const std::string& _str);
Vector2D(const std::u32string& _str);
~Vector2D(void) { }; ~Vector2D(void) { };
/* **************************************************** /* ****************************************************
* = assigment * = assigment
*****************************************************/ *****************************************************/
const Vector2D<T>& operator= (const Vector2D<T>& obj ) { const Vector2D<T>& operator= (const Vector2D<T>& _obj ) {
m_floats[0] = obj.m_floats[0]; m_floats[0] = _obj.m_floats[0];
m_floats[1] = obj.m_floats[1]; m_floats[1] = _obj.m_floats[1];
return *this; return *this;
} }
const Vector2D<T>& operator= (const T val ) { const Vector2D<T>& operator= (const T _val ) {
m_floats[0] = val; m_floats[0] = _val;
m_floats[1] = val; m_floats[1] = _val;
return *this; return *this;
} }
/* **************************************************** /* ****************************************************
* == operator * == operator
*****************************************************/ *****************************************************/
bool operator== (const Vector2D<T>& obj) const { bool operator== (const Vector2D<T>& _obj) const {
return ( (T)obj.m_floats[0] == m_floats[0] return ( (T)_obj.m_floats[0] == m_floats[0]
&& (T)obj.m_floats[1] == m_floats[1]); && (T)_obj.m_floats[1] == m_floats[1]);
} }
/* **************************************************** /* ****************************************************
* != operator * != operator
*****************************************************/ *****************************************************/
bool operator!= (const Vector2D<T>& obj) const { bool operator!= (const Vector2D<T>& _obj) const {
return ( (T)obj.m_floats[0] != m_floats[0] return ( (T)_obj.m_floats[0] != m_floats[0]
|| (T)obj.m_floats[1] != m_floats[1]); || (T)_obj.m_floats[1] != m_floats[1]);
} }
/* **************************************************** /* ****************************************************
* += operator * += operator
*****************************************************/ *****************************************************/
const Vector2D<T>& operator+= (const Vector2D<T>& obj) { const Vector2D<T>& operator+= (const Vector2D<T>& _obj) {
m_floats[0] += obj.m_floats[0]; m_floats[0] += _obj.m_floats[0];
m_floats[1] += obj.m_floats[1]; m_floats[1] += _obj.m_floats[1];
return *this; return *this;
} }
const Vector2D<T>& operator+= (const T val) { const Vector2D<T>& operator+= (const T _val) {
m_floats[0] += val; m_floats[0] += _val;
m_floats[1] += val; m_floats[1] += _val;
return *this; return *this;
} }
/* **************************************************** /* ****************************************************
* + operator * + operator
*****************************************************/ *****************************************************/
Vector2D<T> operator+ (const Vector2D<T>& obj) const { Vector2D<T> operator+ (const Vector2D<T>& _obj) const {
Vector2D<T> tmpp(m_floats[0],m_floats[1]); Vector2D<T> tmpp(m_floats[0],m_floats[1]);
tmpp.m_floats[0] += obj.m_floats[0]; tmpp.m_floats[0] += _obj.m_floats[0];
tmpp.m_floats[1] += obj.m_floats[1]; tmpp.m_floats[1] += _obj.m_floats[1];
return tmpp; return tmpp;
} }
Vector2D<T> operator+ (const T val) const { Vector2D<T> operator+ (const T _val) const {
Vector2D<T> tmpp(m_floats[0],m_floats[1]); Vector2D<T> tmpp(m_floats[0],m_floats[1]);
tmpp.m_floats[0] += val; tmpp.m_floats[0] += _val;
tmpp.m_floats[1] += val; tmpp.m_floats[1] += _val;
return tmpp; return tmpp;
} }
/* **************************************************** /* ****************************************************
* -= operator * -= operator
*****************************************************/ *****************************************************/
const Vector2D<T>& operator-= (const Vector2D<T>& obj) { const Vector2D<T>& operator-= (const Vector2D<T>& _obj) {
m_floats[0] -= obj.m_floats[0]; m_floats[0] -= _obj.m_floats[0];
m_floats[1] -= obj.m_floats[1]; m_floats[1] -= _obj.m_floats[1];
return *this; return *this;
} }
const Vector2D<T>& operator-= (const T val) { const Vector2D<T>& operator-= (const T _val) {
m_floats[0] -= val; m_floats[0] -= _val;
m_floats[1] -= val; m_floats[1] -= _val;
return *this; return *this;
} }
/* **************************************************** /* ****************************************************
* - operator * - operator
*****************************************************/ *****************************************************/
Vector2D<T> operator- (const Vector2D<T>& obj) const { Vector2D<T> operator- (const Vector2D<T>& _obj) const {
Vector2D<T> tmpp(m_floats[0],m_floats[1]); Vector2D<T> tmpp(m_floats[0],m_floats[1]);
tmpp.m_floats[0] -= obj.m_floats[0]; tmpp.m_floats[0] -= _obj.m_floats[0];
tmpp.m_floats[1] -= obj.m_floats[1]; tmpp.m_floats[1] -= _obj.m_floats[1];
return tmpp; return tmpp;
} }
Vector2D<T> operator- (const T val) const { Vector2D<T> operator- (const T _val) const {
Vector2D<T> tmpp(m_floats[0],m_floats[1]); Vector2D<T> tmpp(m_floats[0],m_floats[1]);
tmpp.m_floats[0] -= val; tmpp.m_floats[0] -= _val;
tmpp.m_floats[1] -= val; tmpp.m_floats[1] -= _val;
return tmpp; return tmpp;
} }
/* **************************************************** /* ****************************************************
* *= operator * *= operator
*****************************************************/ *****************************************************/
const Vector2D<T>& operator*= (const Vector2D<T>& obj) { const Vector2D<T>& operator*= (const Vector2D<T>& _obj) {
m_floats[0] *= obj.m_floats[0]; m_floats[0] *= _obj.m_floats[0];
m_floats[1] *= obj.m_floats[1]; m_floats[1] *= _obj.m_floats[1];
return *this; return *this;
} }
const Vector2D<T>& operator*= (const T val) { const Vector2D<T>& operator*= (const T _val) {
m_floats[0] *= val; m_floats[0] *= _val;
m_floats[1] *= val; m_floats[1] *= _val;
return *this; return *this;
} }
/* **************************************************** /* ****************************************************
* * operator * * operator
*****************************************************/ *****************************************************/
Vector2D<T> operator* (const Vector2D<T>& obj) const { Vector2D<T> operator* (const Vector2D<T>& _obj) const {
Vector2D<T> tmpp(m_floats[0],m_floats[1]); Vector2D<T> tmpp(m_floats[0],m_floats[1]);
tmpp.m_floats[0] *= obj.m_floats[0]; tmpp.m_floats[0] *= _obj.m_floats[0];
tmpp.m_floats[1] *= obj.m_floats[1]; tmpp.m_floats[1] *= _obj.m_floats[1];
return tmpp; return tmpp;
} }
Vector2D<T> operator* (const T val) const { Vector2D<T> operator* (const T _val) const {
Vector2D<T> tmpp(m_floats[0],m_floats[1]); Vector2D<T> tmpp(m_floats[0],m_floats[1]);
tmpp.m_floats[0] *= val; tmpp.m_floats[0] *= _val;
tmpp.m_floats[1] *= val; tmpp.m_floats[1] *= _val;
return tmpp; return tmpp;
} }
/* **************************************************** /* ****************************************************
* / operator * / operator
*****************************************************/ *****************************************************/
Vector2D<T> operator/ (const Vector2D<T>& obj) const{ Vector2D<T> operator/ (const Vector2D<T>& _obj) const{
Vector2D<T> tmpp(m_floats[0],m_floats[1]); Vector2D<T> tmpp(m_floats[0], m_floats[1]);
tmpp.m_floats[0] /= obj.m_floats[0]; tmpp.m_floats[0] /= _obj.m_floats[0];
tmpp.m_floats[1] /= obj.m_floats[1]; tmpp.m_floats[1] /= _obj.m_floats[1];
return tmpp; return tmpp;
} }
Vector2D<T> operator/ (const T val) const { Vector2D<T> operator/ (const T _val) const {
Vector2D<T> tmpp(m_floats[0],m_floats[1]); Vector2D<T> tmpp(m_floats[0], m_floats[1]);
tmpp.m_floats[0] /= val; tmpp.m_floats[0] /= _val;
tmpp.m_floats[1] /= val; tmpp.m_floats[1] /= _val;
return tmpp; return tmpp;
} }
/* **************************************************** /* ****************************************************
@ -175,7 +184,7 @@ namespace etk {
++m_floats[1]; ++m_floats[1];
return *this; return *this;
} }
Vector2D<T> operator++(int unused) { Vector2D<T> operator++(int _unused) {
Vector2D<T> result = *this; Vector2D<T> result = *this;
++(*this); ++(*this);
return result; return result;
@ -188,7 +197,7 @@ namespace etk {
--m_floats[1]; --m_floats[1];
return *this; return *this;
} }
Vector2D<T> operator--(int unused) { Vector2D<T> operator--(int _unused) {
Vector2D<T> result = *this; Vector2D<T> result = *this;
--(*this); --(*this);
return result; return result;
@ -197,9 +206,9 @@ namespace etk {
* @brief Return the dot product * @brief Return the dot product
* @param v The other vector in the dot product * @param v The other vector in the dot product
*/ */
btScalar dot(const Vector2D<T>& v) const { btScalar dot(const Vector2D<T>& _v) const {
return m_floats[0] * v.m_floats[0] + return m_floats[0] * _v.m_floats[0]
m_floats[1] * v.m_floats[1]; + m_floats[1] * _v.m_floats[1];
} }
/** /**
* @brief Return the length of the vector squared * @brief Return the length of the vector squared
@ -217,8 +226,8 @@ namespace etk {
* @brief Return the distance squared between the ends of this and another vector * @brief Return the distance squared between the ends of this and another vector
* This is symantically treating the vector like a point * This is symantically treating the vector like a point
*/ */
btScalar distance2(const btVector3& v) const { btScalar distance2(const btVector3& _v) const {
return (v - *this).length2(); return (_v - *this).length2();
} }
/** /**
* @brief Return the distance between the ends of this and another vector * @brief Return the distance between the ends of this and another vector
@ -311,19 +320,19 @@ namespace etk {
} }
/** /**
* @brief Set each element to the max of the current values and the values of another btVector3 * @brief Set each element to the max of the current values and the values of another btVector3
* @param other The other btVector3 to compare with * @param _other The other btVector3 to compare with
*/ */
void setMax(const Vector2D<T>& other) { void setMax(const Vector2D<T>& _other) {
btSetMax(m_floats[0], other.m_floats[0]); btSetMax(m_floats[0], _other.m_floats[0]);
btSetMax(m_floats[1], other.m_floats[1]); btSetMax(m_floats[1], _other.m_floats[1]);
} }
/** /**
* @brief Set each element to the min of the current values and the values of another btVector3 * @brief Set each element to the min of the current values and the values of another btVector3
* @param other The other btVector3 to compare with * @param _other The other btVector3 to compare with
*/ */
void setMin(const Vector2D<T>& other) { void setMin(const Vector2D<T>& _other) {
btSetMin(m_floats[0], other.m_floats[0]); btSetMin(m_floats[0], _other.m_floats[0]);
btSetMin(m_floats[1], other.m_floats[1]); btSetMin(m_floats[1], _other.m_floats[1]);
} }
void setValue(const T& _x, const T& _y) { void setValue(const T& _x, const T& _y) {
m_floats[0]=_x; m_floats[0]=_x;
@ -342,10 +351,13 @@ namespace etk {
/** /**
* @brief Debug operator To display the curent element in a Human redeable information * @brief Debug operator To display the curent element in a Human redeable information
*/ */
etk::CCout& operator <<(etk::CCout &os, const etk::Vector2D<int32_t>& obj); etk::CCout& operator <<(etk::CCout& _os, const etk::Vector2D<int32_t>& _obj);
etk::CCout& operator <<(etk::CCout &os, const etk::Vector2D<float>& obj); //! @previous
etk::CCout& operator <<(etk::CCout &os, const etk::Vector2D<uint32_t>& obj); etk::CCout& operator <<(etk::CCout& _os, const etk::Vector2D<float>& _obj);
etk::CCout& operator <<(etk::CCout &os, const etk::Vector2D<bool>& obj); //! @previous
etk::CCout& operator <<(etk::CCout& _os, const etk::Vector2D<uint32_t>& _obj);
//! @previous
etk::CCout& operator <<(etk::CCout& _os, const etk::Vector2D<bool>& _obj);
}; };
// To siplify the writing of the code ==> this permit to have the same name with the glsl language... // To siplify the writing of the code ==> this permit to have the same name with the glsl language...
typedef etk::Vector2D<float> vec2; typedef etk::Vector2D<float> vec2;
@ -362,4 +374,14 @@ inline vec2 vec2ClipInt64(const vec2& _val) {
return vec2((int64_t)_val.x(), (int64_t)_val.y()); return vec2((int64_t)_val.x(), (int64_t)_val.y());
} }
namespace etk {
etk::CCout& operator <<(etk::CCout& _os, const std::vector<vec2 >& _obj);
//! @previous
etk::CCout& operator <<(etk::CCout& _os, const std::vector<ivec2 >& _obj);
//! @previous
etk::CCout& operator <<(etk::CCout& _os, const std::vector<uivec2 >& _obj);
//! @previous
etk::CCout& operator <<(etk::CCout& _os, const std::vector<bvec2 >& _obj);
};
#endif #endif

View File

@ -57,6 +57,46 @@ etk::CCout& etk::operator <<(etk::CCout &os, const etk::Vector3D<bool> obj)
} }
etk::CCout& etk::operator <<(etk::CCout& _os, const std::vector<vec3 >& _obj) {
for (size_t iii = 0; iii < _obj.size(); ++iii) {
if (iii != 0) {
_os << " ";
}
_os << _obj[iii];
}
return _os;
}
etk::CCout& etk::operator <<(etk::CCout& _os, const std::vector<ivec3 >& _obj) {
for (size_t iii = 0; iii < _obj.size(); ++iii) {
if (iii != 0) {
_os << " ";
}
_os << _obj[iii];
}
return _os;
}
etk::CCout& etk::operator <<(etk::CCout& _os, const std::vector<uivec3 >& _obj) {
for (size_t iii = 0; iii < _obj.size(); ++iii) {
if (iii != 0) {
_os << " ";
}
_os << _obj[iii];
}
return _os;
}
etk::CCout& etk::operator <<(etk::CCout& _os, const std::vector<bvec3 >& _obj) {
for (size_t iii = 0; iii < _obj.size(); ++iii) {
if (iii != 0) {
_os << " ";
}
_os << _obj[iii];
}
return _os;
}
vec3 quaternionToEulerXYZ(const btQuaternion& quat) vec3 quaternionToEulerXYZ(const btQuaternion& quat)
{ {
// back to the euler angle : // back to the euler angle :

View File

@ -29,8 +29,7 @@ namespace etk
/** /**
* @brief No initialization constructor (faster ...) * @brief No initialization constructor (faster ...)
*/ */
Vector3D(void) Vector3D(void) {
{
#ifdef DEBUG #ifdef DEBUG
// in debug mode we set supid value to prevent forget of the inits ... // in debug mode we set supid value to prevent forget of the inits ...
m_floats[0] = (T)34673363; m_floats[0] = (T)34673363;
@ -41,12 +40,11 @@ namespace etk
} }
/** /**
* @brief Constructor from scalars * @brief Constructor from scalars
* @param x X value * @param _x X value
* @param y Y value * @param _y Y value
* @param z Z value * @param _z Z value
*/ */
Vector3D(const T& _x, const T& _y, const T& _z) Vector3D(const T& _x, const T& _y, const T& _z) {
{
m_floats[0] = _x; m_floats[0] = _x;
m_floats[1] = _y; m_floats[1] = _y;
m_floats[2] = _z; m_floats[2] = _z;
@ -55,76 +53,72 @@ namespace etk
/** /**
* @brief Add a vector to this one * @brief Add a vector to this one
* @param The vector to add to this one * @param _v The vector to add to this one
*/ */
Vector3D<T>& operator+=(const Vector3D<T>& v) Vector3D<T>& operator+=(const Vector3D<T>& _v) {
{ m_floats[0] += _v.m_floats[0];
m_floats[0] += v.m_floats[0]; m_floats[1] += _v.m_floats[1];
m_floats[1] += v.m_floats[1]; m_floats[2] += _v.m_floats[2];
m_floats[2] += v.m_floats[2];
return *this; return *this;
} }
Vector3D<T> operator+(const Vector3D<T>& v) //! @previous
{ Vector3D<T> operator+(const Vector3D<T>& _v) {
return Vector3D<T>(m_floats[0] + v.m_floats[0], return Vector3D<T>(m_floats[0] + _v.m_floats[0],
m_floats[1] + v.m_floats[1], m_floats[1] + _v.m_floats[1],
m_floats[2] + v.m_floats[2]); m_floats[2] + _v.m_floats[2]);
} }
/** /**
* @brief Subtract a vector from this one * @brief Subtract a vector from this one
* @param The vector to subtract * @param _v The vector to subtract
*/ */
Vector3D<T>& operator-=(const Vector3D<T>& v) Vector3D<T>& operator-=(const Vector3D<T>& _v) {
{ m_floats[0] -= _v.m_floats[0];
m_floats[0] -= v.m_floats[0]; m_floats[1] -= _v.m_floats[1];
m_floats[1] -= v.m_floats[1]; m_floats[2] -= _v.m_floats[2];
m_floats[2] -= v.m_floats[2];
return *this; return *this;
} }
Vector3D<T> operator-(const Vector3D<T>& v) //! @previous
{ Vector3D<T> operator-(const Vector3D<T>& _v) {
return Vector3D<T>(m_floats[0] - v.m_floats[0], return Vector3D<T>(m_floats[0] - _v.m_floats[0],
m_floats[1] - v.m_floats[1], m_floats[1] - _v.m_floats[1],
m_floats[2] - v.m_floats[2]); m_floats[2] - _v.m_floats[2]);
} }
/** /**
* @brief Scale the vector * @brief Scale the vector
* @param s Scale factor * @param _s Scale factor
*/ */
Vector3D<T>& operator*=(const T& s) Vector3D<T>& operator*=(const T& _s) {
{ m_floats[0] *= _s;
m_floats[0] *= s; m_floats[1] *= _s;
m_floats[1] *= s; m_floats[2] *= _s;
m_floats[2] *= s;
return *this; return *this;
} }
Vector3D<T> operator*(const T& s) //! @previous
{ Vector3D<T> operator*(const T& _s) {
return Vector3D<T>(m_floats[0] * s, return Vector3D<T>(m_floats[0] * _s,
m_floats[1] * s, m_floats[1] * _s,
m_floats[2] * s); m_floats[2] * _s);
} }
/** /**
* @brief Inversely scale the vector * @brief Inversely scale the vector
* @param s Scale factor to divide by * @param _s Scale factor to divide by
*/ */
Vector3D<T>& operator/=(const Vector3D<T>& s) Vector3D<T>& operator/=(const Vector3D<T>& _s) {
{ if (_s != 0) {
if (0!=s) { return *this *= btScalar(1.0) / _s;
return *this *= btScalar(1.0) / s;
} }
return *this; return *this;
} }
Vector3D<T>& operator/=(const T& s) //! @previous
{ Vector3D<T>& operator/=(const T& _s) {
if (0!=s) { if (_s != 0) {
m_floats[0]/=s; m_floats[0] /= _s;
m_floats[1]/=s; m_floats[1] /= _s;
m_floats[2]/=s; m_floats[2] /= _s;
return *this; return *this;
} }
return *this; return *this;
@ -132,28 +126,25 @@ namespace etk
/** /**
* @brief Return the dot product * @brief Return the dot product
* @param v The other vector in the dot product * @param _v The other vector in the dot product
*/ */
btScalar dot(const Vector3D<T>& v) const btScalar dot(const Vector3D<T>& _v) const {
{ return m_floats[0] * _v.m_floats[0]
return m_floats[0] * v.m_floats[0] + + m_floats[1] * _v.m_floats[1]
m_floats[1] * v.m_floats[1] + + m_floats[2] * _v.m_floats[2];
m_floats[2] * v.m_floats[2];
} }
/** /**
* @brief Return the length of the vector squared * @brief Return the length of the vector squared
*/ */
btScalar length2() const btScalar length2(void) const {
{
return dot(*this); return dot(*this);
} }
/** /**
* @brief Return the length of the vector * @brief Return the length of the vector
*/ */
btScalar length() const btScalar length(void) const {
{
return btSqrt(length2()); return btSqrt(length2());
} }
@ -161,22 +152,19 @@ namespace etk
* @brief Return the distance squared between the ends of this and another vector * @brief Return the distance squared between the ends of this and another vector
* This is symantically treating the vector like a point * This is symantically treating the vector like a point
*/ */
btScalar distance2(const btVector3& v) const btScalar distance2(const btVector3& _v) const {
{ return (_v - *this).length2();
return (v - *this).length2();
} }
/** /**
* @brief Return the distance between the ends of this and another vector * @brief Return the distance between the ends of this and another vector
* This is symantically treating the vector like a point * This is symantically treating the vector like a point
*/ */
btScalar distance(const btVector3& v) const btScalar distance(const btVector3& _v) const {
{ return (_v - *this).length();
return (v - *this).length();
} }
Vector3D<T>& safeNormalize() Vector3D<T>& safeNormalize(void) {
{
Vector3D<T> absVec = this->absolute(); Vector3D<T> absVec = this->absolute();
int maxIndex = absVec.maxAxis(); int maxIndex = absVec.maxAxis();
if (absVec[maxIndex]>0) if (absVec[maxIndex]>0)
@ -192,42 +180,38 @@ namespace etk
* @brief Normalize this vector * @brief Normalize this vector
* x^2 + y^2 + z^2 = 1 * x^2 + y^2 + z^2 = 1
*/ */
Vector3D<T>& normalize() Vector3D<T>& normalize(void) {
{
return *this /= length(); return *this /= length();
} }
/** /**
* @brief Return a normalized version of this vector * @brief Return a normalized version of this vector
*/ */
Vector3D<T> normalized() const Vector3D<T> normalized(void) const {
{
return *this / length(); return *this / length();
} }
/** /**
* @brief Return a rotated version of this vector * @brief Return a rotated version of this vector
* @param wAxis The axis to rotate about * @param _wAxis The axis to rotate about
* @param angle The angle to rotate by * @param _angle The angle to rotate by
*/ */
Vector3D<T> rotate( const Vector3D<T>& wAxis, const btScalar angle ) const Vector3D<T> rotate( const Vector3D<T>& _wAxis, const btScalar _angle ) const {
{ Vector3D<T> o = _wAxis * _wAxis.dot( *this );
Vector3D<T> o = wAxis * wAxis.dot( *this ); Vector3D<T> x = *this - o;
Vector3D<T> _x = *this - o; Vector3D<T> y;
Vector3D<T> _y; y = _wAxis.cross( *this );
_y = wAxis.cross( *this ); return ( o + x * cosf(_angle) + y * sinf(_angle) );
return ( o + _x * cosf(angle) + _y * sinf(angle) );
} }
/** /**
* @brief Return the angle between this and another vector * @brief Return the angle between this and another vector
* @param v The other vector * @param _v The other vector
*/ */
btScalar angle(const Vector3D<T>& v) const btScalar angle(const Vector3D<T>& _v) const {
{ btScalar s = sqrtf(length2() * _v.length2());
btScalar s = sqrtf(length2() * v.length2());
if (0!=s) { if (0!=s) {
return acosf(dot(v) / s); return acosf(dot(_v) / s);
} }
return 0; return 0;
} }
@ -235,8 +219,7 @@ namespace etk
/** /**
* @brief Return a vector will the absolute values of each element * @brief Return a vector will the absolute values of each element
*/ */
Vector3D<T> absolute(void) const Vector3D<T> absolute(void) const {
{
return Vector3D<T>( abs(m_floats[0]), return Vector3D<T>( abs(m_floats[0]),
abs(m_floats[1]), abs(m_floats[1]),
abs(m_floats[2])); abs(m_floats[2]));
@ -244,174 +227,196 @@ namespace etk
/** /**
* @brief Return the cross product between this and another vector * @brief Return the cross product between this and another vector
* @param v The other vector * @param _v The other vector
*/ */
Vector3D<T> cross(const Vector3D<T>& v) const Vector3D<T> cross(const Vector3D<T>& _v) const {
{ return Vector3D<T>(m_floats[1] * _v.m_floats[2] - m_floats[2] * _v.m_floats[1],
return Vector3D<T>(m_floats[1] * v.m_floats[2] - m_floats[2] * v.m_floats[1], m_floats[2] * _v.m_floats[0] - m_floats[0] * _v.m_floats[2],
m_floats[2] * v.m_floats[0] - m_floats[0] * v.m_floats[2], m_floats[0] * _v.m_floats[1] - m_floats[1] * _v.m_floats[0]);
m_floats[0] * v.m_floats[1] - m_floats[1] * v.m_floats[0]);
} }
T triple(const Vector3D<T>& v1, const Vector3D<T>& v2) const T triple(const Vector3D<T>& _v1, const Vector3D<T>& _v2) const {
{ return m_floats[0] * (_v1.m_floats[1] * _v2.m_floats[2] - _v1.m_floats[2] * _v2.m_floats[1])
return m_floats[0] * (v1.m_floats[1] * v2.m_floats[2] - v1.m_floats[2] * v2.m_floats[1]) + m_floats[1] * (_v1.m_floats[2] * _v2.m_floats[0] - _v1.m_floats[0] * _v2.m_floats[2])
+ m_floats[1] * (v1.m_floats[2] * v2.m_floats[0] - v1.m_floats[0] * v2.m_floats[2]) + m_floats[2] * (_v1.m_floats[0] * _v2.m_floats[1] - _v1.m_floats[1] * _v2.m_floats[0]);
+ m_floats[2] * (v1.m_floats[0] * v2.m_floats[1] - v1.m_floats[1] * v2.m_floats[0]);
} }
/** /**
* @brief Return the axis with the smallest value * @brief Return the axis with the smallest value
* Note return values are 0,1,2 for x, y, or z * Note return values are 0,1,2 for x, y, or z
*/ */
int32_t minAxis(void) const int32_t minAxis(void) const {
{ if (m_floats[0] < m_floats[1]) {
return m_floats[0] < m_floats[1] ? (m_floats[0] <m_floats[2] ? 0 : 2) : (m_floats[1] <m_floats[2] ? 1 : 2); return m_floats[0] < m_floats[2] ? 0 : 2;
}
return m_floats[1] < m_floats[2] ? 1 : 2;
} }
/** /**
* @brief Return the axis with the largest value * @brief Return the axis with the largest value
* Note return values are 0,1,2 for x, y, or z * Note return values are 0,1,2 for x, y, or z
*/ */
int32_t maxAxis(void) const int32_t maxAxis(void) const {
{ if (m_floats[0] < m_floats[1]) {
return m_floats[0] < m_floats[1] ? (m_floats[1] <m_floats[2] ? 2 : 1) : (m_floats[0] <m_floats[2] ? 2 : 0); return m_floats[1] < m_floats[2] ? 2 : 1;
}
return m_floats[0] < m_floats[2] ? 2 : 0;
} }
int32_t furthestAxis(void) const int32_t furthestAxis(void) const {
{
return absolute().minAxis(); return absolute().minAxis();
} }
int32_t closestAxis(void) const int32_t closestAxis(void) const {
{
return absolute().maxAxis(); return absolute().maxAxis();
} }
void setInterpolate3(const Vector3D<T>& v0, const Vector3D<T>& v1, T rt) void setInterpolate3(const Vector3D<T>& _v0, const Vector3D<T>& _v1, T _rt) {
{ btScalar s = 1.0 - _rt;
btScalar s = 1 - rt; m_floats[0] = s * _v0.m_floats[0] + _rt * _v1.m_floats[0];
m_floats[0] = s * v0.m_floats[0] + rt * v1.m_floats[0]; m_floats[1] = s * _v0.m_floats[1] + _rt * _v1.m_floats[1];
m_floats[1] = s * v0.m_floats[1] + rt * v1.m_floats[1]; m_floats[2] = s * _v0.m_floats[2] + _rt * _v1.m_floats[2];
m_floats[2] = s * v0.m_floats[2] + rt * v1.m_floats[2];
//don't do the unused w component //don't do the unused w component
// m_co[3] = s * v0[3] + rt * v1[3]; // m_co[3] = s * v0[3] + rt * v1[3];
} }
/** /**
* @brief Return the linear interpolation between this and another vector * @brief Return the linear interpolation between this and another vector
* @param v The other vector * @param _v The other vector
* @param t The ration of this to v (t = 0 => return this, t=1 => return other) * @param _t The ration of this to v (t = 0 => return this, t=1 => return other)
*/ */
Vector3D<T> lerp(const Vector3D<T>& v, const btScalar& t) const Vector3D<T> lerp(const Vector3D<T>& _v, const btScalar& _t) const {
{ return Vector3D<T>(m_floats[0] + (_v.m_floats[0] - m_floats[0]) * _t,
return Vector3D<T>(m_floats[0] + (v.m_floats[0] - m_floats[0]) * t, m_floats[1] + (_v.m_floats[1] - m_floats[1]) * _t,
m_floats[1] + (v.m_floats[1] - m_floats[1]) * t, m_floats[2] + (_v.m_floats[2] - m_floats[2]) * _t);
m_floats[2] + (v.m_floats[2] - m_floats[2]) * t);
} }
/** /**
* @brief Elementwise multiply this vector by the other * @brief Elementwise multiply this vector by the other
* @param v The other vector * @param _v The other vector
*/ */
Vector3D<T>& operator*=(const Vector3D<T>& v) Vector3D<T>& operator*=(const Vector3D<T>& _v) {
{ m_floats[0] *= _v.m_floats[0];
m_floats[0] *= v.m_floats[0]; m_floats[1] *= _v.m_floats[1];
m_floats[1] *= v.m_floats[1]; m_floats[2] *= _v.m_floats[2];
m_floats[2] *= v.m_floats[2];
return *this; return *this;
} }
Vector3D<T> operator*(const Vector3D<T>& v) //! @previous
{ Vector3D<T> operator*(const Vector3D<T>& _v) {
return Vector3D<T>(m_floats[0] * v.m_floats[0], return Vector3D<T>(m_floats[0] * _v.m_floats[0],
m_floats[1] * v.m_floats[1], m_floats[1] * _v.m_floats[1],
m_floats[2] * v.m_floats[2]); m_floats[2] * _v.m_floats[2]);
} }
/** /**
* @brief Return the x value * @brief Return the x value
*/ */
const T& getX() const { return m_floats[0]; } const T& getX() const {
return m_floats[0];
}
/** /**
* @brief Return the y value * @brief Return the y value
*/ */
const T& getY() const { return m_floats[1]; } const T& getY() const {
return m_floats[1];
}
/** /**
* @brief Return the z value * @brief Return the z value
*/ */
const T& getZ() const { return m_floats[2]; } const T& getZ() const {
return m_floats[2];
}
/** /**
* @brief Set the x value * @brief Set the x value
*/ */
void setX(T _x) { m_floats[0] = _x;}; void setX(T _x) {
m_floats[0] = _x;
};
/** /**
* @brief Set the y value * @brief Set the y value
*/ */
void setY(T _y) { m_floats[1] = _y;}; void setY(T _y) {
m_floats[1] = _y;
};
/** /**
* @brief Set the z value * @brief Set the z value
*/ */
void setZ(T _z) { m_floats[2] = _z;}; void setZ(T _z) {
m_floats[2] = _z;
};
/** /**
* @brief Set the w value * @brief Set the w value
*/ */
void setW(T _w) { m_floats[3] = _w;}; void setW(T _w) {
m_floats[3] = _w;
};
/** /**
* @brief Return the x value * @brief Return the x value
*/ */
const T& x() const { return m_floats[0]; } const T& x() const {
return m_floats[0];
}
/** /**
* @brief Return the y value * @brief Return the y value
*/ */
const T& y() const { return m_floats[1]; } const T& y() const {
return m_floats[1];
}
/** /**
* @brief Return the z value * @brief Return the z value
*/ */
const T& z() const { return m_floats[2]; } const T& z() const {
return m_floats[2];
}
/** /**
* @brief Return the w value * @brief Return the w value
*/ */
const T& w() const { return m_floats[3]; } const T& w() const {
return m_floats[3];
operator T *() { return &m_floats[0]; }
operator const T *() const { return &m_floats[0]; }
bool operator==(const Vector3D<T>& other) const
{
return ( (m_floats[3]==other.m_floats[3])
&& (m_floats[2]==other.m_floats[2])
&& (m_floats[1]==other.m_floats[1])
&& (m_floats[0]==other.m_floats[0]));
} }
bool operator!=(const Vector3D<T>& other) const operator T *() {
{ return &m_floats[0];
return ( (m_floats[3]!=other.m_floats[3]) }
|| (m_floats[2]!=other.m_floats[2]) //! @previous
|| (m_floats[1]!=other.m_floats[1]) operator const T *() const {
|| (m_floats[0]!=other.m_floats[0])); return &m_floats[0];
}
bool operator==(const Vector3D<T>& _other) const {
return ( (m_floats[3] == _other.m_floats[3])
&& (m_floats[2] == _other.m_floats[2])
&& (m_floats[1] == _other.m_floats[1])
&& (m_floats[0] == _other.m_floats[0]));
}
bool operator!=(const Vector3D<T>& _other) const {
return ( (m_floats[3] != _other.m_floats[3])
|| (m_floats[2] != _other.m_floats[2])
|| (m_floats[1] != _other.m_floats[1])
|| (m_floats[0] != _other.m_floats[0]));
} }
/** /**
* @brief Set each element to the max of the current values and the values of another btVector3 * @brief Set each element to the max of the current values and the values of another btVector3
* @param other The other btVector3 to compare with * @param _other The other btVector3 to compare with
*/ */
void setMax(const Vector3D<T>& other) { void setMax(const Vector3D<T>& _other) {
btSetMax(m_floats[0], other.m_floats[0]); btSetMax(m_floats[0], _other.m_floats[0]);
btSetMax(m_floats[1], other.m_floats[1]); btSetMax(m_floats[1], _other.m_floats[1]);
btSetMax(m_floats[2], other.m_floats[2]); btSetMax(m_floats[2], _other.m_floats[2]);
btSetMax(m_floats[3], other.m_floats[3]); btSetMax(m_floats[3], _other.m_floats[3]);
} }
/** /**
* @brief Set each element to the min of the current values and the values of another btVector3 * @brief Set each element to the min of the current values and the values of another btVector3
* @param other The other btVector3 to compare with * @param _other The other btVector3 to compare with
*/ */
void setMin(const Vector3D<T>& other) { void setMin(const Vector3D<T>& _other) {
btSetMin(m_floats[0], other.m_floats[0]); btSetMin(m_floats[0], _other.m_floats[0]);
btSetMin(m_floats[1], other.m_floats[1]); btSetMin(m_floats[1], _other.m_floats[1]);
btSetMin(m_floats[2], other.m_floats[2]); btSetMin(m_floats[2], _other.m_floats[2]);
btSetMin(m_floats[3], other.m_floats[3]); btSetMin(m_floats[3], _other.m_floats[3]);
} }
void setValue(const T& _x, const T& _y, const T& _z) { void setValue(const T& _x, const T& _y, const T& _z) {
@ -421,35 +426,35 @@ namespace etk
m_floats[3] = 0; m_floats[3] = 0;
} }
void getSkewSymmetricMatrix(Vector3D<T>* v0,Vector3D<T>* v1,Vector3D<T>* v2) const void getSkewSymmetricMatrix(Vector3D<T>* _v0,Vector3D<T>* _v1,Vector3D<T>* _v2) const {
{ _v0->setValue(0. ,-z() ,y());
v0->setValue(0. ,-z() ,y()); _v1->setValue(z() ,0. ,-x());
v1->setValue(z() ,0. ,-x()); _v2->setValue(-y() ,x() ,0.);
v2->setValue(-y() ,x() ,0.);
} }
void setZero(void) void setZero(void) {
{
setValue(0,0,0); setValue(0,0,0);
} }
bool isZero(void) const bool isZero(void) const {
{
return m_floats[0] == 0 && m_floats[1] == 0 && m_floats[2] == 0; return m_floats[0] == 0 && m_floats[1] == 0 && m_floats[2] == 0;
} }
}; };
/** /**
* @brief Debug operator To display the curent element in a Human redeable information * @brief Debug operator To display the curent element in a Human redeable information
*/ */
etk::CCout& operator <<(etk::CCout &os, const etk::Vector3D<int32_t> obj); etk::CCout& operator <<(etk::CCout &_os, const etk::Vector3D<int32_t> _obj);
etk::CCout& operator <<(etk::CCout &os, const btVector3 obj); //! @previous
etk::CCout& operator <<(etk::CCout &os, const etk::Vector3D<uint32_t> obj); etk::CCout& operator <<(etk::CCout &_os, const btVector3 _obj);
etk::CCout& operator <<(etk::CCout &os, const etk::Vector3D<bool> obj); //! @previous
etk::CCout& operator <<(etk::CCout &_os, const etk::Vector3D<uint32_t> _obj);
//! @previous
etk::CCout& operator <<(etk::CCout &_os, const etk::Vector3D<bool> _obj);
}; };
// To siplify the writing of the code ==> this permit to have the same name with the glsl language... // To siplify the writing of the code ==> this permit to have the same name with the glsl language...
typedef btVector3 vec3; typedef btVector3 vec3;
typedef etk::Vector3D<float> ovec3; // specific for OpenGL ... ==> never change this ... typedef etk::Vector3D<float> ovec3; // specific for OpenGL ... ==> never change this ...
typedef etk::Vector3D<int32_t> ivec3; typedef etk::Vector3D<int32_t> ivec3;
// not compatible with glsl ... but it is better to have a same writing // not compatible with glsl ... but it is better to have a same writing
@ -459,15 +464,22 @@ typedef etk::Vector3D<bool> bvec3;
vec3 quaternionToEulerXYZ(const btQuaternion& quat); vec3 quaternionToEulerXYZ(const btQuaternion& quat);
inline vec3 vec3ClipInt32(const vec3& val) inline vec3 vec3ClipInt32(const vec3& val) {
{
return vec3((int32_t)val.x(), (int32_t)val.y(), (int32_t)val.z()); return vec3((int32_t)val.x(), (int32_t)val.y(), (int32_t)val.z());
} }
inline vec3 vec3ClipInt64(const vec3& val) inline vec3 vec3ClipInt64(const vec3& val) {
{
return vec3((int64_t)val.x(), (int64_t)val.y(), (int64_t)val.z()); return vec3((int64_t)val.x(), (int64_t)val.y(), (int64_t)val.z());
} }
namespace etk {
etk::CCout& operator <<(etk::CCout& _os, const std::vector<vec3 >& _obj);
//! @previous
etk::CCout& operator <<(etk::CCout& _os, const std::vector<ivec3 >& _obj);
//! @previous
etk::CCout& operator <<(etk::CCout& _os, const std::vector<uivec3 >& _obj);
//! @previous
etk::CCout& operator <<(etk::CCout& _os, const std::vector<bvec3 >& _obj);
};
#endif #endif