clean up for adding proper transform handling
This commit is contained in:
parent
28bdf476ca
commit
b89c536761
7 changed files with 143 additions and 114 deletions
|
@ -8,23 +8,23 @@ namespace pw {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class axisangle {
|
class axisangle {
|
||||||
protected:
|
protected:
|
||||||
vector3<T> _axis;
|
vector3_<T> _axis;
|
||||||
T _angle;
|
T _angle;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
axisangle()
|
axisangle()
|
||||||
: _axis(vector3<T>::up()),
|
: _axis(vector3_<T>::up()),
|
||||||
_angle(0)
|
_angle(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
axisangle(const vector3<T> &axis,const T &angle)
|
axisangle(const vector3_<T> &axis,const T &angle)
|
||||||
: _axis(axis)
|
: _axis(axis)
|
||||||
, _angle(angle)
|
, _angle(angle)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
vector3<T> axis() const { return _axis; }
|
vector3_<T> axis() const { return _axis; }
|
||||||
void set_axis(const vector3<T> &axis) { _axis = axis; }
|
void set_axis(const vector3_<T> &axis) { _axis = axis; }
|
||||||
|
|
||||||
T angle() const { return _angle; }
|
T angle() const { return _angle; }
|
||||||
void set_angle(const T &angle) { _angle = angle; }
|
void set_angle(const T &angle) { _angle = angle; }
|
||||||
|
|
|
@ -35,23 +35,23 @@ namespace pw {
|
||||||
* simplified quaternion class
|
* simplified quaternion class
|
||||||
*/
|
*/
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class quaternion {
|
class quaternion_ {
|
||||||
|
|
||||||
static const T _sqrt90;
|
static const T _sqrt90;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef vector4<T> coefficient_type;
|
typedef vector4_<T> coefficient_type;
|
||||||
typedef T value_type;
|
typedef T value_type;
|
||||||
|
|
||||||
quaternion() { *this = identity(); }
|
quaternion_() { *this = identity(); }
|
||||||
|
|
||||||
quaternion(const T& x,const T& y,const T& z,const T& w)
|
quaternion_(const T& x,const T& y,const T& z,const T& w)
|
||||||
: _q(coefficient_type(x,y,z,w)) {}
|
: _q(coefficient_type(x,y,z,w)) {}
|
||||||
|
|
||||||
quaternion(const coefficient_type& vec) { *this = vec; }
|
quaternion_(const coefficient_type& vec) { *this = vec; }
|
||||||
|
|
||||||
inline quaternion& operator = (const coefficient_type& vec) { _q = vec; return *this; }
|
inline quaternion_& operator = (const coefficient_type& vec) { _q = vec; return *this; }
|
||||||
|
|
||||||
inline void set(const T& x,const T& y,const T& z,const T& w) {
|
inline void set(const T& x,const T& y,const T& z,const T& w) {
|
||||||
_q.set(x,y,z,w);
|
_q.set(x,y,z,w);
|
||||||
|
@ -76,8 +76,8 @@ public:
|
||||||
|
|
||||||
|
|
||||||
//! multiplication
|
//! multiplication
|
||||||
inline const quaternion operator * (const quaternion& rhs) const {
|
inline const quaternion_ operator * (const quaternion_& rhs) const {
|
||||||
return quaternion(
|
return quaternion_(
|
||||||
rhs.w()*x() + rhs.x()*w() + rhs.y()*z() - rhs.z()*y(),
|
rhs.w()*x() + rhs.x()*w() + rhs.y()*z() - rhs.z()*y(),
|
||||||
rhs.w()*y() - rhs.x()*z() + rhs.y()*w() + rhs.z()*x(),
|
rhs.w()*y() - rhs.x()*z() + rhs.y()*w() + rhs.z()*x(),
|
||||||
rhs.w()*z() + rhs.x()*y() - rhs.y()*x() + rhs.z()*w(),
|
rhs.w()*z() + rhs.x()*y() - rhs.y()*x() + rhs.z()*w(),
|
||||||
|
@ -86,18 +86,18 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
//! multiply with scalar
|
//! multiply with scalar
|
||||||
inline const quaternion operator * (const T& s) const {
|
inline const quaternion_ operator * (const T& s) const {
|
||||||
return quaternion(x()*s,y()*s,z()*s,w()*s);
|
return quaternion_(x()*s,y()*s,z()*s,w()*s);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! addition
|
//! addition
|
||||||
inline const quaternion operator + (const quaternion& rhs) const {
|
inline const quaternion_ operator + (const quaternion_& rhs) const {
|
||||||
return quaternion(coefficient_type(this->_q + rhs._q));
|
return quaternion_(coefficient_type(this->_q + rhs._q));
|
||||||
}
|
}
|
||||||
|
|
||||||
//! addition
|
//! addition
|
||||||
inline const quaternion operator - (const quaternion& rhs) const {
|
inline const quaternion_ operator - (const quaternion_& rhs) const {
|
||||||
return quaternion(this->_q - rhs._q);
|
return quaternion_(this->_q - rhs._q);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! squared norm
|
//! squared norm
|
||||||
|
@ -107,50 +107,50 @@ public:
|
||||||
inline const T norm() const { return _q.norm(); }
|
inline const T norm() const { return _q.norm(); }
|
||||||
|
|
||||||
//! dot product
|
//! dot product
|
||||||
inline const T dot(const quaternion& other) const { return _q.dot(other._q); }
|
inline const T dot(const quaternion_& other) const { return _q.dot(other._q); }
|
||||||
|
|
||||||
//! conjugate
|
//! conjugate
|
||||||
inline quaternion conjugate() const { return quaternion(-x(),-y(),-z(),w()); }
|
inline quaternion_ conjugate() const { return quaternion_(-x(),-y(),-z(),w()); }
|
||||||
|
|
||||||
//! compute inverse
|
//! compute inverse
|
||||||
inline quaternion inverse() const {
|
inline quaternion_ inverse() const {
|
||||||
const T one_over_squared_norm = T(1) / squared_norm();
|
const T one_over_squared_norm = T(1) / squared_norm();
|
||||||
return conjugate() * one_over_squared_norm;
|
return conjugate() * one_over_squared_norm;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! compute normalized
|
//! compute normalized
|
||||||
inline quaternion normalized() const {
|
inline quaternion_ normalized() const {
|
||||||
return quaternion(_q.normalized());
|
return quaternion_(_q.normalized());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void normalize() { *this = this->normalized(); }
|
inline void normalize() { *this = this->normalized(); }
|
||||||
|
|
||||||
//! conversion from a matrix
|
//! conversion from a matrix
|
||||||
inline static const quaternion from_matrix(const matrix_<4,4,T> &m);
|
inline static const quaternion_ from_matrix(const matrix_<4,4,T> &m);
|
||||||
|
|
||||||
//! conversion to a matrix
|
//! conversion to a matrix
|
||||||
const matrix_<4,4,T> to_matrix() const;
|
const matrix_<4,4,T> to_matrix() const;
|
||||||
|
|
||||||
//! return identiy quaternion
|
//! return identiy quaternion
|
||||||
static const quaternion<T> identity();
|
static const quaternion_<T> identity();
|
||||||
|
|
||||||
static const quaternion<T> rotate_180_degree_around_x(); ///< rotate 180 degree around X axis
|
static const quaternion_<T> rotate_180_degree_around_x(); ///< rotate 180 degree around X axis
|
||||||
static const quaternion<T> rotate_180_degree_around_y(); ///< rotate 180 degree around Y axis
|
static const quaternion_<T> rotate_180_degree_around_y(); ///< rotate 180 degree around Y axis
|
||||||
static const quaternion<T> rotate_180_degree_around_z(); ///< rotate 180 degree around Z axis
|
static const quaternion_<T> rotate_180_degree_around_z(); ///< rotate 180 degree around Z axis
|
||||||
|
|
||||||
static const quaternion<T> rotate_90_degree_around_x(bool negative = false);
|
static const quaternion_<T> rotate_90_degree_around_x(bool negative = false);
|
||||||
static const quaternion<T> rotate_90_degree_around_y(bool negative = false);
|
static const quaternion_<T> rotate_90_degree_around_y(bool negative = false);
|
||||||
static const quaternion<T> rotate_90_degree_around_z(bool negative = false);
|
static const quaternion_<T> rotate_90_degree_around_z(bool negative = false);
|
||||||
|
|
||||||
template <typename AxisAngleType>
|
template <typename AxisAngleType>
|
||||||
static const quaternion<T> from_axisangle(const AxisAngleType &aa) {
|
static const quaternion_<T> from_axisangle(const AxisAngleType &aa) {
|
||||||
|
|
||||||
using std::sin;
|
using std::sin;
|
||||||
using std::cos;
|
using std::cos;
|
||||||
|
|
||||||
const T sinHalfAngle(sin(aa.angle() * T(0.5) ));
|
const T sinHalfAngle(sin(aa.angle() * T(0.5) ));
|
||||||
|
|
||||||
return quaternion<T>(aa.axis().x() * sinHalfAngle, // x
|
return quaternion_<T>(aa.axis().x() * sinHalfAngle, // x
|
||||||
aa.axis().y() * sinHalfAngle, // y
|
aa.axis().y() * sinHalfAngle, // y
|
||||||
aa.axis().z() * sinHalfAngle, // z
|
aa.axis().z() * sinHalfAngle, // z
|
||||||
cos(aa.angle() * 0.5) // w
|
cos(aa.angle() * 0.5) // w
|
||||||
|
@ -158,9 +158,9 @@ public:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const quaternion<T> lerp(const quaternion& qa,const quaternion& qb,const T& t);
|
static const quaternion_<T> lerp(const quaternion_& qa,const quaternion_& qb,const T& t);
|
||||||
static const quaternion<T> normalized_lerp(const quaternion& qa,const quaternion& qb,const T& t);
|
static const quaternion_<T> normalized_lerp(const quaternion_& qa,const quaternion_& qb,const T& t);
|
||||||
static const quaternion<T> slerp(const quaternion& qa,const quaternion& qb,const T& t);
|
static const quaternion_<T> slerp(const quaternion_& qa,const quaternion_& qb,const T& t);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -169,18 +169,18 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const T quaternion<T>::_sqrt90 = std::sqrt(0.5);
|
const T quaternion_<T>::_sqrt90 = std::sqrt(0.5);
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const quaternion<T> quaternion<T>::from_matrix(const matrix_<4,4,T> &m) {
|
const quaternion_<T> quaternion_<T>::from_matrix(const matrix_<4,4,T> &m) {
|
||||||
|
|
||||||
using std::sqrt;
|
using std::sqrt;
|
||||||
|
|
||||||
T wtemp = sqrt(T(1) + m.at(0,0) + m.at(1,1) + m.at(2,2)) / T(2.0);
|
T wtemp = sqrt(T(1) + m.at(0,0) + m.at(1,1) + m.at(2,2)) / T(2.0);
|
||||||
|
|
||||||
const T w4 = T(4.0) * wtemp;
|
const T w4 = T(4.0) * wtemp;
|
||||||
return quaternion<T>(
|
return quaternion_<T>(
|
||||||
(m.at(2,1) - m.at(1,2)) / w4,
|
(m.at(2,1) - m.at(1,2)) / w4,
|
||||||
(m.at(0,2) - m.at(2,0)) / w4,
|
(m.at(0,2) - m.at(2,0)) / w4,
|
||||||
(m.at(1,0) - m.at(0,1)) / w4,
|
(m.at(1,0) - m.at(0,1)) / w4,
|
||||||
|
@ -188,7 +188,7 @@ const quaternion<T> quaternion<T>::from_matrix(const matrix_<4,4,T> &m) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const matrix_<4,4,T> quaternion<T>::to_matrix() const {
|
const matrix_<4,4,T> quaternion_<T>::to_matrix() const {
|
||||||
|
|
||||||
matrix_<4,4,T> m; m.set_identity();
|
matrix_<4,4,T> m; m.set_identity();
|
||||||
|
|
||||||
|
@ -220,65 +220,65 @@ const matrix_<4,4,T> quaternion<T>::to_matrix() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const quaternion<T> quaternion<T>::identity()
|
const quaternion_<T> quaternion_<T>::identity()
|
||||||
{
|
{
|
||||||
return quaternion<T>(0,0,0,1);
|
return quaternion_<T>(0,0,0,1);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const quaternion<T> quaternion<T>::rotate_180_degree_around_x()
|
const quaternion_<T> quaternion_<T>::rotate_180_degree_around_x()
|
||||||
{
|
{
|
||||||
return quaternion<T>(1,0,0,0);
|
return quaternion_<T>(1,0,0,0);
|
||||||
}
|
}
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const quaternion<T> quaternion<T>::rotate_180_degree_around_y()
|
const quaternion_<T> quaternion_<T>::rotate_180_degree_around_y()
|
||||||
{
|
{
|
||||||
return quaternion<T>(0,1,0,0);
|
return quaternion_<T>(0,1,0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const quaternion<T> quaternion<T>::rotate_180_degree_around_z()
|
const quaternion_<T> quaternion_<T>::rotate_180_degree_around_z()
|
||||||
{
|
{
|
||||||
return quaternion<T>(0,0,1,0);
|
return quaternion_<T>(0,0,1,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const quaternion<T> quaternion<T>::rotate_90_degree_around_x(bool negative/* = false*/)
|
const quaternion_<T> quaternion_<T>::rotate_90_degree_around_x(bool negative/* = false*/)
|
||||||
{
|
{
|
||||||
return quaternion<T>((negative) ? - _sqrt90 : _sqrt90,0,0,_sqrt90);
|
return quaternion_<T>((negative) ? - _sqrt90 : _sqrt90,0,0,_sqrt90);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const quaternion<T> quaternion<T>::rotate_90_degree_around_y(bool negative/* = false*/)
|
const quaternion_<T> quaternion_<T>::rotate_90_degree_around_y(bool negative/* = false*/)
|
||||||
{
|
{
|
||||||
return quaternion<T>(0, (negative) ? -_sqrt90 : _sqrt90,0,_sqrt90);
|
return quaternion_<T>(0, (negative) ? -_sqrt90 : _sqrt90,0,_sqrt90);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const quaternion<T> quaternion<T>::rotate_90_degree_around_z(bool negative/* = false*/)
|
const quaternion_<T> quaternion_<T>::rotate_90_degree_around_z(bool negative/* = false*/)
|
||||||
{
|
{
|
||||||
return quaternion<T>(0,0,(negative) ? -_sqrt90 : _sqrt90, _sqrt90);
|
return quaternion_<T>(0,0,(negative) ? -_sqrt90 : _sqrt90, _sqrt90);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const quaternion<T> quaternion<T>::lerp(const quaternion<T>& qa,const quaternion<T>& qb,const T& t) {
|
const quaternion_<T> quaternion_<T>::lerp(const quaternion_<T>& qa,const quaternion_<T>& qb,const T& t) {
|
||||||
return quaternion<T>(qa + (qb - qa) * t);
|
return quaternion_<T>(qa + (qb - qa) * t);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const quaternion<T> quaternion<T>::normalized_lerp(const quaternion<T>& qa,const quaternion<T>& qb,const T& t) {
|
const quaternion_<T> quaternion_<T>::normalized_lerp(const quaternion_<T>& qa,const quaternion_<T>& qb,const T& t) {
|
||||||
return quaternion<T>::lerp(qa,qb,t).normalized();
|
return quaternion_<T>::lerp(qa,qb,t).normalized();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const quaternion<T> quaternion<T>::slerp(const quaternion<T>& qa,const quaternion<T>& qb,const T& t)
|
const quaternion_<T> quaternion_<T>::slerp(const quaternion_<T>& qa,const quaternion_<T>& qb,const T& t)
|
||||||
{
|
{
|
||||||
using std::abs;
|
using std::abs;
|
||||||
using std::sqrt;
|
using std::sqrt;
|
||||||
using std::acos;
|
using std::acos;
|
||||||
|
|
||||||
// quaternion to return
|
// quaternion to return
|
||||||
quaternion qm;
|
quaternion_ qm;
|
||||||
// Calculate angle between them.
|
// Calculate angle between them.
|
||||||
double cosHalfTheta = qa.w() * qb.w() + qa.x() * qb.x() + qa.y() * qb.y() + qa.z() * qb.z();
|
double cosHalfTheta = qa.w() * qb.w() + qa.x() * qb.x() + qa.y() * qb.y() + qa.z() * qb.z();
|
||||||
// if qa=qb or qa=-qb then theta = 0 and we can return qa
|
// if qa=qb or qa=-qb then theta = 0 and we can return qa
|
||||||
|
@ -312,8 +312,9 @@ const quaternion<T> quaternion<T>::slerp(const quaternion<T>& qa,const quaternio
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
typedef quaternion<float> quaternionf;
|
typedef quaternion_<real_t> quaternion;
|
||||||
typedef quaternion<double> quaterniond;
|
typedef quaternion_<float> quaternionf;
|
||||||
|
typedef quaternion_<double> quaterniond;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,31 +31,31 @@
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
template <unsigned int components,typename T>
|
template <unsigned int components,typename T>
|
||||||
class vector : public matrix_<components,1,T> {
|
class vector_ : public matrix_<components,1,T> {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
using typename matrix_<components,1,T>::value_type;
|
using typename matrix_<components,1,T>::value_type;
|
||||||
using matrix_<components,1,T>::operator = ;
|
using matrix_<components,1,T>::operator = ;
|
||||||
|
|
||||||
vector() : matrix_<components,1,T>() {}
|
vector_() : matrix_<components,1,T>() {}
|
||||||
|
|
||||||
vector(const vector& other) : matrix_<components,1,T>(other) {}
|
vector_(const vector_& other) : matrix_<components,1,T>(other) {}
|
||||||
|
|
||||||
vector(const matrix_<components,1,T>& other) : matrix_<components,1,T>(other) {}
|
vector_(const matrix_<components,1,T>& other) : matrix_<components,1,T>(other) {}
|
||||||
|
|
||||||
T& operator()(unsigned int c) { return matrixbase<T>::at(c); }
|
T& operator()(unsigned int c) { return matrixbase<T>::at(c); }
|
||||||
const T& operator()(unsigned int c) const { return matrixbase<T>::at(c); }
|
const T& operator()(unsigned int c) const { return matrixbase<T>::at(c); }
|
||||||
|
|
||||||
|
|
||||||
const T dot(const vector<components,T>& other) const {
|
const T dot(const vector_<components,T>& other) const {
|
||||||
T res = 0;
|
T res = 0;
|
||||||
for (unsigned int i = 0; i < components; i++) res += (*this)(i) * other(i);
|
for (unsigned int i = 0; i < components; i++) res += (*this)(i) * other(i);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
const T angle_to(const vector<components,T>& other) const {
|
const T angle_to(const vector_<components,T>& other) const {
|
||||||
using std::acos;
|
using std::acos;
|
||||||
vector<components,T> nself(*this); vector<components,T> nothr = other;
|
vector_<components,T> nself(*this); vector_<components,T> nothr = other;
|
||||||
nself.normalize(); nothr.normalize();
|
nself.normalize(); nothr.normalize();
|
||||||
return acos( nothr.dot(nself) );
|
return acos( nothr.dot(nself) );
|
||||||
}
|
}
|
||||||
|
@ -67,27 +67,27 @@ public:
|
||||||
// Vec3 -----------------------------------------------------------------------
|
// Vec3 -----------------------------------------------------------------------
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
class vector3 : public vector<3,T> {
|
class vector3_ : public vector_<3,T> {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
using vector<3,T>::operator=;
|
using vector_<3,T>::operator=;
|
||||||
|
|
||||||
vector3() : vector<3,T>() {}
|
vector3_() : vector_<3,T>() {}
|
||||||
|
|
||||||
vector3(const vector<3,T>& other) : vector<3, T> (other) {}
|
vector3_(const vector_<3,T>& other) : vector_<3, T> (other) {}
|
||||||
|
|
||||||
vector3(T c1, T c2, T c3) { this->set(c1,c2,c3); }
|
vector3_(T c1, T c2, T c3) { this->set(c1,c2,c3); }
|
||||||
|
|
||||||
void set(T c1, T c2, T c3) { (*this)(0) = c1; (*this)(1) = c2; (*this)(2) = c3; }
|
void set(T c1, T c2, T c3) { (*this)(0) = c1; (*this)(1) = c2; (*this)(2) = c3; }
|
||||||
|
|
||||||
vector3 clone() const { return vector3(*this); }
|
vector3_ clone() const { return vector3_(*this); }
|
||||||
|
|
||||||
inline void set_x(const T& v) { x() = v; }
|
inline void set_x(const T& v) { x() = v; }
|
||||||
inline void set_y(const T& v) { y() = v; }
|
inline void set_y(const T& v) { y() = v; }
|
||||||
inline void set_z(const T& v) { z() = v; }
|
inline void set_z(const T& v) { z() = v; }
|
||||||
|
|
||||||
inline const vector3 cross(const vector3<T>& vec2) const {
|
inline const vector3_ cross(const vector3_<T>& vec2) const {
|
||||||
return vector3<T>((*this)(1) * vec2(2) - vec2(1) * (*this)(2),
|
return vector3_<T>((*this)(1) * vec2(2) - vec2(1) * (*this)(2),
|
||||||
(*this)(2) * vec2(0) - vec2(2) * (*this)(0),
|
(*this)(2) * vec2(0) - vec2(2) * (*this)(0),
|
||||||
(*this)(0) * vec2(1) - vec2(0) * (*this)(1));
|
(*this)(0) * vec2(1) - vec2(0) * (*this)(1));
|
||||||
}
|
}
|
||||||
|
@ -102,8 +102,8 @@ public:
|
||||||
T& z() { return (*this)(2); }
|
T& z() { return (*this)(2); }
|
||||||
|
|
||||||
|
|
||||||
const vector<4,T> project(const T& w) const {
|
const vector_<4,T> project(const T& w) const {
|
||||||
return vector<4,T>(x(),y(),z(),w);
|
return vector_<4,T>(x(),y(),z(),w);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if _GCC_STUPID_
|
#if _GCC_STUPID_
|
||||||
|
@ -113,12 +113,12 @@ public:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static vector3<T> forward() { return vector3<T> ( 0, 0,-1); }
|
inline static vector3_<T> forward() { return vector3_<T> ( 0, 0,-1); }
|
||||||
static vector3<T> backward() { return vector3<T>( 0, 0, 1); }
|
inline static vector3_<T> backward() { return vector3_<T>( 0, 0, 1); }
|
||||||
static vector3<T> right() { return vector3<T> ( 1, 0, 0); }
|
inline static vector3_<T> right() { return vector3_<T> ( 1, 0, 0); }
|
||||||
static vector3<T> left() { return vector3<T> (-1, 0, 0); }
|
inline static vector3_<T> left() { return vector3_<T> (-1, 0, 0); }
|
||||||
static vector3<T> up() { return vector3<T> ( 0, 1, 0); }
|
inline static vector3_<T> up() { return vector3_<T> ( 0, 1, 0); }
|
||||||
static vector3<T> down() { return vector3<T> ( 0,-1, 0); }
|
inline static vector3_<T> down() { return vector3_<T> ( 0,-1, 0); }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -126,12 +126,12 @@ public:
|
||||||
|
|
||||||
// Vec2x -----------------------------------------------------------------------
|
// Vec2x -----------------------------------------------------------------------
|
||||||
|
|
||||||
template <class T> class vector2 : public vector<2,T> {
|
template <class T> class vector2_ : public vector_<2,T> {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
vector2() {}
|
vector2_() {}
|
||||||
|
|
||||||
vector2(T v1,T v2) {
|
vector2_(T v1,T v2) {
|
||||||
this->set(v1,v2);
|
this->set(v1,v2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,12 +149,12 @@ public:
|
||||||
|
|
||||||
// Vec4 -----------------------------------------------------------------------
|
// Vec4 -----------------------------------------------------------------------
|
||||||
|
|
||||||
template <typename T> class vector4 : public vector<4,T> {
|
template <typename T> class vector4_ : public vector_<4,T> {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
using vector<4,T>::vector;
|
using vector_<4,T>::vector_;
|
||||||
|
|
||||||
vector4(const T& v1,const T& v2,const T& v3,const T& v4) {
|
vector4_(const T& v1,const T& v2,const T& v3,const T& v4) {
|
||||||
this->set(v1,v2,v3,v4);
|
this->set(v1,v2,v3,v4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,8 +165,8 @@ public:
|
||||||
(*this)(3) = v4;
|
(*this)(3) = v4;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const vector3<T> xyz() const { return vector3<T>(x(),y(),z()); }
|
inline const vector3_<T> xyz() const { return vector3_<T>(x(),y(),z()); }
|
||||||
inline const vector2<T> xy() const { return vector2<T>(x(),y()); }
|
inline const vector2_<T> xy() const { return vector2_<T>(x(),y()); }
|
||||||
|
|
||||||
const T& x() const { return (*this)(0); }
|
const T& x() const { return (*this)(0); }
|
||||||
T& x() { return (*this)(0); }
|
T& x() { return (*this)(0); }
|
||||||
|
@ -185,31 +185,31 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
typedef vector2<unsigned char> vector2ub;
|
typedef vector2_<unsigned char> vector2ub;
|
||||||
typedef vector2<char> vector2b;
|
typedef vector2_<char> vector2b;
|
||||||
typedef vector2<unsigned short> vector2us;
|
typedef vector2_<unsigned short> vector2us;
|
||||||
typedef vector2<short> vector2s;
|
typedef vector2_<short> vector2s;
|
||||||
typedef vector2<unsigned int> vector2ui;
|
typedef vector2_<unsigned int> vector2ui;
|
||||||
typedef vector2<int> vector2i;
|
typedef vector2_<int> vector2i;
|
||||||
typedef vector2<unsigned long> vector2ul;
|
typedef vector2_<unsigned long> vector2ul;
|
||||||
typedef vector2<long> vector2l;
|
typedef vector2_<long> vector2l;
|
||||||
|
|
||||||
typedef vector2<double> vector2d;
|
typedef vector2_<double> vector2d;
|
||||||
typedef vector2<float> vector2f;
|
typedef vector2_<float> vector2f;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef vector3<double> vector3d;
|
typedef vector3_<double> vector3d;
|
||||||
typedef vector3<float> vector3f;
|
typedef vector3_<float> vector3f;
|
||||||
typedef vector3<int> vector3i;
|
typedef vector3_<int> vector3i;
|
||||||
typedef vector3<unsigned int> vector3ui;
|
typedef vector3_<unsigned int> vector3ui;
|
||||||
|
|
||||||
|
|
||||||
typedef vector4<double> vector4d;
|
typedef vector4_<double> vector4d;
|
||||||
typedef vector4<float> vector4f;
|
typedef vector4_<float> vector4f;
|
||||||
typedef vector4<int> vector4i;
|
typedef vector4_<int> vector4i;
|
||||||
typedef vector4<unsigned int> vector4ui;
|
typedef vector4_<unsigned int> vector4ui;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
int main(int argc,char **argv) {
|
int main(int argc,char **argv) {
|
||||||
|
|
||||||
pw::quaternion<float> qf = pw::quaternionf::rotate_90_degree_around_x();
|
pw::quaternion_<float> qf = pw::quaternionf::rotate_90_degree_around_x();
|
||||||
|
|
||||||
std::cout << "qf = " << pw::serialize::matrix(qf.as_vector()) << std::endl;
|
std::cout << "qf = " << pw::serialize::matrix(qf.as_vector()) << std::endl;
|
||||||
std::cout << "qf.matrix() = " << pw::serialize::matrix(qf.to_matrix()) << std::endl;
|
std::cout << "qf.matrix() = " << pw::serialize::matrix(qf.to_matrix()) << std::endl;
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
int main(int argc,char **argv) {
|
int main(int argc,char **argv) {
|
||||||
|
|
||||||
pw::vector4<float> v4;
|
pw::vector4_<float> v4;
|
||||||
|
|
||||||
v4.fill(1.5);
|
v4.fill(1.5);
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
#define PW_SCENE_TRANSFORM_HPP
|
#define PW_SCENE_TRANSFORM_HPP
|
||||||
|
|
||||||
#include <pw/core/matrix.hpp>
|
#include <pw/core/matrix.hpp>
|
||||||
|
#include <pw/core/quaternion.hpp>
|
||||||
|
#include <pw/core/vector.hpp>
|
||||||
|
|
||||||
#include <pw/scene/component.hpp>
|
#include <pw/scene/component.hpp>
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
@ -24,6 +27,28 @@ public:
|
||||||
update_global_from_local();
|
update_global_from_local();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void rotate(const quaternion& q) {
|
||||||
|
_local *= q.to_matrix();
|
||||||
|
update_global_from_local();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void scale(const real_t &x, const real_t &y, const real_t &z) {
|
||||||
|
_local.at(0,0) *= x; _local.at(1,1) *= y; _local.at(2,2) *= z;
|
||||||
|
update_global_from_local();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void scale(const real_t& uniform_scale) {
|
||||||
|
scale(uniform_scale,uniform_scale,uniform_scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void set_translation(const real_t &x, const real_t &y, const real_t &z) {
|
||||||
|
_local.at(0,3) = x;_local.at(1,3) = y;_local.at(2,3) = z;
|
||||||
|
update_global_from_local();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void update(node &node);
|
void update(node &node);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -41,5 +41,8 @@ void transform::update_global_from_local()
|
||||||
|
|
||||||
void transform::update_local_from_global()
|
void transform::update_local_from_global()
|
||||||
{
|
{
|
||||||
|
|
||||||
// _local = this->global()
|
// _local = this->global()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue