[DEV] add vec2 interface

This commit is contained in:
Edouard DUPIN 2014-10-13 23:16:16 +02:00
parent 73f816c19c
commit addc23bdc7
2 changed files with 36 additions and 2 deletions

View File

@ -85,6 +85,24 @@ std::ostream& etk::operator <<(std::ostream& _os, const std::vector<bvec2 >& _ob
return _os;
}
vec2 vec2rotate(const vec2& _val, const vec2& _point, float _angle) {
vec2 out = _val;
float sinAngle = std::sin(_angle);
float cosAngle = std::cos(_angle);
if (_point == vec2(0,0)) {
float tempX = out.x() * cosAngle - out.y() * sinAngle;
float xVal = out.x();
out.setValue(tempX,
out.y() * cosAngle + xVal * sinAngle);
} else {
float tempX = out.x() - _point.x();
float tempY = out.y() - _point.y();
out.setValue(tempX * cosAngle - tempY * sinAngle + _point.x(),
tempY * cosAngle + tempX * sinAngle + _point.y());
}
return out;
}
namespace etk {
template<> Vector2D<bool>::operator std::string() const {
std::string str;

View File

@ -176,6 +176,19 @@ namespace etk {
tmpp.m_floats[1] /= _val;
return tmpp;
}
/* ****************************************************
* / operator
*****************************************************/
const Vector2D<T>& operator/= (const Vector2D<T>& _obj) {
m_floats[0] /= _obj.m_floats[0];
m_floats[1] /= _obj.m_floats[1];
return *this;
}
const Vector2D<T>& operator/= (const T _val) {
m_floats[0] /= _val;
m_floats[1] /= _val;
return *this;
}
/* ****************************************************
* ++ operator
*****************************************************/
@ -240,8 +253,9 @@ namespace etk {
* @brief Normalize this vector
* x^2 + y^2 + z^2 = 1
*/
Vector3D<T>& normalize() {
return *this /= length();
Vector2D<T>& normalize() {
*this /= length();
return *this;
}
/**
* @brief Return a normalized version of this vector
@ -374,6 +388,8 @@ inline vec2 vec2ClipInt64(const vec2& _val) {
return vec2((int64_t)_val.x(), (int64_t)_val.y());
}
vec2 vec2rotate(const vec2& _val, const vec2& _point, float _angle);
namespace etk {
std::ostream& operator <<(std::ostream& _os, const std::vector<vec2 >& _obj);
//! @previous